1caf5cd79SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3caf5cd79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4caf5cd79SAndrew Rist * or more contributor license agreements. See the NOTICE file 5caf5cd79SAndrew Rist * distributed with this work for additional information 6caf5cd79SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7caf5cd79SAndrew Rist * to you under the Apache License, Version 2.0 (the 8caf5cd79SAndrew Rist * "License"); you may not use this file except in compliance 9caf5cd79SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11caf5cd79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13caf5cd79SAndrew Rist * Unless required by applicable law or agreed to in writing, 14caf5cd79SAndrew Rist * software distributed under the License is distributed on an 15caf5cd79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16caf5cd79SAndrew Rist * KIND, either express or implied. See the License for the 17caf5cd79SAndrew Rist * specific language governing permissions and limitations 18caf5cd79SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20caf5cd79SAndrew Rist *************************************************************/ 21caf5cd79SAndrew Rist 22cdf0e10cSrcweir #ifndef CONNECTIVITY_TSORTINDEX_HXX 23cdf0e10cSrcweir #define CONNECTIVITY_TSORTINDEX_HXX 24cdf0e10cSrcweir 25cdf0e10cSrcweir #include "connectivity/dbtoolsdllapi.hxx" 26cdf0e10cSrcweir #include "TKeyValue.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir namespace connectivity 29cdf0e10cSrcweir { 30cdf0e10cSrcweir typedef enum 31cdf0e10cSrcweir { 32cdf0e10cSrcweir SQL_ORDERBYKEY_NONE, // do not sort 33cdf0e10cSrcweir SQL_ORDERBYKEY_DOUBLE, // numeric key 34cdf0e10cSrcweir SQL_ORDERBYKEY_STRING // String Key 35cdf0e10cSrcweir } OKeyType; 36cdf0e10cSrcweir 37cdf0e10cSrcweir typedef enum 38cdf0e10cSrcweir { 39cdf0e10cSrcweir SQL_ASC = 1, // ascending 40cdf0e10cSrcweir SQL_DESC = -1 // otherwise 41cdf0e10cSrcweir } TAscendingOrder; 42cdf0e10cSrcweir 43cdf0e10cSrcweir class OKeySet; 44cdf0e10cSrcweir class OKeyValue; // simple class which holds a sal_Int32 and a ::std::vector<ORowSetValueDecoratorRef> 45cdf0e10cSrcweir 46cdf0e10cSrcweir /** 47cdf0e10cSrcweir The class OSortIndex can be used to implement a sorted index. 48cdf0e10cSrcweir This can depend on the fields which should be sorted. 49cdf0e10cSrcweir */ 50cdf0e10cSrcweir class OOO_DLLPUBLIC_DBTOOLS OSortIndex 51cdf0e10cSrcweir { 52cdf0e10cSrcweir public: 53cdf0e10cSrcweir typedef ::std::vector< ::std::pair<sal_Int32,OKeyValue*> > TIntValuePairVector; 54cdf0e10cSrcweir typedef ::std::vector<OKeyType> TKeyTypeVector; 55cdf0e10cSrcweir 56cdf0e10cSrcweir private: 57cdf0e10cSrcweir TIntValuePairVector m_aKeyValues; 58cdf0e10cSrcweir TKeyTypeVector m_aKeyType; 59cdf0e10cSrcweir ::std::vector<TAscendingOrder> m_aAscending; 60cdf0e10cSrcweir sal_Bool m_bFrozen; 61cdf0e10cSrcweir 62cdf0e10cSrcweir public: 63cdf0e10cSrcweir 64cdf0e10cSrcweir OSortIndex( const ::std::vector<OKeyType>& _aKeyType, 65cdf0e10cSrcweir const ::std::vector<TAscendingOrder>& _aAscending); 66cdf0e10cSrcweir 67cdf0e10cSrcweir ~OSortIndex(); 68cdf0e10cSrcweir operator new(size_t nSize)69cdf0e10cSrcweir inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () ) 70cdf0e10cSrcweir { return ::rtl_allocateMemory( nSize ); } operator new(size_t,void * _pHint)71cdf0e10cSrcweir inline static void * SAL_CALL operator new( size_t,void* _pHint ) SAL_THROW( () ) 72cdf0e10cSrcweir { return _pHint; } operator delete(void * pMem)73cdf0e10cSrcweir inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () ) 74cdf0e10cSrcweir { ::rtl_freeMemory( pMem ); } operator delete(void *,void *)75cdf0e10cSrcweir inline static void SAL_CALL operator delete( void *,void* ) SAL_THROW( () ) 76cdf0e10cSrcweir { } 77cdf0e10cSrcweir 78cdf0e10cSrcweir 79cdf0e10cSrcweir /** 80cdf0e10cSrcweir AddKeyValue appends a new value. 81cdf0e10cSrcweir @param 82cdf0e10cSrcweir pKeyValue the keyvalue to be appended 83cdf0e10cSrcweir ATTENTION: when the sortindex is already frozen the parameter will be deleted 84cdf0e10cSrcweir */ 85cdf0e10cSrcweir void AddKeyValue(OKeyValue * pKeyValue); 86cdf0e10cSrcweir 87cdf0e10cSrcweir /** 88cdf0e10cSrcweir Freeze freezes the sortindex so that new values could only be appended by their value 89cdf0e10cSrcweir */ 90cdf0e10cSrcweir void Freeze(); 91cdf0e10cSrcweir 92cdf0e10cSrcweir /** 93*e901e6e4Smseidel CreateKeySet creates the keyset which values could be used to travel in your table/result 94cdf0e10cSrcweir The returned keyset is frozen. 95cdf0e10cSrcweir */ 96cdf0e10cSrcweir ::vos::ORef<OKeySet> CreateKeySet(); 97cdf0e10cSrcweir 98cdf0e10cSrcweir 99cdf0e10cSrcweir 100cdf0e10cSrcweir // look at the name IsFrozen() const101cdf0e10cSrcweir sal_Bool IsFrozen() const { return m_bFrozen; } 102cdf0e10cSrcweir // returns the current size of the keyvalues Count() const103cdf0e10cSrcweir sal_Int32 Count() const { return m_aKeyValues.size(); } 104cdf0e10cSrcweir /** GetValue returns the value at position nPos (1..n) [sorted access]. 105cdf0e10cSrcweir It only allowed to call this method after the sortindex has been frozen. 106cdf0e10cSrcweir */ 107cdf0e10cSrcweir 108cdf0e10cSrcweir sal_Int32 GetValue(sal_Int32 nPos) const; 109cdf0e10cSrcweir getKeyType() const110cdf0e10cSrcweir inline const ::std::vector<OKeyType>& getKeyType() const { return m_aKeyType; } getAscending(::std::vector<TAscendingOrder>::size_type _nPos) const111cdf0e10cSrcweir inline TAscendingOrder getAscending(::std::vector<TAscendingOrder>::size_type _nPos) const { return m_aAscending[_nPos]; } 112cdf0e10cSrcweir 113cdf0e10cSrcweir }; 114cdf0e10cSrcweir 115cdf0e10cSrcweir /** 116cdf0e10cSrcweir The class OKeySet is a refcountable vector which also has a state. 117cdf0e10cSrcweir This state gives information about if the keyset is fixed. 118cdf0e10cSrcweir */ 119cdf0e10cSrcweir class OOO_DLLPUBLIC_DBTOOLS OKeySet : public ORefVector<sal_Int32> 120cdf0e10cSrcweir { 121cdf0e10cSrcweir sal_Bool m_bFrozen; 122cdf0e10cSrcweir public: OKeySet()123cdf0e10cSrcweir OKeySet() 124cdf0e10cSrcweir : ORefVector<sal_Int32>() 125cdf0e10cSrcweir , m_bFrozen(sal_False){} OKeySet(Vector::size_type _nSize)126cdf0e10cSrcweir OKeySet(Vector::size_type _nSize) 127cdf0e10cSrcweir : ORefVector<sal_Int32>(_nSize) 128cdf0e10cSrcweir , m_bFrozen(sal_False){} 129cdf0e10cSrcweir isFrozen() const130cdf0e10cSrcweir sal_Bool isFrozen() const { return m_bFrozen; } setFrozen(sal_Bool _bFrozen=sal_True)131cdf0e10cSrcweir void setFrozen(sal_Bool _bFrozen=sal_True) { m_bFrozen = _bFrozen; } 132cdf0e10cSrcweir }; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir #endif // CONNECTIVITY_TSORTINDEX_HXX 135*e901e6e4Smseidel 136*e901e6e4Smseidel /* vim: set noet sw=4 ts=4: */ 137