1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef CONNECTIVITY_TSORTINDEX_HXX 28 #define CONNECTIVITY_TSORTINDEX_HXX 29 30 #include "connectivity/dbtoolsdllapi.hxx" 31 #include "TKeyValue.hxx" 32 33 namespace connectivity 34 { 35 typedef enum 36 { 37 SQL_ORDERBYKEY_NONE, // do not sort 38 SQL_ORDERBYKEY_DOUBLE, // numeric key 39 SQL_ORDERBYKEY_STRING // String Key 40 } OKeyType; 41 42 typedef enum 43 { 44 SQL_ASC = 1, // ascending 45 SQL_DESC = -1 // otherwise 46 } TAscendingOrder; 47 48 class OKeySet; 49 class OKeyValue; // simple class which holds a sal_Int32 and a ::std::vector<ORowSetValueDecoratorRef> 50 51 /** 52 The class OSortIndex can be used to implement a sorted index. 53 This can depend on the fields which should be sorted. 54 */ 55 class OOO_DLLPUBLIC_DBTOOLS OSortIndex 56 { 57 public: 58 typedef ::std::vector< ::std::pair<sal_Int32,OKeyValue*> > TIntValuePairVector; 59 typedef ::std::vector<OKeyType> TKeyTypeVector; 60 61 private: 62 TIntValuePairVector m_aKeyValues; 63 TKeyTypeVector m_aKeyType; 64 ::std::vector<TAscendingOrder> m_aAscending; 65 sal_Bool m_bFrozen; 66 67 public: 68 69 OSortIndex( const ::std::vector<OKeyType>& _aKeyType, 70 const ::std::vector<TAscendingOrder>& _aAscending); 71 72 ~OSortIndex(); 73 74 inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW( () ) 75 { return ::rtl_allocateMemory( nSize ); } 76 inline static void * SAL_CALL operator new( size_t,void* _pHint ) SAL_THROW( () ) 77 { return _pHint; } 78 inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW( () ) 79 { ::rtl_freeMemory( pMem ); } 80 inline static void SAL_CALL operator delete( void *,void* ) SAL_THROW( () ) 81 { } 82 83 84 /** 85 AddKeyValue appends a new value. 86 @param 87 pKeyValue the keyvalue to be appended 88 ATTENTION: when the sortindex is already frozen the parameter will be deleted 89 */ 90 void AddKeyValue(OKeyValue * pKeyValue); 91 92 /** 93 Freeze freezes the sortindex so that new values could only be appended by their value 94 */ 95 void Freeze(); 96 97 /** 98 CreateKeySet creates the keyset which vaalues could be used to travel in your table/result 99 The returned keyset is frozen. 100 */ 101 ::vos::ORef<OKeySet> CreateKeySet(); 102 103 104 105 // look at the name 106 sal_Bool IsFrozen() const { return m_bFrozen; } 107 // returns the current size of the keyvalues 108 sal_Int32 Count() const { return m_aKeyValues.size(); } 109 /** GetValue returns the value at position nPos (1..n) [sorted access]. 110 It only allowed to call this method after the sortindex has been frozen. 111 */ 112 113 sal_Int32 GetValue(sal_Int32 nPos) const; 114 115 inline const ::std::vector<OKeyType>& getKeyType() const { return m_aKeyType; } 116 inline TAscendingOrder getAscending(::std::vector<TAscendingOrder>::size_type _nPos) const { return m_aAscending[_nPos]; } 117 118 }; 119 120 /** 121 The class OKeySet is a refcountable vector which also has a state. 122 This state gives information about if the keyset is fixed. 123 */ 124 class OOO_DLLPUBLIC_DBTOOLS OKeySet : public ORefVector<sal_Int32> 125 { 126 sal_Bool m_bFrozen; 127 public: 128 OKeySet() 129 : ORefVector<sal_Int32>() 130 , m_bFrozen(sal_False){} 131 OKeySet(Vector::size_type _nSize) 132 : ORefVector<sal_Int32>(_nSize) 133 , m_bFrozen(sal_False){} 134 135 sal_Bool isFrozen() const { return m_bFrozen; } 136 void setFrozen(sal_Bool _bFrozen=sal_True) { m_bFrozen = _bFrozen; } 137 }; 138 } 139 #endif // CONNECTIVITY_TSORTINDEX_HXX 140