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: dindexnode.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_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
42 namespace connectivity
49 //==================================================================
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 */
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
);
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
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 //==================================================================
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
134 ONDXPagePtr aParent
, // VaterSeite
135 aChild
; // Zeiger auf rechte ChildPage
137 ONDXNode
* ppNodes
; // array von Knoten
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
);
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;
161 BOOL
IsModified() const;
163 BOOL
HasChild() 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
);
184 ONDXPage(ODbaseIndex
& rIndex
, sal_uInt32 nPos
, ONDXPage
* = NULL
);
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
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())
217 inline void ONDXPage::SetChild(ONDXPagePtr aCh
= ONDXPagePtr())
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 //==================================================================
231 //==================================================================
234 friend class ONDXPage
;
235 ONDXPagePtr aChild
; /* naechster Seitenverweis */
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)
269 // inline ONDXKey::ONDXKey(const rtl::OUString& aStr, UINT32 nRec)
270 // : ONDXKey_BASE(::com::sun::star::sdbc::DataType::VARCHAR)
277 // inline ONDXKey::ONDXKey(double aVal, UINT32 nRec)
278 // : ONDXKey_BASE(::com::sun::star::sdbc::DataType::DOUBLE)
284 // inline ONDXKey::ONDXKey(UINT32 nRec)
289 inline ONDXKey::ONDXKey(const ONDXKey
& rKey
)
290 : ONDXKey_BASE(rKey
.getDBType())
291 ,nRecord(rKey
.nRecord
)
296 inline ONDXKey
& ONDXKey::operator=(const ONDXKey
& rKey
)
301 xValue
= rKey
.xValue
;
302 nRecord
= rKey
.nRecord
;
303 m_eDBType
= rKey
.getDBType();
307 inline BOOL
ONDXKey::operator == (const ONDXKey
& rKey
) const
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
)
338 aChild
->SetParent(pParent
);
348 #endif // _CONNECTIVITY_DBASE_INDEXNODE_HXX_