31 #ifndef DRAIN_REGISTRY_H_
32 #define DRAIN_REGISTRY_H_
34 #include <drain/Log.h>
38 #include "Dictionary.h"
39 #include "ReferenceMap.h"
40 #include "VariableMap.h"
64 typedef std::map<std::string, T &> map_t;
77 void add(T & r,
const std::string & key,
char alias = 0);
82 bool has(
const std::string & key)
const;
85 char getAlias(
const std::string & key)
const;
88 const std::string &
getKey(
char alias)
const;
91 T &
get(
const std::string & name)
const;
94 map_t &
getMap(){
return entryMap; };
97 const map_t &
getMap()
const {
return entryMap; };
101 const typename map_t::const_iterator
find(
const std::string & name)
const {
102 return (name.length() == 1) ? entryMap.find(
getKey(name.at(0))) : entryMap.find(name);
107 typename map_t::iterator
find(
const std::string & name) {
109 return (name.length() == 1) ? entryMap.find(
getKey(name.at(0))) : entryMap.find(name);
129 entryMap.insert(std::pair<std::string, T &>(name, r));
132 aliasesNew.add(alias, name);
142 return (find(name) != entryMap.end());
150 if (it != aliasesNew.end())
153 static const std::string empty;
166 if (it != aliasesNew.end()){
178 const typename map_t::const_iterator it = find(name);
179 if (it != entryMap.end())
182 throw std::runtime_error(name +
": no such entry");
A container for storing global objects like functors, operators or commands. Supports aliases.
Definition: Registry.h:60
char getAlias(const std::string &key) const
Returns a single-letter abbreviation of a command.
Definition: Registry.h:162
T & get(const std::string &name) const
Given a single-letter abbreviation or full command name, returns the command object.
Definition: Registry.h:177
const std::string & getKey(char alias) const
Given a single-letter abbreviation, return the command name.
Definition: Registry.h:146
const map_t::const_iterator find(const std::string &name) const
Like find(), but handles aliases.
Definition: Registry.h:101
map_t::iterator find(const std::string &name)
Like find(), but handles aliases.
Definition: Registry.h:107
Registry()
TODO: reference not recommended.
Definition: Registry.h:69
map_t & getMap()
Returns the actual map containig the entries.
Definition: Registry.h:94
bool has(const std::string &key) const
Queries whether a command has been added.
Definition: Registry.h:140
virtual void add(T &r, const std::string &key, char alias=0)
Adds entry of (base) class T to current section of registry.
Definition: Registry.h:127
const map_t & getMap() const
Returns the actual map containig the entries.
Definition: Registry.h:97
Definition: DataSelector.cpp:1277