From 11e643f4b885ee1f96112fcf531739a339691272 Mon Sep 17 00:00:00 2001 From: Marius Nita Date: Mon, 26 Aug 2002 06:36:37 +0000 Subject: New and improved configuration management. It now handles bool, string and number types, and all conversions happen at initialization time, so retrieval is faster. (yay) --- util/epist/config.hh | 65 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 26 deletions(-) (limited to 'util/epist/config.hh') diff --git a/util/epist/config.hh b/util/epist/config.hh index 443834ed..0cb2a1c0 100644 --- a/util/epist/config.hh +++ b/util/epist/config.hh @@ -26,50 +26,63 @@ #include #include -class ConfigItem; +// forward declarations +struct BoolItem; +struct StringItem; +struct NumberItem; class Config { public: - enum ItemType { - noType, + enum BoolType { + NO_BOOL_TYPE, + stackedCycling, + NUM_BOOL_TYPES + }; + + enum StringType { + NO_STRING_TYPE, + NUM_STRING_TYPES + }; + + enum NumberType { + NO_NUMBER_TYPE, chainTimeout, workspaceColumns, - numTypes + NUM_NUMBER_TYPES }; private: - typedef std::list ItemList; - ItemList items; + typedef std::list BoolItemList; + typedef std::list StringItemList; + typedef std::list NumberItemList; + BoolItemList bool_items; + StringItemList string_items; + NumberItemList number_items; public: Config(); ~Config(); - bool getStringValue(Config::ItemType, std::string &) const; - int getNumberValue(Config::ItemType) const; - void addOption(ConfigItem *); + bool getBoolValue(BoolType, bool &) const; + bool getStringValue(StringType, std::string &) const; + bool getNumberValue(NumberType, int &) const; + void addOption(const std::string &, const std::string &); }; +struct BoolItem { + Config::BoolType type; + bool value; +}; -class ConfigItem { -private: - Config::ItemType _type; - std::string _value; - -public: - ConfigItem(Config::ItemType type, std::string value) - : _type(type), _value(value) {} - ~ConfigItem() {} - - inline const std::string &getStringValue() const - { return _value; } - - inline int getNumberValue() const - { return atoi(_value.c_str()); } +struct StringItem { + Config::StringType type; + std::string value; +}; - inline Config::ItemType getType() const - { return _type; } +struct NumberItem { + Config::NumberType type; + int value; }; #endif // __config_hh -- cgit v1.2.3