Update git submodules
[LibreOffice.git] / connectivity / source / inc / dbase / DIndex.hxx
blob3cc7da9ad1d34d206e0522c14cc6c195aa4e2481
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
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
30 class OIndexIterator;
31 class ONDXKey;
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;
45 public:
47 // Header struct - stays in memory
49 struct NDXHeader
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:
57 0 = Text
58 1 = Numerical */
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) */
66 private:
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,
76 m_nRootPage;
78 ODbaseTable* m_pTable;
79 bool m_bUseCollector : 1; // Use the Garbage Collector
81 OUString getCompletePath() const;
82 void closeImpl();
83 // Closes and kills the index file and throws an error
84 void impl_killFileAndthrowError_throw(TranslateId pErrorId, const OUString& _sFile);
85 protected:
86 virtual ~ODbaseIndex() override;
87 public:
88 ODbaseIndex(ODbaseTable* _pTable);
89 ODbaseIndex(ODbaseTable* _pTable,const NDXHeader& _aHeader,const OUString& Name);
91 void openIndexFile();
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();
111 void CreateImpl();
112 void DropImpl();
114 DECLARE_SERVICE_INFO();
115 protected:
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;}
123 // Tree operations
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: */