|
| DataStore ()=default |
|
| DataStore (const DataStore &)=delete |
|
DataStore & | operator= (const DataStore &)=delete |
|
| DataStore (DataStore &&)=default |
|
DataStore & | operator= (DataStore &&)=default |
|
bool | has (const std::string &name) const noexcept |
| Checks whether an object is in the datastore. More...
|
|
std::vector< std::string > | keys () const noexcept |
| Returns all objects in the datastore. More...
|
|
template<typename T > |
T & | get (const std::string &name) |
| Get a reference to an object on the datastore. More...
|
|
template<typename T > |
const T & | get (const std::string &name) const |
| const variant of get More...
|
|
template<typename T > |
void | get (const std::string &name, T &data) |
| Assign value from the datastore if it exists, leave value unchanged otherwise. More...
|
|
template<typename T > |
const T & | get (const std::string &name, const T &defaultValue) const |
| Gets a value from the datastore if it exists or a default value otherwise. More...
|
|
template<typename T > |
void | assign (const std::string &name, const T &data) |
| Copies an object to an existing datastore object. More...
|
|
template<typename T , typename... ArgsT, typename... Args> |
T & | make (const std::string &name, Args &&... args) |
| Creates an object on the datastore and returns a reference to it. More...
|
|
template<typename T > |
auto | make_call (const std::string &name, T fn) -> typename internal::lambda_traits< T >::fn_t & |
| Creates an object on the datastore and returns a reference to it. More...
|
|
template<typename T , typename... ArgsT, typename... Args> |
T & | make_initializer (const std::string &name, Args &&... args) |
| Creates an object on the datastore using list initialization and returns a reference to it. More...
|
|
template<typename RetT , typename... FuncArgsT, typename... ArgsT, typename std::enable_if< sizeof...(FuncArgsT)==sizeof...(ArgsT) &&!std::is_same< std::tuple< FuncArgsT... >, std::tuple< ArgsT... >>::value, int >::type = 0> |
RetT | call (const std::string &name, ArgsT &&... args) const |
| Calls a function that was registered in the datastore and returns this call result. More...
|
|
template<typename RetT = void, typename... ArgsT> |
RetT | call (const std::string &name, ArgsT &&... args) const |
| Calls a function that was registered in the datastore and returns this call result. More...
|
|
void | remove (const std::string &name) noexcept |
| Removes an object from the datastore. More...
|
|
void | clear () noexcept |
| Remove all entries in the datastore. More...
|
|
const std::string & | name () const noexcept |
| Name of this datastore. More...
|
|
void | name (const std::string &name) noexcept |
| Sets this datastore's name. More...
|
|
Generic data store.
This class allows to store and retrieve C++ objects. It is intended to be used as a way to share arbitrary data between various parts of the framework (states, plugins, observers, etc...)
store.make<std::vector<double>>("Data", 4, 42);
...
auto & data = store.get<std::vector<double>>("Data");
data[3] = 0;
...
auto & data2 = store.get<std::vector<double>>("Data");
data2.push_back(0);
When retrieving an object using get<Type>, checks are performed to ensure that the stored type and Type are compatible.
To handle inheritance, you need to explicitely provide the class hierarchy:
struct A {};
struct B : public A {};
store.make<B, A>("data");
auto & base = store.get<A>("data");
auto & derived = store.get<B>("data");
template<typename RetT , typename... FuncArgsT, typename... ArgsT, typename std::enable_if< sizeof...(FuncArgsT)==sizeof...(ArgsT) &&!std::is_same< std::tuple< FuncArgsT... >, std::tuple< ArgsT... >>::value, int >::type = 0>
RetT mc_rtc::DataStore::call |
( |
const std::string & |
name, |
|
|
ArgsT &&... |
args |
|
) |
| const |
|
inline |
Calls a function that was registered in the datastore and returns this call result.
This is syntactic sugar for getting the function object and calling it
In this version you must specify the argument types for the function you are calling. This is especially useful when the types deduced from the arguments do not match the function type (typically passing a non-const reference to a function expecting a const reference.
- Parameters
-
name | Name of the stored function |
- Template Parameters
-
FunArgsT | Types of arguments expected by the function |
- Parameters
-
args | Arguments passed to the function |
template<typename RetT = void, typename... ArgsT>
RetT mc_rtc::DataStore::call |
( |
const std::string & |
name, |
|
|
ArgsT &&... |
args |
|
) |
| const |
|
inline |
Calls a function that was registered in the datastore and returns this call result.
This is syntaxic sugar for getting the function object and calling it
This version deduces the functions' arguments from the arguments passed to the call. This follows C++ rules for deducing types from universal reference collapsing except for arithmetic types where the type is deduced to be of value type.
If you need to call a callback that takes an arithmetic type by reference then you must specify the arguments' type explicitely
- Parameters
-
name | Name of the stored object |
@params args Arguments passed to the function