#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)<--- Class 'TypedRegistrationInterface' has a constructor with 1 argument that is not explicit. [+]Class 'TypedRegistrationInterface' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.
: 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; }<--- Technically the member function 'RegistrationInterfaceRegistry::registry' can be const. [+]The member function 'RegistrationInterfaceRegistry::registry' can be made a const function. Making this function 'const' should not cause compiler errors. Even though the function can be made const function technically it may not make sense conceptually. Think about your design and the task of the function first - is it a function that must not change object internal state?
};
#endif // _RegistrationInterface_h_