PST File Format SDK v0.4
Loading...
Searching...
No Matches
page.h
Go to the documentation of this file.
1
14
15#ifndef PSTSDK_NDB_PAGE_H
16#define PSTSDK_NDB_PAGE_H
17
18#include <vector>
19
20#include "pstsdk/util/btree.h"
21#include "pstsdk/util/util.h"
22
24
25#ifdef _MSC_VER
26#pragma warning(push)
27#pragma warning(disable:4250)
28#endif
29
30namespace pstsdk
31{
32
35
51class page
52{
53public:
58 : m_db(db), m_pid(pi.id), m_address(pi.address) { }
59
62 page_id get_page_id() const { return m_pid; }
63
66 ulonglong get_address() const { return m_address; }
67
68protected:
73};
74
89template<typename K, typename V>
90class bt_page :
91 public page,
92 public virtual btree_node<K,V>
93{
94public:
99 bt_page(const shared_db_ptr& db, const page_info& pi, ushort level)
100 : page(db, pi), m_level(level) { }
101
104 ushort get_level() const { return m_level; }
105
106private:
107 ushort m_level;
108};
109
118template<typename K, typename V>
120 public bt_page<K,V>,
121 public btree_node_nonleaf<K,V>,
122 public std::enable_shared_from_this<bt_nonleaf_page<K,V> >
123{
124public:
130#ifndef BOOST_NO_RVALUE_REFERENCES
131 bt_nonleaf_page(const shared_db_ptr& db, const page_info& pi, ushort level, std::vector<std::pair<K, page_info> > subpi)
132 : bt_page<K,V>(db, pi, level), m_page_info(std::move(subpi)), m_child_pages(m_page_info.size()) { }
133#else
134 bt_nonleaf_page(const shared_db_ptr& db, const page_info& pi, ushort level, const std::vector<std::pair<K, page_info> >& subpi)
135 : bt_page<K,V>(db, pi, level), m_page_info(subpi), m_child_pages(m_page_info.size()) { }
136#endif
137
138 // btree_node_nonleaf implementation
139 const K& get_key(uint pos) const { return m_page_info[pos].first; }
142 uint num_values() const { return m_child_pages.size(); }
143
144private:
145 std::vector<std::pair<K, page_info> > m_page_info;
146 mutable std::vector<std::shared_ptr<bt_page<K,V> > > m_child_pages;
147};
148
153template<typename K, typename V>
155 public bt_page<K,V>,
156 public btree_node_leaf<K,V>,
157 public std::enable_shared_from_this<bt_leaf_page<K,V> >
158{
159public:
164#ifndef BOOST_NO_RVALUE_REFERENCES
165 bt_leaf_page(const shared_db_ptr& db, const page_info& pi, std::vector<std::pair<K,V> > data)
166 : bt_page<K,V>(db, pi, 0), m_page_data(std::move(data)) { }
167#else
168 bt_leaf_page(const shared_db_ptr& db, const page_info& pi, const std::vector<std::pair<K,V> >& data)
169 : bt_page<K,V>(db, pi, 0), m_page_data(data) { }
170#endif
171
172 // btree_node_leaf implementation
173 const V& get_value(uint pos) const
174 { return m_page_data[pos].second; }
175 const K& get_key(uint pos) const
176 { return m_page_data[pos].first; }
178 { return m_page_data.size(); }
179
180private:
181 std::vector<std::pair<K,V> > m_page_data;
182};
184template<>
185inline bt_page<block_id, block_info>* bt_nonleaf_page<block_id, block_info>::get_child(uint pos)
186{
187 if(m_child_pages[pos] == NULL)
188 {
189 m_child_pages[pos] = this->get_db_ptr()->read_bbt_page(m_page_info[pos].second);
190 }
191
192 return m_child_pages[pos].get();
193}
194
195template<>
196inline const bt_page<block_id, block_info>* bt_nonleaf_page<block_id, block_info>::get_child(uint pos) const
197{
198 if(m_child_pages[pos] == NULL)
199 {
200 m_child_pages[pos] = this->get_db_ptr()->read_bbt_page(m_page_info[pos].second);
201 }
202
203 return m_child_pages[pos].get();
204}
205
206template<>
207inline bt_page<node_id, node_info>* bt_nonleaf_page<node_id, node_info>::get_child(uint pos)
208{
209 if(m_child_pages[pos] == NULL)
210 {
211 m_child_pages[pos] = this->get_db_ptr()->read_nbt_page(m_page_info[pos].second);
212 }
213
214 return m_child_pages[pos].get();
215}
216
217template<>
218inline const bt_page<node_id, node_info>* bt_nonleaf_page<node_id, node_info>::get_child(uint pos) const
219{
220 if(m_child_pages[pos] == NULL)
221 {
222 m_child_pages[pos] = this->get_db_ptr()->read_nbt_page(m_page_info[pos].second);
223 }
224
225 return m_child_pages[pos].get();
226}
228} // end namespace
229
230#ifdef _MSC_VER
231#pragma warning(pop)
232#endif
233
234#endif
Generic BTree implementation.
Contains the actual key value pairs of the btree.
Definition page.h:158
const V & get_value(uint pos) const
Returns the value at the associated position on this leaf node.
Definition page.h:173
uint num_values() const
Returns the number of entries in this btree_node.
Definition page.h:177
const K & get_key(uint pos) const
Returns the key at the specified position.
Definition page.h:175
bt_leaf_page(const shared_db_ptr &db, const page_info &pi, std::vector< std::pair< K, V > > data)
Construct a leaf page from disk.
Definition page.h:165
Contains references to other bt_pages.
Definition page.h:123
const bt_page< K, V > * get_child(uint pos) const
Returns the child btree_node at the requested location.
bt_page< K, V > * get_child(uint pos)
Returns the child btree_node at the requested location.
bt_nonleaf_page(const shared_db_ptr &db, const page_info &pi, ushort level, std::vector< std::pair< K, page_info > > subpi)
Construct a bt_nonleaf_page from disk.
Definition page.h:131
const K & get_key(uint pos) const
Returns the key at the specified position.
Definition page.h:139
uint num_values() const
Returns the number of entries in this btree_node.
Definition page.h:142
bt_page(const shared_db_ptr &db, const page_info &pi, ushort level)
Construct a bt_page from disk.
Definition page.h:99
ushort get_level() const
Returns the level of this bt_page.
Definition page.h:104
Contains references to other bth_node allocations.
Definition heap.h:364
Represents a leaf node in a BTree structure.
Definition btree.h:132
Represents a non-leaf node in a BTree structure.
Definition btree.h:172
A BTree Node.
Definition btree.h:52
Generic base class for all page typesA page which forms a node in the NBT or BBT.
Definition page.h:52
ulonglong get_address() const
Get the physical address of this page.
Definition page.h:66
page_id m_pid
Page id.
Definition page.h:71
page_id get_page_id() const
Get the page id.
Definition page.h:62
shared_db_ptr get_db_ptr() const
Definition page.h:69
page(const shared_db_ptr &db, const page_info &pi)
Construct a page from disk.
Definition page.h:57
weak_db_ptr m_db
The database context we're a member of.
Definition page.h:70
ulonglong m_address
Address of this page.
Definition page.h:72
Database interface.
boost::uint64_t ulonglong
Definition primitives.h:70
boost::uint32_t uint
Definition primitives.h:67
block_id page_id
Definition primitives.h:88
boost::uint16_t ushort
Definition primitives.h:73
Contains the definition of all in memory representations of disk structures.
Definition disk.h:19
std::weak_ptr< db_context > weak_db_ptr
std::shared_ptr< db_context > shared_db_ptr
An in memory, database format agnostic version of disk::block_reference used specifically for the pag...
General utility functions and classes.