Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/connectivity/source/inc/dbase/DIndex.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#pragma once
21
22
#include <sdbcx/VIndex.hxx>
23
#include <dbase/DTable.hxx>
24
#include <dbase/dindexnode.hxx>
25
26
inline constexpr OString dBASE_III_GROUP = "dBase III"_ostr;
27
28
namespace connectivity::dbase
29
{
30
    class OIndexIterator;
31
32
    typedef sdbcx::OIndex ODbaseIndex_BASE;
33
34
    class ODbaseIndex : public ODbaseIndex_BASE
35
    {
36
        friend SvStream& WriteODbaseIndex(SvStream &rStream, const ODbaseIndex&);
37
        friend SvStream& operator >> (SvStream &rStream, ODbaseIndex&);
38
39
        friend class ONDXNode;
40
        friend class ONDXPage;
41
        friend class ONDXPagePtr;
42
        friend class OIndexIterator;
43
44
    public:
45
46
        // Header struct - stays in memory
47
48
        struct NDXHeader
49
        {
50
            sal_uInt32  db_rootpage;                    /* Rootpage position                */
51
            sal_uInt32  db_pagecount;                   /* Page count                       */
52
            sal_uInt8   db_free[4];                     /* Reserved                         */
53
            sal_uInt16  db_keylen;                      /* Key length                       */
54
            sal_uInt16  db_maxkeys;                     /* Maximum number of keys per page  */
55
            sal_uInt16  db_keytype;                     /* Type of key:
56
                                                           0 = Text
57
                                                           1 = Numerical                    */
58
            sal_uInt16  db_keyrec;                      /* Length of an index record
59
                                                           RecordNumber + keylen            */
60
            sal_uInt8   db_free1[3];                    /* Reserved                         */
61
            sal_uInt8   db_unique;                      /* Unique                           */
62
            char        db_name[488];                   /* index_name (field name)          */
63
        };
64
65
    private:
66
        std::unique_ptr<SvStream> m_pFileStream;        // Stream to read/write the index
67
        NDXHeader       m_aHeader = {};
68
        std::vector<ONDXPage*>
69
                        m_aCollector;                   // Pool of obsolete pages
70
        ONDXPagePtr     m_aRoot,                        // Root of the B+ tree
71
                        m_aCurLeaf;                     // Current leaf
72
        sal_uInt16      m_nCurNode;                     // Position of the current node
73
74
        sal_uInt32      m_nPageCount,
75
                        m_nRootPage;
76
77
        ODbaseTable*    m_pTable;
78
        bool        m_bUseCollector : 1;            // Use the Garbage Collector
79
80
        OUString getCompletePath() const;
81
        void closeImpl();
82
        // Closes and kills the index file and throws an error
83
        void impl_killFileAndthrowError_throw(TranslateId pErrorId, const OUString& _sFile);
84
    protected:
85
        virtual ~ODbaseIndex() override;
86
    public:
87
        ODbaseIndex(ODbaseTable* _pTable);
88
        ODbaseIndex(ODbaseTable* _pTable,const NDXHeader& _aHeader,const OUString& Name);
89
90
        void openIndexFile();
91
        virtual void refreshColumns() override;
92
93
0
        const ODbaseTable* getTable() const { return m_pTable; }
94
0
        const NDXHeader& getHeader() const { return m_aHeader; }
95
        std::unique_ptr<OIndexIterator> createIterator();
96
97
0
        void SetRootPos(sal_uInt32 nPos)        {m_nRootPage = nPos;}
98
0
        void SetPageCount(sal_uInt32 nCount)    {m_nPageCount = nCount;}
99
100
0
        sal_uInt32 GetPageCount() const         {return m_nPageCount;}
101
102
0
        sal_uInt16 GetMaxNodes() const          {return m_aHeader.db_maxkeys;}
103
104
        bool Insert(sal_uInt32 nRec, const ORowSetValue& rValue);
105
        bool Update(sal_uInt32 nRec, const ORowSetValue&, const ORowSetValue&);
106
        bool Delete(sal_uInt32 nRec, const ORowSetValue& rValue);
107
        bool Find(sal_uInt32 nRec, const ORowSetValue& rValue);
108
109
        void createINFEntry();
110
        void CreateImpl();
111
        void DropImpl();
112
113
        DECLARE_SERVICE_INFO();
114
    protected:
115
116
        ONDXPage* CreatePage(sal_uInt32 nPagePos, ONDXPage* pParent = nullptr, bool bLoad = false);
117
        void Collect(ONDXPage*);
118
        ONDXPagePtr const & getRoot();
119
120
0
        bool isUnique() const { return m_IsUnique; }
121
0
        bool UseCollector() const {return m_bUseCollector;}
122
        // Tree operations
123
        void Release(bool bSave = true);
124
        bool ConvertToKey(ONDXKey* rKey, sal_uInt32 nRec, const ORowSetValue& rValue);
125
    };
126
127
    SvStream& WriteODbaseIndex(SvStream &rStream, const ODbaseIndex&);
128
    SvStream& operator >> (SvStream &rStream, ODbaseIndex&);
129
130
    void ReadHeader(SvStream & rStream, ODbaseIndex::NDXHeader & rHeader);
131
}
132
133
134
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */