A class that stores all kind of objects. More...
#include <object_store.hpp>
Public Types | |
enum | abstract_type { abstract , not_abstract } |
typedef prototype_iterator | iterator |
typedef const_prototype_iterator | const_iterator |
Public Member Functions | |
object_store (const object_store &)=delete | |
object_store & | operator= (const object_store &)=delete |
object_store () | |
~object_store () | |
template<class T > | |
prototype_iterator | attach (const char *type, const char *parent=nullptr) |
template<class T > | |
prototype_iterator | attach_abstract (const char *type, const char *parent=nullptr) |
template<class T , class S > | |
prototype_iterator | attach (const char *type) |
template<class T , class S > | |
prototype_iterator | attach_abstract (const char *type) |
template<class T > | |
prototype_iterator | attach (const char *type, abstract_type abstract, const char *parent) |
template<class T , template< class U=T > class O> | |
prototype_iterator | attach (const char *type, std::initializer_list< O< T > * > observer={}) |
template<class T , class S , template< class U=T > class O> | |
prototype_iterator | attach (const char *type, std::initializer_list< O< T > * > observer={}) |
template<class T , class S , template< class U=T > class O> | |
prototype_iterator | attach_abstract (const char *type, std::initializer_list< O< T > * > observer) |
template<class T , template< class U=T > class O> | |
prototype_iterator | attach (const char *type, abstract_type abstract, const char *parent, std::initializer_list< O< T > * > observer) |
template<class T , template< class U=T > class O> | |
prototype_iterator | attach (prototype_node *node, const char *parent, std::initializer_list< O< T > * > observer) |
template<class T , template< class U=T > class O> | |
prototype_iterator | attach (prototype_node *node, std::initializer_list< O< T > * > observer) |
template<class T > | |
prototype_iterator | attach (prototype_node *node, const char *parent=nullptr) |
template<class T , template< class U=T > class O> | |
prototype_iterator | attach_internal (prototype_node *node, const char *parent, std::vector< O< T > * > observer) |
void | detach (const char *type) |
iterator | detach (const prototype_iterator &i) |
template<class T > | |
std::string | type () const |
iterator | find (const char *type) |
Finds prototype node. | |
const_iterator | find (const char *type) const |
Finds prototype node. | |
template<class T > | |
iterator | find () |
Finds prototype node by template type. | |
template<class T > | |
const_iterator | find () const |
Finds prototype node by template type. | |
template<class T > | |
object_ptr< T > | get (const identifier &pk) |
Get object by primary key. | |
const_iterator | begin () const |
iterator | begin () |
const_iterator | end () const |
iterator | end () |
void | clear (bool full=false) |
void | clear (const char *type) |
void | clear (const prototype_iterator &node) |
size_t | size () const |
bool | empty () const |
template<class T > | |
T * | create () const |
template<typename P > | |
void | for_each_root_node (P pred) const |
object_proxy * | insert (object_proxy *proxy, bool notify) |
Inserts a new proxy into the object store. | |
template<class T > | |
object_ptr< T > | insert (T *o) |
template<class Type , typename... Args> | |
object_ptr< Type > | insert (Args &&... args) |
template<class T > | |
object_ptr< T > | insert (const object_ptr< T > &o) |
template<class T > | |
bool | is_removable (const object_ptr< T > &o) |
void | remove_proxy (object_proxy *proxy) |
void | remove (object_proxy *proxy, bool check_if_deletable) |
template<class T > | |
void | remove (object_ptr< T > &o) |
object_proxy * | find_proxy (unsigned long long id) const |
Finds object proxy with id. | |
object_proxy * | insert_proxy (object_proxy *proxy) |
transaction | current_transaction () |
bool | has_transaction () const |
void | mark_modified (object_proxy *proxy) |
template<class T > | |
void | mark_modified (const object_ptr< T > &optr) |
void | on_proxy_delete (std::function< void(object_proxy *)> callback) |
A class that stores all kind of objects.
This class is the main container class for all objects. To manage the internal list of objects the store must know the object class hierarchy.
Therefor an object prototype tree holds the object hierarchy representation including a producer class object of all known types.
typedef const_prototype_iterator matador::object_store::const_iterator |
Shortcut for the list const iterator.
typedef prototype_iterator matador::object_store::iterator |
Shortcut for the list iterator.
matador::object_store::object_store | ( | ) |
Create an empty object store.
matador::object_store::~object_store | ( | ) |
Destroys all prototypes, objects and observers in store.
|
inline |
Inserts a new concrete object prototype into the prototype tree. The prototype consists of a unique type name.
T | The type of the prototype node |
S | The type of the parent prototype node |
type | The unique name of the type. |
|
inline |
If the abstract flag is true prototype is treated as abstract. No concrete object can be inserted for this prototype.
T | The type of the prototype node |
type | The unique name of the type. |
abstract | Indicates if the producers object is treated as an abstract node. |
parent | Name of the parent node |
|
inline |
Inserts a new abstract object prototype into the prototype tree. The prototype consists of a unique type name.
T | The type of the prototype node |
O | The type of the observer classes |
type | The unique name of the type. |
abstract | Indicates weather type is abstract or not |
parent | The name of the parent node. |
observer | A list of observer to be called an attach |
|
inline |
Inserts a new concrete object prototype into the object_store. The prototype consists of a unique type name. The type of the prototype is given via template parameter T. If parent name is given prototype node is inserted below the found parent node.
T | Type of the prototype |
type | Name of the prototype |
parent | Name of the parent node |
|
inline |
Inserts a new concrete object prototype into the prototype tree. The prototype consists of a unique type name.
T | The type of the prototype node |
O | The type of the observer classes |
type | The unique name of the type. |
observer | A list of observer to be called an attach |
|
inline |
Inserts a new concrete object prototype into the prototype tree. The prototype consists of a unique type name.
T | The type of the prototype node |
S | The type of the parent prototype node |
O | The type of the observer classes |
type | The unique name of the type. |
observer | A list of observer to be called an attach |
prototype_iterator matador::object_store::attach | ( | prototype_node * | node, |
const char * | parent, | ||
std::initializer_list< O< T > * > | observer | ||
) |
Inserts a new object prototype into the object_store. The type of the prototype is given via template parameter T. A prepared prototype node is passed to be inserted. If parent name is given prototype node is inserted below the found parent node.
T | The type of the prototype node |
O | The type of the observer classes |
node | The prototype node to be inserted |
parent | The name of the parent node. |
observer | A list of observer to be called an attach |
|
inline |
Inserts a new object prototype into the object_store. The type of the prototype is given via template parameter T. A prepared prototype node is passed to be inserted. If parent name is given prototype node is inserted below the found parent node.
T | The type of the prototype node |
node | The prototype node to be inserted |
parent | The name of the parent node. |
|
inline |
Inserts a new object prototype into the object_store as a root object type. The type of the prototype is given via template parameter T. A prepared prototype node is passed to be inserted.
T | The type of the prototype node |
O | The type of the observer classes |
node | The prototype node to be inserted |
observer | A list of observer to be called an attach |
|
inline |
Inserts a new abstract object prototype into the prototype tree. The prototype consists of a unique type name.
T | The type of the prototype node |
S | The type of the parent prototype node |
type | The unique name of the type. |
|
inline |
Inserts a new abstract object prototype into the object_store. The prototype consists of a unique type name. The type of the prototype is given via template parameter T. If parent name is given prototype node is inserted below the found parent node.
T | Type of the prototype |
type | Name of the prototype |
parent | Name of the parent node |
|
inline |
Inserts a new abstract object prototype into the prototype tree. The prototype consists of a unique type name.
T | The type of the prototype node |
S | The type of the parent prototype node |
O | The type of the observer classes |
type | The unique name of the type. |
observer | A list of observer to be called an attach |
prototype_iterator matador::object_store::attach_internal | ( | prototype_node * | node, |
const char * | parent, | ||
std::vector< O< T > * > | observer | ||
) |
Inserts a new object prototype into the object_store as a root object type. The type of the prototype is given via template parameter T. A prepared prototype node is passed to be inserted.
T | The type of the prototype node |
O | The type of the observer classes |
node | The prototype node to be inserted |
parent | The name of the parent node. |
observer | A list of observer to be called an attach |
iterator matador::object_store::begin | ( | ) |
Return the first prototype node.
const_iterator matador::object_store::begin | ( | ) | const |
Return the first prototype node.
void matador::object_store::clear | ( | bool | full = false | ) |
Removes all inserted prototypes and all inserted objects.
void matador::object_store::clear | ( | const char * | type | ) |
Clears a prototype node and its children nodes. All objects will be deleted.
type | The name of the type to remove. |
matador::object_exception | on error |
void matador::object_store::clear | ( | const prototype_iterator & | node | ) |
Clears a prototype node by an iterator and its children nodes. All object_proxy objects will be deleted.
node | The prototype_iterator to remove. |
matador::object_exception | on error |
|
inline |
Creates an object of the given type name.
transaction matador::object_store::current_transaction | ( | ) |
Return the current transaction in stack
void matador::object_store::detach | ( | const char * | type | ) |
Removes an object prototype from the prototype tree. All children nodes and all objects are also removed.
type | The name of the type to remove. |
iterator matador::object_store::detach | ( | const prototype_iterator & | i | ) |
Erase a prototype node identified by its iterator. The successor iterator is returned.
i | The prototype iterator to be erased |
bool matador::object_store::empty | ( | ) | const |
Returns true if the object_store contains no elements (objects)
iterator matador::object_store::end | ( | ) |
Return the last prototype node.
const_iterator matador::object_store::end | ( | ) | const |
Return the last prototype node.
|
inline |
Finds prototype node by template type.
Template | type. |
Finds and returns prototype node iterator identified by the given template typeid. If the prototype couldn't be found prototype_iterator end is returned.
|
inline |
Finds prototype node by template type.
Template | type. |
Finds and returns prototype node iterator identified by the given template typeid. If the prototype couldn't be found prototype_iterator end is returned.
iterator matador::object_store::find | ( | const char * | type | ) |
Finds prototype node.
Finds and returns prototype node iterator identified by the given name or classname (typeid). If the prototype couldn't be found prototype_iterator end is returned.
type | Name or class name of the prototype |
const_iterator matador::object_store::find | ( | const char * | type | ) | const |
Finds prototype node.
Finds and returns prototype node iterator identified by the given name or classname (typeid). If the prototype couldn't be found prototype_iterator end is returned.
type | Name or class name of the prototype |
object_proxy * matador::object_store::find_proxy | ( | unsigned long long | id | ) | const |
Finds object proxy with id.
Try to find the object proxy with given id in object stores proxy map. If object can't be found NULL is returned.
id | ID of object proxy to find |
|
inline |
Executes a predicate for each root node
P | The type of the predicate function object |
pred | The function object to be executed |
|
inline |
Get object by primary key.
Gets an object of given type and given primary key. If the object can't be found an empty object is returned.
T | The type of the requested object. |
pk | The primary key value |
bool matador::object_store::has_transaction | ( | ) | const |
Returns true if there is at least one transaction on stack.
|
inline |
Inserts an object of a specific type. On successful insertion an object_ptr element with the inserted object is returned.
Type | Type of the object to insert |
Args | Argument types of the constructor arguments |
args | Arguments to construct the object |
|
inline |
Inserts a given object_ptr of specific type. On successfully insertion an object_ptr element with the inserted object is returned.
o | object_ptr to be inserted. |
object_proxy * matador::object_store::insert | ( | object_proxy * | proxy, |
bool | notify | ||
) |
Inserts a new proxy into the object store.
proxy | Object proxy to insert |
notify | Indicates whether all observers should be notified. |
|
inline |
Inserts an object of a specific type. On successful insertion an object_ptr element with the inserted object is returned.
o | Object to be inserted. |
object_proxy * matador::object_store::insert_proxy | ( | object_proxy * | proxy | ) |
Insert object proxy into object store Object id must be set
|
inline |
Returns true if the underlying object is removable.
o | The object to check. |
|
inline |
Marks the given object_ptr as modified and notifies all transactions
T | Object type of the object_ptr |
optr | The modified object_ptr |
void matador::object_store::mark_modified | ( | object_proxy * | proxy | ) |
Marks the given object proxy as modified and notifies all transactions
proxy | The modified object proxy |
void matador::object_store::on_proxy_delete | ( | std::function< void(object_proxy *)> | callback | ) |
Registers a callback when an object proxy is deleted from the object store
callback | To be called when an object proxy is deleted |
void matador::object_store::remove | ( | object_proxy * | proxy, |
bool | check_if_deletable | ||
) |
Remove the given object_proxy. The prototype_node id extracted from the given proxy to remove the proxy from its proxy list.
If the notify flag is true all observers are notified on successfully deletion.
If check_if_deletable flag is true method checks if the proxy is deletable.
proxy | The object_proxy to be removed. |
check_if_deletable | If true methods checks if proxy is deletable. |
|
inline |
Removes an object from the object store. After successful removal the object is set to zero and isn't valid any more.
Before removal is done a reference and pointer counter check is done. If at least one counter is greater than zero the object can't be removed and false is returned.
object_exception |
o | Object to remove. |
void matador::object_store::remove_proxy | ( | object_proxy * | proxy | ) |
Remove the given object_proxy. The prototype_node id extracted from the given proxy to remove the proxy from its proxy list.
proxy | The object_proxy to be removed. |
size_t matador::object_store::size | ( | ) | const |
Return count of prototype nodes
|
inline |
Finds the typename to the given class. If no typename is found an empty string is returned.
class | type to find |