1 #ifndef oo_ObjDictionary_H__
2 #define oo_ObjDictionary_H__
22 template<
class Key,
class Value>
26 std::map<Key, Value> dictionary_;
32 dictionary_ = b.dictionary_;
42 self.copyFrom(b.self);
46 self()->dictionary_ = d;
63 return self->dictionary_.size();
66 return self->dictionary_.empty();
70 self()->dictionary_.clear();
73 std::map<Key, Value>::const_iterator
end()
const {
74 return self->dictionary_.end();
77 std::map<Key, Value>::iterator
end() {
78 return self()->dictionary_.end();
81 std::map<Key, Value>::const_iterator
find(Key
const& k)
const {
82 return self->dictionary_.find(k);
85 std::map<Key, Value>::iterator
find(Key
const& k) {
86 return self()->dictionary_.find(k);
89 bool exist(Key
const& k)
const {
93 void insert(Key
const& k, Value
const& v) {
94 self->dictionary_.insert(std::pair<Key, Value>(k, v));
102 return self()->dictionary_[k];
105 bool write(FILE* f,
bool bin,
unsigned int fg)
const {
108 if (fwrite(&sz,
sizeof(
size_t), 1, f) < 1)
return false;
111 if (fprintf(f,
"%lu\n", sz) < 1)
return false;
113 for (std::map<Key, Value>::const_iterator
114 it = self->dictionary_.begin(); it !=
self->dictionary_.end(); ++it) {
115 if (it->first .write(f, bin, fg) ==
false)
return false;
116 if (it->second.write(f, bin, fg) ==
false)
return false;
121 bool read(FILE* f,
bool bin,
unsigned int fg) {
124 if (fread(&sz,
sizeof(
size_t), 1, f) < 1)
return false;
127 if (fscanf(f,
"%lu\n", &sz) < 0)
return false;
129 for (
size_t i = 0; i < sz; i++) {
132 if (k.read(f, bin, fg) ==
false)
return false;
133 if (v.read(f, bin, fg) ==
false)
return false;
148 return typeid(*this).name();
152 return std::string(
ctype());
158 #endif // oo_ObjDictionary_H__