Class used to read constant B-tree database files. More...
#include <stx-cbtreedb.h>
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. | |
Reader & | operator= (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 SignaturePage & | GetSignature () 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 | |
ReaderImpl * | m_impl |
pointer to implementation class. |
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.
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.
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.
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.
void stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::Close | ( | ) | [inline] |
Close the opened database.
Definition at line 2197 of file stx-cbtreedb.h.
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::Exists | ( | const key_type & | key | ) | [inline] |
Check if a key is in the constant database.
key | key to lookup |
Definition at line 2231 of file stx-cbtreedb.h.
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.
index | zero-based index of item to retrieve | |
outkey | set to key of item | |
outvalue | string to hold data of value |
Definition at line 2312 of file stx-cbtreedb.h.
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.
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 |
Definition at line 2298 of file stx-cbtreedb.h.
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.
index | zero-based index of item to retrieve | |
outkey | set to key of item |
Definition at line 2283 of file stx-cbtreedb.h.
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.
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.
key | key to lookup | |
outvalue | string filled with the associated value if the key is found |
Definition at line 2258 of file stx-cbtreedb.h.
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.
key | key to lookup | |
outvalue | buffer filled with the associated value if the key is found | |
maxsize | maximum size of buffer |
Definition at line 2245 of file stx-cbtreedb.h.
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.
file | database file input stream to attach. | |
errortext | in case of error, set to an informative text. |
Definition at line 2189 of file stx-cbtreedb.h.
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.
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.
key | key to lookup |
Definition at line 2271 of file stx-cbtreedb.h.
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.
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.
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.
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::Verify | ( | ) | [inline] |
Verify all aspects of the loaded database.
Definition at line 2322 of file stx-cbtreedb.h.
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::VerifyBTree | ( | ) | [inline] |
Verify B-tree structure in the loaded database.
Definition at line 2332 of file stx-cbtreedb.h.
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::VerifyBTreeChecksum | ( | ) | [inline] |
Verify the SHA256 checksum of the B-tree pages in the loaded database.
Definition at line 2343 of file stx-cbtreedb.h.
bool stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::VerifyValueChecksum | ( | ) | [inline] |
Verify the SHA256 checksum of value data area in the loaded database.
Definition at line 2354 of file stx-cbtreedb.h.
ReaderImpl* stx::CBTreeDB< _Key, _Compare, _BTreePageSize, _AppVersionId >::Reader::m_impl [protected] |
pointer to implementation class.
Definition at line 2129 of file stx-cbtreedb.h.