<commit_before>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: RTableConnectionData.hxx,v $
 * $Revision: 1.8 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
#ifndef DBAUI_RTABLECONNECTIONDATA_HXX
#define DBAUI_RTABLECONNECTIONDATA_HXX

#ifndef DBAUI_TABLECONNECTIONDATA_HXX
#include "TableConnectionData.hxx"
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef DBAUI_ENUMTYPES_HXX
#include "QEnumTypes.hxx"
#endif

namespace dbaui
{
    const UINT16 CARDINAL_UNDEFINED = 0x0000;
    const UINT16 CARDINAL_ONE_MANY  = 0x0001;
    const UINT16 CARDINAL_MANY_ONE  = 0x0002;
    const UINT16 CARDINAL_ONE_ONE   = 0x0004;

    class OConnectionLineData;
    //==================================================================
    class ORelationTableConnectionData :    public OTableConnectionData
    {
        friend bool operator==(const ORelationTableConnectionData& lhs, const ORelationTableConnectionData& rhs);
        friend bool operator!=(const ORelationTableConnectionData& lhs, const ORelationTableConnectionData& rhs) { return !(lhs == rhs); }

        ::osl::Mutex    m_aMutex;
        ::rtl::OUString m_sDatabaseName;

        // @see com.sun.star.sdbc.KeyRule
        sal_Int32 m_nUpdateRules;
        sal_Int32 m_nDeleteRules;
        sal_Int32 m_nCardinality;

        BOOL checkPrimaryKey(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xTable,EConnectionSide _eEConnectionSide) const;
        BOOL IsSourcePrimKey()  const { return checkPrimaryKey(getReferencingTable()->getTable(),JTCS_FROM);    }
        BOOL IsDestPrimKey()    const { return checkPrimaryKey(getReferencedTable()->getTable(),JTCS_TO);       }

    protected:
        virtual OConnectionLineDataRef CreateLineDataObj();
        virtual OConnectionLineDataRef CreateLineDataObj( const OConnectionLineData& rConnLineData );

        ORelationTableConnectionData& operator=( const ORelationTableConnectionData& rConnData );
    public:
        ORelationTableConnectionData();
        ORelationTableConnectionData( const ORelationTableConnectionData& rConnData );
        ORelationTableConnectionData( const TTableWindowData::value_type& _pReferencingTable,
                                      const TTableWindowData::value_type& _pReferencedTable,
                                      const ::rtl::OUString& rConnName = ::rtl::OUString() );
        virtual ~ORelationTableConnectionData();

        virtual void CopyFrom(const OTableConnectionData& rSource);
        virtual OTableConnectionData* NewInstance() const { return new ORelationTableConnectionData(); }

        inline ::rtl::OUString GetDatabaseName() const { return m_sDatabaseName; }

        /** Update create a new relation

            @return true if successful
        */
        virtual BOOL Update();

        void        SetCardinality();
        inline void SetUpdateRules( sal_Int32 nAttr ){ m_nUpdateRules = nAttr; }
        inline void SetDeleteRules( sal_Int32 nAttr ){ m_nDeleteRules = nAttr; }

        inline sal_Int32    GetUpdateRules() const { return m_nUpdateRules; }
        inline sal_Int32    GetDeleteRules() const { return m_nDeleteRules; }
        inline sal_Int32    GetCardinality() const { return m_nCardinality; }

        BOOL        IsConnectionPossible();
        void        ChangeOrientation();
        BOOL        DropRelation();
    };
}

#endif // DBAUI_RTABLECONNECTIONDATA_HXX

<commit_msg>INTEGRATION: CWS dba30c (1.8.8); FILE MERGED 2008/05/05 11:13:36 oj 1.8.8.1: #i87131# collect keys only once, getKeys always refetch keys<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: RTableConnectionData.hxx,v $
 * $Revision: 1.9 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/
#ifndef DBAUI_RTABLECONNECTIONDATA_HXX
#define DBAUI_RTABLECONNECTIONDATA_HXX

#ifndef DBAUI_TABLECONNECTIONDATA_HXX
#include "TableConnectionData.hxx"
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef DBAUI_ENUMTYPES_HXX
#include "QEnumTypes.hxx"
#endif

namespace dbaui
{
    const UINT16 CARDINAL_UNDEFINED = 0x0000;
    const UINT16 CARDINAL_ONE_MANY  = 0x0001;
    const UINT16 CARDINAL_MANY_ONE  = 0x0002;
    const UINT16 CARDINAL_ONE_ONE   = 0x0004;

    class OConnectionLineData;
    //==================================================================
    class ORelationTableConnectionData :    public OTableConnectionData
    {
        friend bool operator==(const ORelationTableConnectionData& lhs, const ORelationTableConnectionData& rhs);
        friend bool operator!=(const ORelationTableConnectionData& lhs, const ORelationTableConnectionData& rhs) { return !(lhs == rhs); }

        ::osl::Mutex    m_aMutex;
        ::rtl::OUString m_sDatabaseName;

        // @see com.sun.star.sdbc.KeyRule
        sal_Int32 m_nUpdateRules;
        sal_Int32 m_nDeleteRules;
        sal_Int32 m_nCardinality;

        BOOL checkPrimaryKey(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess>& _xKeys,EConnectionSide _eEConnectionSide) const;
        BOOL IsSourcePrimKey()  const { return checkPrimaryKey(getReferencingTable()->getKeys(),JTCS_FROM); }
        BOOL IsDestPrimKey()    const { return checkPrimaryKey(getReferencedTable()->getKeys(),JTCS_TO);        }

    protected:
        virtual OConnectionLineDataRef CreateLineDataObj();
        virtual OConnectionLineDataRef CreateLineDataObj( const OConnectionLineData& rConnLineData );

        ORelationTableConnectionData& operator=( const ORelationTableConnectionData& rConnData );
    public:
        ORelationTableConnectionData();
        ORelationTableConnectionData( const ORelationTableConnectionData& rConnData );
        ORelationTableConnectionData( const TTableWindowData::value_type& _pReferencingTable,
                                      const TTableWindowData::value_type& _pReferencedTable,
                                      const ::rtl::OUString& rConnName = ::rtl::OUString() );
        virtual ~ORelationTableConnectionData();

        virtual void CopyFrom(const OTableConnectionData& rSource);
        virtual OTableConnectionData* NewInstance() const { return new ORelationTableConnectionData(); }

        inline ::rtl::OUString GetDatabaseName() const { return m_sDatabaseName; }

        /** Update create a new relation

            @return true if successful
        */
        virtual BOOL Update();

        void        SetCardinality();
        inline void SetUpdateRules( sal_Int32 nAttr ){ m_nUpdateRules = nAttr; }
        inline void SetDeleteRules( sal_Int32 nAttr ){ m_nDeleteRules = nAttr; }

        inline sal_Int32    GetUpdateRules() const { return m_nUpdateRules; }
        inline sal_Int32    GetDeleteRules() const { return m_nDeleteRules; }
        inline sal_Int32    GetCardinality() const { return m_nCardinality; }

        BOOL        IsConnectionPossible();
        void        ChangeOrientation();
        BOOL        DropRelation();
    };
}

#endif // DBAUI_RTABLECONNECTIONDATA_HXX

<|endoftext|>


<commit_before>// https://github.com/KubaO/stackoverflown/tree/master/questions/button-grid-22641306
#if 0

#include <QtGui>
#if QT_VERSION_MAJOR >= 5
#include <QtWidgets>
#endif

const char kIndex[] = "index";
struct Display : QLabel {
   Q_SLOT void onClicked() {
      setText(sender()->property(kIndex).toString());
   }
   Q_OBJECT
};

int main(int argc, char *argv[])
{
   QApplication a{argc, argv};
   QWidget window;
   QGridLayout layout{&window};
   QVarLengthArray<QPushButton, 12> buttons(12);
   Display display;

   const int rows = 4, columns = 3;
   for (int i = 0; i < rows; ++ i)
      for (int j = 0; j < columns; ++j) {
         auto index = QString{"(%1,%2)"}.arg(i).arg(j);
         auto & button = buttons[i*columns+j];
         button.setText(index);
         button.setProperty(kIndex, index);
         layout.addWidget(&button, i, j);
         display.connect(&button, SIGNAL(clicked()), SLOT(onClicked()));
      }
   layout.addWidget(&display, rows, 0, 1, columns);

   window.show();
   return a.exec();
}
#include "main.moc"

#endif

#if 0

#include <QtGui>
#if QT_VERSION_MAJOR >= 5
#include <QtWidgets>
#endif

int main(int argc, char *argv[])
{
   QApplication a{argc, argv};
   QSignalMapper mapper;
   QWidget window;
   QGridLayout layout{&window};
   QVarLengthArray<QPushButton, 12> buttons(12);
   QLabel display;

   const int rows = 4, columns = 3;
   for (int i = 0; i < rows; ++ i)
      for (int j = 0; j < columns; ++j) {
         auto text = QString{"(%1,%2)"}.arg(i).arg(j);
         auto & button = buttons[i*columns+j];
         button.setText(text);
         layout.addWidget(&button, i, j);
         mapper.connect(&button, SIGNAL(clicked()), SLOT(map()));
         mapper.setMapping(&button, text);
      }
   display.connect(&mapper, SIGNAL(mapped(QString)), SLOT(setText(QString)));
   layout.addWidget(&display, rows, 0, 1, columns);

   window.show();
   return a.exec();
}

#endif

#if 0

#include <QtWidgets>

int main(int argc, char *argv[])
{
   QApplication a{argc, argv};
   QWidget window;
   QGridLayout layout{&window};
   QVarLengthArray<QPushButton, 12> buttons(12);
   QLabel display;

   const int rows = 4, columns = 3;
   for (int i = 0; i < rows; ++ i)
      for (int j = 0; j < columns; ++j) {
         auto text = QStringLiteral("(%1,%2)").arg(i).arg(j);
         auto & button = buttons[i*columns+j];
         button.setText(text);
         layout.addWidget(&button, i, j);
         QObject::connect(&button, &QPushButton::clicked, [&display, text] {
            display.setText(text);
         });
      }
   layout.addWidget(&display, rows, 0, 1, columns);

   window.show();
   return a.exec();
}

#endif

#if 1

#include <QtGui>
#if QT_VERSION_MAJOR >= 5
#include <QtWidgets>
#endif

struct Display : QLabel {
   Q_SLOT void onClicked() {
      setText(sender()->objectName());
   }
   Q_OBJECT
};

int main(int argc, char *argv[])
{
   QApplication a{argc, argv};
   QWidget window;
   QGridLayout layout{&window};
   QVarLengthArray<QPushButton, 12> buttons(12);
   Display display;

   const int rows = 4, columns = 3;
   for (int i = 0; i < rows; ++ i)
      for (int j = 0; j < columns; ++j) {
         auto & button = buttons[i*columns+j];
         button.setText(QString{"(%1,%2)"}.arg(i).arg(j));
         button.setObjectName(QString{"buton_%1_%2"}.arg(i).arg(j));
         layout.addWidget(&button, i, j);
         display.connect(&button, SIGNAL(clicked()), SLOT(onClicked()));
      }
   layout.addWidget(&display, rows, 0, 1, columns);

   window.show();
   return a.exec();
}
#include "main.moc"

#endif
<commit_msg>Unify functionality of all implementations.<commit_after>// https://github.com/KubaO/stackoverflown/tree/master/questions/button-grid-22641306
#define VARIANT 3

#if VARIANT==1

#include <QtGui>
#if QT_VERSION_MAJOR >= 5
#include <QtWidgets>
#endif

const char kIndex[] = "index";
struct Display : QLabel {
   Q_SLOT void onClicked() {
      setText(sender()->property(kIndex).toString());
   }
   Q_OBJECT
};

int main(int argc, char *argv[])
{
   QApplication a{argc, argv};
   QWidget window;
   QGridLayout layout{&window};
   QVarLengthArray<QPushButton, 12> buttons(12);
   Display display;

   const int rows = 4, columns = 3;
   for (int i = 0; i < rows; ++ i)
      for (int j = 0; j < columns; ++j) {
         auto index = QString{"(%1,%2)"}.arg(i).arg(j);
         auto & button = buttons[i*columns+j];
         button.setText(index);
         button.setProperty(kIndex, index);
         layout.addWidget(&button, i, j);
         display.connect(&button, SIGNAL(clicked()), SLOT(onClicked()));
      }
   layout.addWidget(&display, rows, 0, 1, columns);

   window.show();
   return a.exec();
}
#include "main.moc"

#elif VARIANT==2

#include <QtGui>
#if QT_VERSION_MAJOR >= 5
#include <QtWidgets>
#endif

int main(int argc, char *argv[])
{
   QApplication a{argc, argv};
   QSignalMapper mapper;
   QWidget window;
   QGridLayout layout{&window};
   QVarLengthArray<QPushButton, 12> buttons(12);
   QLabel display;

   const int rows = 4, columns = 3;
   for (int i = 0; i < rows; ++ i)
      for (int j = 0; j < columns; ++j) {
         auto text = QString{"(%1,%2)"}.arg(i).arg(j);
         auto & button = buttons[i*columns+j];
         button.setText(text);
         layout.addWidget(&button, i, j);
         mapper.connect(&button, SIGNAL(clicked()), SLOT(map()));
         mapper.setMapping(&button, text);
      }
   display.connect(&mapper, SIGNAL(mapped(QString)), SLOT(setText(QString)));
   layout.addWidget(&display, rows, 0, 1, columns);

   window.show();
   return a.exec();
}

#elif VARIANT==3

#include <QtWidgets>

int main(int argc, char *argv[])
{
   QApplication a{argc, argv};
   QWidget window;
   QGridLayout layout{&window};
   QVarLengthArray<QPushButton, 12> buttons(12);
   QLabel display;

   const int rows = 4, columns = 3;
   for (int i = 0; i < rows; ++ i)
      for (int j = 0; j < columns; ++j) {
         auto text = QStringLiteral("(%1,%2)").arg(i).arg(j);
         auto & button = buttons[i*columns+j];
         button.setText(text);
         layout.addWidget(&button, i, j);
         QObject::connect(&button, &QPushButton::clicked, [&display, text] {
            display.setText(text);
         });
      }
   layout.addWidget(&display, rows, 0, 1, columns);

   window.show();
   return a.exec();
}

#elif VARIANT==4

#include <QtGui>
#if QT_VERSION_MAJOR >= 5
#include <QtWidgets>
#endif

struct Display : QLabel {
   Q_SLOT void onClicked() {
      auto const elements = sender()->objectName().split('_');
      auto const i = elements.at(1).toInt();
      auto const j = elements.at(2).toInt();
      setText(QString{"(%1,%2)"}.arg(i).arg(j));
   }
   Q_OBJECT
};

int main(int argc, char *argv[])
{
   QApplication a{argc, argv};
   QWidget window;
   QGridLayout layout{&window};
   QVarLengthArray<QPushButton, 12> buttons(12);
   Display display;

   const int rows = 4, columns = 3;
   for (int i = 0; i < rows; ++ i)
      for (int j = 0; j < columns; ++j) {
         auto & button = buttons[i*columns+j];
         button.setText(QString{"(%1,%2)"}.arg(i).arg(j));
         button.setObjectName(QString{"button_%1_%2"}.arg(i).arg(j));
         layout.addWidget(&button, i, j);
         display.connect(&button, SIGNAL(clicked()), SLOT(onClicked()));
      }
   layout.addWidget(&display, rows, 0, 1, columns);

   window.show();
   return a.exec();
}
#include "main.moc"

#endif
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: querycontainerwindow.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 16:00:22 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef DBAUI_QUERYCONTAINERWINDOW_HXX
#define DBAUI_QUERYCONTAINERWINDOW_HXX

#ifndef _SV_WINDOW_HXX
#include <vcl/window.hxx>
#endif
#ifndef _SV_SPLIT_HXX
#include <vcl/split.hxx>
#endif
#ifndef DBAUI_DATAVIEW_HXX
#include "dataview.hxx"
#endif
#ifndef _COM_SUN_STAR_FRAME_XFRAME_HPP_
#include <com/sun/star/frame/XFrame.hpp>
#endif
#ifndef DBAUI_QUERYVIEWSWITCH_HXX
#include "QueryViewSwitch.hxx"
#endif
#ifndef _SV_DOCKWIN_HXX
#include <vcl/dockwin.hxx>
#endif

class FixedLine;
//.........................................................................
namespace dbaui
{
//.........................................................................

    //=====================================================================
    //= OBeamer
    //=====================================================================
    // tempoaray class until the beamer is implemented
    class OBeamer : public DockingWindow
    {
    public:
        OBeamer(Window* _pParent) : DockingWindow(_pParent,0){}
    };

    //=====================================================================
    //= OQueryContainerWindow
    //=====================================================================
    class OQueryContainerWindow : public ODataView
    {
        OQueryViewSwitch*   m_pViewSwitch;
        OBeamer*            m_pBeamer;
        Splitter*           m_pSplitter;
        ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xBeamer;

        DECL_LINK( SplitHdl, void* );
    public:
        OQueryContainerWindow(Window* pParent, OQueryController* _pController,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
        ~OQueryContainerWindow();

        virtual void Construct();

        virtual long        PreNotify( NotifyEvent& rNEvt );

        // show the beamer
        void    showPreview(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _xFrame);
            // called when the beamer has been disposed
        void    disposingPreview();

        ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >
                getPreviewFrame() const { return m_xBeamer; }

        void initialize(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _xFrame);

        OQueryDesignView*   getDesignView() { return m_pViewSwitch->getDesignView(); }

        sal_Bool isCutAllowed()     { return m_pViewSwitch->isCutAllowed(); }
        sal_Bool isPasteAllowed()   { return m_pViewSwitch->isPasteAllowed(); }
        sal_Bool isCopyAllowed()    { return m_pViewSwitch->isCopyAllowed(); }
        void copy()                 { m_pViewSwitch->copy(); }
        void cut()                  { m_pViewSwitch->cut(); }
        void paste()                { m_pViewSwitch->paste(); }

        void clear()                                                        { m_pViewSwitch->clear(); }
        sal_Bool isSlotEnabled( sal_Int32 _nSlotId )                        { return m_pViewSwitch->isSlotEnabled( _nSlotId ); }
        void     setSlotEnabled( sal_Int32 _nSlotId, sal_Bool _bEnable )    { m_pViewSwitch->setSlotEnabled( _nSlotId, _bEnable ); }
        void     setNoneVisbleRow(sal_Int32 _nRows)                         { m_pViewSwitch->setNoneVisbleRow( _nRows); }

        void setReadOnly( sal_Bool _bReadOnly )                             { m_pViewSwitch->setReadOnly( _bReadOnly ); }

        sal_Bool checkStatement()                                           { return m_pViewSwitch->checkStatement( ); }
        ::rtl::OUString getStatement()                                      { return m_pViewSwitch->getStatement( ); }
        void setStatement( const ::rtl::OUString& _rsStatement )            { m_pViewSwitch->setStatement( _rsStatement ); }

        void initialize()                                                   { m_pViewSwitch->initialize(); }
        void SaveUIConfig()                                                 { m_pViewSwitch->SaveUIConfig(); }
        void reset()                                                        { m_pViewSwitch->reset(); }

        sal_Bool switchView();
        virtual void GetFocus();

    protected:
        // re-arrange the controls belonging to the document itself
        virtual void resizeAll( const Rectangle& _rPlayground );

        // arrange dericed classes controls in the rectangle given
        virtual void resizeDocumentView(Rectangle& _rPlayground);
    };
    // end of temp classes

//.........................................................................
}   // namespace dbaui
//.........................................................................

#endif // DBAUI_QUERYCONTAINERWINDOW_HXX

<commit_msg>INTEGRATION: CWS dba23a (1.7.254); FILE MERGED 2007/02/26 11:48:16 fs 1.7.254.1: remove unused code Issue number:  #i74804# Submitted by:  jnavrati@openoffice.org Reviewed by:   frank.schoenheit@sun.com<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: querycontainerwindow.hxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: kz $ $Date: 2007-05-10 10:33:14 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef DBAUI_QUERYCONTAINERWINDOW_HXX
#define DBAUI_QUERYCONTAINERWINDOW_HXX

#ifndef _SV_WINDOW_HXX
#include <vcl/window.hxx>
#endif
#ifndef _SV_SPLIT_HXX
#include <vcl/split.hxx>
#endif
#ifndef DBAUI_DATAVIEW_HXX
#include "dataview.hxx"
#endif
#ifndef _COM_SUN_STAR_FRAME_XFRAME_HPP_
#include <com/sun/star/frame/XFrame.hpp>
#endif
#ifndef DBAUI_QUERYVIEWSWITCH_HXX
#include "QueryViewSwitch.hxx"
#endif
#ifndef _SV_DOCKWIN_HXX
#include <vcl/dockwin.hxx>
#endif

class FixedLine;
//.........................................................................
namespace dbaui
{
//.........................................................................

    //=====================================================================
    //= OBeamer
    //=====================================================================
    // tempoaray class until the beamer is implemented
    class OBeamer : public DockingWindow
    {
    public:
        OBeamer(Window* _pParent) : DockingWindow(_pParent,0){}
    };

    //=====================================================================
    //= OQueryContainerWindow
    //=====================================================================
    class OQueryContainerWindow : public ODataView
    {
        OQueryViewSwitch*   m_pViewSwitch;
        OBeamer*            m_pBeamer;
        Splitter*           m_pSplitter;
        ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > m_xBeamer;

        DECL_LINK( SplitHdl, void* );
    public:
        OQueryContainerWindow(Window* pParent, OQueryController* _pController,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
        ~OQueryContainerWindow();

        virtual void Construct();

        virtual long        PreNotify( NotifyEvent& rNEvt );

        // show the beamer
        void    showPreview(const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _xFrame);
            // called when the beamer has been disposed
        void    disposingPreview();

        ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >
                getPreviewFrame() const { return m_xBeamer; }

        OQueryDesignView*   getDesignView() { return m_pViewSwitch->getDesignView(); }

        sal_Bool isCutAllowed()     { return m_pViewSwitch->isCutAllowed(); }
        sal_Bool isPasteAllowed()   { return m_pViewSwitch->isPasteAllowed(); }
        sal_Bool isCopyAllowed()    { return m_pViewSwitch->isCopyAllowed(); }
        void copy()                 { m_pViewSwitch->copy(); }
        void cut()                  { m_pViewSwitch->cut(); }
        void paste()                { m_pViewSwitch->paste(); }

        void clear()                                                        { m_pViewSwitch->clear(); }
        sal_Bool isSlotEnabled( sal_Int32 _nSlotId )                        { return m_pViewSwitch->isSlotEnabled( _nSlotId ); }
        void     setSlotEnabled( sal_Int32 _nSlotId, sal_Bool _bEnable )    { m_pViewSwitch->setSlotEnabled( _nSlotId, _bEnable ); }
        void     setNoneVisbleRow(sal_Int32 _nRows)                         { m_pViewSwitch->setNoneVisbleRow( _nRows); }

        void setReadOnly( sal_Bool _bReadOnly )                             { m_pViewSwitch->setReadOnly( _bReadOnly ); }

        sal_Bool checkStatement()                                           { return m_pViewSwitch->checkStatement( ); }
        ::rtl::OUString getStatement()                                      { return m_pViewSwitch->getStatement( ); }
        void setStatement( const ::rtl::OUString& _rsStatement )            { m_pViewSwitch->setStatement( _rsStatement ); }

        void initialize()                                                   { m_pViewSwitch->initialize(); }
        void SaveUIConfig()                                                 { m_pViewSwitch->SaveUIConfig(); }
        void reset()                                                        { m_pViewSwitch->reset(); }

        sal_Bool switchView();
        virtual void GetFocus();

    protected:
        // re-arrange the controls belonging to the document itself
        virtual void resizeAll( const Rectangle& _rPlayground );

        // arrange dericed classes controls in the rectangle given
        virtual void resizeDocumentView(Rectangle& _rPlayground);
    };
    // end of temp classes

//.........................................................................
}   // namespace dbaui
//.........................................................................

#endif // DBAUI_QUERYCONTAINERWINDOW_HXX

<|endoftext|>


<commit_before>// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "exegesis/x86/cleanup_instruction_set_alternatives.h"

#include <cstdint>
#include <unordered_map>
#include <vector>
#include "strings/string.h"

#include "exegesis/base/cleanup_instruction_set.h"
#include "exegesis/proto/instructions.pb.h"
#include "glog/logging.h"
#include "strings/str_cat.h"
#include "util/gtl/map_util.h"
#include "util/task/canonical_errors.h"
#include "util/task/status.h"

namespace exegesis {
namespace x86 {
namespace {

using ::exegesis::util::InvalidArgumentError;
using ::exegesis::util::OkStatus;
using ::exegesis::util::Status;

// Information about an operand that need to be modified when adding an
// alternative. There is one instance of this struct for each alternative.
struct OperandAlternative {
  // The new name of the operand.
  const char* operand_name;

  // The new addressing mode of the operand.
  InstructionOperand::AddressingMode addressing_mode;

  // The new value of the operand.
  uint32_t value_size;
};
using OperandAlternativeMap =
    std::unordered_map<string, std::vector<OperandAlternative>>;

// Returns the list of operand alternatives indexed by the name of the operand.
// TODO(ondrasej): Re-enable broadcasted arguments when we have a way to
// represent them in the proto.
const OperandAlternativeMap& GetOperandAlternativesByName() {
  static const OperandAlternativeMap* const kAlternatives = []() {
    constexpr InstructionOperand::AddressingMode DIRECT_ADDRESSING =
        InstructionOperand::DIRECT_ADDRESSING;
    constexpr InstructionOperand::AddressingMode INDIRECT_ADDRESSING =
        InstructionOperand::INDIRECT_ADDRESSING;
    return new OperandAlternativeMap({
        {"mm/m32",
         {{"mm1", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"mm/m64",
         {{"mm1", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"mm2/m64",
         {{"mm2", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"r/m8",
         {{"r8", DIRECT_ADDRESSING, 8}, {"m8", INDIRECT_ADDRESSING, 8}}},
        {"r/m16",
         {{"r16", DIRECT_ADDRESSING, 16}, {"m16", INDIRECT_ADDRESSING, 16}}},
        {"r/m32",
         {{"r32", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"r/m64",
         {{"r64", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"r32/m8",
         {{"r32", DIRECT_ADDRESSING, 32}, {"m8", INDIRECT_ADDRESSING, 8}}},
        {"r32/m16",
         {{"r32", DIRECT_ADDRESSING, 32}, {"m16", INDIRECT_ADDRESSING, 16}}},
        {"r64/m16",
         {{"r64", DIRECT_ADDRESSING, 64}, {"m16", INDIRECT_ADDRESSING, 16}}},
        {"reg/m8",
         {{"r32", DIRECT_ADDRESSING, 32}, {"m8", INDIRECT_ADDRESSING, 8}}},
        {"reg/m16",
         {{"r32", DIRECT_ADDRESSING, 32}, {"m16", INDIRECT_ADDRESSING, 16}}},
        {"reg/m32",
         {{"r32", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"xmm2/m8",
         {{"xmm2", DIRECT_ADDRESSING, 8}, {"m8", INDIRECT_ADDRESSING, 8}}},
        {"xmm2/m16",
         {{"xmm2", DIRECT_ADDRESSING, 16}, {"m16", INDIRECT_ADDRESSING, 8}}},
        {"xmm/m32",
         {{"xmm2", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"xmm1/m32",
         {{"xmm1", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"xmm2/m32",
         {{"xmm2", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"xmm3/m32",
         {{"xmm3", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"xmm/m64",
         {{"xmm2", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"xmm1/m64",
         {{"xmm1", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"xmm1/m128",
         {{"xmm1", DIRECT_ADDRESSING, 128},
          {"m128", INDIRECT_ADDRESSING, 128}}},
        {"xmm2/m64",
         {{"xmm2", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"xmm3/m64",
         {{"xmm3", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"xmm/m128",
         {{"xmm2", DIRECT_ADDRESSING, 128},
          {"m128", INDIRECT_ADDRESSING, 128}}},
        {"xmm2/m128",
         {{"xmm2", DIRECT_ADDRESSING, 128},
          {"m128", INDIRECT_ADDRESSING, 128}}},
        {"xmm3/m128",
         {{"xmm3", DIRECT_ADDRESSING, 128},
          {"m128", INDIRECT_ADDRESSING, 128}}},
        {"xmm2/m256",
         {{"xmm2", DIRECT_ADDRESSING, 256},
          {"m256", INDIRECT_ADDRESSING, 256}}},
        {"xmm3/m256",
         {{"xmm3", DIRECT_ADDRESSING, 256},
          {"m256", INDIRECT_ADDRESSING, 256}}},
        {"ymm2/m256",
         {{"ymm2", DIRECT_ADDRESSING, 256},
          {"m256", INDIRECT_ADDRESSING, 256}}},
        {"ymm3/m256",
         {{"ymm3", DIRECT_ADDRESSING, 256},
          {"m256", INDIRECT_ADDRESSING, 256}}},
        {"xmm2/m128/m32bcst",
         {
             {"xmm2", DIRECT_ADDRESSING, 128},
             {"m128", INDIRECT_ADDRESSING, 128},
             // {"m32bcst", INDIRECT_ADDRESSING, 128},
         }},
        {"xmm3/m128/m32bcst",
         {
             {"xmm3", DIRECT_ADDRESSING, 128},
             {"m128", INDIRECT_ADDRESSING, 128},
             // {"m32bcst", INDIRECT_ADDRESSING, 128},
         }},
        {"xmm3/m128/m64bcst",
         {
             {"xmm3", DIRECT_ADDRESSING, 128},
             {"m128", INDIRECT_ADDRESSING, 128},
             // {"m64bcst", INDIRECT_ADDRESSING, 128},
         }},
        {"ymm2/m256/m32bcst",
         {
             {"ymm2", DIRECT_ADDRESSING, 256},
             {"m256", INDIRECT_ADDRESSING, 256},
             // {"m32bcst", INDIRECT_ADDRESSING, 256},
         }},
        {"ymm3/m256/m32bcst",
         {
             {"ymm3", DIRECT_ADDRESSING, 256},
             {"m256", INDIRECT_ADDRESSING, 256},
             // {"m32bcst", INDIRECT_ADDRESSING, 256},
         }},
        {"ymm3/m256/m64bcst",
         {
             {"ymm3", DIRECT_ADDRESSING, 256},
             {"m256", INDIRECT_ADDRESSING, 256},
             // {"m64bcst", INDIRECT_ADDRESSING, 256},
         }},
        {"zmm2/m512/m32bcst",
         {
             {"zmm2", DIRECT_ADDRESSING, 512},
             {"m512", INDIRECT_ADDRESSING, 512},
             // {"m32bcst", INDIRECT_ADDRESSING, 512},
         }},
        {"zmm2/m512/m64bcst",
         {
             {"zmm2", DIRECT_ADDRESSING, 512},
             {"m512", INDIRECT_ADDRESSING, 512},
             // {"m64bcst", INDIRECT_ADDRESSING, 512},
         }},
        {"zmm3/m512/m32bcst",
         {
             {"zmm3", DIRECT_ADDRESSING, 512},
             {"m512", INDIRECT_ADDRESSING, 512},
             // {"m32bcst", INDIRECT_ADDRESSING, 512},
         }},
        {"zmm3/m512/m64bcst",
         {
             {"zmm3", DIRECT_ADDRESSING, 512},
             {"m512", INDIRECT_ADDRESSING, 512},
             // {"m642bcst", INDIRECT_ADDRESSING, 512},
         }},
        {"bnd1/m128",
         {{"bnd1", DIRECT_ADDRESSING, 128},
          {"m128", INDIRECT_ADDRESSING, 128}}},
        {"bnd2/m128",
         {{"bnd2", DIRECT_ADDRESSING, 128},
          {"m128", INDIRECT_ADDRESSING, 128}}},
        {"k2/m8",
         {{"k2", DIRECT_ADDRESSING, 8}, {"m8", INDIRECT_ADDRESSING, 8}}},
        {"k2/m16",
         {{"k2", DIRECT_ADDRESSING, 16}, {"m16", INDIRECT_ADDRESSING, 16}}},
        {"k2/m32",
         {{"k2", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"k2/m64",
         {{"k2", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
    });
  }();
  return *kAlternatives;
}

}  // namespace

Status AddAlternatives(InstructionSetProto* instruction_set) {
  CHECK(instruction_set != nullptr);
  Status status = OkStatus();
  const OperandAlternativeMap& alternatives_by_name =
      GetOperandAlternativesByName();
  std::vector<InstructionProto> new_instructions;
  for (InstructionProto& instruction :
       *instruction_set->mutable_instructions()) {
    InstructionFormat* const vendor_syntax =
        instruction.mutable_vendor_syntax();
    for (int operand_index = 0; operand_index < vendor_syntax->operands_size();
         ++operand_index) {
      InstructionOperand* const operand =
          vendor_syntax->mutable_operands(operand_index);
      const std::vector<OperandAlternative>* const alternatives =
          FindOrNull(alternatives_by_name, operand->name());
      if (alternatives == nullptr) continue;

      // The only encoding that allows alternatives is modrm.rm. An operand with
      // alternatives anywhere else means that there is an error in the data.
      if (operand->encoding() != InstructionOperand::MODRM_RM_ENCODING) {
        return InvalidArgumentError(
            StrCat("Instruction does not use modrm.rm encoding:\n",
                   instruction.DebugString()));
      }
      // The altenatives are always "register" vs "memory", because that is the
      // only kind of alternatives that can be expressed through operand
      // encoding.
      if (operand->addressing_mode() !=
          InstructionOperand::ANY_ADDRESSING_WITH_FLEXIBLE_REGISTERS) {
        return InvalidArgumentError(StrCat(
            "The addressing mode does not allow splitting: ",
            InstructionOperand::AddressingMode_Name(operand->addressing_mode()),
            "\n", instruction.DebugString()));
      }
      // Note that we start iterating at 1, and that we will be reusing
      // the existing instruction for the first alternative.
      for (int i = 1; i < alternatives->size(); ++i) {
        const OperandAlternative& alternative = (*alternatives)[i];
        new_instructions.push_back(instruction);
        InstructionOperand* const new_instruction_operand =
            new_instructions.back().mutable_vendor_syntax()->mutable_operands(
                operand_index);
        new_instruction_operand->set_name(alternative.operand_name);
        new_instruction_operand->set_addressing_mode(
            alternative.addressing_mode);
        new_instruction_operand->set_value_size_bits(alternative.value_size);
      }
      // Now overwrite the current instruction's operand.
      const OperandAlternative& first_alternative = alternatives->front();
      operand->set_name(first_alternative.operand_name);
      operand->set_addressing_mode(first_alternative.addressing_mode);
      operand->set_value_size_bits(first_alternative.value_size);
    }
  }
  for (InstructionProto& new_instruction : new_instructions) {
    instruction_set->add_instructions()->Swap(&new_instruction);
  }
  return status;
}
REGISTER_INSTRUCTION_SET_TRANSFORM(AddAlternatives, 6000);

}  // namespace x86
}  // namespace exegesis
<commit_msg>Added missing operand alternatives.<commit_after>// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "exegesis/x86/cleanup_instruction_set_alternatives.h"

#include <cstdint>
#include <unordered_map>
#include <vector>
#include "strings/string.h"

#include "exegesis/base/cleanup_instruction_set.h"
#include "exegesis/proto/instructions.pb.h"
#include "glog/logging.h"
#include "strings/str_cat.h"
#include "util/gtl/map_util.h"
#include "util/task/canonical_errors.h"
#include "util/task/status.h"

namespace exegesis {
namespace x86 {
namespace {

using ::exegesis::util::InvalidArgumentError;
using ::exegesis::util::OkStatus;
using ::exegesis::util::Status;

// Information about an operand that need to be modified when adding an
// alternative. There is one instance of this struct for each alternative.
struct OperandAlternative {
  // The new name of the operand.
  const char* operand_name;

  // The new addressing mode of the operand.
  InstructionOperand::AddressingMode addressing_mode;

  // The new value of the operand.
  uint32_t value_size;
};
using OperandAlternativeMap =
    std::unordered_map<string, std::vector<OperandAlternative>>;

// Returns the list of operand alternatives indexed by the name of the operand.
// TODO(ondrasej): Re-enable broadcasted arguments when we have a way to
// represent them in the proto.
const OperandAlternativeMap& GetOperandAlternativesByName() {
  static const OperandAlternativeMap* const kAlternatives = []() {
    constexpr InstructionOperand::AddressingMode DIRECT_ADDRESSING =
        InstructionOperand::DIRECT_ADDRESSING;
    constexpr InstructionOperand::AddressingMode INDIRECT_ADDRESSING =
        InstructionOperand::INDIRECT_ADDRESSING;
    return new OperandAlternativeMap({
        {"mm/m32",
         {{"mm1", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"mm/m64",
         {{"mm1", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"mm2/m64",
         {{"mm2", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"r/m8",
         {{"r8", DIRECT_ADDRESSING, 8}, {"m8", INDIRECT_ADDRESSING, 8}}},
        {"r/m16",
         {{"r16", DIRECT_ADDRESSING, 16}, {"m16", INDIRECT_ADDRESSING, 16}}},
        {"r/m32",
         {{"r32", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"r/m64",
         {{"r64", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"r32/m8",
         {{"r32", DIRECT_ADDRESSING, 32}, {"m8", INDIRECT_ADDRESSING, 8}}},
        {"r32/m16",
         {{"r32", DIRECT_ADDRESSING, 32}, {"m16", INDIRECT_ADDRESSING, 16}}},
        {"r64/m16",
         {{"r64", DIRECT_ADDRESSING, 64}, {"m16", INDIRECT_ADDRESSING, 16}}},
        {"reg/m8",
         {{"r32", DIRECT_ADDRESSING, 32}, {"m8", INDIRECT_ADDRESSING, 8}}},
        {"reg/m16",
         {{"r32", DIRECT_ADDRESSING, 32}, {"m16", INDIRECT_ADDRESSING, 16}}},
        {"reg/m32",
         {{"r32", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"xmm2/m8",
         {{"xmm2", DIRECT_ADDRESSING, 8}, {"m8", INDIRECT_ADDRESSING, 8}}},
        {"xmm2/m16",
         {{"xmm2", DIRECT_ADDRESSING, 16}, {"m16", INDIRECT_ADDRESSING, 16}}},
        {"xmm/m32",
         {{"xmm2", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"xmm1/m32",
         {{"xmm1", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"xmm2/m32",
         {{"xmm2", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"xmm3/m32",
         {{"xmm3", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"xmm/m64",
         {{"xmm2", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"xmm1/m16",
         {{"xmm1", DIRECT_ADDRESSING, 16}, {"m16", INDIRECT_ADDRESSING, 16}}},
        {"xmm1/m64",
         {{"xmm1", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"xmm1/m128",
         {{"xmm1", DIRECT_ADDRESSING, 128},
          {"m128", INDIRECT_ADDRESSING, 128}}},
        {"xmm2/m64",
         {{"xmm2", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"xmm2/m64/m32bcst",
         {
             {"xmm2", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64},
             // {"m32bcst", INDIRECT_ADDRESSING, 32},
         }},
        {"xmm2/m128/m64bcst",
         {
             {"xmm2", DIRECT_ADDRESSING, 128},
             {"m128", INDIRECT_ADDRESSING, 128},
             // {"m64bcst", INDIRECT_ADDRESSING, 128},
         }},
        {"xmm3/m64",
         {{"xmm3", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
        {"xmm/m128",
         {{"xmm2", DIRECT_ADDRESSING, 128},
          {"m128", INDIRECT_ADDRESSING, 128}}},
        {"xmm2/m128",
         {{"xmm2", DIRECT_ADDRESSING, 128},
          {"m128", INDIRECT_ADDRESSING, 128}}},
        {"xmm3/m128",
         {{"xmm3", DIRECT_ADDRESSING, 128},
          {"m128", INDIRECT_ADDRESSING, 128}}},
        {"xmm2/m256",
         {{"xmm2", DIRECT_ADDRESSING, 256},
          {"m256", INDIRECT_ADDRESSING, 256}}},
        {"xmm3/m256",
         {{"xmm3", DIRECT_ADDRESSING, 256},
          {"m256", INDIRECT_ADDRESSING, 256}}},
        {"ymm2/m256",
         {{"ymm2", DIRECT_ADDRESSING, 256},
          {"m256", INDIRECT_ADDRESSING, 256}}},
        {"ymm3/m256",
         {{"ymm3", DIRECT_ADDRESSING, 256},
          {"m256", INDIRECT_ADDRESSING, 256}}},
        {"xmm2/m128/m32bcst",
         {
             {"xmm2", DIRECT_ADDRESSING, 128},
             {"m128", INDIRECT_ADDRESSING, 128},
             // {"m32bcst", INDIRECT_ADDRESSING, 128},
         }},
        {"xmm3/m128/m32bcst",
         {
             {"xmm3", DIRECT_ADDRESSING, 128},
             {"m128", INDIRECT_ADDRESSING, 128},
             // {"m32bcst", INDIRECT_ADDRESSING, 128},
         }},
        {"xmm3/m128/m64bcst",
         {
             {"xmm3", DIRECT_ADDRESSING, 128},
             {"m128", INDIRECT_ADDRESSING, 128},
             // {"m64bcst", INDIRECT_ADDRESSING, 128},
         }},
        {"ymm1/m256",
         {
             {"ymm1", DIRECT_ADDRESSING, 256},
             {"m256", INDIRECT_ADDRESSING, 256},
         }},
        {"ymm2/m256/m64bcst",
         {
             {"ymm2", DIRECT_ADDRESSING, 256},
             {"m256", INDIRECT_ADDRESSING, 256},
             // {"m64bcst", INDIRECT_ADDRESSING, 256},
         }},
        {"ymm2/m256/m32bcst",
         {
             {"ymm2", DIRECT_ADDRESSING, 256},
             {"m256", INDIRECT_ADDRESSING, 256},
             // {"m32bcst", INDIRECT_ADDRESSING, 256},
         }},
        {"ymm3/m256/m32bcst",
         {
             {"ymm3", DIRECT_ADDRESSING, 256},
             {"m256", INDIRECT_ADDRESSING, 256},
             // {"m32bcst", INDIRECT_ADDRESSING, 256},
         }},
        {"ymm3/m256/m64bcst",
         {
             {"ymm3", DIRECT_ADDRESSING, 256},
             {"m256", INDIRECT_ADDRESSING, 256},
             // {"m64bcst", INDIRECT_ADDRESSING, 256},
         }},
        {"zmm1/m512",
         {
             {"zmm1", DIRECT_ADDRESSING, 512},
             {"m512", INDIRECT_ADDRESSING, 512},
         }},
        {"zmm2/m512",
         {
             {"zmm2", DIRECT_ADDRESSING, 512},
             {"m512", INDIRECT_ADDRESSING, 512},
         }},
        {"zmm3/m512",
         {
             {"zmm3", DIRECT_ADDRESSING, 512},
             {"m512", INDIRECT_ADDRESSING, 512},
         }},
        {"zmm2/m512/m32bcst",
         {
             {"zmm2", DIRECT_ADDRESSING, 512},
             {"m512", INDIRECT_ADDRESSING, 512},
             // {"m32bcst", INDIRECT_ADDRESSING, 512},
         }},
        {"zmm2/m512/m64bcst",
         {
             {"zmm2", DIRECT_ADDRESSING, 512},
             {"m512", INDIRECT_ADDRESSING, 512},
             // {"m64bcst", INDIRECT_ADDRESSING, 512},
         }},
        {"zmm3/m512/m32bcst",
         {
             {"zmm3", DIRECT_ADDRESSING, 512},
             {"m512", INDIRECT_ADDRESSING, 512},
             // {"m32bcst", INDIRECT_ADDRESSING, 512},
         }},
        {"zmm3/m512/m64bcst",
         {
             {"zmm3", DIRECT_ADDRESSING, 512},
             {"m512", INDIRECT_ADDRESSING, 512},
             // {"m642bcst", INDIRECT_ADDRESSING, 512},
         }},
        {"bnd1/m128",
         {{"bnd1", DIRECT_ADDRESSING, 128},
          {"m128", INDIRECT_ADDRESSING, 128}}},
        {"bnd2/m128",
         {{"bnd2", DIRECT_ADDRESSING, 128},
          {"m128", INDIRECT_ADDRESSING, 128}}},
        {"k2/m8",
         {{"k2", DIRECT_ADDRESSING, 8}, {"m8", INDIRECT_ADDRESSING, 8}}},
        {"k2/m16",
         {{"k2", DIRECT_ADDRESSING, 16}, {"m16", INDIRECT_ADDRESSING, 16}}},
        {"k2/m32",
         {{"k2", DIRECT_ADDRESSING, 32}, {"m32", INDIRECT_ADDRESSING, 32}}},
        {"k2/m64",
         {{"k2", DIRECT_ADDRESSING, 64}, {"m64", INDIRECT_ADDRESSING, 64}}},
    });
  }();
  return *kAlternatives;
}

}  // namespace

Status AddAlternatives(InstructionSetProto* instruction_set) {
  CHECK(instruction_set != nullptr);
  Status status = OkStatus();
  const OperandAlternativeMap& alternatives_by_name =
      GetOperandAlternativesByName();
  std::vector<InstructionProto> new_instructions;
  for (InstructionProto& instruction :
       *instruction_set->mutable_instructions()) {
    InstructionFormat* const vendor_syntax =
        instruction.mutable_vendor_syntax();
    for (int operand_index = 0; operand_index < vendor_syntax->operands_size();
         ++operand_index) {
      InstructionOperand* const operand =
          vendor_syntax->mutable_operands(operand_index);
      const std::vector<OperandAlternative>* const alternatives =
          FindOrNull(alternatives_by_name, operand->name());
      if (alternatives == nullptr) continue;

      // The only encoding that allows alternatives is modrm.rm. An operand with
      // alternatives anywhere else means that there is an error in the data.
      if (operand->encoding() != InstructionOperand::MODRM_RM_ENCODING) {
        return InvalidArgumentError(
            StrCat("Instruction does not use modrm.rm encoding:\n",
                   instruction.DebugString()));
      }
      // The altenatives are always "register" vs "memory", because that is the
      // only kind of alternatives that can be expressed through operand
      // encoding.
      if (operand->addressing_mode() !=
          InstructionOperand::ANY_ADDRESSING_WITH_FLEXIBLE_REGISTERS) {
        return InvalidArgumentError(StrCat(
            "The addressing mode does not allow splitting: ",
            InstructionOperand::AddressingMode_Name(operand->addressing_mode()),
            "\n", instruction.DebugString()));
      }
      // Note that we start iterating at 1, and that we will be reusing
      // the existing instruction for the first alternative.
      for (int i = 1; i < alternatives->size(); ++i) {
        const OperandAlternative& alternative = (*alternatives)[i];
        new_instructions.push_back(instruction);
        InstructionOperand* const new_instruction_operand =
            new_instructions.back().mutable_vendor_syntax()->mutable_operands(
                operand_index);
        new_instruction_operand->set_name(alternative.operand_name);
        new_instruction_operand->set_addressing_mode(
            alternative.addressing_mode);
        new_instruction_operand->set_value_size_bits(alternative.value_size);
      }
      // Now overwrite the current instruction's operand.
      const OperandAlternative& first_alternative = alternatives->front();
      operand->set_name(first_alternative.operand_name);
      operand->set_addressing_mode(first_alternative.addressing_mode);
      operand->set_value_size_bits(first_alternative.value_size);
    }
  }
  for (InstructionProto& new_instruction : new_instructions) {
    instruction_set->add_instructions()->Swap(&new_instruction);
  }
  return status;
}
REGISTER_INSTRUCTION_SET_TRANSFORM(AddAlternatives, 6000);

}  // namespace x86
}  // namespace exegesis
<|endoftext|>


<commit_before>/*
Copyright (c) 2014, Peter G. Baum
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "gpio.h"
#include <unistd.h>
#include <fcntl.h>
#include <string>
#include <stdexcept>
#include <map>
#include <cstring>

namespace
{
   const char *basePath = "/sys/class/gpio/";
   struct Comp
   {
      bool operator()( const char *a, const char *b ) const
      {
         return strcmp( a, b ) < 0;
      }
   };

   const std::map<const char *,int, Comp> nameMap =
   {
      { "P8.3", 32 + 6 },
      { "P8.4", 32 + 7 },
      { "P8.5", 32 + 2 },
      { "P8.6", 32 + 3 },
      { "P8.7", 64 + 2 },
      { "P8.8", 64 + 3 },
      { "P8.9", 64 + 5 },
      { "P8.10", 64 + 4 },
      { "P8.11", 32 + 13 },
      { "P8.12", 32 + 12 },
      { "P8.13", 0 + 23 },
      { "P8.14", 0 + 26 },
      { "P8.15", 32 + 15 },
      { "P8.16", 32 + 14 },
      { "P8.17", 0 + 27 },
      { "P8.18", 64 + 1 },
      { "P8.19", 0 + 22 },
      { "P8.20", 32 + 31 },
      { "P8.21", 32 + 30 },
      { "P8.22", 32 + 5 },
      { "P8.23", 32 + 4 },
      { "P8.24", 32 + 1 },
      { "P8.25", 32 + 0 },
      { "P8.26", 32 + 29 },
      { "P8.27", 64 + 22 },
      { "P8.28", 64 + 24 },
      { "P8.29", 64 + 23 },
      { "P8.30", 64 + 25 },
      { "P8.31", 0 + 10 },
      { "P8.32", 0 + 11 },
      { "P8.33", 0 + 9 },
      { "P8.34", 64 + 17 },
      { "P8.35", 0 + 8 },
      { "P8.36", 64 + 16 },
      { "P8.37", 64 + 14 },
      { "P8.38", 64 + 15 },
      { "P8.39", 64 + 12 },
      { "P8.40", 64 + 13 },
      { "P8.41", 64 + 10 },
      { "P8.42", 64 + 11 },
      { "P8.43", 64 + 8 },
      { "P8.44", 64 + 9 },
      { "P8.45", 64 + 6 },
      { "P8.46", 64 + 7 },
      { "P9.11", 0 + 30 },
      { "P9.12", 32 + 28 },
      { "P9.13", 0 + 31 },
      { "P9.14", 32 + 18 },
      { "P9.15", 32 + 16 },
      { "P9.16", 32 + 19 },
      { "P9.17", 0 + 5 },
      { "P9.18", 0 + 4 },
      { "P9.19", 0 + 13 },
      { "P9.20", 0 + 12 },
      { "P9.21", 0 + 3 },
      { "P9.22", 0 + 2 },
      { "P9.23", 32 + 17 },
      { "P9.24", 0 + 15 },
      { "P9.25", 96 + 21 },
      { "P9.26", 0 + 14 },
      { "P9.27", 96 + 19 },
      { "P9.28", 96 + 17 },
      { "P9.29", 96 + 15 },
      { "P9.30", 96 + 16 },
      { "P9.31", 96 + 14 },
      // LEDs
      { "USR0", 32 + 21 },
      { "USR1", 32 + 22 },
      { "USR2", 32 + 23 },
      { "USR3", 32 + 24 },
   };

   int getNumberFromName( const char *name )
   {
      if( strncmp( name, "GPIO", 4 ) == 0 )
      {
         const int bank = atoi( name + 4 );
         const char *p = strchr( name, '_' );
         if( p == nullptr )
            throw std::invalid_argument( "Invalid GPIO name" );
         const int num = atoi( p + 1 );
         return bank * 32 + num;
      }
      auto p( nameMap.find( name ) );
      if( p == nameMap.end() )
         throw std::invalid_argument( "Invalid header name" );
      return p->second;
   }
}

GPIO::GPIO( int gpio_, int direction ) : gpio( gpio_ )
{
   const std::string path(  basePath );
   int fd = open( ( path + "export" ).c_str(), O_WRONLY );
   if( fd < 0 )
      throw std::invalid_argument( strerror( errno ) );
   std::string str = std::to_string( gpio );
   write( fd, str.c_str(), str.size() + 1 );
   ::close( fd );

   fd = open( (path + "gpio" + std::to_string( gpio ) + "/direction").c_str(),
         O_WRONLY );
   if( fd < 0 )
   {
      close();
      throw std::invalid_argument( strerror( errno ) );
   }
   if( direction == IN )
      write( fd, "in", 3 );
   else
      write( fd, "out", 4 );
   ::close( fd );
}

void GPIO::close( )
{
   const std::string path( basePath );
   int fd = open( (path + "unexport" ).c_str(), O_WRONLY );
   std::string str = std::to_string( gpio );
   write( fd, str.c_str(), str.size() + 1 );
   ::close( fd );
}

GPIO::~GPIO( )
{
   try
   {
      close();
   }
   catch( ... )
   {
   }
}

GPO::GPO( int gpio_ ) : gpio( gpio_, GPIO::OUT )
{
   const std::string path(  basePath );
   fd = open( (path + "gpio" + std::to_string( gpio_ ) + "/value").c_str(),
         O_WRONLY );
   if( fd < 0 )
      throw std::invalid_argument( strerror( errno ) );
}

GPO::GPO( const char *name ) : GPO( getNumberFromName( name ) )
{
}

GPO::~GPO( )
{
   if( fd > 0 )
      close();
}

void GPO::set( bool val )
{
   write( fd, val ? "1": "0", 2 );
}

void GPO::close( )
{
   ::close( fd );
   fd = 0;
   gpio.close();
}
<commit_msg>gpio: use #define to reduce std::string overhead<commit_after>/*
Copyright (c) 2014, Peter G. Baum
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "gpio.h"
#include <unistd.h>
#include <fcntl.h>
#include <string>
#include <stdexcept>
#include <map>
#include <cstring>

#define SYSFS_GPIO_DIR "/sys/class/gpio/"

namespace
{
   struct Comp
   {
      bool operator()( const char *a, const char *b ) const
      {
         return strcmp( a, b ) < 0;
      }
   };

   const std::map<const char *,int, Comp> nameMap =
   {
      { "P8.3", 32 + 6 },
      { "P8.4", 32 + 7 },
      { "P8.5", 32 + 2 },
      { "P8.6", 32 + 3 },
      { "P8.7", 64 + 2 },
      { "P8.8", 64 + 3 },
      { "P8.9", 64 + 5 },
      { "P8.10", 64 + 4 },
      { "P8.11", 32 + 13 },
      { "P8.12", 32 + 12 },
      { "P8.13", 0 + 23 },
      { "P8.14", 0 + 26 },
      { "P8.15", 32 + 15 },
      { "P8.16", 32 + 14 },
      { "P8.17", 0 + 27 },
      { "P8.18", 64 + 1 },
      { "P8.19", 0 + 22 },
      { "P8.20", 32 + 31 },
      { "P8.21", 32 + 30 },
      { "P8.22", 32 + 5 },
      { "P8.23", 32 + 4 },
      { "P8.24", 32 + 1 },
      { "P8.25", 32 + 0 },
      { "P8.26", 32 + 29 },
      { "P8.27", 64 + 22 },
      { "P8.28", 64 + 24 },
      { "P8.29", 64 + 23 },
      { "P8.30", 64 + 25 },
      { "P8.31", 0 + 10 },
      { "P8.32", 0 + 11 },
      { "P8.33", 0 + 9 },
      { "P8.34", 64 + 17 },
      { "P8.35", 0 + 8 },
      { "P8.36", 64 + 16 },
      { "P8.37", 64 + 14 },
      { "P8.38", 64 + 15 },
      { "P8.39", 64 + 12 },
      { "P8.40", 64 + 13 },
      { "P8.41", 64 + 10 },
      { "P8.42", 64 + 11 },
      { "P8.43", 64 + 8 },
      { "P8.44", 64 + 9 },
      { "P8.45", 64 + 6 },
      { "P8.46", 64 + 7 },
      { "P9.11", 0 + 30 },
      { "P9.12", 32 + 28 },
      { "P9.13", 0 + 31 },
      { "P9.14", 32 + 18 },
      { "P9.15", 32 + 16 },
      { "P9.16", 32 + 19 },
      { "P9.17", 0 + 5 },
      { "P9.18", 0 + 4 },
      { "P9.19", 0 + 13 },
      { "P9.20", 0 + 12 },
      { "P9.21", 0 + 3 },
      { "P9.22", 0 + 2 },
      { "P9.23", 32 + 17 },
      { "P9.24", 0 + 15 },
      { "P9.25", 96 + 21 },
      { "P9.26", 0 + 14 },
      { "P9.27", 96 + 19 },
      { "P9.28", 96 + 17 },
      { "P9.29", 96 + 15 },
      { "P9.30", 96 + 16 },
      { "P9.31", 96 + 14 },
      // LEDs
      { "USR0", 32 + 21 },
      { "USR1", 32 + 22 },
      { "USR2", 32 + 23 },
      { "USR3", 32 + 24 },
   };

   int getNumberFromName( const char *name )
   {
      if( strncmp( name, "GPIO", 4 ) == 0 )
      {
         const int bank = atoi( name + 4 );
         const char *p = strchr( name, '_' );
         if( p == nullptr )
            throw std::invalid_argument( "Invalid GPIO name" );
         const int num = atoi( p + 1 );
         return bank * 32 + num;
      }
      auto p( nameMap.find( name ) );
      if( p == nameMap.end() )
         throw std::invalid_argument( "Invalid header name" );
      return p->second;
   }
}

GPIO::GPIO( int gpio_, int direction ) : gpio( gpio_ )
{
   int fd = open( SYSFS_GPIO_DIR "export", O_WRONLY );
   if( fd < 0 )
      throw std::invalid_argument( strerror( errno ) );
   std::string str = std::to_string( gpio );
   write( fd, str.c_str(), str.size() + 1 );
   ::close( fd );

   fd = open( ( std::string( SYSFS_GPIO_DIR "gpio" )
         + std::to_string( gpio ) + "/direction").c_str(), O_WRONLY );
   if( fd < 0 )
   {
      close();
      throw std::invalid_argument( strerror( errno ) );
   }
   if( direction == IN )
      write( fd, "in", 3 );
   else
      write( fd, "out", 4 );
   ::close( fd );
}

void GPIO::close( )
{
   int fd = open( SYSFS_GPIO_DIR "unexport", O_WRONLY );
   std::string str = std::to_string( gpio );
   write( fd, str.c_str(), str.size() + 1 );
   ::close( fd );
}

GPIO::~GPIO( )
{
   try
   {
      close();
   }
   catch( ... )
   {
   }
}

GPO::GPO( int gpio_ ) : gpio( gpio_, GPIO::OUT )
{
   const std::string path( SYSFS_GPIO_DIR "gpio"  );
   fd = open( (path + std::to_string( gpio_ ) + "/value").c_str(),
         O_WRONLY );
   if( fd < 0 )
      throw std::invalid_argument( strerror( errno ) );
}

GPO::GPO( const char *name ) : GPO( getNumberFromName( name ) )
{
}

GPO::~GPO( )
{
   if( fd > 0 )
      close();
}

void GPO::set( bool val )
{
   write( fd, val ? "1": "0", 2 );
}

void GPO::close( )
{
   ::close( fd );
   fd = 0;
   gpio.close();
}
<|endoftext|>


<commit_before>#include "SalomeApp_SelectionMgr.h"

#include "SalomeApp_Study.h"
#include "SalomeApp_DataOwner.h"
#include "SalomeApp_DataSubOwner.h"
#include "SalomeApp_Application.h"

#include <SUIT_Session.h>

#include <SALOME_ListIO.hxx>
#include <SALOME_ListIteratorOfListIO.hxx>

// Open CASCADE Include
#include <TColStd_MapOfInteger.hxx>
#include <TColStd_MapIteratorOfMapOfInteger.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>

#include "SALOMEDSClient.hxx"

SalomeApp_SelectionMgr::SalomeApp_SelectionMgr( SalomeApp_Application* app, const bool fb )
: SUIT_SelectionMgr( fb ),
myApp( app )
{
}

SalomeApp_SelectionMgr::~SalomeApp_SelectionMgr()
{
}

SalomeApp_Application* SalomeApp_SelectionMgr::application() const
{
  return myApp;
}

/*
  get all selected objects from selection manager

*/
void SalomeApp_SelectionMgr::selectedObjects( SALOME_ListIO& lst ) const
{
  lst.Clear();

  if ( !application() )
    return;

  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
  if ( !appStudy )
    return;

  _PTR(Study) aStudy ( appStudy->studyDS() );
  if ( !aStudy )
    return;

  SUIT_DataOwnerPtrList aList;
  selected( aList );

  for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
  {
    const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
    if( owner )
      lst.Append( owner->IO() );
/*

    if ( owner && dynamic_cast<const SalomeApp_DataSubOwner*>( owner ) )
    { //get only subowners, insert into lst unique subowners (subowners with different entries)
      if ( !anEntryList.contains( owner->entry() ) )
      {
	anEntryList.append( owner->entry() );

	//construct SALOME_InteractiveObject with predefined entry
	_PTR(SObject) anObj ( aStudy->FindObjectID( owner->entry().latin1() ) );
	if ( anObj )
	{
	  _PTR(SComponent) aFC (anObj->GetFatherComponent());
	  if ( aFC )
	  {
	    anIO = new SALOME_InteractiveObject( anObj->GetID().c_str(), aFC->ComponentDataType().c_str(), anObj->GetName().c_str() );
	    if ( anIO ) lst.Append( anIO );
	  }
	}
      }
    }
    else if ( owner )
    { //get not subowners data owners
      _PTR(SObject) anObj ( aStudy->FindObjectID( owner->entry().latin1() ) );
      if ( anObj )
      {
        _PTR(SComponent) aFC (anObj->GetFatherComponent());
        if ( aFC )
        {
          anIO = new SALOME_InteractiveObject( anObj->GetID().c_str(), aFC->ComponentDataType().c_str(), anObj->GetName().c_str() );
	  if ( anIO ) lst.Append( anIO );
        }
      }
    }
*/
  }
}

void SalomeApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
{
  if ( !application() )
    return;

  SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( application()->activeStudy() );
  if ( !appStudy )
    return;

  _PTR(Study) aStudy ( appStudy->studyDS() );
  if ( !aStudy )
    return;

  SUIT_DataOwnerPtrList owners;
  for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
  {
    if ( it.Value()->hasEntry() )
      owners.append( new SalomeApp_DataOwner( it.Value()->getEntry() ) );
  }
  setSelected( owners, append );
}

void SalomeApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
{
  SUIT_SelectionMgr::selectionChanged( theSel );

  emit currentSelectionChanged();
}

/*
  get map of indexes for the given SALOME_InteractiveObject

*/
void SalomeApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject,
					 TColStd_IndexedMapOfInteger& theIndex)
{
  theIndex.Clear();

  SUIT_DataOwnerPtrList aList;
  selected( aList );

  for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
  {
    const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
    if ( subOwner )
      if ( subOwner->entry() == QString(IObject->getEntry()) )
	theIndex.Add( subOwner->index() );
  }

}

/*
  get map of indexes for the given entry of SALOME_InteractiveObject

*/
void SalomeApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
{
  theIndex.Clear();

  SUIT_DataOwnerPtrList aList;
  selected( aList );

  for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
  {
    const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
    if ( subOwner )
      if ( subOwner->entry() == theEntry )
	theIndex.Add( subOwner->index() );
  }

}

bool SalomeApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
					       const TColStd_MapOfInteger& theIndexes,
					       bool modeShift)
{
  SUIT_DataOwnerPtrList remainsOwners;

  SUIT_DataOwnerPtrList aList;
  selected( aList );

  if ( !modeShift ) {
    for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
    {
      const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
      if ( owner )
      {
	if ( owner->entry() != QString(IObject->getEntry()) )
	{
	  const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( owner );
	  if ( subOwner )
	    remainsOwners.append( new SalomeApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
	  else
	    remainsOwners.append( new SalomeApp_DataOwner( owner->entry() ) );
	}
      }
    }
  }
  else
    remainsOwners = aList;

  TColStd_MapIteratorOfMapOfInteger It;
  It.Initialize(theIndexes);
  for(;It.More();It.Next())
    remainsOwners.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), It.Key() ) );

  bool append = false;
  setSelected( remainsOwners, append );

  emit currentSelectionChanged();

  TColStd_IndexedMapOfInteger anIndexes;
  GetIndexes( IObject, anIndexes );
  return !anIndexes.IsEmpty();

}

/*
  select 'subobjects' with given indexes

*/
void SalomeApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject,
					    TColStd_IndexedMapOfInteger theIndex, bool append )
{
  SUIT_DataOwnerPtrList aList;

  if ( theIndex.IsEmpty() )
    aList.append( new SalomeApp_DataOwner( QString(IObject->getEntry()) ) );
  else
    {
      int i;
      for ( i = 1; i <= theIndex.Extent(); i++ )
	aList.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
    }

  setSelected( aList, append );

}

/*
  select 'subobjects' with given indexes

*/
void SalomeApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
{
  SUIT_DataOwnerPtrList aList;

  MapIOOfMapOfInteger::Iterator it;
  for ( it = theMapIO.begin(); it != theMapIO.end(); ++it )
    {
      if ( it.data().IsEmpty() )
	aList.append( new SalomeApp_DataOwner( QString(it.key()->getEntry()) ) );
      else
	{
	  int i;
	  for ( i = 1; i <= it.data().Extent(); i++ )
	    aList.append( new SalomeApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) );
	}
    }

  setSelected( aList, append );

}

/*
  get map of selected subowners : object's entry <-> map of indexes

*/
void SalomeApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
{
  theMap.clear();

  TColStd_IndexedMapOfInteger anIndexes;

  SUIT_DataOwnerPtrList aList;
  selected( aList );

  for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
  {
    const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
    if ( subOwner )
    {
      if ( !theMap.contains( subOwner->entry() ) )
      {
	anIndexes.Clear();
	GetIndexes( subOwner->entry(), anIndexes );
	theMap.insert( subOwner->entry(), anIndexes );
      }
    }
  }
}
<commit_msg>To adjust to new SalomeApp_DataOwner, which now holds SALOME_InteractiveObject<commit_after>#include "SalomeApp_SelectionMgr.h"

#include "SalomeApp_Study.h"
#include "SalomeApp_DataOwner.h"
#include "SalomeApp_DataSubOwner.h"
#include "SalomeApp_Application.h"

#include <SUIT_Session.h>

#include <SALOME_ListIO.hxx>
#include <SALOME_ListIteratorOfListIO.hxx>

// Open CASCADE Include
#include <TColStd_MapOfInteger.hxx>
#include <TColStd_MapIteratorOfMapOfInteger.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>

#include "SALOMEDSClient.hxx"

SalomeApp_SelectionMgr::SalomeApp_SelectionMgr( SalomeApp_Application* app, const bool fb )
: SUIT_SelectionMgr( fb ),
myApp( app )
{
}

SalomeApp_SelectionMgr::~SalomeApp_SelectionMgr()
{
}

SalomeApp_Application* SalomeApp_SelectionMgr::application() const
{
  return myApp;
}

/*
  get all selected objects from selection manager

*/
void SalomeApp_SelectionMgr::selectedObjects( SALOME_ListIO& lst ) const
{
  lst.Clear();

  SUIT_DataOwnerPtrList aList;
  selected( aList );

  for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
  {
    const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
    if( owner )
      lst.Append( owner->IO() );
  }
}

void SalomeApp_SelectionMgr::setSelectedObjects( const SALOME_ListIO& lst, const bool append )
{
  SUIT_DataOwnerPtrList owners;
  for ( SALOME_ListIteratorOfListIO it( lst ); it.More(); it.Next() )
  {
    if ( it.Value()->hasEntry() )
      owners.append( new SalomeApp_DataOwner( it.Value() ) );
  }

  setSelected( owners, append );
}

void SalomeApp_SelectionMgr::selectionChanged( SUIT_Selector* theSel )
{
  SUIT_SelectionMgr::selectionChanged( theSel );

  emit currentSelectionChanged();
}

/*
  get map of indexes for the given SALOME_InteractiveObject

*/
void SalomeApp_SelectionMgr::GetIndexes( const Handle(SALOME_InteractiveObject)& IObject,
					 TColStd_IndexedMapOfInteger& theIndex)
{
  theIndex.Clear();

  SUIT_DataOwnerPtrList aList;
  selected( aList );

  for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
  {
    const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
    if ( subOwner )
      if ( subOwner->entry() == QString(IObject->getEntry()) )
	theIndex.Add( subOwner->index() );
  }

}

/*
  get map of indexes for the given entry of SALOME_InteractiveObject

*/
void SalomeApp_SelectionMgr::GetIndexes( const QString& theEntry, TColStd_IndexedMapOfInteger& theIndex )
{
  theIndex.Clear();

  SUIT_DataOwnerPtrList aList;
  selected( aList );

  for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
  {
    const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
    if ( subOwner )
      if ( subOwner->entry() == theEntry )
	theIndex.Add( subOwner->index() );
  }

}

bool SalomeApp_SelectionMgr::AddOrRemoveIndex( const Handle(SALOME_InteractiveObject)& IObject,
					       const TColStd_MapOfInteger& theIndexes,
					       bool modeShift)
{
  SUIT_DataOwnerPtrList remainsOwners;

  SUIT_DataOwnerPtrList aList;
  selected( aList );

  if ( !modeShift ) {
    for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
    {
      const SalomeApp_DataOwner* owner = dynamic_cast<const SalomeApp_DataOwner*>( (*itr).operator->() );
      if ( owner )
      {
	if ( owner->entry() != QString(IObject->getEntry()) )
	{
	  const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( owner );
	  if ( subOwner )
	    remainsOwners.append( new SalomeApp_DataSubOwner( subOwner->entry(), subOwner->index() ) );
	  else
	    remainsOwners.append( new SalomeApp_DataOwner( owner->entry() ) );
	}
      }
    }
  }
  else
    remainsOwners = aList;

  TColStd_MapIteratorOfMapOfInteger It;
  It.Initialize(theIndexes);
  for(;It.More();It.Next())
    remainsOwners.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), It.Key() ) );

  bool append = false;
  setSelected( remainsOwners, append );

  emit currentSelectionChanged();

  TColStd_IndexedMapOfInteger anIndexes;
  GetIndexes( IObject, anIndexes );
  return !anIndexes.IsEmpty();

}

/*
  select 'subobjects' with given indexes

*/
void SalomeApp_SelectionMgr::selectObjects( const Handle(SALOME_InteractiveObject)& IObject,
					    TColStd_IndexedMapOfInteger theIndex, bool append )
{
  SUIT_DataOwnerPtrList aList;

  if ( theIndex.IsEmpty() )
    aList.append( new SalomeApp_DataOwner( QString(IObject->getEntry()) ) );
  else
    {
      int i;
      for ( i = 1; i <= theIndex.Extent(); i++ )
	aList.append( new SalomeApp_DataSubOwner( QString(IObject->getEntry()), theIndex( i ) ) );
    }

  setSelected( aList, append );

}

/*
  select 'subobjects' with given indexes

*/
void SalomeApp_SelectionMgr::selectObjects( MapIOOfMapOfInteger theMapIO, bool append )
{
  SUIT_DataOwnerPtrList aList;

  MapIOOfMapOfInteger::Iterator it;
  for ( it = theMapIO.begin(); it != theMapIO.end(); ++it )
    {
      if ( it.data().IsEmpty() )
	aList.append( new SalomeApp_DataOwner( QString(it.key()->getEntry()) ) );
      else
	{
	  int i;
	  for ( i = 1; i <= it.data().Extent(); i++ )
	    aList.append( new SalomeApp_DataSubOwner( QString(it.key()->getEntry()), it.data()( i ) ) );
	}
    }

  setSelected( aList, append );

}

/*
  get map of selected subowners : object's entry <-> map of indexes

*/
void SalomeApp_SelectionMgr::selectedSubOwners( MapEntryOfMapOfInteger& theMap )
{
  theMap.clear();

  TColStd_IndexedMapOfInteger anIndexes;

  SUIT_DataOwnerPtrList aList;
  selected( aList );

  for ( SUIT_DataOwnerPtrList::const_iterator itr = aList.begin(); itr != aList.end(); ++itr )
  {
    const SalomeApp_DataSubOwner* subOwner = dynamic_cast<const SalomeApp_DataSubOwner*>( (*itr).operator->() );
    if ( subOwner )
    {
      if ( !theMap.contains( subOwner->entry() ) )
      {
	anIndexes.Clear();
	GetIndexes( subOwner->entry(), anIndexes );
	theMap.insert( subOwner->entry(), anIndexes );
      }
    }
  }
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: fltlst.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: hr $ $Date: 2003-04-04 16:07:41 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _SFX_FLTLST_HXX
#define _SFX_FLTLST_HXX

//*****************************************************************************************************************
//  includes
//*****************************************************************************************************************
#ifndef _SFX_FCONTNR_HXX
#include <fcontnr.hxx>
#endif

#ifndef _CPPUHELPER_IMPLBASE1_HXX_
#include <cppuhelper/implbase1.hxx>
#endif

#ifndef _RTL_USTRING_HXX_
#include <rtl/ustring.hxx>
#endif

#ifndef _OSL_MUTEX_HXX_
#include <osl/mutex.hxx>
#endif

#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
#include <com/sun/star/uno/Reference.hxx>
#endif

#ifndef _COM_SUN_STAR_UTIL_XFLUSHABLE_HPP_
#include <com/sun/star/util/XFlushable.hpp>
#endif

#ifndef _COM_SUN_STAR_UTIL_XFLUSHLISTENER_HPP_
#include <com/sun/star/util/XFlushListener.hpp>
#endif

#ifndef _COM_SUN_STAR_DOCUMENT_XEVENTLISTENER_HPP_
#include <com/sun/star/document/XEventListener.hpp>
#endif

#ifndef _COM_SUN_STAR_LANG_EVENTOBJECT_HPP_
#include <com/sun/star/lang/EventObject.hpp>
#endif

#ifndef _COM_SUN_STAR_UNO_RUNTIMEEXCEPTION_HPP_
#include <com/sun/star/uno/RuntimeException.hpp>
#endif

//*****************************************************************************************************************
//  declarations
//*****************************************************************************************************************
class SfxFilterListener : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XFlushListener >
{
    // member
    private:
        ::osl::Mutex                                                            m_aMutex      ;
        ::rtl::OUString                                                         m_sFactory    ;
        ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushable >  m_xTypeCache  ;
        ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushable >  m_xFilterCache;
        SfxFilterContainer*                                                     m_pContainer  ;

    // c++ interface
    public:
              SfxFilterListener( const ::rtl::OUString&    sFactory   ,
                                       SfxFilterContainer* pContainer );
             ~SfxFilterListener(                                      );

    // uno interface
    public:
        // XFlushListener
        virtual void SAL_CALL flushed( const ::com::sun::star::lang::EventObject& aSource ) throw( ::com::sun::star::uno::RuntimeException );
        // XEventListener
        virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aSource ) throw( ::com::sun::star::uno::RuntimeException );

};  // SfxFilterListener

#endif // _SFX_FLTLST_HXX
<commit_msg>INTEGRATION: CWS fwkq1 (1.4.66); FILE MERGED 2003/07/14 18:00:09 mba 1.4.66.1: #110843#: get rid of factories<commit_after>/*************************************************************************
 *
 *  $RCSfile: fltlst.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: rt $ $Date: 2003-09-19 07:58:10 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _SFX_FLTLST_HXX
#define _SFX_FLTLST_HXX

//*****************************************************************************************************************
//  includes
//*****************************************************************************************************************
#ifndef _SFX_FCONTNR_HXX
#include <fcontnr.hxx>
#endif

#ifndef _CPPUHELPER_IMPLBASE1_HXX_
#include <cppuhelper/implbase1.hxx>
#endif

#ifndef _RTL_USTRING_HXX_
#include <rtl/ustring.hxx>
#endif

#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
#include <com/sun/star/uno/Reference.hxx>
#endif

#ifndef _COM_SUN_STAR_UTIL_XFLUSHABLE_HPP_
#include <com/sun/star/util/XFlushable.hpp>
#endif

#ifndef _COM_SUN_STAR_UTIL_XFLUSHLISTENER_HPP_
#include <com/sun/star/util/XFlushListener.hpp>
#endif

#ifndef _COM_SUN_STAR_DOCUMENT_XEVENTLISTENER_HPP_
#include <com/sun/star/document/XEventListener.hpp>
#endif

#ifndef _COM_SUN_STAR_LANG_EVENTOBJECT_HPP_
#include <com/sun/star/lang/EventObject.hpp>
#endif

#ifndef _COM_SUN_STAR_UNO_RUNTIMEEXCEPTION_HPP_
#include <com/sun/star/uno/RuntimeException.hpp>
#endif

//*****************************************************************************************************************
//  declarations
//*****************************************************************************************************************
class SfxFilterListener : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XFlushListener >
{
    // member
    private:
        ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushable >  m_xTypeCache  ;
        ::com::sun::star::uno::Reference< ::com::sun::star::util::XFlushable >  m_xFilterCache;

    // c++ interface
    public:
              SfxFilterListener();
             ~SfxFilterListener();

    // uno interface
    public:
        // XFlushListener
        virtual void SAL_CALL flushed( const ::com::sun::star::lang::EventObject& aSource ) throw( ::com::sun::star::uno::RuntimeException );
        // XEventListener
        virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aSource ) throw( ::com::sun::star::uno::RuntimeException );

};  // SfxFilterListener

#endif // _SFX_FLTLST_HXX
<|endoftext|>


<commit_before>#include "sixtracklib/cuda/argument.h"

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <fstream>
#include <iterator>
#include <sstream>

#include <gtest/gtest.h>

#include "sixtracklib/testlib.h"

#include "sixtracklib/common/definitions.h"
#include "sixtracklib/common/generated/path.h"
#include "sixtracklib/common/buffer.h"
#include "sixtracklib/common/particles.h"
#include "sixtracklib/common/context/definitions.h"
#include "sixtracklib/cuda/context.h"

TEST( C99_CudaArgumentTests, ArgumentCObjectBufferTest )
{
    using argument_t  = ::NS(CudaArgument);
    using context_t   = ::NS(CudaContext);
    using particles_t = ::NS(Particles);
    using buffer_t    = ::NS(Buffer);
    using buf_size_t  = ::NS(buffer_size_t);
    using ctx_size_t  = ::NS(context_size_t);

    buf_size_t const NUM_PARTICLES = 100;
    buffer_t* pb = ::NS(Buffer_new)( 0u );

    particles_t* particles = ::NS(Particles_new)( pb, NUM_PARTICLES );
    SIXTRL_ASSERT( particles != nullptr );

    context_t*  context = ::NS(CudaContext_create)();
    ASSERT_TRUE( context != nullptr );

    argument_t* particles_arg = ::NS(CudaArgument_new)( context );
    ASSERT_TRUE( particles_arg != nullptr );

    bool success = ::NS(CudaArgument_send_buffer)( particles_arg, pb );
    ASSERT_TRUE( success );

    ::NS(CudaArgument_delete)( particles_arg );
    ::NS(CudaContext_delete)( context );
    ::NS(Buffer_delete)( pb );

    context = nullptr;
    particles_arg = nullptr;
    particles = nullptr;
    pb = nullptr;
}

/* end: tests/sixtracklib/cuda/test_context_cxx.cpp */
<commit_msg>tests/sixtracklib: expand the NS(CudaArgument_*) related C99 unit-test<commit_after>#include "sixtracklib/cuda/argument.h"

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <fstream>
#include <iterator>
#include <sstream>

#include <gtest/gtest.h>

#include "sixtracklib/testlib.h"

#include "sixtracklib/common/definitions.h"
#include "sixtracklib/common/generated/path.h"
#include "sixtracklib/common/buffer.h"
#include "sixtracklib/common/particles.h"
#include "sixtracklib/common/context/definitions.h"
#include "sixtracklib/cuda/context.h"

TEST( C99_CudaArgumentTests, ArgumentCObjectBufferTest )
{
    using argument_t  = ::NS(CudaArgument);
    using context_t   = ::NS(CudaContext);
    using particles_t = ::NS(Particles);
    using buffer_t    = ::NS(Buffer);
    using buf_size_t  = ::NS(buffer_size_t);
    using ctx_size_t  = ::NS(context_size_t);

    buf_size_t const NUM_PARTICLES = 1000;
    buffer_t* pb = ::NS(Buffer_new)( 0u );

    buffer_t* cmp_pb = ::NS(Buffer_new)( 0u );

    particles_t* particles = ::NS(Particles_new)( pb, NUM_PARTICLES );
    SIXTRL_ASSERT( particles != nullptr );

    ::NS(Particles_realistic_init)( particles );

    particles_t* cmp_particles = ::NS(Particles_add_copy)( cmp_pb, particles );
    SIXTRL_ASSERT( cmp_particles != nullptr );
    SIXTRL_ASSERT( ::NS(Particles_compare_values)(
        particles, cmp_particles ) == 0 );

    context_t*  context = ::NS(CudaContext_create)();
    ASSERT_TRUE( context != nullptr );

    argument_t* particles_arg = ::NS(CudaArgument_new)( context );
    ASSERT_TRUE( particles_arg != nullptr );

    bool success = ::NS(CudaArgument_send_buffer)( particles_arg, pb );
    ASSERT_TRUE( success );

    success = ::NS(CudaArgument_receive_buffer)( particles_arg, pb );
    ASSERT_TRUE( success );

    particles = ::NS(Particles_buffer_get_particles)( pb, 00 );
    ASSERT_TRUE( particles != nullptr );

    ASSERT_TRUE( ::NS(Particles_compare_values)(
        particles, cmp_particles ) == 0 );

    ::NS(CudaArgument_delete)( particles_arg );
    ::NS(CudaContext_delete)( context );
    ::NS(Buffer_delete)( pb );
    ::NS(Buffer_delete)( cmp_pb );

    cmp_particles = nullptr;
    particles = nullptr;

    context = nullptr;
    particles_arg = nullptr;
    cmp_pb = nullptr;
    pb = nullptr;
}

/* end: tests/sixtracklib/cuda/test_context_cxx.cpp */
<|endoftext|>