stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader Class Reference

Class used to read constant B-tree database files. More...

#include <stx-cbtreedb.h>

Collaboration diagram for stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Reader (const key_compare &key_less=key_compare())
 Create new reader, which is initially set to closed state.
 Reader (const Reader &rd)
 Copy Constructor: increment reference counter on base object.
 ~Reader ()
 Destructor: decrement reference counter on buffer and possibly deallocate it.
Readeroperator= (const Reader &rd)
 Assignment Operator: increment reference counter on base object.
void SetSignature (const char *newsignature)
 Change the database signature (first 8 bytes) from 'cbtreedb' to a custom string.
bool Open (std::istream &file, std::string *errortext=NULL)
 Attempt to open a cbtreedb database file.
void Close ()
 Close the opened database.
void SetPageCache (PageCache *newpagecache)
 Change the currently used page cache object.
uint32_t Size () const
 Returns the number of items in the loaded database.
const SignaturePageGetSignature () const
 Returns a const reference to the signature page of the currently loaded database.
bool Exists (const key_type &key)
 Check if a key is in the constant database.
bool Lookup (const key_type &key, void *outvalue, uint32_t maxsize)
 Find a key in the constant database.
bool Lookup (const key_type &key, std::string &outvalue)
 Find a key in the constant database.
std::string operator[] (const key_type &key)
 Find a key in the constant database.
uint32_t GetIndex (uint32_t index, key_type &outkey)
 Returns only the key by index.
uint32_t GetIndex (uint32_t index, key_type &outkey, void *outvalue, uint32_t maxsize)
 Return a key and associated value by index.
uint32_t GetIndex (uint32_t index, key_type &outkey, std::string &outvalue)
 Return a key and associated value by index.
bool Verify ()
 Verify all aspects of the loaded database.
bool VerifyBTree ()
 Verify B-tree structure in the loaded database.
bool VerifyBTreeChecksum ()
 Verify the SHA256 checksum of the B-tree pages in the loaded database.
bool VerifyValueChecksum ()
 Verify the SHA256 checksum of value data area in the loaded database.

Protected Attributes

ReaderImplm_impl
 pointer to implementation class.

Detailed Description

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
class stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader

Class used to read constant B-tree database files.

This is a reference counted front-end to ReaderImpl.

Refer to Design Principles and Database Architecture and Example Usage on how to use this class.

Definition at line 2124 of file stx-cbtreedb.h.


Constructor & Destructor Documentation

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::Reader ( const key_compare key_less = key_compare()  )  [inline]

Create new reader, which is initially set to closed state.

Definition at line 2133 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::Reader ( const Reader rd  )  [inline]

Copy Constructor: increment reference counter on base object.

Definition at line 2140 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::~Reader (  )  [inline]

Destructor: decrement reference counter on buffer and possibly deallocate it.

Definition at line 2148 of file stx-cbtreedb.h.


Member Function Documentation

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
void stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::Close (  )  [inline]

Close the opened database.

Definition at line 2197 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::Exists ( const key_type key  )  [inline]

Check if a key is in the constant database.

Parameters:
key key to lookup
Returns:
true if found.

Definition at line 2231 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
uint32_t stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::GetIndex ( uint32_t  index,
key_type outkey,
std::string &  outvalue 
) [inline]

Return a key and associated value by index.

Looks directly into the leaf pages.

Parameters:
index zero-based index of item to retrieve
outkey set to key of item
outvalue string to hold data of value
Returns:
size of associated value

Definition at line 2312 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
uint32_t stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::GetIndex ( uint32_t  index,
key_type outkey,
void *  outvalue,
uint32_t  maxsize 
) [inline]

Return a key and associated value by index.

Looks directly into the leaf pages.

Parameters:
index zero-based index of item to retrieve
outkey set to key of item
outvalue buffer to hold data of value
maxsize maximum size of buffer
Returns:
size of associated value

Definition at line 2298 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
uint32_t stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::GetIndex ( uint32_t  index,
key_type outkey 
) [inline]

Returns only the key by index.

Looks directly into the leaf pages.

Parameters:
index zero-based index of item to retrieve
outkey set to key of item
Returns:
size of key's data

Definition at line 2283 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
const SignaturePage& stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::GetSignature (  )  const [inline]

Returns a const reference to the signature page of the currently loaded database.

Definition at line 2220 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::Lookup ( const key_type key,
std::string &  outvalue 
) [inline]

Find a key in the constant database.

If found the coresponding value is copied into the output string buffer.

Parameters:
key key to lookup
outvalue string filled with the associated value if the key is found
Returns:
true if found.

Definition at line 2258 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::Lookup ( const key_type key,
void *  outvalue,
uint32_t  maxsize 
) [inline]

Find a key in the constant database.

If found the corresponding value is copied into the output buffer.

Parameters:
key key to lookup
outvalue buffer filled with the associated value if the key is found
maxsize maximum size of buffer
Returns:
true if found.

Definition at line 2245 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::Open ( std::istream &  file,
std::string *  errortext = NULL 
) [inline]

Attempt to open a cbtreedb database file.

Reads and verifies the signature and initializes the reader. Note that this function does not through an exception if the file could not be loaded! The istream object must exist as long as the Reader is used.

Parameters:
file database file input stream to attach.
errortext in case of error, set to an informative text.
Returns:
true if loaded and verified correctly.

Definition at line 2189 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
Reader& stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::operator= ( const Reader rd  )  [inline]

Assignment Operator: increment reference counter on base object.

Definition at line 2155 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
std::string stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::operator[] ( const key_type key  )  [inline]

Find a key in the constant database.

If found the corresponding value is copied into the output string buffer. If the key does not exist, an empty string is returned.

Parameters:
key key to lookup
Returns:
string containing the value

Definition at line 2271 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
void stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::SetPageCache ( PageCache newpagecache  )  [inline]

Change the currently used page cache object.

Definition at line 2203 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
void stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::SetSignature ( const char *  newsignature  )  [inline]

Change the database signature (first 8 bytes) from 'cbtreedb' to a custom string.

The signature is always 8 bytes long. Longer strings are truncated, shorter ones padded with nulls.

Definition at line 2174 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
uint32_t stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::Size (  )  const [inline]

Returns the number of items in the loaded database.

Definition at line 2211 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::Verify (  )  [inline]

Verify all aspects of the loaded database.

Returns:
true if database is ok.

Definition at line 2322 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::VerifyBTree (  )  [inline]

Verify B-tree structure in the loaded database.

Returns:
true if database is ok.

Definition at line 2332 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::VerifyBTreeChecksum (  )  [inline]

Verify the SHA256 checksum of the B-tree pages in the loaded database.

Returns:
true if database is ok.

Definition at line 2343 of file stx-cbtreedb.h.

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::VerifyValueChecksum (  )  [inline]

Verify the SHA256 checksum of value data area in the loaded database.

Returns:
true if database is ok.

Definition at line 2354 of file stx-cbtreedb.h.


Member Data Documentation

template<typename _Key = uint32_t, typename _Compare = std::less<_Key>, unsigned int _BTreePageSize = 1024, uint32_t _AppVersionId = 0>
ReaderImpl* stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::m_impl [protected]

pointer to implementation class.

Definition at line 2129 of file stx-cbtreedb.h.


The documentation for this class was generated from the following file:
Generated on Wed Apr 14 13:43:41 2010 for stx-cbtreedb by  doxygen 1.6.3