<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: KeySet.hxx,v $
 *
 *  $Revision: 1.22 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 09:59:59 $
 *
 *  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 DBACCESS_CORE_API_KEYSET_HXX
#define DBACCESS_CORE_API_KEYSET_HXX

#ifndef DBACCESS_CORE_API_CACHESET_HXX
#include "CacheSet.hxx"
#endif

#ifndef _CPPUHELPER_IMPLBASE1_HXX_
#include <cppuhelper/implbase1.hxx>
#endif
#ifndef _MAP_
#include <map>
#endif
#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
#include <com/sun/star/lang/XUnoTunnel.hpp>
#endif
#ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYANALYZER_HPP_
#include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
#endif
#ifndef _COMPHELPER_STLTYPES_HXX_
#include <comphelper/stl_types.hxx>
#endif

namespace dbaccess
{
    typedef ::std::pair<sal_Int32,::rtl::OUString>          TTypeDefaultValuePair;
    typedef ::std::pair<sal_Int32,TTypeDefaultValuePair>    TPositionTypePair;
    DECLARE_STL_MAP(::rtl::OUString, TPositionTypePair,::comphelper::UStringMixLess,OColumnNamePos);

    // the elements of _rxQueryColumns must have the properties PROPERTY_REALNAME and PROPERTY_TABLENAME
    void getColumnPositions(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxQueryColumns,
                            const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxColumns,
                            const ::rtl::OUString& _rsUpdateTableName,
                            OColumnNamePos& _rColumnNames /* out */);

    typedef ::std::pair<ORowSetRow,sal_Int32> OKeySetValue;
    typedef ::std::map<sal_Int32,OKeySetValue > OKeySetMatrix;
    // is used when the source supports keys
    class OKeySet : public OCacheSet
    {
        OKeySetMatrix                                           m_aKeyMap;
        OKeySetMatrix::iterator                                 m_aKeyIter;

        ::std::vector< ::rtl::OUString >                        m_aAutoColumns;  // contains all columns which are autoincrement ones

        OColumnNamePos*                                         m_pKeyColumnNames;  // contains all key column names
        OColumnNamePos*                                         m_pColumnNames;     // contains all column names
        connectivity::OSQLTable                                 m_xTable; // reference to our table
        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement>   m_xStatement;
        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>           m_xSet;
        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow>                 m_xRow;
        ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >   m_xComposer;
        ::rtl::OUString                                                                 m_sUpdateTableName;
        ::rtl::OUString                                                                 m_aSelectComposedTableName;

        sal_Bool m_bRowCountFinal;

        /**
            getComposedTableName return the composed table name for the query
            @param _sCatalog    the catalogname may be empty
            @param _sSchema     the schemaname may be empty
            @param _sTable      the tablename

            @return the composed name
        */
        ::rtl::OUString getComposedTableName( const ::rtl::OUString& _sCatalog,
                                              const ::rtl::OUString& _sSchema,
                                              const ::rtl::OUString& _sTable);

        ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > getKeyColumns() const;
        void fillAllRows();
        sal_Bool fetchRow();
    protected:
        virtual ~OKeySet();
    public:
        OKeySet(const connectivity::OSQLTable& _xTable,
                const ::rtl::OUString& _rUpdateTableName,
                const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >& _xComposer);

        // late ctor which can throw exceptions
        virtual void construct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet);

        // ::com::sun::star::sdbc::XRow
        virtual sal_Bool SAL_CALL wasNull(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::rtl::OUString SAL_CALL getString( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);

        virtual sal_Bool SAL_CALL rowUpdated(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL rowInserted(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL rowDeleted(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // ::com::sun::star::sdbc::XResultSet
        virtual sal_Bool SAL_CALL next(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isBeforeFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isAfterLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL beforeFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL afterLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL first(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL last(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int32 SAL_CALL getRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL previous(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL refreshRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // ::com::sun::star::sdbcx::XRowLocate
        virtual ::com::sun::star::uno::Any SAL_CALL getBookmark( const ORowSetRow& _rRow ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // -------------------------------------------------------------------------
        virtual sal_Bool SAL_CALL moveToBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // -------------------------------------------------------------------------
        virtual sal_Bool SAL_CALL moveRelativeToBookmark( const ::com::sun::star::uno::Any& bookmark, sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // -------------------------------------------------------------------------
        virtual sal_Int32 SAL_CALL compareBookmarks( const ::com::sun::star::uno::Any& first, const ::com::sun::star::uno::Any& second ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // -------------------------------------------------------------------------
        virtual sal_Bool SAL_CALL hasOrderedBookmarks(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // -------------------------------------------------------------------------
        virtual sal_Int32 SAL_CALL hashBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // -------------------------------------------------------------------------
        // ::com::sun::star::sdbcx::XDeleteRows
        virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rows ,const connectivity::OSQLTable& _xTable) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // ::com::sun::star::sdbc::XResultSetUpdate
        virtual void SAL_CALL updateRow(const ORowSetRow& _rInsertRow,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& _xTable   ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL deleteRow(const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable   ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL cancelRowUpdates(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL moveToInsertRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL moveToCurrentRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
    };
}
#endif // DBACCESS_CORE_API_KEYSET_HXX

<commit_msg>INTEGRATION: CWS dba201b (1.21.38); FILE MERGED 2005/09/21 06:44:56 oj 1.21.38.2: RESYNC: (1.21-1.22); FILE MERGED 2005/07/11 13:36:58 fs 1.21.38.1: merging CWS dba201 into CWS dba201b<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: KeySet.hxx,v $
 *
 *  $Revision: 1.23 $
 *
 *  last change: $Author: hr $ $Date: 2005-09-23 12:02:30 $
 *
 *  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 DBACCESS_CORE_API_KEYSET_HXX
#define DBACCESS_CORE_API_KEYSET_HXX

#ifndef DBACCESS_CORE_API_CACHESET_HXX
#include "CacheSet.hxx"
#endif

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

#ifndef _COM_SUN_STAR_LANG_XUNOTUNNEL_HPP_
#include <com/sun/star/lang/XUnoTunnel.hpp>
#endif
#ifndef _COM_SUN_STAR_SDB_XSINGLESELECTQUERYANALYZER_HPP_
#include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
#endif
#ifndef _COMPHELPER_STLTYPES_HXX_
#include <comphelper/stl_types.hxx>
#endif

namespace dbaccess
{
    typedef ::std::pair<sal_Int32,::rtl::OUString>          TTypeDefaultValuePair;
    typedef ::std::pair<sal_Int32,TTypeDefaultValuePair>    TPositionTypePair;
    DECLARE_STL_MAP(::rtl::OUString, TPositionTypePair,::comphelper::UStringMixLess,OColumnNamePos);

    // the elements of _rxQueryColumns must have the properties PROPERTY_REALNAME and PROPERTY_TABLENAME
    void getColumnPositions(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxQueryColumns,
                            const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _rxColumns,
                            const ::rtl::OUString& _rsUpdateTableName,
                            OColumnNamePos& _rColumnNames /* out */);

    typedef ::std::pair<ORowSetRow,sal_Int32> OKeySetValue;
    typedef ::std::map<sal_Int32,OKeySetValue > OKeySetMatrix;
    // is used when the source supports keys
    class OKeySet : public OCacheSet
    {
        OKeySetMatrix                                           m_aKeyMap;
        OKeySetMatrix::iterator                                 m_aKeyIter;

        ::std::vector< ::rtl::OUString >                        m_aAutoColumns;  // contains all columns which are autoincrement ones

        OColumnNamePos*                                         m_pKeyColumnNames;  // contains all key column names
        OColumnNamePos*                                         m_pColumnNames;     // contains all column names
        connectivity::OSQLTable                                 m_xTable; // reference to our table
        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement>   m_xStatement;
        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>           m_xSet;
        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow>                 m_xRow;
        ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >   m_xComposer;
        ::rtl::OUString                                                                 m_sUpdateTableName;
        ::rtl::OUString                                                                 m_aSelectComposedTableName;

        sal_Bool m_bRowCountFinal;

        /**
            getComposedTableName return the composed table name for the query
            @param _sCatalog    the catalogname may be empty
            @param _sSchema     the schemaname may be empty
            @param _sTable      the tablename

            @return the composed name
        */
        ::rtl::OUString getComposedTableName( const ::rtl::OUString& _sCatalog,
                                              const ::rtl::OUString& _sSchema,
                                              const ::rtl::OUString& _sTable);

        ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > getKeyColumns() const;
        void fillAllRows();
        sal_Bool fetchRow();
    protected:
        virtual ~OKeySet();
    public:
        OKeySet(const connectivity::OSQLTable& _xTable,
                const ::rtl::OUString& _rUpdateTableName,
                const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >& _xComposer);

        // late ctor which can throw exceptions
        virtual void construct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet);

        // ::com::sun::star::sdbc::XRow
        virtual sal_Bool SAL_CALL wasNull(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::rtl::OUString SAL_CALL getString( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL getBoolean( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int8 SAL_CALL getByte( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int16 SAL_CALL getShort( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int32 SAL_CALL getInt( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int64 SAL_CALL getLong( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual float SAL_CALL getFloat( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual double SAL_CALL getDouble( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getBytes( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::util::Date SAL_CALL getDate( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::util::Time SAL_CALL getTime( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::util::DateTime SAL_CALL getTimestamp( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getBinaryStream( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getCharacterStream( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Any SAL_CALL getObject( sal_Int32 columnIndex, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRef > SAL_CALL getRef( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XBlob > SAL_CALL getBlob( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XClob > SAL_CALL getClob( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XArray > SAL_CALL getArray( sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);

        virtual sal_Bool SAL_CALL rowUpdated(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL rowInserted(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL rowDeleted(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // ::com::sun::star::sdbc::XResultSet
        virtual sal_Bool SAL_CALL next(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isBeforeFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isAfterLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL isLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL beforeFirst(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL afterLast(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL first(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL last(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Int32 SAL_CALL getRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL absolute( sal_Int32 row ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL relative( sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual sal_Bool SAL_CALL previous(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL refreshRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // ::com::sun::star::sdbcx::XRowLocate
        virtual ::com::sun::star::uno::Any SAL_CALL getBookmark( const ORowSetRow& _rRow ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // -------------------------------------------------------------------------
        virtual sal_Bool SAL_CALL moveToBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // -------------------------------------------------------------------------
        virtual sal_Bool SAL_CALL moveRelativeToBookmark( const ::com::sun::star::uno::Any& bookmark, sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // -------------------------------------------------------------------------
        virtual sal_Int32 SAL_CALL compareBookmarks( const ::com::sun::star::uno::Any& first, const ::com::sun::star::uno::Any& second ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // -------------------------------------------------------------------------
        virtual sal_Bool SAL_CALL hasOrderedBookmarks(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // -------------------------------------------------------------------------
        virtual sal_Int32 SAL_CALL hashBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // -------------------------------------------------------------------------
        // ::com::sun::star::sdbcx::XDeleteRows
        virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL deleteRows( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rows ,const connectivity::OSQLTable& _xTable) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        // ::com::sun::star::sdbc::XResultSetUpdate
        virtual void SAL_CALL updateRow(const ORowSetRow& _rInsertRow,const ORowSetRow& _rOrginalRow,const connectivity::OSQLTable& _xTable   ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL deleteRow(const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable   ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL insertRow( const ORowSetRow& _rInsertRow,const connectivity::OSQLTable& _xTable ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL cancelRowUpdates(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL moveToInsertRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
        virtual void SAL_CALL moveToCurrentRow(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
    };
}
#endif // DBACCESS_CORE_API_KEYSET_HXX

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: adtabdlg.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: oj $ $Date: 2001-02-05 12:31:44 $
 *
 *  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 DBAUI_QYDLGTAB_HXX
#include "adtabdlg.hxx"
#endif
#ifndef DBAUI_ADTABDLG_HRC
#include "adtabdlg.hrc"
#endif
#ifndef _DBAUI_SQLMESSAGE_HXX_
#include "sqlmessage.hxx"
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#include "dbaccess_helpid.hrc"
#ifndef _DBU_RESOURCE_HRC_
#include "dbu_resource.hrc"
#endif
#ifndef _SFXSIDS_HRC
#include <sfx2/sfxsids.hrc>
#endif
#ifndef _DBAUI_MODULE_DBU_HXX_
#include "moduledbu.hxx"
#endif
#ifndef DBAUI_QUERYTABLEVIEW_HXX
#include "QueryTableView.hxx"
#endif
#ifndef DBAUI_QUERYDESIGNVIEW_HXX
#include "QueryDesignView.hxx"
#endif
#ifndef DBAUI_QUERYCONTROLLER_HXX
#include "querycontroller.hxx"
#endif
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
#include <connectivity/dbtools.hxx>
#endif
#ifndef DBACCESS_UI_BROWSER_ID_HXX
#include "browserids.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XViewsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif

// slot ids
using namespace dbaui;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace dbtools;

DBG_NAME(OAddTableDlg);
//------------------------------------------------------------------------------
OAddTableDlg::OAddTableDlg( Window* pParent)
             :ModelessDialog( pParent, ModuleRes(DLG_JOIN_TABADD) )
             ,aFTTable( this, ResId( FT_TABLE ) )
             ,aTableList( this, ResId( LB_TABLE ) )
             ,aAddButton( this, ResId( PB_ADDTABLE ) )
             ,aCloseButton( this, ResId( PB_CLOSE ) )
             ,aHelpButton( this, ResId( PB_HELP ) )
             ,aGroupBoxTable( this, ResId( GB_TABLE ) )
             ,aDefaultString( ResId( STR_DEFAULT ) )
{
    DBG_CTOR(OAddTableDlg,NULL);
    m_pTableView = static_cast<OQueryTableView*>(pParent);
    // der Close-Button hat schon einen Standard-Help-Text, den ich aber hier nicht haben moechte, also den Text ruecksetzen
    // und eine neue ID verteilen
    aCloseButton.SetHelpText(String());
    aCloseButton.SetHelpId(HID_JOINSH_ADDTAB_CLOSE);

    aTableList.SetHelpId(HID_JOINSH_ADDTAB_TABLELIST);

    //////////////////////////////////////////////////////////////////////
    // Handler setzen
    aAddButton.SetClickHdl( LINK(this,OAddTableDlg, AddClickHdl) );
    aCloseButton.SetClickHdl( LINK(this,OAddTableDlg, CloseClickHdl) );
    aTableList.SetDoubleClickHdl( LINK(this,OAddTableDlg, TableListDoubleClickHdl) );

    aTableList.EnableInplaceEditing( FALSE );
    aTableList.SetWindowBits(WB_BORDER | WB_HASLINES |WB_HASBUTTONS | WB_HASBUTTONSATROOT | WB_HASLINESATROOT | WB_SORT | WB_HSCROLL );
    aTableList.EnableCheckButton( NULL ); // do not show any buttons
    aTableList.SetSelectionMode( SINGLE_SELECTION );

    FreeResource();
}

//------------------------------------------------------------------------------
OAddTableDlg::~OAddTableDlg()
{
    DBG_DTOR(OAddTableDlg,NULL);
}

//------------------------------------------------------------------------------
void OAddTableDlg::Update()
{
//  if (m_pShellAttachedTo == pNewShell)
//      return;
//
//  m_pShellAttachedTo = pNewShell;
//  if (m_pShellAttachedTo)
//  {
//      xDatabase = m_pShellAttachedTo->GetDocShell()->GetJoinDocDatabase();
    UpdateTableList(sal_True);
//  }

    //DetermineAddTable();
}

//------------------------------------------------------------------------------
void OAddTableDlg::AddTable()
{
    //////////////////////////////////////////////////////////////////
    // Tabelle hinzufuegen
    SvLBoxEntry* pEntry = aTableList.FirstSelected();
    if( pEntry && !aTableList.GetModel()->HasChilds(pEntry))
    {
        ::rtl::OUString aCatalog,aSchema,aTableName;
        SvLBoxEntry* pSchema = aTableList.GetParent(pEntry);
        if(pSchema)
        {
            SvLBoxEntry* pCatalog = aTableList.GetParent(pSchema);
            if(pCatalog)
                aCatalog = aTableList.GetEntryText(pCatalog);
            aSchema = aTableList.GetEntryText(pSchema);
        }
        aTableName = aTableList.GetEntryText(pEntry);

        // den Datenbank-Namen besorgen

        ::rtl::OUString aComposedName;
        ::dbtools::composeTableName(m_pTableView->getDesignView()->getController()->getConnection()->getMetaData(),
                                    aCatalog,aSchema,aTableName,aComposedName,sal_False);
        // aOrigTableName is used because AddTabWin would like to have this
        // und das Ganze dem Container uebergeben
        m_pTableView->AddTabWin( aComposedName,aTableName, TRUE );
    }
}

//------------------------------------------------------------------------------
IMPL_LINK( OAddTableDlg, AddClickHdl, Button*, pButton )
{
    if (IsAddAllowed())
        AddTable();

    if (!IsAddAllowed())
        Close();

    return 0;
}

//------------------------------------------------------------------------------
IMPL_LINK( OAddTableDlg, TableListDoubleClickHdl, ListBox *, pListBox )
{
    if (IsAddAllowed())
        AddTable();

    if (!IsAddAllowed())
        Close();

    return 0;
}

//------------------------------------------------------------------------------
IMPL_LINK( OAddTableDlg, CloseClickHdl, Button*, pButton )
{
    return Close();
}

//------------------------------------------------------------------------------
BOOL OAddTableDlg::Close()
{
    m_pTableView->getDesignView()->getController()->InvalidateFeature(ID_BROWSER_ADDTABLE);
    return ModelessDialog::Close();
}

//------------------------------------------------------------------------------
BOOL OAddTableDlg::IsAddAllowed()
{
    return  m_pTableView && m_pTableView->IsAddAllowed();
}

//------------------------------------------------------------------------------
void OAddTableDlg::UpdateTableList(BOOL bViewsAllowed)
{
    //////////////////////////////////////////////////////////////////////
    // Datenbank- und Tabellennamen setzen
    Reference< XTablesSupplier > xTableSupp(m_pTableView->getDesignView()->getController()->getConnection(),UNO_QUERY);
    Reference< XViewsSupplier > xViewSupp;
    Reference< XNameAccess > xTables, xViews;

    xTables = xTableSupp->getTables();

    // get the views supplier and the views
    xViewSupp = Reference< XViewsSupplier >(xTableSupp, UNO_QUERY);
    if (xViewSupp.is())
        xViews = xViewSupp->getViews();

    Sequence< ::rtl::OUString> sTables,sViews;
    if (xTables.is())
        sTables = xTables->getElementNames();
    if (xViews.is())
        sViews = xViews->getElementNames();

    aTableList.UpdateTableList(Reference< XConnection>(xTableSupp,UNO_QUERY)->getMetaData(),sTables,sViews);
/*
    //////////////////////////////////////////////////////////////////////
    // Ersten Eintrag selektieren
    if( aTableList.GetEntryCount() )
        aTableList.SelectEntryPos( 0 );
*/
}
<commit_msg>table tree got new ctor<commit_after>/*************************************************************************
 *
 *  $RCSfile: adtabdlg.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: oj $ $Date: 2001-02-05 14:45:38 $
 *
 *  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 DBAUI_QYDLGTAB_HXX
#include "adtabdlg.hxx"
#endif
#ifndef DBAUI_ADTABDLG_HRC
#include "adtabdlg.hrc"
#endif
#ifndef _DBAUI_SQLMESSAGE_HXX_
#include "sqlmessage.hxx"
#endif
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#include "dbaccess_helpid.hrc"
#ifndef _DBU_RESOURCE_HRC_
#include "dbu_resource.hrc"
#endif
#ifndef _SFXSIDS_HRC
#include <sfx2/sfxsids.hrc>
#endif
#ifndef _DBAUI_MODULE_DBU_HXX_
#include "moduledbu.hxx"
#endif
#ifndef DBAUI_QUERYTABLEVIEW_HXX
#include "QueryTableView.hxx"
#endif
#ifndef DBAUI_QUERYDESIGNVIEW_HXX
#include "QueryDesignView.hxx"
#endif
#ifndef DBAUI_QUERYCONTROLLER_HXX
#include "querycontroller.hxx"
#endif
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
#include <connectivity/dbtools.hxx>
#endif
#ifndef DBACCESS_UI_BROWSER_ID_HXX
#include "browserids.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBCX_XVIEWSSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XViewsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif

// slot ids
using namespace dbaui;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace dbtools;

DBG_NAME(OAddTableDlg);
//------------------------------------------------------------------------------
OAddTableDlg::OAddTableDlg( Window* pParent)
             :ModelessDialog( pParent, ModuleRes(DLG_JOIN_TABADD) )
             ,aFTTable( this, ResId( FT_TABLE ) )
             ,aTableList( this, ResId( LB_TABLE ),sal_False )
             ,aAddButton( this, ResId( PB_ADDTABLE ) )
             ,aCloseButton( this, ResId( PB_CLOSE ) )
             ,aHelpButton( this, ResId( PB_HELP ) )
             ,aGroupBoxTable( this, ResId( GB_TABLE ) )
             ,aDefaultString( ResId( STR_DEFAULT ) )
{
    DBG_CTOR(OAddTableDlg,NULL);
    m_pTableView = static_cast<OQueryTableView*>(pParent);
    // der Close-Button hat schon einen Standard-Help-Text, den ich aber hier nicht haben moechte, also den Text ruecksetzen
    // und eine neue ID verteilen
    aCloseButton.SetHelpText(String());
    aCloseButton.SetHelpId(HID_JOINSH_ADDTAB_CLOSE);

    aTableList.SetHelpId(HID_JOINSH_ADDTAB_TABLELIST);

    //////////////////////////////////////////////////////////////////////
    // Handler setzen
    aAddButton.SetClickHdl( LINK(this,OAddTableDlg, AddClickHdl) );
    aCloseButton.SetClickHdl( LINK(this,OAddTableDlg, CloseClickHdl) );
    aTableList.SetDoubleClickHdl( LINK(this,OAddTableDlg, TableListDoubleClickHdl) );

    aTableList.EnableInplaceEditing( FALSE );
    aTableList.SetWindowBits(WB_BORDER | WB_HASLINES |WB_HASBUTTONS | WB_HASBUTTONSATROOT | WB_HASLINESATROOT | WB_SORT | WB_HSCROLL );
    aTableList.EnableCheckButton( NULL ); // do not show any buttons
    aTableList.SetSelectionMode( SINGLE_SELECTION );

    FreeResource();
}

//------------------------------------------------------------------------------
OAddTableDlg::~OAddTableDlg()
{
    DBG_DTOR(OAddTableDlg,NULL);
}

//------------------------------------------------------------------------------
void OAddTableDlg::Update()
{
//  if (m_pShellAttachedTo == pNewShell)
//      return;
//
//  m_pShellAttachedTo = pNewShell;
//  if (m_pShellAttachedTo)
//  {
//      xDatabase = m_pShellAttachedTo->GetDocShell()->GetJoinDocDatabase();
    UpdateTableList(sal_True);
//  }

    //DetermineAddTable();
}

//------------------------------------------------------------------------------
void OAddTableDlg::AddTable()
{
    //////////////////////////////////////////////////////////////////
    // Tabelle hinzufuegen
    SvLBoxEntry* pEntry = aTableList.FirstSelected();
    if( pEntry && !aTableList.GetModel()->HasChilds(pEntry))
    {
        ::rtl::OUString aCatalog,aSchema,aTableName;
        SvLBoxEntry* pSchema = aTableList.GetParent(pEntry);
        if(pSchema && pSchema != aTableList.getAllObjectsEntry())
        {
            SvLBoxEntry* pCatalog = aTableList.GetParent(pSchema);
            if(pCatalog && pCatalog != aTableList.getAllObjectsEntry())
                aCatalog = aTableList.GetEntryText(pCatalog);
            aSchema = aTableList.GetEntryText(pSchema);
        }
        aTableName = aTableList.GetEntryText(pEntry);

        // den Datenbank-Namen besorgen

        ::rtl::OUString aComposedName;
        ::dbtools::composeTableName(m_pTableView->getDesignView()->getController()->getConnection()->getMetaData(),
                                    aCatalog,aSchema,aTableName,aComposedName,sal_False);
        // aOrigTableName is used because AddTabWin would like to have this
        // und das Ganze dem Container uebergeben
        m_pTableView->AddTabWin( aComposedName,aTableName, TRUE );
    }
}

//------------------------------------------------------------------------------
IMPL_LINK( OAddTableDlg, AddClickHdl, Button*, pButton )
{
    if (IsAddAllowed())
        AddTable();

    if (!IsAddAllowed())
        Close();

    return 0;
}

//------------------------------------------------------------------------------
IMPL_LINK( OAddTableDlg, TableListDoubleClickHdl, ListBox *, pListBox )
{
    if (IsAddAllowed())
        AddTable();

    if (!IsAddAllowed())
        Close();

    return 0;
}

//------------------------------------------------------------------------------
IMPL_LINK( OAddTableDlg, CloseClickHdl, Button*, pButton )
{
    return Close();
}

//------------------------------------------------------------------------------
BOOL OAddTableDlg::Close()
{
    m_pTableView->getDesignView()->getController()->InvalidateFeature(ID_BROWSER_ADDTABLE);
    return ModelessDialog::Close();
}

//------------------------------------------------------------------------------
BOOL OAddTableDlg::IsAddAllowed()
{
    return  m_pTableView && m_pTableView->IsAddAllowed();
}

//------------------------------------------------------------------------------
void OAddTableDlg::UpdateTableList(BOOL bViewsAllowed)
{
    //////////////////////////////////////////////////////////////////////
    // Datenbank- und Tabellennamen setzen
    Reference< XTablesSupplier > xTableSupp(m_pTableView->getDesignView()->getController()->getConnection(),UNO_QUERY);
    Reference< XViewsSupplier > xViewSupp;
    Reference< XNameAccess > xTables, xViews;

    xTables = xTableSupp->getTables();

    // get the views supplier and the views
    xViewSupp = Reference< XViewsSupplier >(xTableSupp, UNO_QUERY);
    if (xViewSupp.is())
        xViews = xViewSupp->getViews();

    Sequence< ::rtl::OUString> sTables,sViews;
    if (xTables.is())
        sTables = xTables->getElementNames();
    if (xViews.is())
        sViews = xViews->getElementNames();

    aTableList.UpdateTableList(Reference< XConnection>(xTableSupp,UNO_QUERY)->getMetaData(),sTables,sViews);
/*
    //////////////////////////////////////////////////////////////////////
    // Ersten Eintrag selektieren
    if( aTableList.GetEntryCount() )
        aTableList.SelectEntryPos( 0 );
*/
}
<|endoftext|>


<commit_before><commit_msg>Code for wxWidgets did not compile so removing.<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: dsselect.cxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: rt $ $Date: 2004-11-26 18:19:18 $
 *
 *  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 EXPRESS 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 _DBAUI_ODBC_CONFIG_HXX_
#include "odbcconfig.hxx"
#endif

#ifndef _DBAUI_DSSELECT_HXX_
#include "dsselect.hxx"
#endif
#ifndef _DBAUI_DSSELECT_HRC_
#include "dsselect.hrc"
#endif
#ifndef _DBAUI_MODULE_DBU_HXX_
#include "moduledbu.hxx"
#endif
#ifndef _DBU_DLG_HRC_
#include "dbu_dlg.hrc"
#endif
#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#ifndef _DBAUI_LOCALRESACCESS_HXX_
#include "localresaccess.hxx"
#endif
#ifndef _TOOLS_RCID_H
#include <tools/rcid.h>
#endif

#if defined( WIN ) || defined( WNT )
#define HWND    void*
#define HMENU   void*
typedef void*               HDC;
    // was unable to include windows.h, that's why this direct define
#endif
#ifndef _SV_SYSDATA_HXX
#include <vcl/sysdata.hxx>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XCREATECATALOG_HPP_
#include <com/sun/star/sdbcx/XCreateCatalog.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_XEXECUTABLEDIALOG_HPP_
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
#include <com/sun/star/awt/XWindow.hpp>
#endif
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
#include "dbustrings.hrc"
#endif
#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
#include <toolkit/helper/vclunohelper.hxx>
#endif
#ifndef _COMPHELPER_EXTRACT_HXX_
#include <comphelper/extract.hxx>
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
#include <comphelper/processfactory.hxx>
#endif
#ifndef _DBAUI_DATASOURCEITEMS_HXX_
#include "dsitems.hxx"
#endif
#ifndef _SFXSTRITEM_HXX
#include <svtools/stritem.hxx>
#endif
#ifndef _SFXINTITEM_HXX
#include <svtools/intitem.hxx>
#endif
#ifndef _SFXITEMSET_HXX
#include <svtools/itemset.hxx>
#endif

//.........................................................................
namespace dbaui
{
//.........................................................................
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::comphelper;
//==================================================================
ODatasourceSelectDialog::ODatasourceSelectDialog(Window* _pParent, const StringBag& _rDatasources, DATASOURCE_TYPE _eType,SfxItemSet* _pOutputSet)
     :ModalDialog(_pParent, ModuleRes(DLG_DATASOURCE_SELECTION))
     ,m_aDescription        (this, ResId(FT_DESCRIPTION))
     ,m_aDatasource         (this, ResId(LB_DATASOURCE))
     ,m_aOk                 (this, ResId(PB_OK))
     ,m_aCancel             (this, ResId(PB_CANCEL))
     ,m_aHelp               (this, ResId(PB_HELP))
     ,m_aManageDatasources  (this, ResId(PB_MANAGE))
     ,m_aCreateAdabasDB     (this, ResId(PB_CREATE))
     ,m_pOutputSet(_pOutputSet)
{
    if (DST_ADABAS == _eType)
    {   // set a new title (indicating that we're browsing local data sources only)
        SetText(ResId(STR_LOCAL_DATASOURCES));
        m_aDescription.SetText(ResId(STR_DESCRIPTION2));

        m_aCreateAdabasDB.Show();
        m_aCreateAdabasDB.SetClickHdl(LINK(this,ODatasourceSelectDialog,CreateDBClickHdl));

        // resize the dialog a little bit, 'cause Adabas data source names are usually somewhat shorter
        // than ODBC ones are

        // shrink the listbox
        Size aOldSize = m_aDatasource.GetSizePixel();
        Size aNewSize(3 * aOldSize.Width() / 4, aOldSize.Height());
        m_aDatasource.SetSizePixel(aNewSize);

        sal_Int32 nLostPixels = aOldSize.Width() - aNewSize.Width();

        // shrink the fixed text
        aOldSize = m_aDescription.GetSizePixel();
        m_aDescription.SetSizePixel(Size(aOldSize.Width() - nLostPixels, aOldSize.Height()));

        // move the buttons
        PushButton* pButtons[] = { &m_aOk, &m_aCancel, &m_aHelp ,&m_aCreateAdabasDB};
        for (sal_Int32 i=0; i<sizeof(pButtons)/sizeof(pButtons[0]); ++i)
        {
            Point aOldPos = pButtons[i]->GetPosPixel();
            pButtons[i]->SetPosPixel(Point(aOldPos.X() - nLostPixels, aOldPos.Y()));
        }

        // resize the dialog itself
        aOldSize = GetSizePixel();
        SetSizePixel(Size(aOldSize.Width() - nLostPixels, aOldSize.Height()));
    }

    fillListBox(_rDatasources);

    // allow ODBC datasource managenment
    if ( DST_ODBC == _eType || DST_MYSQL_ODBC == _eType )
    {
        m_aManageDatasources.Show();
        m_aManageDatasources.Enable();
        m_aManageDatasources.SetClickHdl(LINK(this,ODatasourceSelectDialog,ManageClickHdl));
    }

    m_aDatasource.SetDoubleClickHdl(LINK(this,ODatasourceSelectDialog,ListDblClickHdl));
    FreeResource();
}

// -----------------------------------------------------------------------
IMPL_LINK( ODatasourceSelectDialog, ListDblClickHdl, ListBox *, pListBox )
{
    if (pListBox->GetSelectEntryCount())
        EndDialog(RET_OK);
    return 0;
}
// -----------------------------------------------------------------------
IMPL_LINK( ODatasourceSelectDialog, CreateDBClickHdl, PushButton*, pButton )
{
    try
    {
        OSL_ENSURE(m_pOutputSet,"No itemset given!");
        Reference< ::com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
        Reference<XCreateCatalog> xCatalog(xORB->createInstance(SERVICE_EXTENDED_ADABAS_DRIVER),UNO_QUERY);
        if ( xCatalog.is() && m_pOutputSet )
        {
            Sequence< Any > aArgs(2);
            aArgs[0] <<= PropertyValue(::rtl::OUString::createFromAscii("CreateCatalog"), 0,makeAny(xCatalog) , PropertyState_DIRECT_VALUE);
            aArgs[1] <<= PropertyValue(PROPERTY_PARENTWINDOW, 0, makeAny(VCLUnoHelper::GetInterface(this)), PropertyState_DIRECT_VALUE);

            Reference< XExecutableDialog > xDialog(
                xORB->createInstanceWithArguments(SERVICE_SDB_ADABASCREATIONDIALOG, aArgs), UNO_QUERY);
            if (!xDialog.is())
            {
                //  ShowServiceNotAvailableError(this, String(SERVICE_SDB_ADABASCREATIONDIALOG), sal_True);
                return 0L;
            }

            if ( xDialog->execute() == RET_OK )
            {
                Reference<XPropertySet> xProp(xDialog,UNO_QUERY);
                if(xProp.is())
                {
                    Reference<XPropertySetInfo> xPropInfo(xProp->getPropertySetInfo());
                    if(xPropInfo->hasPropertyByName(PROPERTY_DATABASENAME))
                    {
                        String sDatabaseName;
                        sDatabaseName = String(::comphelper::getString(xProp->getPropertyValue(PROPERTY_DATABASENAME)));
                        m_aDatasource.SelectEntry(m_aDatasource.InsertEntry( sDatabaseName ));

                    }
                    if ( xPropInfo->hasPropertyByName(PROPERTY_CONTROLUSER) )
                        m_pOutputSet->Put(SfxStringItem(DSID_CONN_CTRLUSER, ::comphelper::getString(xProp->getPropertyValue(PROPERTY_CONTROLUSER))));
                    if ( xPropInfo->hasPropertyByName(PROPERTY_CONTROLPASSWORD) )
                        m_pOutputSet->Put(SfxStringItem(DSID_CONN_CTRLPWD, ::comphelper::getString(xProp->getPropertyValue(PROPERTY_CONTROLPASSWORD))));
                    if ( xPropInfo->hasPropertyByName(PROPERTY_USER) )
                        m_pOutputSet->Put(SfxStringItem(DSID_USER, ::comphelper::getString(xProp->getPropertyValue(PROPERTY_USER))));
                    if ( xPropInfo->hasPropertyByName(PROPERTY_PASSWORD) )
                        m_pOutputSet->Put(SfxStringItem(DSID_PASSWORD, ::comphelper::getString(xProp->getPropertyValue(PROPERTY_PASSWORD))));
                    if ( xPropInfo->hasPropertyByName(PROPERTY_CACHESIZE) )
                        m_pOutputSet->Put(SfxInt32Item(DSID_CONN_CACHESIZE, ::comphelper::getINT32(xProp->getPropertyValue(PROPERTY_CACHESIZE))));
                }
            }
        }
    }
    catch(Exception&)
    {
    }
    return 0L;
}
// -----------------------------------------------------------------------
IMPL_LINK( ODatasourceSelectDialog, ManageClickHdl, PushButton*, pButton )
{
    OOdbcManagement aOdbcConfig;
#ifdef HAVE_ODBC_ADMINISTRATION
    if (!aOdbcConfig.isLoaded())
    {
#endif
        // show an error message
        OLocalResourceAccess aLocRes(DLG_DATASOURCE_SELECTION, RSC_MODALDIALOG);
        String sError(ModuleRes(STR_COULDNOTLOAD_CONFIGLIB));
        sError.SearchAndReplaceAscii("#lib#", aOdbcConfig.getLibraryName());
        ErrorBox aDialog(this, WB_OK, sError);
        aDialog.Execute();
        m_aDatasource.GrabFocus();
        m_aManageDatasources.Disable();
        return 1L;
#ifdef HAVE_ODBC_ADMINISTRATION
    }

    aOdbcConfig.manageDataSources(GetSystemData()->hWnd);
    // now we have to look if there are any new datasources added
    StringBag aOdbcDatasources;
    OOdbcEnumeration aEnumeration;
    aEnumeration.getDatasourceNames(aOdbcDatasources);
    fillListBox(aOdbcDatasources);

    return 0L;
#endif
}
// -----------------------------------------------------------------------------
void ODatasourceSelectDialog::fillListBox(const StringBag& _rDatasources)
{
    m_aDatasource.Clear();
    // fill the list
    for (   ConstStringBagIterator aDS = _rDatasources.begin();
            aDS != _rDatasources.end();
            ++aDS
        )
    {
        m_aDatasource.InsertEntry( *aDS );
    }

    // select the first entry
    if (m_aDatasource.GetEntryCount())
        m_aDatasource.SelectEntryPos(0);
}

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

<commit_msg>INTEGRATION: CWS dba20 (1.8.56); FILE MERGED 2004/12/13 13:24:00 oj 1.8.56.3: RESYNC: (1.9-1.10); FILE MERGED 2004/11/29 09:30:54 oj 1.8.56.2: RESYNC: (1.8-1.9); FILE MERGED 2004/11/22 14:52:57 oj 1.8.56.1: #i36777# disable manage button under sol and linux<commit_after>/*************************************************************************
 *
 *  $RCSfile: dsselect.cxx,v $
 *
 *  $Revision: 1.11 $
 *
 *  last change: $Author: obo $ $Date: 2005-01-05 12:35:17 $
 *
 *  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 EXPRESS 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 _DBAUI_ODBC_CONFIG_HXX_
#include "odbcconfig.hxx"
#endif

#ifndef _DBAUI_DSSELECT_HXX_
#include "dsselect.hxx"
#endif
#ifndef _DBAUI_DSSELECT_HRC_
#include "dsselect.hrc"
#endif
#ifndef _DBAUI_MODULE_DBU_HXX_
#include "moduledbu.hxx"
#endif
#ifndef _DBU_DLG_HRC_
#include "dbu_dlg.hrc"
#endif
#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#ifndef _DBAUI_LOCALRESACCESS_HXX_
#include "localresaccess.hxx"
#endif
#ifndef _TOOLS_RCID_H
#include <tools/rcid.h>
#endif

#if defined( WIN ) || defined( WNT )
#define HWND    void*
#define HMENU   void*
typedef void*               HDC;
    // was unable to include windows.h, that's why this direct define
#endif
#ifndef _SV_SYSDATA_HXX
#include <vcl/sysdata.hxx>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XCREATECATALOG_HPP_
#include <com/sun/star/sdbcx/XCreateCatalog.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_XEXECUTABLEDIALOG_HPP_
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
#include <com/sun/star/awt/XWindow.hpp>
#endif
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
#include "dbustrings.hrc"
#endif
#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
#include <toolkit/helper/vclunohelper.hxx>
#endif
#ifndef _COMPHELPER_EXTRACT_HXX_
#include <comphelper/extract.hxx>
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
#include <comphelper/processfactory.hxx>
#endif
#ifndef _DBAUI_DATASOURCEITEMS_HXX_
#include "dsitems.hxx"
#endif
#ifndef _SFXSTRITEM_HXX
#include <svtools/stritem.hxx>
#endif
#ifndef _SFXINTITEM_HXX
#include <svtools/intitem.hxx>
#endif
#ifndef _SFXITEMSET_HXX
#include <svtools/itemset.hxx>
#endif

//.........................................................................
namespace dbaui
{
//.........................................................................
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::comphelper;
//==================================================================
ODatasourceSelectDialog::ODatasourceSelectDialog(Window* _pParent, const StringBag& _rDatasources, DATASOURCE_TYPE _eType,SfxItemSet* _pOutputSet)
     :ModalDialog(_pParent, ModuleRes(DLG_DATASOURCE_SELECTION))
     ,m_aDescription        (this, ResId(FT_DESCRIPTION))
     ,m_aDatasource         (this, ResId(LB_DATASOURCE))
     ,m_aOk                 (this, ResId(PB_OK))
     ,m_aCancel             (this, ResId(PB_CANCEL))
     ,m_aHelp               (this, ResId(PB_HELP))
     ,m_aManageDatasources  (this, ResId(PB_MANAGE))
     ,m_aCreateAdabasDB     (this, ResId(PB_CREATE))
     ,m_pOutputSet(_pOutputSet)
{
    if (DST_ADABAS == _eType)
    {   // set a new title (indicating that we're browsing local data sources only)
        SetText(ResId(STR_LOCAL_DATASOURCES));
        m_aDescription.SetText(ResId(STR_DESCRIPTION2));

        m_aCreateAdabasDB.Show();
        m_aCreateAdabasDB.SetClickHdl(LINK(this,ODatasourceSelectDialog,CreateDBClickHdl));

        // resize the dialog a little bit, 'cause Adabas data source names are usually somewhat shorter
        // than ODBC ones are

        // shrink the listbox
        Size aOldSize = m_aDatasource.GetSizePixel();
        Size aNewSize(3 * aOldSize.Width() / 4, aOldSize.Height());
        m_aDatasource.SetSizePixel(aNewSize);

        sal_Int32 nLostPixels = aOldSize.Width() - aNewSize.Width();

        // shrink the fixed text
        aOldSize = m_aDescription.GetSizePixel();
        m_aDescription.SetSizePixel(Size(aOldSize.Width() - nLostPixels, aOldSize.Height()));

        // move the buttons
        PushButton* pButtons[] = { &m_aOk, &m_aCancel, &m_aHelp ,&m_aCreateAdabasDB};
        for (sal_Int32 i=0; i<sizeof(pButtons)/sizeof(pButtons[0]); ++i)
        {
            Point aOldPos = pButtons[i]->GetPosPixel();
            pButtons[i]->SetPosPixel(Point(aOldPos.X() - nLostPixels, aOldPos.Y()));
        }

        // resize the dialog itself
        aOldSize = GetSizePixel();
        SetSizePixel(Size(aOldSize.Width() - nLostPixels, aOldSize.Height()));
    }

    fillListBox(_rDatasources);
#ifdef HAVE_ODBC_ADMINISTRATION
    // allow ODBC datasource managenment
    if ( DST_ODBC == _eType || DST_MYSQL_ODBC == _eType )
    {
        m_aManageDatasources.Show();
        m_aManageDatasources.Enable();
        m_aManageDatasources.SetClickHdl(LINK(this,ODatasourceSelectDialog,ManageClickHdl));
    }
#endif
    m_aDatasource.SetDoubleClickHdl(LINK(this,ODatasourceSelectDialog,ListDblClickHdl));
    FreeResource();
}

// -----------------------------------------------------------------------
IMPL_LINK( ODatasourceSelectDialog, ListDblClickHdl, ListBox *, pListBox )
{
    if (pListBox->GetSelectEntryCount())
        EndDialog(RET_OK);
    return 0;
}
// -----------------------------------------------------------------------
IMPL_LINK( ODatasourceSelectDialog, CreateDBClickHdl, PushButton*, pButton )
{
    try
    {
        OSL_ENSURE(m_pOutputSet,"No itemset given!");
        Reference< ::com::sun::star::lang::XMultiServiceFactory > xORB = ::comphelper::getProcessServiceFactory();
        Reference<XCreateCatalog> xCatalog(xORB->createInstance(SERVICE_EXTENDED_ADABAS_DRIVER),UNO_QUERY);
        if ( xCatalog.is() && m_pOutputSet )
        {
            Sequence< Any > aArgs(2);
            aArgs[0] <<= PropertyValue(::rtl::OUString::createFromAscii("CreateCatalog"), 0,makeAny(xCatalog) , PropertyState_DIRECT_VALUE);
            aArgs[1] <<= PropertyValue(PROPERTY_PARENTWINDOW, 0, makeAny(VCLUnoHelper::GetInterface(this)), PropertyState_DIRECT_VALUE);

            Reference< XExecutableDialog > xDialog(
                xORB->createInstanceWithArguments(SERVICE_SDB_ADABASCREATIONDIALOG, aArgs), UNO_QUERY);
            if (!xDialog.is())
            {
                //  ShowServiceNotAvailableError(this, String(SERVICE_SDB_ADABASCREATIONDIALOG), sal_True);
                return 0L;
            }

            if ( xDialog->execute() == RET_OK )
            {
                Reference<XPropertySet> xProp(xDialog,UNO_QUERY);
                if(xProp.is())
                {
                    Reference<XPropertySetInfo> xPropInfo(xProp->getPropertySetInfo());
                    if(xPropInfo->hasPropertyByName(PROPERTY_DATABASENAME))
                    {
                        String sDatabaseName;
                        sDatabaseName = String(::comphelper::getString(xProp->getPropertyValue(PROPERTY_DATABASENAME)));
                        m_aDatasource.SelectEntry(m_aDatasource.InsertEntry( sDatabaseName ));

                    }
                    if ( xPropInfo->hasPropertyByName(PROPERTY_CONTROLUSER) )
                        m_pOutputSet->Put(SfxStringItem(DSID_CONN_CTRLUSER, ::comphelper::getString(xProp->getPropertyValue(PROPERTY_CONTROLUSER))));
                    if ( xPropInfo->hasPropertyByName(PROPERTY_CONTROLPASSWORD) )
                        m_pOutputSet->Put(SfxStringItem(DSID_CONN_CTRLPWD, ::comphelper::getString(xProp->getPropertyValue(PROPERTY_CONTROLPASSWORD))));
                    if ( xPropInfo->hasPropertyByName(PROPERTY_USER) )
                        m_pOutputSet->Put(SfxStringItem(DSID_USER, ::comphelper::getString(xProp->getPropertyValue(PROPERTY_USER))));
                    if ( xPropInfo->hasPropertyByName(PROPERTY_PASSWORD) )
                        m_pOutputSet->Put(SfxStringItem(DSID_PASSWORD, ::comphelper::getString(xProp->getPropertyValue(PROPERTY_PASSWORD))));
                    if ( xPropInfo->hasPropertyByName(PROPERTY_CACHESIZE) )
                        m_pOutputSet->Put(SfxInt32Item(DSID_CONN_CACHESIZE, ::comphelper::getINT32(xProp->getPropertyValue(PROPERTY_CACHESIZE))));
                }
            }
        }
    }
    catch(Exception&)
    {
    }
    return 0L;
}
// -----------------------------------------------------------------------
#ifdef HAVE_ODBC_ADMINISTRATION
IMPL_LINK( ODatasourceSelectDialog, ManageClickHdl, PushButton*, pButton )
{
    OOdbcManagement aOdbcConfig;
    if (!aOdbcConfig.isLoaded())
    {
        // show an error message
        OLocalResourceAccess aLocRes(DLG_DATASOURCE_SELECTION, RSC_MODALDIALOG);
        String sError(ModuleRes(STR_COULDNOTLOAD_CONFIGLIB));
        sError.SearchAndReplaceAscii("#lib#", aOdbcConfig.getLibraryName());
        ErrorBox aDialog(this, WB_OK, sError);
        aDialog.Execute();
        m_aDatasource.GrabFocus();
        m_aManageDatasources.Disable();
        return 1L;
    }

    aOdbcConfig.manageDataSources(GetSystemData()->hWnd);
    // now we have to look if there are any new datasources added
    StringBag aOdbcDatasources;
    OOdbcEnumeration aEnumeration;
    aEnumeration.getDatasourceNames(aOdbcDatasources);
    fillListBox(aOdbcDatasources);

    return 0L;
}
#endif
// -----------------------------------------------------------------------------
void ODatasourceSelectDialog::fillListBox(const StringBag& _rDatasources)
{
    m_aDatasource.Clear();
    // fill the list
    for (   ConstStringBagIterator aDS = _rDatasources.begin();
            aDS != _rDatasources.end();
            ++aDS
        )
    {
        m_aDatasource.InsertEntry( *aDS );
    }

    // select the first entry
    if (m_aDatasource.GetEntryCount())
        m_aDatasource.SelectEntryPos(0);
}

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

<|endoftext|>


<commit_before>#include "actionlib/client/action_client.h"
#include "control_msgs/FollowJointTrajectoryAction.h"
#include "rapid_pbd/action_names.h"
#include "rapid_pbd/pr2_actions.h"
#include "ros/ros.h"

bool wait_for_server(const actionlib::SimpleActionClient<
    control_msgs::FollowJointTrajectoryAction>& arm) {
  bool success = arm.waitForServer(ros::Duration(5));
  if (!success) {
    ROS_ERROR("Error connecting to arm server");
  }
  return success;
}

int main(int argc, char** argv) {
  ros::init(argc, argv, "pr2_arm_demo");

  actionlib::SimpleActionClient<control_msgs::FollowJointTrajectoryAction>
      left_arm(rapid::pbd::kLeftArmJointActionName, true);
  actionlib::SimpleActionClient<control_msgs::FollowJointTrajectoryAction>
      right_arm(rapid::pbd::kRightArmJointActionName, true);
  if (!wait_for_server(left_arm)) {
    left_arm.cancelAllGoals();
    return 1;
  }
  if (!wait_for_server(right_arm)) {
    right_arm.cancelAllGoals();
    return 1;
  }

  control_msgs::FollowJointTrajectoryGoal left_goal;
  left_goal.trajectory.header.stamp = ros::Time::now() + ros::Duration(0.1);
  left_goal.trajectory.joint_names.push_back("l_shoulder_pan_joint");
  left_goal.trajectory.joint_names.push_back("l_shoulder_lift_joint");
  left_goal.trajectory.joint_names.push_back("l_upper_arm_roll_joint");
  left_goal.trajectory.joint_names.push_back("l_elbow_flex_joint");
  left_goal.trajectory.joint_names.push_back("l_forearm_roll_joint");
  left_goal.trajectory.joint_names.push_back("l_wrist_flex_joint");
  left_goal.trajectory.joint_names.push_back("l_wrist_roll_joint");
  left_goal.trajectory.points.resize(1);
  left_goal.trajectory.points[0].positions.resize(7);
  left_goal.trajectory.points[0].positions[0] = 0;
  left_goal.trajectory.points[0].positions[1] = 0;
  left_goal.trajectory.points[0].positions[2] = 0;
  left_goal.trajectory.points[0].positions[3] = 0;
  left_goal.trajectory.points[0].positions[4] = 0;
  left_goal.trajectory.points[0].positions[5] = 0;
  left_goal.trajectory.points[0].positions[6] = 0;
  left_goal.trajectory.points[0].time_from_start = ros::Duration(4);
  for (int i = 0; i < 7; ++i) {
    left_goal.trajectory.points[0].velocities.push_back(0);
  }

  control_msgs::FollowJointTrajectoryGoal right_goal;
  right_goal.trajectory.header.stamp = ros::Time::now() + ros::Duration(0.1);
  right_goal.trajectory.joint_names.push_back("r_shoulder_pan_joint");
  right_goal.trajectory.joint_names.push_back("r_shoulder_lift_joint");
  right_goal.trajectory.joint_names.push_back("r_upper_arm_roll_joint");
  right_goal.trajectory.joint_names.push_back("r_elbow_flex_joint");
  right_goal.trajectory.joint_names.push_back("r_forearm_roll_joint");
  right_goal.trajectory.joint_names.push_back("r_wrist_flex_joint");
  right_goal.trajectory.joint_names.push_back("r_wrist_roll_joint");
  right_goal.trajectory.points.resize(1);
  right_goal.trajectory.points[0].positions.resize(7);
  right_goal.trajectory.points[0].positions[0] = 0;
  right_goal.trajectory.points[0].positions[1] = 0;
  right_goal.trajectory.points[0].positions[2] = 0;
  right_goal.trajectory.points[0].positions[3] = 0;
  right_goal.trajectory.points[0].positions[4] = 0;
  right_goal.trajectory.points[0].positions[5] = 0;
  right_goal.trajectory.points[0].positions[6] = 0;
  right_goal.trajectory.points[0].time_from_start = ros::Duration(4);
  for (int i = 0; i < 7; ++i) {
    right_goal.trajectory.points[0].velocities.push_back(0);
  }

  left_arm.sendGoal(left_goal);
  right_arm.sendGoal(right_goal);
  bool l_success = left_arm.waitForResult(ros::Duration(5));
  bool r_success = right_arm.waitForResult(ros::Duration(5));
  if (!l_success) {
    ROS_ERROR("Left arm failed!");
  }
  if (!r_success) {
    ROS_ERROR("Right arm failed!");
  }

  control_msgs::FollowJointTrajectoryGoal left_goal2;
  left_goal2.trajectory.header.stamp = ros::Time::now() + ros::Duration(0.1);
  left_goal2.trajectory.joint_names.push_back("l_shoulder_pan_joint");
  left_goal2.trajectory.joint_names.push_back("l_shoulder_lift_joint");
  left_goal2.trajectory.joint_names.push_back("l_upper_arm_roll_joint");
  left_goal2.trajectory.joint_names.push_back("l_elbow_flex_joint");
  left_goal2.trajectory.joint_names.push_back("l_forearm_roll_joint");
  left_goal2.trajectory.joint_names.push_back("l_wrist_flex_joint");
  left_goal2.trajectory.joint_names.push_back("l_wrist_roll_joint");
  left_goal2.trajectory.points.resize(1);
  left_goal2.trajectory.points[0].positions.resize(7);
  left_goal2.trajectory.points[0].positions[0] = -0.3;
  left_goal2.trajectory.points[0].positions[1] = 0.2;
  left_goal2.trajectory.points[0].positions[2] = -0.1;
  left_goal2.trajectory.points[0].positions[3] = -1.2;
  left_goal2.trajectory.points[0].positions[4] = 1.5;
  left_goal2.trajectory.points[0].positions[5] = -0.3;
  left_goal2.trajectory.points[0].positions[6] = 0.5;
  left_goal2.trajectory.points[0].time_from_start = ros::Duration(4);
  for (int i = 0; i < 7; ++i) {
    left_goal2.trajectory.points[0].velocities.push_back(0);
  }

  control_msgs::FollowJointTrajectoryGoal right_goal2;
  right_goal2.trajectory.header.stamp = ros::Time::now() + ros::Duration(0.1);
  right_goal2.trajectory.joint_names.push_back("r_shoulder_pan_joint");
  right_goal2.trajectory.joint_names.push_back("r_shoulder_lift_joint");
  right_goal2.trajectory.joint_names.push_back("r_upper_arm_roll_joint");
  right_goal2.trajectory.joint_names.push_back("r_elbow_flex_joint");
  right_goal2.trajectory.joint_names.push_back("r_forearm_roll_joint");
  right_goal2.trajectory.joint_names.push_back("r_wrist_flex_joint");
  right_goal2.trajectory.joint_names.push_back("r_wrist_roll_joint");
  right_goal2.trajectory.points.resize(1);
  right_goal2.trajectory.points[0].positions.resize(7);
  right_goal2.trajectory.points[0].positions[0] = -1.3;
  right_goal2.trajectory.points[0].positions[1] = -0.04;
  right_goal2.trajectory.points[0].positions[2] = -1.4;
  right_goal2.trajectory.points[0].positions[3] = -1.2;
  right_goal2.trajectory.points[0].positions[4] = -1.78;
  right_goal2.trajectory.points[0].positions[5] = -1.64;
  right_goal2.trajectory.points[0].positions[6] = -7.59;
  right_goal2.trajectory.points[0].time_from_start = ros::Duration(4);
  for (int i = 0; i < 7; ++i) {
    right_goal2.trajectory.points[0].velocities.push_back(0);
  }

  left_arm.sendGoal(left_goal2);
  right_arm.sendGoal(right_goal2);
  l_success = left_arm.waitForResult(ros::Duration(5));
  r_success = right_arm.waitForResult(ros::Duration(5));
  if (!l_success) {
    ROS_ERROR("Left arm failed!");
  }
  if (!r_success) {
    ROS_ERROR("Right arm failed!");
  }

  left_arm.cancelAllGoals();
  right_arm.cancelAllGoals();
  ros::spinOnce();
  return 0;
}
<commit_msg>Fixed includes.<commit_after>#include "actionlib/client/simple_action_client.h"
#include "control_msgs/FollowJointTrajectoryAction.h"
#include "rapid_pbd/action_names.h"
#include "ros/ros.h"

bool wait_for_server(const actionlib::SimpleActionClient<
    control_msgs::FollowJointTrajectoryAction>& arm) {
  bool success = arm.waitForServer(ros::Duration(5));
  if (!success) {
    ROS_ERROR("Error connecting to arm server");
  }
  return success;
}

int main(int argc, char** argv) {
  ros::init(argc, argv, "pr2_arm_demo");

  actionlib::SimpleActionClient<control_msgs::FollowJointTrajectoryAction>
      left_arm(rapid::pbd::kLeftArmJointActionName, true);
  actionlib::SimpleActionClient<control_msgs::FollowJointTrajectoryAction>
      right_arm(rapid::pbd::kRightArmJointActionName, true);
  if (!wait_for_server(left_arm)) {
    left_arm.cancelAllGoals();
    return 1;
  }
  if (!wait_for_server(right_arm)) {
    right_arm.cancelAllGoals();
    return 1;
  }

  control_msgs::FollowJointTrajectoryGoal left_goal;
  left_goal.trajectory.header.stamp = ros::Time::now() + ros::Duration(0.1);
  left_goal.trajectory.joint_names.push_back("l_shoulder_pan_joint");
  left_goal.trajectory.joint_names.push_back("l_shoulder_lift_joint");
  left_goal.trajectory.joint_names.push_back("l_upper_arm_roll_joint");
  left_goal.trajectory.joint_names.push_back("l_elbow_flex_joint");
  left_goal.trajectory.joint_names.push_back("l_forearm_roll_joint");
  left_goal.trajectory.joint_names.push_back("l_wrist_flex_joint");
  left_goal.trajectory.joint_names.push_back("l_wrist_roll_joint");
  left_goal.trajectory.points.resize(1);
  left_goal.trajectory.points[0].positions.resize(7);
  left_goal.trajectory.points[0].positions[0] = 0;
  left_goal.trajectory.points[0].positions[1] = 0;
  left_goal.trajectory.points[0].positions[2] = 0;
  left_goal.trajectory.points[0].positions[3] = 0;
  left_goal.trajectory.points[0].positions[4] = 0;
  left_goal.trajectory.points[0].positions[5] = 0;
  left_goal.trajectory.points[0].positions[6] = 0;
  left_goal.trajectory.points[0].time_from_start = ros::Duration(4);
  for (int i = 0; i < 7; ++i) {
    left_goal.trajectory.points[0].velocities.push_back(0);
  }

  control_msgs::FollowJointTrajectoryGoal right_goal;
  right_goal.trajectory.header.stamp = ros::Time::now() + ros::Duration(0.1);
  right_goal.trajectory.joint_names.push_back("r_shoulder_pan_joint");
  right_goal.trajectory.joint_names.push_back("r_shoulder_lift_joint");
  right_goal.trajectory.joint_names.push_back("r_upper_arm_roll_joint");
  right_goal.trajectory.joint_names.push_back("r_elbow_flex_joint");
  right_goal.trajectory.joint_names.push_back("r_forearm_roll_joint");
  right_goal.trajectory.joint_names.push_back("r_wrist_flex_joint");
  right_goal.trajectory.joint_names.push_back("r_wrist_roll_joint");
  right_goal.trajectory.points.resize(1);
  right_goal.trajectory.points[0].positions.resize(7);
  right_goal.trajectory.points[0].positions[0] = 0;
  right_goal.trajectory.points[0].positions[1] = 0;
  right_goal.trajectory.points[0].positions[2] = 0;
  right_goal.trajectory.points[0].positions[3] = 0;
  right_goal.trajectory.points[0].positions[4] = 0;
  right_goal.trajectory.points[0].positions[5] = 0;
  right_goal.trajectory.points[0].positions[6] = 0;
  right_goal.trajectory.points[0].time_from_start = ros::Duration(4);
  for (int i = 0; i < 7; ++i) {
    right_goal.trajectory.points[0].velocities.push_back(0);
  }

  left_arm.sendGoal(left_goal);
  right_arm.sendGoal(right_goal);
  bool l_success = left_arm.waitForResult(ros::Duration(5));
  bool r_success = right_arm.waitForResult(ros::Duration(5));
  if (!l_success) {
    ROS_ERROR("Left arm failed!");
  }
  if (!r_success) {
    ROS_ERROR("Right arm failed!");
  }

  control_msgs::FollowJointTrajectoryGoal left_goal2;
  left_goal2.trajectory.header.stamp = ros::Time::now() + ros::Duration(0.1);
  left_goal2.trajectory.joint_names.push_back("l_shoulder_pan_joint");
  left_goal2.trajectory.joint_names.push_back("l_shoulder_lift_joint");
  left_goal2.trajectory.joint_names.push_back("l_upper_arm_roll_joint");
  left_goal2.trajectory.joint_names.push_back("l_elbow_flex_joint");
  left_goal2.trajectory.joint_names.push_back("l_forearm_roll_joint");
  left_goal2.trajectory.joint_names.push_back("l_wrist_flex_joint");
  left_goal2.trajectory.joint_names.push_back("l_wrist_roll_joint");
  left_goal2.trajectory.points.resize(1);
  left_goal2.trajectory.points[0].positions.resize(7);
  left_goal2.trajectory.points[0].positions[0] = -0.3;
  left_goal2.trajectory.points[0].positions[1] = 0.2;
  left_goal2.trajectory.points[0].positions[2] = -0.1;
  left_goal2.trajectory.points[0].positions[3] = -1.2;
  left_goal2.trajectory.points[0].positions[4] = 1.5;
  left_goal2.trajectory.points[0].positions[5] = -0.3;
  left_goal2.trajectory.points[0].positions[6] = 0.5;
  left_goal2.trajectory.points[0].time_from_start = ros::Duration(4);
  for (int i = 0; i < 7; ++i) {
    left_goal2.trajectory.points[0].velocities.push_back(0);
  }

  control_msgs::FollowJointTrajectoryGoal right_goal2;
  right_goal2.trajectory.header.stamp = ros::Time::now() + ros::Duration(0.1);
  right_goal2.trajectory.joint_names.push_back("r_shoulder_pan_joint");
  right_goal2.trajectory.joint_names.push_back("r_shoulder_lift_joint");
  right_goal2.trajectory.joint_names.push_back("r_upper_arm_roll_joint");
  right_goal2.trajectory.joint_names.push_back("r_elbow_flex_joint");
  right_goal2.trajectory.joint_names.push_back("r_forearm_roll_joint");
  right_goal2.trajectory.joint_names.push_back("r_wrist_flex_joint");
  right_goal2.trajectory.joint_names.push_back("r_wrist_roll_joint");
  right_goal2.trajectory.points.resize(1);
  right_goal2.trajectory.points[0].positions.resize(7);
  right_goal2.trajectory.points[0].positions[0] = -1.3;
  right_goal2.trajectory.points[0].positions[1] = -0.04;
  right_goal2.trajectory.points[0].positions[2] = -1.4;
  right_goal2.trajectory.points[0].positions[3] = -1.2;
  right_goal2.trajectory.points[0].positions[4] = -1.78;
  right_goal2.trajectory.points[0].positions[5] = -1.64;
  right_goal2.trajectory.points[0].positions[6] = -7.59;
  right_goal2.trajectory.points[0].time_from_start = ros::Duration(4);
  for (int i = 0; i < 7; ++i) {
    right_goal2.trajectory.points[0].velocities.push_back(0);
  }

  left_arm.sendGoal(left_goal2);
  right_arm.sendGoal(right_goal2);
  l_success = left_arm.waitForResult(ros::Duration(5));
  r_success = right_arm.waitForResult(ros::Duration(5));
  if (!l_success) {
    ROS_ERROR("Left arm failed!");
  }
  if (!r_success) {
    ROS_ERROR("Right arm failed!");
  }

  left_arm.cancelAllGoals();
  right_arm.cancelAllGoals();
  ros::spinOnce();
  return 0;
}
<|endoftext|>


<commit_before>// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/

#ifndef PEGTL_INTERNAL_RAISE_HH
#define PEGTL_INTERNAL_RAISE_HH

#include "../analysis/generic.hh"

namespace pegtl
{
   namespace internal
   {
      template< typename Exception >
      struct raise
      {
         using analyze_t = analysis::generic< analysis::rule_type::ANY >;

         template< typename Input >
         static bool match( Input & in )
         {
           throw Exception( in );
         }
      };

   } // internal

} // pegtl

#endif
<commit_msg>Style<commit_after>// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/

#ifndef PEGTL_INTERNAL_RAISE_HH
#define PEGTL_INTERNAL_RAISE_HH

#include "../analysis/generic.hh"

namespace pegtl
{
   namespace internal
   {
      template< typename Exception >
      struct raise
      {
         using analyze_t = analysis::generic< analysis::rule_type::ANY >;

         template< typename Input >
         static bool match( Input & in )
         {
            throw Exception( in );
         }
      };

   } // internal

} // pegtl

#endif
<|endoftext|>


<commit_before>// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/

#ifndef PEGTL_INTERNAL_STATE_HH
#define PEGTL_INTERNAL_STATE_HH

#include "seq.hh"
#include "rule_match_three.hh"
#include "skip_control.hh"

#include "../analysis/generic.hh"

namespace pegtl
{
   namespace internal
   {
      template< typename State, typename ... Rules >
      struct state
      {
         using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules ... >;

         template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States >
         static bool match( Input & in, States && ... st )
         {
            State s{ static_cast< const Input & >( in ), st ... };

            if ( rule_match_three< seq< Rules ... >, A, Action, Control >::match( in, s ) ) {
               s.success( static_cast< const Input & >( in ), st ... );
               return true;
            }
            return false;
         }
      };

      template< typename State, typename ... Rules >
      struct skip_control< state< State, Rules ... > > : std::true_type {};

   } // internal

} // pegtl

#endif
<commit_msg>Style<commit_after>// Copyright (c) 2014-2015 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/ColinH/PEGTL/

#ifndef PEGTL_INTERNAL_STATE_HH
#define PEGTL_INTERNAL_STATE_HH

#include "seq.hh"
#include "rule_match_three.hh"
#include "skip_control.hh"

#include "../analysis/generic.hh"

namespace pegtl
{
   namespace internal
   {
      template< typename State, typename ... Rules >
      struct state
      {
         using analyze_t = analysis::generic< analysis::rule_type::SEQ, Rules ... >;

         template< apply_mode A, template< typename ... > class Action, template< typename ... > class Control, typename Input, typename ... States >
         static bool match( Input & in, States && ... st )
         {
            State s( static_cast< const Input & >( in ), st ... );
            if ( rule_match_three< seq< Rules ... >, A, Action, Control >::match( in, s ) ) {
               s.success( static_cast< const Input & >( in ), st ... );
               return true;
            }
            return false;
         }
      };

      template< typename State, typename ... Rules >
      struct skip_control< state< State, Rules ... > > : std::true_type {};

   } // internal

} // pegtl

#endif
<|endoftext|>


<commit_before><commit_msg>Added button reactor to ui builder.<commit_after><|endoftext|>


<commit_before>#include <cstdio>

#include <memory>
#include <mutex>

/**
* Important Usage Note: This library reserves one spare entry for queue-full detection
* Otherwise, corner cases and detecting difference between full/empty is hard.
* You are not seeing an accidental off-by-one.
*/

template <class T>
class circular_buffer {
public:
	circular_buffer(size_t size) :
		buf_(std::unique_ptr<T[]>(new T[size])),
		size_(size)
	{
		//empty constructor
	}

	void put(T item)
	{
		std::lock_guard<std::mutex> lock(mutex_);

		buf_[head_] = item;
		head_ = (head_ + 1) % size_;

		if(head_ == tail_)
		{
			tail_ = (tail_ + 1) % size_;
		}
	}

	T get(void) const
	{
		std::lock_guard<std::mutex> lock(mutex_);

		if(empty())
		{
			return T();
		}

		//Read data and advance the tail (we now have a free space)
		auto val = buf_[tail_];
		tail_ = (tail_ + 1) % size_;

		return val;
	}

	void reset(void)
	{
		std::lock_guard<std::mutex> lock(mutex_);
		head_ = tail_;
	}

	bool empty(void) const
	{
		//if head and tail are equal, we are empty
		return head_ == tail_;
	}

	bool full(void) const
	{
		//If tail is ahead the head by 1, we are full
		return ((head_ + 1) % size_) == tail_;
	}

	size_t size(void) const
	{
		return size_ - 1;
	}

private:
	std::mutex mutex_;
	std::unique_ptr<T[]> buf_;
	size_t head_ = 0;
	size_t tail_ = 0;
	size_t size_;
};

int main(void)
{
	circular_buffer<uint32_t> circle(10);
	printf("\n === CPP Circular buffer check ===\n");
	printf("Capacity: %zu\n", circle.size());
	uint32_t x = 1;
	printf("Put 1, val: %d\n", x);
	circle.put(x);
	x = circle.get();
	printf("Popped: %d\n", x);
	printf("Empty: %d\n", circle.empty());

	printf("Adding 9 values\n");
	for(uint32_t i = 0; i < circle.size(); i++)
	{
		circle.put(i);
	}

	printf("Full: %d\n", circle.full());

	printf("Reading back values: ");
	while(!circle.empty())
	{
		printf("%u ", circle.get());
	}
	printf("\n");

	printf("Adding 15 values\n");
	for(uint32_t i = 0; i < circle.size() + 5; i++)
	{
		circle.put(i);
	}

	printf("Full: %d\n", circle.full());

	printf("Reading back values: ");
	while(!circle.empty())
	{
		printf("%u ", circle.get());
	}
	printf("\n");

	printf("Empty: %d\n", circle.empty());
	printf("Full: %d\n", circle.full());

	return 0;
}
<commit_msg>Prevent implicit conversions.<commit_after>#include <cstdio>

#include <memory>
#include <mutex>

/**
* Important Usage Note: This library reserves one spare entry for queue-full detection
* Otherwise, corner cases and detecting difference between full/empty is hard.
* You are not seeing an accidental off-by-one.
*/

template <class T>
class circular_buffer {
public:
	explicit circular_buffer(size_t size) :
		buf_(std::unique_ptr<T[]>(new T[size])),
		size_(size)
	{
		//empty constructor
	}

	void put(T item)
	{
		std::lock_guard<std::mutex> lock(mutex_);

		buf_[head_] = item;
		head_ = (head_ + 1) % size_;

		if(head_ == tail_)
		{
			tail_ = (tail_ + 1) % size_;
		}
	}

	T get(void) const
	{
		std::lock_guard<std::mutex> lock(mutex_);

		if(empty())
		{
			return T();
		}

		//Read data and advance the tail (we now have a free space)
		auto val = buf_[tail_];
		tail_ = (tail_ + 1) % size_;

		return val;
	}

	void reset(void)
	{
		std::lock_guard<std::mutex> lock(mutex_);
		head_ = tail_;
	}

	bool empty(void) const
	{
		//if head and tail are equal, we are empty
		return head_ == tail_;
	}

	bool full(void) const
	{
		//If tail is ahead the head by 1, we are full
		return ((head_ + 1) % size_) == tail_;
	}

	size_t size(void) const
	{
		return size_ - 1;
	}

private:
	std::mutex mutex_;
	std::unique_ptr<T[]> buf_;
	size_t head_ = 0;
	size_t tail_ = 0;
	size_t size_;
};

int main(void)
{
	circular_buffer<uint32_t> circle(10);
	printf("\n === CPP Circular buffer check ===\n");
	printf("Capacity: %zu\n", circle.size());
	uint32_t x = 1;
	printf("Put 1, val: %d\n", x);
	circle.put(x);
	x = circle.get();
	printf("Popped: %d\n", x);
	printf("Empty: %d\n", circle.empty());

	printf("Adding 9 values\n");
	for(uint32_t i = 0; i < circle.size(); i++)
	{
		circle.put(i);
	}

	printf("Full: %d\n", circle.full());

	printf("Reading back values: ");
	while(!circle.empty())
	{
		printf("%u ", circle.get());
	}
	printf("\n");

	printf("Adding 15 values\n");
	for(uint32_t i = 0; i < circle.size() + 5; i++)
	{
		circle.put(i);
	}

	printf("Full: %d\n", circle.full());

	printf("Reading back values: ");
	while(!circle.empty())
	{
		printf("%u ", circle.get());
	}
	printf("\n");

	printf("Empty: %d\n", circle.empty());
	printf("Full: %d\n", circle.full());

	return 0;
}
<|endoftext|>