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 #ifndef INCLUDED_STORE_SOURCE_STORPAGE_HXX
21 #define INCLUDED_STORE_SOURCE_STORPAGE_HXX
22 
23 #include <sal/types.h>
24 #include <rtl/string.h>
25 
26 #include "object.hxx"
27 
28 #include "storbase.hxx"
29 #include "storbios.hxx"
30 #include "stortree.hxx"
31 
32 namespace store
33 {
34 
35 class ILockBytes;
36 struct OStoreDirectoryPageData;
37 class  OStoreDirectoryPageObject;
38 
39 class OStorePageManager : public store::OStorePageBIOS
40 {
41 public:
42     OStorePageManager();
43 
44     /** Initialization (two-phase construction).
45      */
46     virtual storeError initialize (
47         ILockBytes *    pLockBytes,
48         storeAccessMode eAccessMode,
49         sal_uInt16 &    rnPageSize) override;
50 
51     /** isValid.
52      *  @return sal_True  upon successful initialization,
53      *          sal_False otherwise.
54      */
55     inline bool isValid() const;
56 
57     /** DirectoryPage I/O (managed).
58      */
59     static storeError namei (
60         const rtl_String *pPath,
61         const rtl_String *pName,
62         OStorePageKey    &rKey);
63 
64     storeError iget (
65         OStoreDirectoryPageObject & rPage, // [out]
66         sal_uInt32                  nAttrib,
67         const rtl_String *          pPath,
68         const rtl_String *          pName,
69         storeAccessMode             eMode);
70 
71     storeError iterate (
72         OStorePageKey &  rKey,
73         OStorePageLink & rLink,
74         sal_uInt32 &     rAttrib);
75 
76     /** remove.
77      *  @see store_remove()
78      */
79     storeError remove (
80         const OStorePageKey &rKey);
81 
82     /** IStoreHandle.
83      */
84     virtual bool isKindOf (sal_uInt32 nTypeId) override;
85 
86 protected:
87     virtual ~OStorePageManager() override;
88 
89 private:
90     typedef OStorePageBIOS            base;
91     typedef OStorePageManager         self;
92 
93     typedef OStoreBTreeEntry          entry;
94     typedef OStoreBTreeNodeData       page;
95     typedef OStoreBTreeNodeObject     node;
96 
97     typedef OStoreDirectoryPageData   inode;
98     typedef PageHolderObject< inode > inode_holder_type;
99 
100     /** IStoreHandle TypeId.
101      */
102     static const sal_uInt32 m_nTypeId;
103 
104     /** IStoreHandle query() template function specialization.
105      */
106     friend OStorePageManager*
107     SAL_CALL query<> (OStoreObject *pHandle, OStorePageManager*);
108 
109     /** Representation.
110     */
111     OStoreBTreeRootObject m_aRoot;
112 
113     /** DirectoryPage I/O (managed).
114      */
115     storeError load_dirpage_Impl(
116         const OStorePageKey       &rKey,
117         OStoreDirectoryPageObject &rPage);
118 
119     storeError save_dirpage_Impl(
120         const OStorePageKey       &rKey,
121         OStoreDirectoryPageObject &rPage);
122 
123     /** find_lookup (node page and index, w/o split).
124     */
125     storeError find_lookup (
126         OStoreBTreeNodeObject & rNode,
127         sal_uInt16 &            rIndex,
128         OStorePageKey const &   rKey);
129 
130     /** remove (possibly down from root).
131     */
132     storeError remove_Impl (entry & rEntry);
133 
134     OStorePageManager (const OStorePageManager&) = delete;
135     OStorePageManager& operator= (const OStorePageManager&) = delete;
136 };
137 
isValid() const138 inline bool OStorePageManager::isValid() const
139 {
140     return base::isValid();
141 }
142 
143 template<> inline OStorePageManager*
query(OStoreObject * pHandle,SAL_UNUSED_PARAMETER OStorePageManager *)144 SAL_CALL query (OStoreObject *pHandle, SAL_UNUSED_PARAMETER OStorePageManager*)
145 {
146     if (pHandle && pHandle->isKindOf (OStorePageManager::m_nTypeId))
147     {
148         // Handle is kind of OStorePageManager.
149         return static_cast<OStorePageManager*>(pHandle);
150     }
151     return nullptr;
152 }
153 
154 } // namespace store
155 
156 #endif // INCLUDED_STORE_SOURCE_STORPAGE_HXX
157 
158 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
159