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 "base/debuginfo.hpp"
19 virtual Value Get(const DebugInfo& debugInfo = DebugInfo()) const = 0;
20 virtual void Set(const Value& value, bool overrideFrozen, const DebugInfo& debugInfo = DebugInfo()) = 0;
23 struct EmbeddedNamespaceValue : public NamespaceValue
25 EmbeddedNamespaceValue(const Value& value);
27 Value Get(const DebugInfo& debugInfo) const override;
28 void Set(const Value& value, bool overrideFrozen, const DebugInfo& debugInfo) override;
34 struct ConstEmbeddedNamespaceValue : public EmbeddedNamespaceValue
36 using EmbeddedNamespaceValue::EmbeddedNamespaceValue;
38 void Set(const Value& value, bool overrideFrozen, const DebugInfo& debugInfo) override;
43 struct NamespaceBehavior
45 virtual void Register(const boost::intrusive_ptr<Namespace>& ns, const String& field, const Value& value, bool overrideFrozen, const DebugInfo& debugInfo) const;
46 virtual void Remove(const boost::intrusive_ptr<Namespace>& ns, const String& field, bool overrideFrozen);
49 struct ConstNamespaceBehavior : public NamespaceBehavior
51 void Register(const boost::intrusive_ptr<Namespace>& ns, const String& field, const Value& value, bool overrideFrozen, const DebugInfo& debugInfo) const override;
52 void Remove(const boost::intrusive_ptr<Namespace>& ns, const String& field, bool overrideFrozen) override;
64 class Namespace final : public Object
67 DECLARE_OBJECT(Namespace);
69 typedef std::map<String, std::shared_ptr<NamespaceValue> >::iterator Iterator;
71 typedef std::map<String, std::shared_ptr<NamespaceValue> >::value_type Pair;
73 Namespace(NamespaceBehavior *behavior = new NamespaceBehavior);
75 Value Get(const String& field) const;
76 bool Get(const String& field, Value *value) const;
77 void Set(const String& field, const Value& value, bool overrideFrozen = false);
78 bool Contains(const String& field) const;
79 void Remove(const String& field, bool overrideFrozen = false);
81 std::shared_ptr<NamespaceValue> GetAttribute(const String& field) const;
82 void SetAttribute(const String& field, const std::shared_ptr<NamespaceValue>& nsVal);
83 void RemoveAttribute(const String& field);
88 Value GetFieldByName(const String& field, bool sandboxed, const DebugInfo& debugInfo) const override;
89 void SetFieldByName(const String& field, const Value& value, bool overrideFrozen, const DebugInfo& debugInfo) override;
90 bool HasOwnField(const String& field) const override;
91 bool GetOwnField(const String& field, Value *result) const override;
93 static Object::Ptr GetPrototype();
96 std::map<String, std::shared_ptr<NamespaceValue> > m_Data;
97 std::unique_ptr<NamespaceBehavior> m_Behavior;
100 Namespace::Iterator begin(const Namespace::Ptr& x);
101 Namespace::Iterator end(const Namespace::Ptr& x);
105 extern template class std::map<icinga::String, std::shared_ptr<icinga::NamespaceValue> >;
107 #endif /* NAMESPACE_H */