INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), false); \
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
- nsp->SetAttribute(#name, std::make_shared<ConstEmbeddedNamespaceValue>(sf)); \
+ nsp->SetAttribute(#name, new ConstEmbeddedNamespaceValue(sf)); \
}, 10)
#define REGISTER_SAFE_FUNCTION(ns, name, callback, args) \
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), true); \
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
- nsp->SetAttribute(#name, std::make_shared<ConstEmbeddedNamespaceValue>(sf)); \
+ nsp->SetAttribute(#name, new ConstEmbeddedNamespaceValue(sf)); \
}, 10)
#define REGISTER_FUNCTION_NONCONST(ns, name, callback, args) \
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), false); \
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
- nsp->SetAttribute(#name, std::make_shared<EmbeddedNamespaceValue>(sf)); \
+ nsp->SetAttribute(#name, new EmbeddedNamespaceValue(sf)); \
}, 10)
#define REGISTER_SAFE_FUNCTION_NONCONST(ns, name, callback, args) \
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
Function::Ptr sf = new icinga::Function(#ns "#" #name, callback, String(args).Split(":"), true); \
Namespace::Ptr nsp = ScriptGlobal::Get(#ns); \
- nsp->SetAttribute(#name, std::make_shared<EmbeddedNamespaceValue>(sf)); \
+ nsp->SetAttribute(#name, new EmbeddedNamespaceValue(sf)); \
}, 10)
}
jsonNSBehavior->Freeze();
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
- systemNS->SetAttribute("Json", std::make_shared<ConstEmbeddedNamespaceValue>(jsonNS));
+ systemNS->SetAttribute("Json", new ConstEmbeddedNamespaceValue(jsonNS));
});
mathNSBehavior->Freeze();
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
- systemNS->SetAttribute("Math", std::make_shared<ConstEmbeddedNamespaceValue>(mathNS));
+ systemNS->SetAttribute("Math", new ConstEmbeddedNamespaceValue(mathNS));
});
m_Data.erase(it);
}
-std::shared_ptr<NamespaceValue> Namespace::GetAttribute(const String& key) const
+NamespaceValue::Ptr Namespace::GetAttribute(const String& key) const
{
ObjectLock olock(this);
return it->second;
}
-void Namespace::SetAttribute(const String& key, const std::shared_ptr<NamespaceValue>& nsVal)
+void Namespace::SetAttribute(const String& key, const NamespaceValue::Ptr& nsVal)
{
ObjectLock olock(this);
void NamespaceBehavior::Register(const Namespace::Ptr& ns, const String& field, const Value& value, bool overrideFrozen, const DebugInfo& debugInfo) const
{
- ns->SetAttribute(field, std::make_shared<EmbeddedNamespaceValue>(value));
+ ns->SetAttribute(field, new EmbeddedNamespaceValue(value));
}
void NamespaceBehavior::Remove(const Namespace::Ptr& ns, const String& field, bool overrideFrozen)
if (m_Frozen && !overrideFrozen)
BOOST_THROW_EXCEPTION(ScriptError("Namespace is read-only and must not be modified.", debugInfo));
- ns->SetAttribute(field, std::make_shared<ConstEmbeddedNamespaceValue>(value));
+ ns->SetAttribute(field, new ConstEmbeddedNamespaceValue(value));
}
void ConstNamespaceBehavior::Remove(const Namespace::Ptr& ns, const String& field, bool overrideFrozen)
#include "base/i2-base.hpp"
#include "base/object.hpp"
+#include "base/shared-object.hpp"
#include "base/value.hpp"
#include "base/debuginfo.hpp"
#include <map>
namespace icinga
{
-struct NamespaceValue
+struct NamespaceValue : public SharedObject
{
+ DECLARE_PTR_TYPEDEFS(NamespaceValue);
+
virtual Value Get(const DebugInfo& debugInfo = DebugInfo()) const = 0;
virtual void Set(const Value& value, bool overrideFrozen, const DebugInfo& debugInfo = DebugInfo()) = 0;
};
public:
DECLARE_OBJECT(Namespace);
- typedef std::map<String, std::shared_ptr<NamespaceValue> >::iterator Iterator;
+ typedef std::map<String, NamespaceValue::Ptr>::iterator Iterator;
- typedef std::map<String, std::shared_ptr<NamespaceValue> >::value_type Pair;
+ typedef std::map<String, NamespaceValue::Ptr>::value_type Pair;
Namespace(NamespaceBehavior *behavior = new NamespaceBehavior);
bool Contains(const String& field) const;
void Remove(const String& field, bool overrideFrozen = false);
- std::shared_ptr<NamespaceValue> GetAttribute(const String& field) const;
- void SetAttribute(const String& field, const std::shared_ptr<NamespaceValue>& nsVal);
+ NamespaceValue::Ptr GetAttribute(const String& field) const;
+ void SetAttribute(const String& field, const NamespaceValue::Ptr& nsVal);
void RemoveAttribute(const String& field);
Iterator Begin();
static Object::Ptr GetPrototype();
private:
- std::map<String, std::shared_ptr<NamespaceValue> > m_Data;
+ std::map<String, NamespaceValue::Ptr> m_Data;
std::unique_ptr<NamespaceBehavior> m_Behavior;
};
auto systemNSBehavior = new ConstNamespaceBehavior();
systemNSBehavior->Freeze();
Namespace::Ptr systemNS = new Namespace(systemNSBehavior);
- globalNS->SetAttribute("System", std::make_shared<ConstEmbeddedNamespaceValue>(systemNS));
+ globalNS->SetAttribute("System", new ConstEmbeddedNamespaceValue(systemNS));
- systemNS->SetAttribute("Configuration", std::make_shared<EmbeddedNamespaceValue>(new Configuration()));
+ systemNS->SetAttribute("Configuration", new EmbeddedNamespaceValue(new Configuration()));
auto typesNSBehavior = new ConstNamespaceBehavior();
typesNSBehavior->Freeze();
Namespace::Ptr typesNS = new Namespace(typesNSBehavior);
- globalNS->SetAttribute("Types", std::make_shared<ConstEmbeddedNamespaceValue>(typesNS));
+ globalNS->SetAttribute("Types", new ConstEmbeddedNamespaceValue(typesNS));
auto statsNSBehavior = new ConstNamespaceBehavior();
statsNSBehavior->Freeze();
Namespace::Ptr statsNS = new Namespace(statsNSBehavior);
- globalNS->SetAttribute("StatsFunctions", std::make_shared<ConstEmbeddedNamespaceValue>(statsNS));
+ globalNS->SetAttribute("StatsFunctions", new ConstEmbeddedNamespaceValue(statsNS));
Namespace::Ptr internalNS = new Namespace(l_InternalNSBehavior);
- globalNS->SetAttribute("Internal", std::make_shared<ConstEmbeddedNamespaceValue>(internalNS));
+ globalNS->SetAttribute("Internal", new ConstEmbeddedNamespaceValue(internalNS));
}, 1000);
INITIALIZE_ONCE_WITH_PRIORITY([]() {
void ScriptGlobal::SetConst(const String& name, const Value& value)
{
- GetGlobals()->SetAttribute(name, std::make_shared<ConstEmbeddedNamespaceValue>(value));
+ GetGlobals()->SetAttribute(name, new ConstEmbeddedNamespaceValue(value));
}
bool ScriptGlobal::Exists(const String& name)
CHECK_RESULT(operandres);
Value operand = operandres.GetValue();
- globals->SetAttribute(m_Name, std::make_shared<ConstEmbeddedNamespaceValue>(operand));
+ globals->SetAttribute(m_Name, new ConstEmbeddedNamespaceValue(operand));
return Empty;
}
auto icingaNSBehavior = new ConstNamespaceBehavior();
icingaNSBehavior->Freeze();
Namespace::Ptr icingaNS = new Namespace(icingaNSBehavior);
- globalNS->SetAttribute("Icinga", std::make_shared<ConstEmbeddedNamespaceValue>(icingaNS));
+ globalNS->SetAttribute("Icinga", new ConstEmbeddedNamespaceValue(icingaNS));
}
REGISTER_STATSFUNCTION(IcingaApplication, &IcingaApplication::StatsFunc);