From 86e5f80837ad55932f2469d79d9e6b6bb07cf5ed Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 28 Sep 2009 19:09:22 +0200 Subject: Implemented new ConfigManager --- src/Core/ConfigEntry.h | 75 ++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 39 deletions(-) (limited to 'src/Core/ConfigEntry.h') 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 +#include #include +#include namespace Mad { namespace Core { -class MAD_CORE_EXPORT ConfigEntry { - public: - class MAD_CORE_EXPORT Entry { - private: - String key; - std::vector value; - - String zero, constZero; +class ConfigManager; - public: - Entry() {} - Entry(const std::vector &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 > EntryVector; + typedef std::map EntryMap; - bool isEmpty() const { - return key.isEmpty(); - } + ConfigEntry *parent; - String &getKey() {return key;} - const String &getKey() const {return key;} + std::vector 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 &values0) + : parent(parent0), values(values0) {} - private: - std::vector entries; - Entry zero, constZero; + void addChild(const String &key, boost::shared_ptr 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& 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 getEntries(const String &key) const; + + std::vector getAll(const String &key) const; + String get(const String &key, const String &defaultValue = String()) const; }; } -- cgit v1.2.3