1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <sdbcx/VIndex.hxx>
23 #include <dbase/DTable.hxx>
24 #include <dbase/dindexnode.hxx>
26 inline constexpr OString dBASE_III_GROUP
= "dBase III"_ostr
;
28 namespace connectivity::dbase
33 typedef sdbcx::OIndex ODbaseIndex_BASE
;
35 class ODbaseIndex
: public ODbaseIndex_BASE
37 friend SvStream
& WriteODbaseIndex(SvStream
&rStream
, const ODbaseIndex
&);
38 friend SvStream
& operator >> (SvStream
&rStream
, ODbaseIndex
&);
40 friend class ONDXNode
;
41 friend class ONDXPage
;
42 friend class ONDXPagePtr
;
43 friend class OIndexIterator
;
47 // Header struct - stays in memory
51 sal_uInt32 db_rootpage
; /* Rootpage position */
52 sal_uInt32 db_pagecount
; /* Page count */
53 sal_uInt8 db_free
[4]; /* Reserved */
54 sal_uInt16 db_keylen
; /* Key length */
55 sal_uInt16 db_maxkeys
; /* Maximum number of keys per page */
56 sal_uInt16 db_keytype
; /* Type of key:
59 sal_uInt16 db_keyrec
; /* Length of an index record
60 RecordNumber + keylen */
61 sal_uInt8 db_free1
[3]; /* Reserved */
62 sal_uInt8 db_unique
; /* Unique */
63 char db_name
[488]; /* index_name (field name) */
67 std::unique_ptr
<SvStream
> m_pFileStream
; // Stream to read/write the index
68 NDXHeader m_aHeader
= {};
69 std::vector
<ONDXPage
*>
70 m_aCollector
; // Pool of obsolete pages
71 ONDXPagePtr m_aRoot
, // Root of the B+ tree
72 m_aCurLeaf
; // Current leaf
73 sal_uInt16 m_nCurNode
; // Position of the current node
75 sal_uInt32 m_nPageCount
,
78 ODbaseTable
* m_pTable
;
79 bool m_bUseCollector
: 1; // Use the Garbage Collector
81 OUString
getCompletePath() const;
83 // Closes and kills the index file and throws an error
84 void impl_killFileAndthrowError_throw(TranslateId pErrorId
, const OUString
& _sFile
);
86 virtual ~ODbaseIndex() override
;
88 ODbaseIndex(ODbaseTable
* _pTable
);
89 ODbaseIndex(ODbaseTable
* _pTable
,const NDXHeader
& _aHeader
,const OUString
& Name
);
92 virtual void refreshColumns() override
;
94 const ODbaseTable
* getTable() const { return m_pTable
; }
95 const NDXHeader
& getHeader() const { return m_aHeader
; }
96 std::unique_ptr
<OIndexIterator
> createIterator();
98 void SetRootPos(sal_uInt32 nPos
) {m_nRootPage
= nPos
;}
99 void SetPageCount(sal_uInt32 nCount
) {m_nPageCount
= nCount
;}
101 sal_uInt32
GetPageCount() const {return m_nPageCount
;}
103 sal_uInt16
GetMaxNodes() const {return m_aHeader
.db_maxkeys
;}
105 bool Insert(sal_uInt32 nRec
, const ORowSetValue
& rValue
);
106 bool Update(sal_uInt32 nRec
, const ORowSetValue
&, const ORowSetValue
&);
107 bool Delete(sal_uInt32 nRec
, const ORowSetValue
& rValue
);
108 bool Find(sal_uInt32 nRec
, const ORowSetValue
& rValue
);
110 void createINFEntry();
114 DECLARE_SERVICE_INFO();
117 ONDXPage
* CreatePage(sal_uInt32 nPagePos
, ONDXPage
* pParent
= nullptr, bool bLoad
= false);
118 void Collect(ONDXPage
*);
119 ONDXPagePtr
const & getRoot();
121 bool isUnique() const { return m_IsUnique
; }
122 bool UseCollector() const {return m_bUseCollector
;}
124 void Release(bool bSave
= true);
125 bool ConvertToKey(ONDXKey
* rKey
, sal_uInt32 nRec
, const ORowSetValue
& rValue
);
128 SvStream
& WriteODbaseIndex(SvStream
&rStream
, const ODbaseIndex
&);
129 SvStream
& operator >> (SvStream
&rStream
, ODbaseIndex
&);
131 void ReadHeader(SvStream
& rStream
, ODbaseIndex::NDXHeader
& rHeader
);
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */