22 #ifndef EMP_CONFIG_MANAGER_H 23 #define EMP_CONFIG_MANAGER_H 40 : type_keyword(_type), command_keyword(_command) { ; }
46 virtual void NewObject(
const std::string & obj_name) = 0;
47 virtual void UseObject(
const std::string & obj_name) = 0;
53 std::map<std::string, MANAGED_TYPE *> name_map;
54 MANAGED_TYPE * cur_obj;
55 std::function<bool(MANAGED_TYPE &, std::string)> callback_fun;
59 std::function<
bool(MANAGED_TYPE &, std::string)> _fun)
68 return (name_map.find(obj_name) != name_map.end());
72 if (HasObject(obj_name) ==
true) {
74 ss <<
"Building new object of type '" <<
type_keyword <<
"' named '" 75 << obj_name <<
"' when one already exists. Replacing." <<
std::endl;
77 delete name_map[obj_name];
79 cur_obj =
new MANAGED_TYPE;
80 name_map[obj_name] = cur_obj;
84 if (HasObject(obj_name) ==
false) {
86 ss <<
"Trying to use object of type '" <<
type_keyword <<
"' named '" 87 << obj_name <<
"', but does not exist. Ignoring." <<
std::endl;
91 cur_obj = name_map[obj_name];
95 if (cur_obj ==
nullptr) {
97 ss <<
"Must build new '" <<
type_keyword <<
"' object before using command '" 103 return callback_fun(*cur_obj, command);
ConfigManager(const std::string &_type, const std::string &_command, std::function< bool(MANAGED_TYPE &, std::string)> _fun)
Definition: ConfigManager.h:58
void NewObject(const std::string &obj_name)
Definition: ConfigManager.h:71
const std::string type_keyword
Definition: ConfigManager.h:35
virtual bool CommandCallback(const std::string &command)=0
void NotifyError(Ts &&...msg)
End user has done something resulting in an non-recoverable problem.
Definition: errors.h:145
const std::string command_keyword
Definition: ConfigManager.h:36
ConfigManager_Base(const std::string &_type, const std::string &_command)
Definition: ConfigManager.h:39
bool CommandCallback(const std::string &command)
Definition: ConfigManager.h:94
static const PrintStr endl("<br>")
Pre-define emp::endl to insert a "<br>" and thus acting like a newline.
Definition: ConfigManager.h:33
bool HasObject(const std::string &obj_name)
Definition: ConfigManager.h:67
If we are in emscripten, make sure to include the header.
Definition: array.h:37
virtual void UseObject(const std::string &obj_name)=0
~ConfigManager()
Definition: ConfigManager.h:65
const std::string & GetCommandKeyword() const
Definition: ConfigManager.h:44
virtual ~ConfigManager_Base()
Definition: ConfigManager.h:41
const std::string & GetTypeKeyword() const
Definition: ConfigManager.h:43
Definition: ConfigManager.h:51
virtual void NewObject(const std::string &obj_name)=0
void UseObject(const std::string &obj_name)
Definition: ConfigManager.h:83