Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef CONNECTIVITY_TSORTINDEX_HXX
20 : #define CONNECTIVITY_TSORTINDEX_HXX
21 :
22 : #include "connectivity/dbtoolsdllapi.hxx"
23 : #include "TKeyValue.hxx"
24 :
25 : namespace connectivity
26 : {
27 : typedef enum
28 : {
29 : SQL_ORDERBYKEY_NONE, // do not sort
30 : SQL_ORDERBYKEY_DOUBLE, // numeric key
31 : SQL_ORDERBYKEY_STRING // String Key
32 : } OKeyType;
33 :
34 : typedef enum
35 : {
36 : SQL_ASC = 1, // ascending
37 : SQL_DESC = -1 // otherwise
38 : } TAscendingOrder;
39 :
40 : class OKeySet;
41 : class OKeyValue; // simple class which holds a sal_Int32 and a ::std::vector<ORowSetValueDecoratorRef>
42 :
43 : /**
44 : The class OSortIndex can be used to implement a sorted index.
45 : This can depend on the fields which should be sorted.
46 : */
47 : class OOO_DLLPUBLIC_DBTOOLS OSortIndex
48 : {
49 : public:
50 : typedef ::std::vector< ::std::pair<sal_Int32,OKeyValue*> > TIntValuePairVector;
51 : typedef ::std::vector<OKeyType> TKeyTypeVector;
52 :
53 : private:
54 : TIntValuePairVector m_aKeyValues;
55 : TKeyTypeVector m_aKeyType;
56 : ::std::vector<TAscendingOrder> m_aAscending;
57 : sal_Bool m_bFrozen;
58 :
59 : public:
60 :
61 : OSortIndex( const ::std::vector<OKeyType>& _aKeyType,
62 : const ::std::vector<TAscendingOrder>& _aAscending);
63 :
64 : ~OSortIndex();
65 :
66 0 : inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW(())
67 0 : { return ::rtl_allocateMemory( nSize ); }
68 : inline static void * SAL_CALL operator new( size_t,void* _pHint ) SAL_THROW(())
69 : { return _pHint; }
70 0 : inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW(())
71 0 : { ::rtl_freeMemory( pMem ); }
72 : inline static void SAL_CALL operator delete( void *,void* ) SAL_THROW(())
73 : { }
74 :
75 :
76 : /**
77 : AddKeyValue appends a new value.
78 : @param
79 : pKeyValue the keyvalue to be appended
80 : ATTENTION: when the sortindex is already frozen the parameter will be deleted
81 : */
82 : void AddKeyValue(OKeyValue * pKeyValue);
83 :
84 : /**
85 : Freeze freezes the sortindex so that new values could only be appended by their value
86 : */
87 : void Freeze();
88 :
89 : /**
90 : CreateKeySet creates the keyset which vaalues could be used to travel in your table/result
91 : The returned keyset is frozen.
92 : */
93 : ::rtl::Reference<OKeySet> CreateKeySet();
94 :
95 :
96 :
97 : // look at the name
98 : sal_Bool IsFrozen() const { return m_bFrozen; }
99 : // returns the current size of the keyvalues
100 : size_t Count() const { return m_aKeyValues.size(); }
101 :
102 0 : inline const ::std::vector<OKeyType>& getKeyType() const { return m_aKeyType; }
103 0 : inline TAscendingOrder getAscending(::std::vector<TAscendingOrder>::size_type _nPos) const { return m_aAscending[_nPos]; }
104 :
105 : };
106 :
107 : /**
108 : The class OKeySet is a refcountable vector which also has a state.
109 : This state gives information about if the keyset is fixed.
110 : */
111 0 : class OOO_DLLPUBLIC_DBTOOLS OKeySet : public ORefVector<sal_Int32>
112 : {
113 : sal_Bool m_bFrozen;
114 : public:
115 0 : OKeySet()
116 : : ORefVector<sal_Int32>()
117 0 : , m_bFrozen(sal_False){}
118 : OKeySet(Vector::size_type _nSize)
119 : : ORefVector<sal_Int32>(_nSize)
120 : , m_bFrozen(sal_False){}
121 :
122 0 : sal_Bool isFrozen() const { return m_bFrozen; }
123 0 : void setFrozen(sal_Bool _bFrozen=sal_True) { m_bFrozen = _bFrozen; }
124 : };
125 : }
126 : #endif // CONNECTIVITY_TSORTINDEX_HXX
127 :
128 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|