1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TSortIndex.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef CONNECTIVITY_TSORTINDEX_HXX
31 #define CONNECTIVITY_TSORTINDEX_HXX
33 #include "connectivity/dbtoolsdllapi.hxx"
34 #include "TKeyValue.hxx"
36 namespace connectivity
40 SQL_ORDERBYKEY_NONE
, // do not sort
41 SQL_ORDERBYKEY_DOUBLE
, // numeric key
42 SQL_ORDERBYKEY_STRING
// String Key
47 SQL_ASC
= 1, // ascending
48 SQL_DESC
= -1 // otherwise
52 class OKeyValue
; // simple class which holds a sal_Int32 and a ::std::vector<ORowSetValueDecoratorRef>
55 The class OSortIndex can be used to implement a sorted index.
56 This can depend on the fields which should be sorted.
58 class OOO_DLLPUBLIC_DBTOOLS OSortIndex
61 typedef ::std::vector
< ::std::pair
<sal_Int32
,OKeyValue
*> > TIntValuePairVector
;
62 typedef ::std::vector
<OKeyType
> TKeyTypeVector
;
65 TIntValuePairVector m_aKeyValues
;
66 TKeyTypeVector m_aKeyType
;
67 ::std::vector
<TAscendingOrder
> m_aAscending
;
72 OSortIndex( const ::std::vector
<OKeyType
>& _aKeyType
,
73 const ::std::vector
<TAscendingOrder
>& _aAscending
);
77 inline static void * SAL_CALL
operator new( size_t nSize
) SAL_THROW( () )
78 { return ::rtl_allocateMemory( nSize
); }
79 inline static void * SAL_CALL
operator new( size_t,void* _pHint
) SAL_THROW( () )
81 inline static void SAL_CALL
operator delete( void * pMem
) SAL_THROW( () )
82 { ::rtl_freeMemory( pMem
); }
83 inline static void SAL_CALL
operator delete( void *,void* ) SAL_THROW( () )
88 AddKeyValue appends a new value.
90 pKeyValue the keyvalue to be appended
91 ATTENTION: when the sortindex is already frozen the parameter will be deleted
93 void AddKeyValue(OKeyValue
* pKeyValue
);
96 Freeze freezes the sortindex so that new values could only be appended by their value
101 CreateKeySet creates the keyset which vaalues could be used to travel in your table/result
102 The returned keyset is frozen.
104 ::vos::ORef
<OKeySet
> CreateKeySet();
109 sal_Bool
IsFrozen() const { return m_bFrozen
; }
110 // returns the current size of the keyvalues
111 sal_Int32
Count() const { return m_aKeyValues
.size(); }
112 /** GetValue returns the value at position nPos (1..n) [sorted access].
113 It only allowed to call this method after the sortindex has been frozen.
116 sal_Int32
GetValue(sal_Int32 nPos
) const;
118 inline const ::std::vector
<OKeyType
>& getKeyType() const { return m_aKeyType
; }
119 inline TAscendingOrder
getAscending(::std::vector
<TAscendingOrder
>::size_type _nPos
) const { return m_aAscending
[_nPos
]; }
124 The class OKeySet is a refcountable vector which also has a state.
125 This state gives information about if the keyset is fixed.
127 class OOO_DLLPUBLIC_DBTOOLS OKeySet
: public ORefVector
<sal_Int32
>
132 : ORefVector
<sal_Int32
>()
133 , m_bFrozen(sal_False
){}
134 OKeySet(Vector::size_type _nSize
)
135 : ORefVector
<sal_Int32
>(_nSize
)
136 , m_bFrozen(sal_False
){}
138 sal_Bool
isFrozen() const { return m_bFrozen
; }
139 void setFrozen(sal_Bool _bFrozen
=sal_True
) { m_bFrozen
= _bFrozen
; }
142 #endif // CONNECTIVITY_TSORTINDEX_HXX