diff options
Diffstat (limited to 'meowpp/oo/ObjDictionary.h')
-rw-r--r-- | meowpp/oo/ObjDictionary.h | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/meowpp/oo/ObjDictionary.h b/meowpp/oo/ObjDictionary.h index 39e103e..f43be58 100644 --- a/meowpp/oo/ObjDictionary.h +++ b/meowpp/oo/ObjDictionary.h @@ -24,26 +24,27 @@ class ObjDictionary: public ObjBase { private: struct Myself { std::map<Key, Value> dictionary_; + Myself() { } - ~Myself() { + + Myself(Myself const& b): dictionary_(b.dictionary_) { } - Myself& copyFrom(Myself const& b) { - dictionary_ = b.dictionary_; - return *this; + + ~Myself() { } }; + Self<Myself> const self; public: - ObjDictionary(): self(true) { + ObjDictionary(): self() { } - ObjDictionary(ObjDictionary const& d): self(false) { + ObjDictionary(ObjDictionary const& d): self(d.self, Self<Myself>::COPY_FROM) { self.copyFrom(b.self); } - ObjDictionary(std::map<Key, Value> const& d): self(true) { - self()->dictionary_ = d; + ObjDictionary(std::map<Key, Value> const& d): self(Myself(d)) { } ~ObjDictionary() { @@ -62,6 +63,7 @@ public: size_t size() const { return self->dictionary_.size(); } + bool empty() const { return self->dictionary_.empty(); } @@ -70,8 +72,16 @@ public: self()->dictionary_.clear(); } + std::map<Key, Value>::const_iterator first() const { + return self()->dictionary_.begin(); + } + + std::map<Key, Value>::iterator first() { + return self()->dictionary_.begin(); + } + std::map<Key, Value>::const_iterator end() const { - return self->dictionary_.end(); + return self()->dictionary_.end(); // OAO!!! } std::map<Key, Value>::iterator end() { @@ -79,7 +89,7 @@ public: } std::map<Key, Value>::const_iterator find(Key const& k) const { - return self->dictionary_.find(k); + return self()->dictionary_.find(k); // OAO!!! } std::map<Key, Value>::iterator find(Key const& k) { @@ -97,8 +107,8 @@ public: ObjDictionary& operator=(ObjDictionary const& a) { return copyFrom(a); } - - Value& operator[](Key const& k) { + + Value operator[](Key const& k) { return self()->dictionary_[k]; } @@ -110,8 +120,7 @@ public: else { if (fprintf(f, "%lu\n", sz) < 1) return false; } - for (std::map<Key, Value>::const_iterator - it = self->dictionary_.begin(); it != self->dictionary_.end(); ++it) { + for (std::map<Key, Value>::const_iterator it = begin(); it != end(); ++it) { if (it->first .write(f, bin, fg) == false) return false; if (it->second.write(f, bin, fg) == false) return false; } @@ -135,19 +144,19 @@ public: } return true; } - + ObjBase* create() const { return new ObjDictionary(); } - + ObjBase* copyFrom(ObjBase const* b) { - return &(copyFrom(*(ObjDictionary*)b)); + return &(copyFrom(*(ObjDictionary const*)b)); } - + char const* ctype() const { return typeid(*this).name(); } - + std::string type() const { return std::string(ctype()); } |