Replace std::shared_ptr<NamespaceValue> with NamespaceValue::Ptr

refs #7361
This commit is contained in:
Alexander A. Klimov 2019-07-26 14:45:11 +02:00 committed by Michael Friedrich
parent aa4cad7482
commit 768044a754
9 changed files with 27 additions and 24 deletions

View File

@ -60,28 +60,28 @@ private:
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)
}

View File

@ -25,5 +25,5 @@ INITIALIZE_ONCE([]() {
jsonNSBehavior->Freeze();
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
systemNS->SetAttribute("Json", std::make_shared<ConstEmbeddedNamespaceValue>(jsonNS));
systemNS->SetAttribute("Json", new ConstEmbeddedNamespaceValue(jsonNS));
});

View File

@ -181,5 +181,5 @@ INITIALIZE_ONCE([]() {
mathNSBehavior->Freeze();
Namespace::Ptr systemNS = ScriptGlobal::Get("System");
systemNS->SetAttribute("Math", std::make_shared<ConstEmbeddedNamespaceValue>(mathNS));
systemNS->SetAttribute("Math", new ConstEmbeddedNamespaceValue(mathNS));
});

View File

@ -75,7 +75,7 @@ void Namespace::RemoveAttribute(const String& field)
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);
@ -87,7 +87,7 @@ std::shared_ptr<NamespaceValue> Namespace::GetAttribute(const String& key) const
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);
@ -162,7 +162,7 @@ void ConstEmbeddedNamespaceValue::Set(const Value& value, bool overrideFrozen, c
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)
@ -182,7 +182,7 @@ void ConstNamespaceBehavior::Register(const Namespace::Ptr& ns, const String& fi
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)

View File

@ -5,6 +5,7 @@
#include "base/i2-base.hpp"
#include "base/object.hpp"
#include "base/shared-object.hpp"
#include "base/value.hpp"
#include "base/debuginfo.hpp"
#include <map>
@ -14,8 +15,10 @@
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;
};
@ -66,9 +69,9 @@ class Namespace final : public Object
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);
@ -78,8 +81,8 @@ public:
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();
@ -93,7 +96,7 @@ public:
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;
};

View File

@ -22,22 +22,22 @@ INITIALIZE_ONCE_WITH_PRIORITY([]() {
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([]() {

View File

@ -65,7 +65,7 @@ void ScriptGlobal::Set(const String& name, const Value& value, bool overrideFroz
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)

View File

@ -689,7 +689,7 @@ ExpressionResult SetConstExpression::DoEvaluate(ScriptFrame& frame, DebugHint *d
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;
}

View File

@ -60,7 +60,7 @@ void IcingaApplication::StaticInitialize()
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);