diff options
Diffstat (limited to 'src/Core/ConfigEntry.h')
-rw-r--r-- | src/Core/ConfigEntry.h | 75 |
1 files changed, 36 insertions, 39 deletions
diff --git a/src/Core/ConfigEntry.h b/src/Core/ConfigEntry.h index 26e77d2..1724267 100644 --- a/src/Core/ConfigEntry.h +++ b/src/Core/ConfigEntry.h @@ -23,63 +23,60 @@ #include "export.h" #include "String.h" - -#include <stdexcept> +#include <map> #include <vector> +#include <boost/shared_ptr.hpp> namespace Mad { namespace Core { -class MAD_CORE_EXPORT ConfigEntry { - public: - class MAD_CORE_EXPORT Entry { - private: - String key; - std::vector<String> value; - - String zero, constZero; +class ConfigManager; - public: - Entry() {} - Entry(const std::vector<String> &args) { - if(args.empty()) - return; - - key = args.front(); +class MAD_CORE_EXPORT ConfigEntry { + private: + friend class ConfigManager; - value.assign(args.begin()+1, args.end()); - } + typedef std::vector<boost::shared_ptr<ConfigEntry> > EntryVector; + typedef std::map<String, EntryVector> EntryMap; - bool isEmpty() const { - return key.isEmpty(); - } + ConfigEntry *parent; - String &getKey() {return key;} - const String &getKey() const {return key;} + std::vector<String> values; + EntryMap children; - std::size_t getSize() const {return value.size();} + protected: + ConfigEntry() : parent(0) {} - String& operator[] (std::size_t i); - const String& operator[] (std::size_t i) const; - }; + public: + ConfigEntry(ConfigEntry *parent0, const std::vector<String> &values0) + : parent(parent0), values(values0) {} - private: - std::vector<Entry> entries; - Entry zero, constZero; + void addChild(const String &key, boost::shared_ptr<ConfigEntry> entry); - public: - std::size_t getSize() const {return entries.size();} + const ConfigEntry* getParent() const { + return parent; + } - Entry& operator[] (std::size_t i); - const Entry& operator[] (std::size_t i) const; + ConfigEntry* getParent() { + return parent; + } - void push(const Entry &entry) { - entries.push_back(entry); + const std::vector<String>& getValues() const { + return values; } - void pop() { - entries.pop_back(); + String getValue(const String &defaultValue = String()) const { + if(values.empty()) + return defaultValue; + else + return values.front(); } + + const ConfigEntry* getEntry(const String &key) const; + std::vector<const ConfigEntry*> getEntries(const String &key) const; + + std::vector<String> getAll(const String &key) const; + String get(const String &key, const String &defaultValue = String()) const; }; } |