1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef _RegistrationInterface_h_
#define _RegistrationInterface_h_


#include "BlackBoard.h"
#include "DataHolder.h"

/**
* 
*/
class RegistrationInterface
{
private:
  std::string name;

public:
  RegistrationInterface(const std::string& name) : name(name){}
  virtual ~RegistrationInterface(){}
  const std::string getName() const { return name; }

  virtual Representation& registerAtBlackBoard(BlackBoard& blackBoard) = 0;
};

/** type for a named map of representation interfaces */
typedef std::map<std::string, RegistrationInterface*> RegistrationInterfaceMap;

/**
*
*/
template<class T>
class TypedRegistrationInterface: public RegistrationInterface
{
public:

  TypedRegistrationInterface(const std::string& name)
    : RegistrationInterface(name)
  {}

  Representation& registerAtBlackBoard(BlackBoard& blackBoard)
  {
    return blackBoard.template getRepresentation<DataHolder<T> >(getName());
  }
};//end class TypedRegistrationInterface


/**
*/
class RegistrationInterfaceRegistry
{
private:
  RegistrationInterfaceMap registry_map;

public:
  ~RegistrationInterfaceRegistry() {
    for(RegistrationInterfaceMap::iterator i = registry_map.begin(); i != registry_map.end(); ++i) {
      delete i->second;
    }
  }

  template<class R>
  RegistrationInterface* registerInterface(const std::string& name)
  {
    RegistrationInterfaceMap::iterator i = registry_map.find(name);
    if(i == registry_map.end()) {
      i = registry_map.insert(registry_map.begin(), std::make_pair(name, new TypedRegistrationInterface<R>(name)));
    }

    return i->second;
  }

  inline const RegistrationInterfaceMap& registry() { return registry_map; }
};
#endif // _RegistrationInterface_h_