ETSI STF525 / Internal Testing test suite
This project provides an internal testing test suite and its associated Test Adapter/Codec
registration.hh
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <string>
14 #include <map>
15 
22 template <typename TItem>
23 class registration { // TODO Refine the naming, derive from std::map<std::string, TItem*>
24  std::map<std::string, TItem*> _items;
25 
27 private:
28  registration(): _items() { }; // can not be created manually
29 public:
31 
32 public:
33  void add_item(const std::string& type, TItem* f);
34  TItem * get_item(const std::string& type);
35 }; // End of class registration
36 
37 template <typename TItem>
39 
40 // static functions
41 template <typename TItem>
43 {
44  return (_instance != nullptr) ? *_instance : *(_instance = new registration());
45 }
46 
47 template <typename TItem>
48 void registration<TItem>::add_item(const std::string & type, TItem * f)
49 {
50  _items[type] = f;
51 }
52 
53 template <typename TItem>
54 TItem* registration<TItem>::get_item(const std::string & type)
55 {
56  typename std::map<std::string, TItem*>::const_iterator it =_items.find(type);
57  if (it == _items.cend()) {
58  return nullptr;
59  }
60 
61  return it->second;
62 } // End of class registration
void add_item(const std::string &type, TItem *f)
Definition: registration.hh:48
static registration< TItem > & get_instance()
Definition: registration.hh:42
This class provides a way to register items and its object reference The registered items are accessi...
Definition: registration.hh:23
std::map< std::string, TItem * > _items
Definition: registration.hh:24
TItem * get_item(const std::string &type)
Definition: registration.hh:54
static registration< TItem > * _instance
Definition: registration.hh:26
registration()
Definition: registration.hh:28