Thrive
Public Member Functions | Static Public Member Functions | Friends | List of all members
thrive::StorageContainer Class Reference

A key-value storage for serialization. More...

#include <serialization.h>

Public Member Functions

 StorageContainer ()
 Constructor.
 
 StorageContainer (const StorageContainer &other)
 Copy-constructor. More...
 
 StorageContainer (StorageContainer &&other)
 Move-constructor. More...
 
 ~StorageContainer ()
 Destructor.
 
StorageContainer & operator= (const StorageContainer &other)
 Copy-assignment. More...
 
StorageContainer & operator= (StorageContainer &&other)
 Move assignment. More...
 
bool contains (const std::string &key) const
 Checks for a key. More...
 
template<typename T >
bool contains (const std::string &key) const
 Checks for a key together with type. More...
 
template<typename T >
T get (const std::string &key, const T &defaultValue=T()) const
 Retrieves a value from the container. More...
 
std::list< std::string > keys () const
 Returns a list of all keys in this container.
 
luabind::object luaGet (const std::string &key, luabind::object defaultValue) const
 Lua version of StorageContainer::get. More...
 
template<typename T >
void set (const std::string &key, T value)
 Sets a value in this container. More...
 

Static Public Member Functions

static luabind::scope luaBindings ()
 Lua bindings. More...
 

Friends

std::ostream & operator<< (std::ostream &stream, const StorageContainer &storage)
 Output stream operator for StorageContainer. More...
 
std::istream & operator>> (std::istream &stream, StorageContainer &storage)
 Input stream operator for StorageContainer. More...
 

Detailed Description

A key-value storage for serialization.

Constructor & Destructor Documentation

thrive::StorageContainer::StorageContainer ( const StorageContainer &  other)

Copy-constructor.

Parameters
other
thrive::StorageContainer::StorageContainer ( StorageContainer &&  other)

Move-constructor.

Parameters
other

Member Function Documentation

bool thrive::StorageContainer::contains ( const std::string &  key) const

Checks for a key.

Parameters
keyThe key to check for
Returns
true if the key is present in this container, false otherwise
template<typename T >
bool thrive::StorageContainer::contains ( const std::string &  key) const

Checks for a key together with type.

Template Parameters
TThe expected type of the key's associated value
Parameters
keyThe key to check for
Returns
true if the key is present and associated with a value of type T, false otherwise
template<typename T >
T thrive::StorageContainer::get ( const std::string &  key,
const T &  defaultValue = T() 
) const

Retrieves a value from the container.

Template Parameters
TThe value's type
Parameters
keyThe key to retrieve
defaultValueThe value to return when the key is not present (or the value has the wrong type)
Returns
The value associated with key or defaultValue if the key could not be found or has a value associated with it that is not T.
static luabind::scope thrive::StorageContainer::luaBindings ( )
static
luabind::object thrive::StorageContainer::luaGet ( const std::string &  key,
luabind::object  defaultValue 
) const

Lua version of StorageContainer::get.

Parameters
key
defaultValue
Returns
StorageContainer& thrive::StorageContainer::operator= ( const StorageContainer &  other)

Copy-assignment.

Parameters
other
StorageContainer& thrive::StorageContainer::operator= ( StorageContainer &&  other)

Move assignment.

Parameters
other
template<typename T >
void thrive::StorageContainer::set ( const std::string &  key,
T  value 
)

Sets a value in this container.

If key is already associated with a value, it is overwritten.

Template Parameters
TThe type of value
Parameters
keyThe key to associate with the value
valueThe value to insert

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  stream,
const StorageContainer &  storage 
)
friend

Output stream operator for StorageContainer.

Parameters
stream
storage
Returns
std::istream& operator>> ( std::istream &  stream,
StorageContainer &  storage 
)
friend

Input stream operator for StorageContainer.

Parameters
stream
storage
Returns

The documentation for this class was generated from the following file: