1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
6 #include "base/i2-base.hpp"
7 #include "base/object.hpp"
8 #include "base/value.hpp"
9 #include <boost/range/iterator.hpp>
16 typedef std::vector<std::pair<String, Value> > DictionaryData;
19 * A container that holds key-value pairs.
23 class Dictionary final : public Object
26 DECLARE_OBJECT(Dictionary);
29 * An iterator that can be used to iterate over dictionary elements.
31 typedef std::map<String, Value>::iterator Iterator;
33 typedef std::map<String, Value>::size_type SizeType;
35 typedef std::map<String, Value>::value_type Pair;
37 Dictionary() = default;
38 Dictionary(const DictionaryData& other);
39 Dictionary(DictionaryData&& other);
40 Dictionary(std::initializer_list<Pair> init);
42 Value Get(const String& key) const;
43 bool Get(const String& key, Value *result) const;
44 void Set(const String& key, Value value, bool overrideFrozen = false);
45 bool Contains(const String& key) const;
50 size_t GetLength() const;
52 void Remove(const String& key, bool overrideFrozen = false);
54 void Remove(Iterator it, bool overrideFrozen = false);
56 void Clear(bool overrideFrozen = false);
58 void CopyTo(const Dictionary::Ptr& dest) const;
59 Dictionary::Ptr ShallowClone() const;
61 std::vector<String> GetKeys() const;
63 static Object::Ptr GetPrototype();
65 Object::Ptr Clone() const override;
67 String ToString() const override;
71 Value GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const override;
72 void SetFieldByName(const String& field, const Value& value, bool overrideFrozen, const DebugInfo& debugInfo) override;
73 bool HasOwnField(const String& field) const override;
74 bool GetOwnField(const String& field, Value *result) const override;
77 std::map<String, Value> m_Data; /**< The data for the dictionary. */
81 Dictionary::Iterator begin(const Dictionary::Ptr& x);
82 Dictionary::Iterator end(const Dictionary::Ptr& x);
86 extern template class std::map<icinga::String, icinga::Value>;
88 #endif /* DICTIONARY_H */