merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / inc / dbase / dindexnode.hxx
blobdeb67e1d0e6c0afae119985b33675be9c1023991
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: dindexnode.hxx,v $
10 * $Revision: 1.17 $
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_DBASE_INDEXNODE_HXX_
31 #define _CONNECTIVITY_DBASE_INDEXNODE_HXX_
33 #include "file/fcode.hxx"
34 #include "file/FTable.hxx"
35 #include "dbase/DIndexPage.hxx"
36 #include "connectivity/FValue.hxx"
37 #include <tools/ref.hxx>
39 #define NODE_NOTFOUND 0xFFFF
40 #define PAGE_SIZE 512
42 namespace connectivity
44 namespace dbase
47 class ONDXNode;
48 class ODbaseIndex;
49 //==================================================================
50 // Index Key
51 //==================================================================
52 typedef file::OOperand ONDXKey_BASE;
53 class ONDXKey : public ONDXKey_BASE
55 friend class ONDXNode;
56 UINT32 nRecord; /* Satzzeiger */
57 ORowSetValue xValue; /* Schluesselwert */
59 public:
60 ONDXKey(UINT32 nRec=0);
61 ONDXKey(const ORowSetValue& rVal, sal_Int32 eType, UINT32 nRec);
62 ONDXKey(const rtl::OUString& aStr, UINT32 nRec = 0);
63 ONDXKey(double aVal, UINT32 nRec = 0);
65 inline ONDXKey(const ONDXKey& rKey);
67 inline ONDXKey& operator= (const ONDXKey& rKey);
68 virtual void setValue(const ORowSetValue& _rVal);
70 virtual const ORowSetValue& getValue() const;
72 UINT32 GetRecord() const { return nRecord; }
73 void setRecord(UINT32 _nRec) { nRecord = _nRec; }
74 void ResetRecord() { nRecord = 0; }
76 BOOL operator == (const ONDXKey& rKey) const;
77 BOOL operator != (const ONDXKey& rKey) const;
78 BOOL operator < (const ONDXKey& rKey) const;
79 BOOL operator <= (const ONDXKey& rKey) const;
80 BOOL operator > (const ONDXKey& rKey) const;
81 BOOL operator >= (const ONDXKey& rKey) const;
83 BOOL Load (SvFileStream& rStream, BOOL bText);
84 BOOL Write(SvFileStream& rStream, BOOL bText);
86 static BOOL IsText(sal_Int32 eType);
88 private:
89 StringCompare Compare(const ONDXKey& rKey) const;
95 //==================================================================
96 // Index Seitenverweis
97 //==================================================================
98 SV_DECL_REF(ONDXPage) // Basisklasse da weitere Informationen gehalten werden muessen
101 class ONDXPagePtr : public ONDXPageRef
103 friend SvStream& operator << (SvStream &rStream, const ONDXPagePtr&);
104 friend SvStream& operator >> (SvStream &rStream, ONDXPagePtr&);
106 UINT32 nPagePos; // Position in der Indexdatei
108 public:
109 ONDXPagePtr(UINT32 nPos = 0):nPagePos(nPos){}
110 ONDXPagePtr(const ONDXPagePtr& rRef);
111 ONDXPagePtr(ONDXPage* pRefPage);
113 ONDXPagePtr& operator=(const ONDXPagePtr& rRef);
114 ONDXPagePtr& operator=(ONDXPage* pPageRef);
116 UINT32 GetPagePos() const {return nPagePos;}
117 BOOL HasPage() const {return nPagePos != 0;}
118 // sal_Bool Is() const { return isValid(); }
120 //==================================================================
121 // Index Seite
122 //==================================================================
123 class ONDXPage : public SvRefBase
125 friend class ODbaseIndex;
127 friend SvStream& operator << (SvStream &rStream, const ONDXPage&);
128 friend SvStream& operator >> (SvStream &rStream, ONDXPage&);
130 UINT32 nPagePos; // Position in der Indexdatei
131 BOOL bModified : 1;
132 USHORT nCount;
134 ONDXPagePtr aParent, // VaterSeite
135 aChild; // Zeiger auf rechte ChildPage
136 ODbaseIndex& rIndex;
137 ONDXNode* ppNodes; // array von Knoten
139 public:
140 // Knoten Operationen
141 USHORT Count() const {return nCount;}
143 BOOL Insert(ONDXNode& rNode, sal_uInt32 nRowsLeft = 0);
144 BOOL Insert(USHORT nIndex, ONDXNode& rNode);
145 BOOL Append(ONDXNode& rNode);
146 BOOL Delete(USHORT);
147 void Remove(USHORT);
148 void Release(BOOL bSave = TRUE);
149 void ReleaseFull(BOOL bSave = TRUE);
151 // Aufteilen und Zerlegen
152 ONDXNode Split(ONDXPage& rPage);
153 void Merge(USHORT nParentNodePos, ONDXPagePtr xPage);
155 // Zugriffsoperationen
156 ONDXNode& operator[] (USHORT nPos);
157 const ONDXNode& operator[] (USHORT nPos) const;
159 BOOL IsRoot() const;
160 BOOL IsLeaf() const;
161 BOOL IsModified() const;
162 BOOL HasParent();
163 BOOL HasChild() const;
165 BOOL IsFull() const;
167 UINT32 GetPagePos() const {return nPagePos;}
168 ONDXPagePtr& GetChild(ODbaseIndex* pIndex = 0);
170 // Parent braucht nicht nachgeladen zu werden
171 ONDXPagePtr GetParent();
172 ODbaseIndex& GetIndex() {return rIndex;}
173 const ODbaseIndex& GetIndex() const {return rIndex;}
175 // Setzen des Childs, ueber Referenz, um die PagePos zu erhalten
176 void SetChild(ONDXPagePtr aCh);
177 void SetParent(ONDXPagePtr aPa);
179 USHORT Search(const ONDXKey& rSearch);
180 USHORT Search(const ONDXPage* pPage);
181 void SearchAndReplace(const ONDXKey& rSearch, ONDXKey& rReplace);
183 protected:
184 ONDXPage(ODbaseIndex& rIndex, sal_uInt32 nPos, ONDXPage* = NULL);
185 ~ONDXPage();
187 virtual void QueryDelete();
189 void SetModified(BOOL bMod) {bModified = bMod;}
190 void SetPagePos(UINT32 nPage) {nPagePos = nPage;}
192 BOOL Find(const ONDXKey&); // rek. Abstieg
193 USHORT FindPos(const ONDXKey& rKey) const;
195 #if OSL_DEBUG_LEVEL > 1
196 void PrintPage();
197 #endif
200 SV_IMPL_REF(ONDXPage);
202 SvStream& operator << (SvStream &rStream, const ONDXPagePtr&);
203 SvStream& operator >> (SvStream &rStream, ONDXPagePtr&);
205 inline BOOL ONDXPage::IsRoot() const {return !aParent.Is();}
206 inline BOOL ONDXPage::IsLeaf() const {return !aChild.HasPage();}
207 inline BOOL ONDXPage::IsModified() const {return bModified;}
208 inline BOOL ONDXPage::HasParent() {return aParent.Is();}
209 inline BOOL ONDXPage::HasChild() const {return aChild.HasPage();}
210 inline ONDXPagePtr ONDXPage::GetParent() {return aParent;}
212 inline void ONDXPage::SetParent(ONDXPagePtr aPa = ONDXPagePtr())
214 aParent = aPa;
217 inline void ONDXPage::SetChild(ONDXPagePtr aCh = ONDXPagePtr())
219 aChild = aCh;
220 if (aChild.Is())
221 aChild->SetParent(this);
223 SvStream& operator >> (SvStream &rStream, ONDXPage& rPage);
224 SvStream& operator << (SvStream &rStream, const ONDXPage& rPage);
227 typedef ::std::vector<ONDXPage*> ONDXPageList;
229 //==================================================================
230 // Index Knoten
231 //==================================================================
232 class ONDXNode
234 friend class ONDXPage;
235 ONDXPagePtr aChild; /* naechster Seitenverweis */
236 ONDXKey aKey;
238 public:
239 ONDXNode(){}
240 ONDXNode(const ONDXKey& rKey,
241 ONDXPagePtr aPagePtr = ONDXPagePtr())
242 :aChild(aPagePtr),aKey(rKey) {}
244 // verweist der Knoten auf eine Seite
245 BOOL HasChild() const {return aChild.HasPage();}
246 // Ist ein Index angegeben, kann gegebenfalls die Seite nachgeladen werden
247 ONDXPagePtr& GetChild(ODbaseIndex* pIndex = NULL, ONDXPage* = NULL);
249 const ONDXKey& GetKey() const { return aKey;}
250 ONDXKey& GetKey() { return aKey;}
252 // Setzen des Childs, ueber Referenz, um die PagePos zu erhalten
253 void SetChild(ONDXPagePtr aCh = ONDXPagePtr(), ONDXPage* = NULL);
254 void SetKey(ONDXKey& rKey) {aKey = rKey;}
256 void Write(SvStream &rStream, const ONDXPage& rPage) const;
257 void Read(SvStream &rStream, ODbaseIndex&);
259 //==================================================================
260 // inline implementation
261 //==================================================================
262 // inline ONDXKey::ONDXKey(const ORowSetValue& rVal, sal_Int32 eType, UINT32 nRec)
263 // : ONDXKey_BASE(eType)
264 // , nRecord(nRec),xValue(rVal)
265 // {
266 // }
269 // inline ONDXKey::ONDXKey(const rtl::OUString& aStr, UINT32 nRec)
270 // : ONDXKey_BASE(::com::sun::star::sdbc::DataType::VARCHAR)
271 // ,nRecord(nRec)
272 // {
273 // if (aStr.len())
274 // xValue = aStr;
275 // }
277 // inline ONDXKey::ONDXKey(double aVal, UINT32 nRec)
278 // : ONDXKey_BASE(::com::sun::star::sdbc::DataType::DOUBLE)
279 // ,nRecord(nRec)
280 // ,xValue(aVal)
281 // {
282 // }
284 // inline ONDXKey::ONDXKey(UINT32 nRec)
285 // :nRecord(nRec)
286 // {
287 // }
289 inline ONDXKey::ONDXKey(const ONDXKey& rKey)
290 : ONDXKey_BASE(rKey.getDBType())
291 ,nRecord(rKey.nRecord)
292 ,xValue(rKey.xValue)
296 inline ONDXKey& ONDXKey::operator=(const ONDXKey& rKey)
298 if(&rKey == this)
299 return *this;
301 xValue = rKey.xValue;
302 nRecord = rKey.nRecord;
303 m_eDBType = rKey.getDBType();
304 return *this;
307 inline BOOL ONDXKey::operator == (const ONDXKey& rKey) const
309 if(&rKey == this)
310 return sal_True;
311 return Compare(rKey) == COMPARE_EQUAL;
313 inline BOOL ONDXKey::operator != (const ONDXKey& rKey) const
315 return !operator== (rKey);
317 inline BOOL ONDXKey::operator < (const ONDXKey& rKey) const
319 return Compare(rKey) == COMPARE_LESS;
321 inline BOOL ONDXKey::operator > (const ONDXKey& rKey) const
323 return Compare(rKey) == COMPARE_GREATER;
325 inline BOOL ONDXKey::operator <= (const ONDXKey& rKey) const
327 return !operator > (rKey);
329 inline BOOL ONDXKey::operator >= (const ONDXKey& rKey) const
331 return !operator< (rKey);
334 inline void ONDXNode::SetChild(ONDXPagePtr aCh, ONDXPage* pParent)
336 aChild = aCh;
337 if (aChild.Is())
338 aChild->SetParent(pParent);
348 #endif // _CONNECTIVITY_DBASE_INDEXNODE_HXX_