MVault 0.0.1
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
mvlt::DataContainer< C > Class Template Reference

Template prototype of a container for storing different types of data. More...

#include <DataContainer.h>

Public Types

typedef C::iterator iterator
 Redefine iterator from C container.
 
typedef C::const_iterator const_iterator
 Redefine const_iterator from C container.
 

Public Member Functions

iterator begin () noexcept
 Begin provides access to the Data iterator.
 
const_iterator cbegin () const noexcept
 Cbegin provides access to the Data const_iterator.
 
iterator end () noexcept
 End provides access to the Data iterator.
 
const_iterator cend () const noexcept
 Cend provides access to the Data const_iterator.
 
template<class T >
void AddData (const std::string &key, const T &data) noexcept
 Template method for adding a new data to the container.
 
template<class T , class F >
void AddData (const std::string &key, const T &data, F &&deleteFunc) noexcept
 Template method for adding a new data to the container and a function to delete this data.
 
void AddDataFromDataSaver (const std::string &key, const DataSaver &dataSaver) noexcept
 Method for adding a new data to the container.
 
template<class T >
void SetData (const std::string &key, const T &data) noexcept
 Method for changing the value of a data inside a container using a key.
 
template<class T , class F >
void SetData (const std::string &key, const T &data, F &&deleteFunc) noexcept
 Method for changing the value of a data inside a container using a key.
 
void SetDataFromDataSaver (const std::string &key, const DataSaver &dataSaver) noexcept
 Method for changing the value of a data inside a container using a key.
 
bool SetDataFromString (const std::string &key, const std::string &str) noexcept
 Method for setting data by key.
 
template<class T >
bool GetData (const std::string &key, T &data) const noexcept
 Method for getting data from a container using a key.
 
bool GetDataSaver (const std::string &key, DataSaver &dataSaver) const noexcept
 Method for getting dataSaver from a container using a key.
 
bool GetDataAsString (const std::string &key, std::string &str) const noexcept
 Method for getting data converted to string from a container using a key.
 
bool IsData (const std::string &key) const noexcept
 A method for checking whether data with such a key is in the container.
 
void EraseData (const std::string &key) noexcept
 Function for erasing data from a container.
 
void Clear () noexcept
 Method for clear all data inside container.
 
std::size_t Size () const noexcept
 Method for getting the container size.
 

Protected Attributes

C Container
 Container to store all data inside C container.
 

Detailed Description

template<class C>
class mvlt::DataContainer< C >

Template prototype of a container for storing different types of data.

Template Parameters
<C>The container class for which this class will be the wrapper. Container have to support find(), begin(), end(), emplace(), erase().
Types that are used in inheritors:
<std::set>A container built on an avl tree.
<std::map>A container built on an avl tree. Stores a pair of key and value.
<std::unordered_set>A container built on a hash table.
<std::unordered_map>A container built on a hash table. Stores a pair of key and value.

The container should work according to the std::map type, i.e. store a key and value pair in itself. Using class specialization, you can define an internal container. If a pointer is written to one of the elements, then you can set a custom data deletion function.

Member Function Documentation

◆ AddData() [1/2]

template<class C >
template<class T >
void mvlt::DataContainer< C >::AddData ( const std::string &  key,
const T data 
)
inlinenoexcept

Template method for adding a new data to the container.

Wrapper over emplace std container

Template Parameters
<T>Any type of data except for c arrays
Parameters
[in]keykey for storing the data
[in]datadata to store in container

◆ AddData() [2/2]

template<class C >
template<class T , class F >
void mvlt::DataContainer< C >::AddData ( const std::string &  key,
const T data,
F &&  deleteFunc 
)
inlinenoexcept

Template method for adding a new data to the container and a function to delete this data.

Wrapper over emplace std container

Template Parameters
<T>Any type of data except for c arrays
<F>Function pointer or lambda function
Parameters
[in]keykey for storing the data
[in]datadata to store in container
[in]deleteFuncfunction to delete data

◆ AddDataFromDataSaver()

template<class C >
void mvlt::DataContainer< C >::AddDataFromDataSaver ( const std::string &  key,
const DataSaver dataSaver 
)
inlinenoexcept

Method for adding a new data to the container.

Parameters
[in]keythe key whose value needs to be changed
[in]dataSaverdataSaver with any type, the value from which will be copied to the container

◆ Clear()

template<class C >
void mvlt::DataContainer< C >::Clear ( )
inlinenoexcept

Method for clear all data inside container.

Note that if pointers were stored in the container, they must be cleaned manually

◆ EraseData()

template<class C >
void mvlt::DataContainer< C >::EraseData ( const std::string &  key)
inlinenoexcept

Function for erasing data from a container.

If a custom deletion function has been set for the data, it will be called

Parameters
[in]keykey to find in container

◆ GetData()

template<class C >
template<class T >
bool mvlt::DataContainer< C >::GetData ( const std::string &  key,
T data 
) const
inlinenoexcept

Method for getting data from a container using a key.

Template Parameters
<T>Any type of data except for c arrays
Parameters
[in]keykey for getting data
[out]dataa reference to data of type T to write data from the container there. If the data was not found, then nothing will be written to the data
Returns
Returns false if the key was not found, and otherwise returns true.

◆ GetDataAsString()

template<class C >
bool mvlt::DataContainer< C >::GetDataAsString ( const std::string &  key,
std::string &  str 
) const
inlinenoexcept

Method for getting data converted to string from a container using a key.

Parameters
[in]keykey for getting data
[out]stra reference to string to write data from the container there. If the data was not found, then nothing will be written to the str
Returns
Returns false if the key was not found, and otherwise returns true.

◆ GetDataSaver()

template<class C >
bool mvlt::DataContainer< C >::GetDataSaver ( const std::string &  key,
DataSaver dataSaver 
) const
inlinenoexcept

Method for getting dataSaver from a container using a key.

Parameters
[in]keykey for getting data
[out]dataSavera reference to dataSaver to write data from the container there. If the data was not found, then nothing will be written to the dataSaver
Returns
Returns false if the key was not found, and otherwise returns true.

◆ IsData()

template<class C >
bool mvlt::DataContainer< C >::IsData ( const std::string &  key) const
inlinenoexcept

A method for checking whether data with such a key is in the container.

Parameters
[in]keykey to find in container
Returns
Returns false if the key was not found, and otherwise returns true.

◆ SetData() [1/2]

template<class C >
template<class T >
void mvlt::DataContainer< C >::SetData ( const std::string &  key,
const T data 
)
inlinenoexcept

Method for changing the value of a data inside a container using a key.

If there was no data with such a key, it will be created

Template Parameters
<T>Any type of data except for c arrays
Parameters
[in]keythe key whose value needs to be changed
[in]datanew key value

◆ SetData() [2/2]

template<class C >
template<class T , class F >
void mvlt::DataContainer< C >::SetData ( const std::string &  key,
const T data,
F &&  deleteFunc 
)
inlinenoexcept

Method for changing the value of a data inside a container using a key.

If there was no data with such a key, it will be created

Template Parameters
<T>Any type of data except for c arrays
<F>Function pointer or lambda function
Parameters
[in]keythe key whose value needs to be changed
[in]datanew key value
[in]deleteFuncfunction to delete data

◆ SetDataFromDataSaver()

template<class C >
void mvlt::DataContainer< C >::SetDataFromDataSaver ( const std::string &  key,
const DataSaver dataSaver 
)
inlinenoexcept

Method for changing the value of a data inside a container using a key.

If there was no data with such a key, it will be created

Parameters
[in]keythe key whose value needs to be changed
[in]dataSaverdataSaver with any type, the value from which will be copied to the container

◆ SetDataFromString()

template<class C >
bool mvlt::DataContainer< C >::SetDataFromString ( const std::string &  key,
const std::string &  str 
)
inlinenoexcept

Method for setting data by key.

Parameters
[in]keythe key to set the data on
[in]strthe string that will be converted to data
Returns
true in success, otherwise return false

◆ Size()

template<class C >
std::size_t mvlt::DataContainer< C >::Size ( ) const
inlinenoexcept

Method for getting the container size.

Returns
Container size

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