update dev300-m58
[ooovba.git] / connectivity / source / inc / TSortIndex.hxx
blobe5614edbaae61e7053291ad0b227c40933c857a4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TSortIndex.hxx,v $
10 * $Revision: 1.7 $
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
38 typedef enum
40 SQL_ORDERBYKEY_NONE, // do not sort
41 SQL_ORDERBYKEY_DOUBLE, // numeric key
42 SQL_ORDERBYKEY_STRING // String Key
43 } OKeyType;
45 typedef enum
47 SQL_ASC = 1, // ascending
48 SQL_DESC = -1 // otherwise
49 } TAscendingOrder;
51 class OKeySet;
52 class OKeyValue; // simple class which holds a sal_Int32 and a ::std::vector<ORowSetValueDecoratorRef>
54 /**
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
60 public:
61 typedef ::std::vector< ::std::pair<sal_Int32,OKeyValue*> > TIntValuePairVector;
62 typedef ::std::vector<OKeyType> TKeyTypeVector;
64 private:
65 TIntValuePairVector m_aKeyValues;
66 TKeyTypeVector m_aKeyType;
67 ::std::vector<TAscendingOrder> m_aAscending;
68 sal_Bool m_bFrozen;
70 public:
72 OSortIndex( const ::std::vector<OKeyType>& _aKeyType,
73 const ::std::vector<TAscendingOrder>& _aAscending);
75 ~OSortIndex();
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( () )
80 { return _pHint; }
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( () )
84 { }
87 /**
88 AddKeyValue appends a new value.
89 @param
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);
95 /**
96 Freeze freezes the sortindex so that new values could only be appended by their value
98 void Freeze();
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();
108 // look at the name
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>
129 sal_Bool m_bFrozen;
130 public:
131 OKeySet()
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