bump product version to 5.0.4.1
[LibreOffice.git] / connectivity / source / inc / dbase / DIndex.hxx
blobed424641373ce6180b4464743501c582b1297750
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 #ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEX_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEX_HXX
23 #include <connectivity/sdbcx/VIndex.hxx>
24 #include <com/sun/star/lang/XUnoTunnel.hpp>
25 #include "dbase/DTable.hxx"
26 #include "dbase/dindexnode.hxx"
28 #define dBASE_III_GROUP "dBase III"
30 namespace connectivity
32 namespace dbase
34 class OIndexIterator;
35 class ONDXKey;
37 typedef sdbcx::OIndex ODbaseIndex_BASE;
38 typedef file::OBoolOperator OBoolOperator_BASE;
39 typedef file::OOperand OOperand_BASE;
41 class ODbaseIndex : public ODbaseIndex_BASE
43 friend SvStream& WriteODbaseIndex(SvStream &rStream, ODbaseIndex&);
44 friend SvStream& operator >> (SvStream &rStream, ODbaseIndex&);
46 friend class ONDXNode;
47 friend class ONDXPage;
48 friend class ONDXPagePtr;
49 friend class OIndexIterator;
51 public:
53 // Header struct - stays in memory
55 struct NDXHeader
57 sal_uInt32 db_rootpage; /* Rootpage position */
58 sal_uInt32 db_pagecount; /* Page count */
59 sal_uInt8 db_frei[4]; /* Reserved */
60 sal_uInt16 db_keylen; /* Key length */
61 sal_uInt16 db_maxkeys; /* Maximum number of keys per page */
62 sal_uInt16 db_keytype; /* Type of key:
63 0 = Text
64 1 = Numerical */
65 sal_uInt16 db_keyrec; /* Length of an index record
66 RecordNumber + keylen */
67 sal_uInt8 db_frei1[3]; /* Reserved */
68 sal_uInt8 db_unique; /* Unique */
69 char db_name[488]; /* index_name (field name) */
72 private:
73 SvStream* m_pFileStream; // Stream to read/write the index
74 NDXHeader m_aHeader;
75 ONDXPageList m_aCollector; // Pool of obsolete pages
76 ONDXPagePtr m_aRoot, // Root of the B+ tree
77 m_aCurLeaf; // Current leaf
78 sal_uInt16 m_nCurNode; // Position of the current node
80 sal_uInt32 m_nPageCount,
81 m_nRootPage;
83 ODbaseTable* m_pTable;
84 bool m_bUseCollector : 1; // Use the Garbage Collector
86 OUString getCompletePath();
87 void closeImpl();
88 // Closes and kills the index file and throws an error
89 void impl_killFileAndthrowError_throw(sal_uInt16 _nErrorId,const OUString& _sFile);
90 protected:
91 virtual ~ODbaseIndex();
92 public:
93 ODbaseIndex(ODbaseTable* _pTable);
94 ODbaseIndex(ODbaseTable* _pTable,const NDXHeader& _aHeader,const OUString& _Name);
96 bool openIndexFile();
97 virtual void refreshColumns() SAL_OVERRIDE;
99 // com::sun::star::lang::XUnoTunnel
100 virtual sal_Int64 SAL_CALL getSomething( const com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
101 static com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId();
103 virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
104 virtual void SAL_CALL release() throw() SAL_OVERRIDE;
106 const ODbaseTable* getTable() const { return m_pTable; }
107 const NDXHeader& getHeader() const { return m_aHeader; }
108 OIndexIterator* createIterator(OBoolOperator_BASE* pOp,
109 const OOperand_BASE* pOperand = NULL);
111 void SetRootPos(sal_uInt32 nPos) {m_nRootPage = nPos;}
112 void SetPageCount(sal_uInt32 nCount) {m_nPageCount = nCount;}
114 sal_uInt32 GetRootPos() {return m_nRootPage;}
115 sal_uInt32 GetPageCount() {return m_nPageCount;}
117 bool IsText() const {return m_aHeader.db_keytype == 0;}
118 sal_uInt16 GetMaxNodes() const {return m_aHeader.db_maxkeys;}
120 bool Insert(sal_uInt32 nRec, const ORowSetValue& rValue);
121 bool Update(sal_uInt32 nRec, const ORowSetValue&, const ORowSetValue&);
122 bool Delete(sal_uInt32 nRec, const ORowSetValue& rValue);
123 bool Find(sal_uInt32 nRec, const ORowSetValue& rValue);
125 void createINFEntry();
126 bool CreateImpl();
127 bool DropImpl();
129 DECLARE_SERVICE_INFO();
130 protected:
132 ONDXPage* CreatePage(sal_uInt32 nPagePos, ONDXPage* pParent = NULL, bool bLoad = false);
133 void Collect(ONDXPage*);
134 ONDXPagePtr getRoot();
136 bool isUnique() const { return m_IsUnique; }
137 bool UseCollector() const {return m_bUseCollector;}
138 // Tree operations
139 void Insert(ONDXPagePtr aCurPage, ONDXNode& rNode);
140 void Release(bool bSave = true);
141 bool ConvertToKey(ONDXKey* rKey, sal_uInt32 nRec, const ORowSetValue& rValue);
144 SvStream& WriteODbaseIndex(SvStream &rStream, ODbaseIndex&);
145 SvStream& operator >> (SvStream &rStream, ODbaseIndex&);
149 #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_DBASE_DINDEX_HXX
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */