#include <Persistent.hpp>
Public Member Functions | |
Persistent (const std::function< std::unique_ptr< ObjectType >(void)> &object_factory, const char *object_name=nullptr, PersistentRegistry *persistent_registry=nullptr, mutils::DeserializationManager dm={{}}) noexcept(false) | |
constructor 1 is for building a persistent<T> locally, load/create a log and register itself to a persistent registry. More... | |
Persistent (Persistent &&other) noexcept(false) | |
constructor 2 is move constructor. More... | |
Persistent (const char *object_name, std::unique_ptr< ObjectType > &wrapped_obj_ptr, const char *log_tail=nullptr, PersistentRegistry *persistent_registry=nullptr, mutils::DeserializationManager dm={{}}) noexcept(false) | |
constructor 3 is for deserialization. More... | |
Persistent (const Persistent &)=delete | |
constructor 4, the default copy constructor, is disabled More... | |
virtual | ~Persistent () noexcept(true) |
destructor: release the resources More... | |
ObjectType & | operator* () |
ObjectType * | operator-> () |
overload the '->' operator to access the wrapped object More... | |
const ObjectType & | getConstRef () const |
get a const reference to the wrapped object More... | |
const std::string & | getObjectName () |
get object name More... | |
template<typename Func > | |
auto | get (const Func &fun, mutils::DeserializationManager *dm=nullptr) noexcept(false) |
get the latest Value of T. More... | |
std::unique_ptr< ObjectType > | get (mutils::DeserializationManager *dm=nullptr) |
get the latest Value of T, returns a unique pointer to the object More... | |
template<typename Func > | |
auto | getByIndex (int64_t idx, const Func &fun, mutils::DeserializationManager *dm=nullptr) noexcept(false) |
get a version of Value T. More... | |
std::unique_ptr< ObjectType > | getByIndex (int64_t idx, mutils::DeserializationManager *dm=nullptr) noexcept(false) |
get a version of value T. More... | |
template<typename Func > | |
auto | get (const int64_t &ver, const Func &fun, mutils::DeserializationManager *dm=nullptr) noexcept(false) |
get a version of Value T, specified by version. More... | |
std::unique_ptr< ObjectType > | get (const int64_t &ver, mutils::DeserializationManager *dm=nullptr) noexcept(false) |
get a version of value T. More... | |
template<typename TKey > | |
void | trim (const TKey &k) noexcept(false) |
trim by version or index More... | |
void | truncate (const int64_t &ver) |
truncate the log More... | |
template<typename Func > | |
auto | get (const HLC &hlc, const Func &fun, mutils::DeserializationManager *dm=nullptr) noexcept(false) |
get a version of Value T, specified by HLC clock. More... | |
std::unique_ptr< ObjectType > | get (const HLC &hlc, mutils::DeserializationManager *dm=nullptr) noexcept(false) |
get a version of value T. More... | |
std::unique_ptr< ObjectType > | operator[] (const int64_t ver) noexcept(false) |
syntax sugar: get a specified version of T without DSM More... | |
std::unique_ptr< ObjectType > | operator[] (const HLC &hlc) noexcept(false) |
syntax sugar: get a specified version of T without DSM More... | |
virtual int64_t | getNumOfVersions () noexcept(false) |
get the number of versions excluding trimmed ones. More... | |
virtual int64_t | getEarliestIndex () noexcept(false) |
get the earliest index excluding trimmed ones. More... | |
virtual int64_t | getEarliestVersion () noexcept(false) |
get the earliest version excluding trimmed ones. More... | |
virtual int64_t | getLatestIndex () noexcept(false) |
get the latest index excluding truncated ones. More... | |
virtual int64_t | getLatestVersion () noexcept(false) |
get the lastest version excluding truncated ones. More... | |
virtual const int64_t | getLastPersisted () noexcept(false) |
get the last persisted index. More... | |
virtual void | set (ObjectType &v, const version_t &ver, const HLC &mhlc) noexcept(false) |
make a version with a version number and mhlc clock More... | |
virtual void | set (ObjectType &v, const version_t &ver) noexcept(false) |
make a version with only a version number More... | |
virtual void | version (const version_t &ver) noexcept(false) |
make a version with only a version number, using the current state. More... | |
virtual const int64_t | persist () noexcept(false) |
persist till version More... | |
std::size_t | to_bytes (char *ret) const |
Write this class's marshalled representation into the array found at v. More... | |
std::size_t | bytes_size () const |
the size of the marshalled representation of this object. More... | |
void | post_object (const std::function< void(char const *const, std::size_t)> &f) const |
Pass a pointer to a buffer containing this class's marshalled representation into the function f. More... | |
virtual void | ensure_registered (mutils::DeserializationManager &) |
void | applyLogTail (mutils::DeserializationManager *dsm, char const *v) |
virtual void | print_performance_stat () |
Public Member Functions inherited from mutils::ByteRepresentable | |
virtual | ~ByteRepresentable () |
Static Public Member Functions | |
static std::unique_ptr< Persistent > | from_bytes (mutils::DeserializationManager *dsm, char const *v) |
Public Attributes | |
std::unique_ptr< ObjectType > | m_pWrappedObject |
uint64_t | ns_in_persist = 0ul |
uint64_t | ns_in_set = 0ul |
uint64_t | cnt_in_persist = 0ul |
uint64_t | cnt_in_set = 0ul |
Protected Member Functions | |
void | initialize_log (const char *object_name) noexcept(false) |
initialize from local state. More... | |
void | initialize_object_from_log (const std::function< std::unique_ptr< ObjectType >(void)> &object_factory, mutils::DeserializationManager *dm) |
initialize the object from log More... | |
void | register_callbacks () noexcept(false) |
register the callbacks. More... | |
void | unregister_callbacks () noexcept(false) |
unregister the callbacks. More... | |
Static Protected Member Functions | |
static _NameMaker< ObjectType, storageType > & | getNameMaker (const std::string &prefix=std::string("")) |
Protected Attributes | |
std::unique_ptr< PersistLog > | m_pLog |
PersistentRegistry * | m_pRegistry |
Definition at line 320 of file Persistent.hpp.
|
noexcept |
constructor 1 is for building a persistent<T> locally, load/create a log and register itself to a persistent registry.
object_factory | A factory to create an empty Object. |
object_name | This name is used for persistent data in file. |
persistent_registry | A normal pointer to the registry. |
dm | The deserialization manager for deserializing local log entries. |
Definition at line 146 of file Persistent_impl.hpp.
|
noexcept |
constructor 2 is move constructor.
It "steals" the resource from another object.
other | The other object. |
Definition at line 162 of file Persistent_impl.hpp.
|
noexcept |
constructor 3 is for deserialization.
It builds a Persistent<T> from the object name, a unique_ptr to the wrapped object, a unique_ptr to the log.
object_name | The name is used for persistent data in file. |
wrapped_obj_ptr | A unique pointer to the wrapped object. |
log_ptr | A unique pointer to the log. |
dm | The deserialization manager for deserializing local log entries. |
Definition at line 171 of file Persistent_impl.hpp.
|
delete |
constructor 4, the default copy constructor, is disabled
|
virtualnoexcept |
destructor: release the resources
Definition at line 193 of file Persistent_impl.hpp.
void persistent::Persistent< ObjectType, storageType >::applyLogTail | ( | mutils::DeserializationManager * | dsm, |
char const * | v | ||
) |
Definition at line 546 of file Persistent_impl.hpp.
|
virtual |
the size of the marshalled representation of this object.
useful when allocating arrays in which to store this object.
NOTE: it is recommended that users not call this directly, and prefer to use mutils::bytes_size(T,v) instead.
Implements mutils::ByteRepresentable.
Definition at line 510 of file Persistent_impl.hpp.
|
inlinevirtual |
Definition at line 585 of file Persistent.hpp.
|
static |
Definition at line 525 of file Persistent_impl.hpp.
|
noexcept |
get the latest Value of T.
The user lambda will be fed with the latest object zerocopy:this object will not live once it returns. return value is decided by user lambda
Definition at line 232 of file Persistent_impl.hpp.
|
noexcept |
get the latest Value of T, returns a unique pointer to the object
Definition at line 240 of file Persistent_impl.hpp.
|
noexcept |
get a version of Value T, specified by version.
the user lambda will be fed with an object of T. zerocopy: this object will not live once it returns. return value is decided by the user lambda.
Definition at line 286 of file Persistent_impl.hpp.
|
noexcept |
get a version of value T.
specified version. return a deserialized copy for the variable.
Definition at line 306 of file Persistent_impl.hpp.
|
noexcept |
get a version of Value T, specified by HLC clock.
the user lambda will be fed with an object of T. zerocopy: this object will not live once it returns. return value is decided by the user lambda.
Definition at line 343 of file Persistent_impl.hpp.
|
noexcept |
get a version of value T.
specified by HLC clock.
Definition at line 371 of file Persistent_impl.hpp.
|
noexcept |
get a version of Value T.
the user lambda will be fed with the given object zerocopy:this object will not live once it returns. return value is decided by user lambda
Definition at line 248 of file Persistent_impl.hpp.
|
noexcept |
get a version of value T.
returns a unique pointer to the object
Definition at line 263 of file Persistent_impl.hpp.
const ObjectType & persistent::Persistent< ObjectType, storageType >::getConstRef | ( | ) | const |
get a const reference to the wrapped object
Definition at line 219 of file Persistent_impl.hpp.
|
virtualnoexcept |
get the earliest index excluding trimmed ones.
Definition at line 403 of file Persistent_impl.hpp.
|
virtualnoexcept |
get the earliest version excluding trimmed ones.
Definition at line 409 of file Persistent_impl.hpp.
|
virtualnoexcept |
get the last persisted index.
Definition at line 427 of file Persistent_impl.hpp.
|
virtualnoexcept |
get the latest index excluding truncated ones.
Definition at line 415 of file Persistent_impl.hpp.
|
virtualnoexcept |
get the lastest version excluding truncated ones.
Definition at line 421 of file Persistent_impl.hpp.
|
staticprotectednoexcept |
Definition at line 567 of file Persistent_impl.hpp.
|
virtualnoexcept |
get the number of versions excluding trimmed ones.
Definition at line 397 of file Persistent_impl.hpp.
const std::string & persistent::Persistent< ObjectType, storageType >::getObjectName | ( | ) |
get object name
Definition at line 225 of file Persistent_impl.hpp.
|
inlineprotectednoexcept |
initialize from local state.
object_name | Object name |
Definition at line 83 of file Persistent_impl.hpp.
|
inlineprotected |
initialize the object from log
Definition at line 111 of file Persistent_impl.hpp.
ObjectType & persistent::Persistent< ObjectType, storageType >::operator* | ( | ) |
Definition at line 207 of file Persistent_impl.hpp.
ObjectType * persistent::Persistent< ObjectType, storageType >::operator-> | ( | ) |
overload the '->' operator to access the wrapped object
Definition at line 213 of file Persistent_impl.hpp.
|
inlinenoexcept |
syntax sugar: get a specified version of T without DSM
Definition at line 493 of file Persistent.hpp.
|
inlinenoexcept |
syntax sugar: get a specified version of T without DSM
Definition at line 500 of file Persistent.hpp.
|
virtualnoexcept |
persist till version
ver | version number |
Definition at line 478 of file Persistent_impl.hpp.
|
virtual |
Pass a pointer to a buffer containing this class's marshalled representation into the function f.
This pointer is not guaranteed to live beyond the duration of the call to f, so make a copy if you need to keep it around.
NOTE: it is recommended that users not call this directly, and prefer to use mutils::post_object(f,T) instead.
Implements mutils::ByteRepresentable.
Definition at line 516 of file Persistent_impl.hpp.
|
virtual |
|
inlineprotectednoexcept |
register the callbacks.
Definition at line 123 of file Persistent_impl.hpp.
|
virtualnoexcept |
make a version with a version number and mhlc clock
Definition at line 433 of file Persistent_impl.hpp.
|
virtualnoexcept |
make a version with only a version number
Definition at line 454 of file Persistent_impl.hpp.
|
virtual |
Write this class's marshalled representation into the array found at v.
assume v has at least bytes_size() of free memory available; behavior is undefined otherwise.
Returns number of bytes written, which should be the same as bytes_size().
NOTE: it is recommended that users not call this directly, and prefer to use mutils::to_bytes(T,v) instead.
Implements mutils::ByteRepresentable.
Definition at line 494 of file Persistent_impl.hpp.
|
noexcept |
trim by version or index
Definition at line 326 of file Persistent_impl.hpp.
void persistent::Persistent< ObjectType, storageType >::truncate | ( | const int64_t & | ver | ) |
truncate the log
ver | all versions strictly newer than 'ver' will be truncated. |
Definition at line 334 of file Persistent_impl.hpp.
|
inlineprotectednoexcept |
unregister the callbacks.
Definition at line 138 of file Persistent_impl.hpp.
|
virtualnoexcept |
make a version with only a version number, using the current state.
Definition at line 471 of file Persistent_impl.hpp.
uint64_t persistent::Persistent< ObjectType, storageType >::cnt_in_persist = 0ul |
Definition at line 594 of file Persistent.hpp.
uint64_t persistent::Persistent< ObjectType, storageType >::cnt_in_set = 0ul |
Definition at line 595 of file Persistent.hpp.
|
protected |
Definition at line 561 of file Persistent.hpp.
|
protected |
Definition at line 563 of file Persistent.hpp.
std::unique_ptr<ObjectType> persistent::Persistent< ObjectType, storageType >::m_pWrappedObject |
Definition at line 557 of file Persistent.hpp.
uint64_t persistent::Persistent< ObjectType, storageType >::ns_in_persist = 0ul |
Definition at line 592 of file Persistent.hpp.
uint64_t persistent::Persistent< ObjectType, storageType >::ns_in_set = 0ul |
Definition at line 593 of file Persistent.hpp.