Registrar< RegisteredType, KeyType, class > Class Template Reference

Stores key object pairs. More...

#include <ArmarXCore/core/util/Registrar.h>

Classes

struct  RegisterElement
 Registers the object passed to the constructor. More...
 

Public Types

using ContainerType = std::unordered_map< KeyType, RegisteredType >
 

Static Public Member Functions

static const RegisteredType & get (const KeyType &key)
 Returns the registered object for the given key. More...
 
static std::vector< KeyType > getKeys ()
 Retrieves the list of all registered elements. More...
 
static bool has (const KeyType &key)
 
static void registerElement (const KeyType &key, RegisteredType element)
 Registers an element. More...
 

Detailed Description

template<class RegisteredType, class KeyType = std::string, class = void>
class armarx::Registrar< RegisteredType, KeyType, class >

Stores key object pairs.

The third template parameter offers the option to tag this registrar with a class.

If polymorphic objects are required use a base class and unique pointers. E.g.:

class Base{};
class DerivedA{};
class DerivedB{};
Registrar<std::unique_ptr<Base>>::registerElement("A", DerivedA{});
Registrar<std::unique_ptr<Base>>::registerElement("B", DerivedB{});

If functions are stored use std::function (or function pointers).

To register elements on file inclusion use this code in the header (note the missing static).

Registrar<Type>::RegisterElement register("A", object);

Example for strings

Registrar<std::string>::RegisterElement register1("key 1", "value 1");
Registrar<std::string>::RegisterElement register2("key 2", "value 2");

Definition at line 62 of file Registrar.h.

Member Typedef Documentation

◆ ContainerType

using ContainerType = std::unordered_map<KeyType, RegisteredType>

Definition at line 65 of file Registrar.h.

Member Function Documentation

◆ get()

static const RegisteredType& get ( const KeyType &  key)
inlinestatic

Returns the registered object for the given key.

Parameters
keyThe object's key.
Returns
The registered object for the given key.

Definition at line 84 of file Registrar.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getKeys()

static std::vector<KeyType> getKeys ( )
inlinestatic

Retrieves the list of all registered elements.

Returns
The list of all registered elements.

Definition at line 115 of file Registrar.h.

+ Here is the caller graph for this function:

◆ has()

static bool has ( const KeyType &  key)
inlinestatic

Definition at line 94 of file Registrar.h.

+ Here is the caller graph for this function:

◆ registerElement()

static void registerElement ( const KeyType &  key,
RegisteredType  element 
)
inlinestatic

Registers an element.

Parameters
keyThe element's key.
elementThe element.

Definition at line 105 of file Registrar.h.

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file:
armarx::Registrar::registerElement
static void registerElement(const KeyType &key, RegisteredType element)
Registers an element.
Definition: Registrar.h:105