PST File Format SDK v0.4
Loading...
Searching...
No Matches
propbag.h
Go to the documentation of this file.
1
5
6#ifndef PSTSDK_LTP_PROPBAG_H
7#define PSTSDK_LTP_PROPBAG_H
8
9#include <vector>
10#include <algorithm>
11
13#include "pstsdk/util/errors.h"
14
15#include "pstsdk/ndb/node.h"
16
17#include "pstsdk/ltp/object.h"
18#include "pstsdk/ltp/heap.h"
19
20namespace pstsdk
21{
22
24
29
41{
42public:
45 explicit property_bag(const node& n);
51 explicit property_bag(const heap& h);
61
62#ifndef BOOST_NO_RVALUE_REFERENCES
65 property_bag(property_bag&& other) : m_pbth(std::move(other.m_pbth)) { }
66#endif
67
68 std::vector<prop_id> get_prop_list() const;
70 { return (prop_type)m_pbth->lookup(id).type; }
71 bool prop_exists(prop_id id) const;
72 size_t size(prop_id id) const;
74
77 const node& get_node() const { return m_pbth->get_node(); }
80 node& get_node() { return m_pbth->get_node(); }
81
82 std::vector<byte> get_value_variable(prop_id id) const;
83private:
84 property_bag& operator=(const property_bag& other); // = delete
85
86 byte get_value_1(prop_id id) const
87 { return (byte)m_pbth->lookup(id).id; }
88 ushort get_value_2(prop_id id) const
89 { return (ushort)m_pbth->lookup(id).id; }
90 ulong get_value_4(prop_id id) const
91 { return (ulong)m_pbth->lookup(id).id; }
92 ulonglong get_value_8(prop_id id) const;
93
94 void get_prop_list_impl(std::vector<prop_id>& proplist, const pc_bth_node* pbth_node) const;
95
96 std::shared_ptr<pc_bth_node> m_pbth;
97};
98
99} // end pstsdk namespace
100
102{
104
105 m_pbth = h.open_bth<prop_id, disk::prop_entry>(h.get_root_id());
106}
107
109{
111
112 m_pbth = h.open_bth<prop_id, disk::prop_entry>(h.get_root_id());
113}
114
116{
117#ifdef PSTSDK_VALIDATION_LEVEL_WEAK
118 if(h.get_client_signature() != disk::heap_sig_pc)
119 throw sig_mismatch("expected heap_sig_pc", 0, h.get_node().get_id(), h.get_client_signature(), disk::heap_sig_pc);
120#endif
121
122 heap my_heap(h);
123
124 m_pbth = my_heap.open_bth<prop_id, disk::prop_entry>(my_heap.get_root_id());
125}
126
128{
129#ifdef PSTSDK_VALIDATION_LEVEL_WEAK
130 if(h.get_client_signature() != disk::heap_sig_pc)
131 throw sig_mismatch("expected heap_sig_pc", 0, h.get_node().get_id(), h.get_client_signature(), disk::heap_sig_pc);
132#endif
133
135
136 m_pbth = my_heap.open_bth<prop_id, disk::prop_entry>(my_heap.get_root_id());
137}
138
140{
141 heap h(other.m_pbth->get_node());
142
143 m_pbth = h.open_bth<prop_id, disk::prop_entry>(h.get_root_id());
144}
145
147{
148 heap h(other.m_pbth->get_node(), alias_tag());
149
150 m_pbth = h.open_bth<prop_id, disk::prop_entry>(h.get_root_id());
151}
152
153inline std::vector<pstsdk::prop_id> pstsdk::property_bag::get_prop_list() const
154{
155 std::vector<prop_id> proplist;
156
157 get_prop_list_impl(proplist, m_pbth.get());
158
159 return proplist;
160}
161
162inline void pstsdk::property_bag::get_prop_list_impl(std::vector<prop_id>& proplist, const pc_bth_node* pbth_node) const
163{
164 if(pbth_node->get_level() == 0)
165 {
166 // leaf
167 const pc_bth_leaf_node* pleaf = static_cast<const pc_bth_leaf_node*>(pbth_node);
168
169 for(uint i = 0; i < pleaf->num_values(); ++i)
170 proplist.push_back(pleaf->get_key(i));
171 }
172 else
173 {
174 // non-leaf
175 const pc_bth_nonleaf_node* pnonleaf = static_cast<const pc_bth_nonleaf_node*>(pbth_node);
176 for(uint i = 0; i < pnonleaf->num_values(); ++i)
177 get_prop_list_impl(proplist, pnonleaf->get_child(i));
178 }
179}
180
182{
183 try
184 {
185 (void)m_pbth->lookup(id);
186 }
188 {
189 return false;
190 }
191
192 return true;
193}
194
195
196inline pstsdk::ulonglong pstsdk::property_bag::get_value_8(prop_id id) const
197{
198 std::vector<byte> buffer = get_value_variable(id);
199
200 return *(ulonglong*)&buffer[0];
201}
202
203inline std::vector<pstsdk::byte> pstsdk::property_bag::get_value_variable(prop_id id) const
204{
205 heapnode_id h_id = (heapnode_id)get_value_4(id);
206 std::vector<byte> buffer;
207
209 {
210 node sub(m_pbth->get_node().lookup(h_id));
211 buffer.resize(sub.size());
212 sub.read(buffer, 0);
213 }
214 else
215 {
216 buffer = m_pbth->get_heap_ptr()->read(h_id);
217 }
218
219 return buffer;
220}
221
222
223inline size_t pstsdk::property_bag::size(prop_id id) const
224{
225 heapnode_id h_id = (heapnode_id)get_value_4(id);
226
228 return node(m_pbth->get_node().lookup(h_id)).size();
229 else
230 return m_pbth->get_heap_ptr()->size(h_id);
231}
232
234{
235 heapnode_id h_id = (heapnode_id)get_value_4(id);
236
237 if(h_id == 0)
238 return m_pbth->get_heap_ptr()->open_stream(h_id);
239
241 return m_pbth->get_node().lookup(h_id).open_as_stream();
242 else
243 return m_pbth->get_heap_ptr()->open_stream(h_id);
244}
245#endif
The object which forms the root of the BTH hierarchy.
Definition heap.h:294
const heap_ptr get_heap_ptr() const
Returns the heap this bth_node is in.
Definition heap.h:335
heap_id get_id() const
Return the heap_id of this bth_node.
Definition heap.h:322
ushort get_level() const
Return the leve of this bth_node.
Definition heap.h:325
const node & get_node() const
Get the node underlying this BTH.
Definition heap.h:342
Contains references to other bth_node allocations.
Definition heap.h:364
const K & get_key(uint pos) const
Returns the key at the specified position.
Definition heap.h:379
uint num_values() const
Returns the number of entries in this btree_node.
Definition heap.h:382
const V & lookup(const K &key) const
Looks up the associated value for a given key.
Definition btree.h:358
Property object base class.
Definition object.h:94
Heap-on-Node implementation.
Definition heap.h:195
Defines a stream device which can wrap one of the two prop sources.
Definition object.h:56
An in memory representation of the "node" concept in a PST data file.
Definition node.h:320
size_t read(std::vector< byte > &buffer, ulong offset) const
Read data from this node.
Definition node.h:387
size_t size() const
Returns the size of this node.
Definition node.h:425
Property Context (PC) Implementation.
Definition propbag.h:41
node & get_node()
Get the node underlying this property_bag.
Definition propbag.h:80
prop_type get_prop_type(prop_id id) const
Get the property type of a given prop_id.
Definition propbag.h:69
const node & get_node() const
Get the node underlying this property_bag.
Definition propbag.h:77
property_bag(const node &n)
Construct a property_bag from this node.
Definition propbag.h:101
bool prop_exists(prop_id id) const
Indicates the existance of a given property on this object.
Definition propbag.h:181
std::vector< byte > get_value_variable(prop_id id) const
Implemented by child classes to fetch a variable sized property.
Definition propbag.h:203
property_bag(property_bag &&other)
Move construct a property_bag.
Definition propbag.h:65
hnid_stream_device open_prop_stream(prop_id id)
Creates a stream device over a property on this object.
Definition propbag.h:233
std::vector< prop_id > get_prop_list() const
Get a list of all properties on this object.
Definition propbag.h:153
size_t size(prop_id id) const
Returns the total size of a variable length property.
Definition propbag.h:223
An unexpected signature was encountered.
Definition errors.h:98
The exceptions used by pstsdk.
@ heap_sig_pc
Definition disk.h:1234
boost::uint64_t ulonglong
Definition primitives.h:70
boost::uint32_t uint
Definition primitives.h:67
boost::uint32_t ulong
Definition primitives.h:68
ulong heapnode_id
Definition primitives.h:91
boost::uint16_t ushort
Definition primitives.h:73
ushort prop_id
Definition primitives.h:93
bool is_subnode_id(heapnode_id id)
Inspects a heapnode_id (also known as a HNID) to determine if it is a node_id (NID)
Definition primitives.h:281
prop_type
The different property types as defined by MAPI.
Definition primitives.h:292
Heap-on-Node (HN) and BTree-on-Heap (BTH) implementation.
Contains the definition of all in memory representations of disk structures.
Definition disk.h:19
bth_node< prop_id, disk::prop_entry > pc_bth_node
Definition propbag.h:25
bth_nonleaf_node< prop_id, disk::prop_entry > pc_bth_nonleaf_node
Definition propbag.h:26
bth_leaf_node< prop_id, disk::prop_entry > pc_bth_leaf_node
Definition propbag.h:27
Node and Block definitions.
Property access base class.
Primitive structures defined by MS-PST and MAPI.
Tag structure used to indicate a copy constructed class should be an alias (shallow copy) rather than...
Definition primitives.h:110
The value type of the BTH backing a pc.
Definition disk.h:1424