From 768044a754017627bc2078a3cef3a50a0d2cf0a5 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 26 Jul 2019 14:45:11 +0200 Subject: [PATCH] Replace std::shared_ptr with NamespaceValue::Ptr refs #7361 --- lib/base/function.hpp | 8 ++++---- lib/base/json-script.cpp | 2 +- lib/base/math-script.cpp | 2 +- lib/base/namespace.cpp | 8 ++++---- lib/base/namespace.hpp | 15 +++++++++------ lib/base/scriptframe.cpp | 10 +++++----- lib/base/scriptglobal.cpp | 2 +- lib/config/expression.cpp | 2 +- lib/icinga/icingaapplication.cpp | 2 +- 9 files changed, 27 insertions(+), 24 deletions(-) diff --git a/lib/base/function.hpp b/lib/base/function.hpp index d6f1d17e0..e0067d226 100644 --- a/lib/base/function.hpp +++ b/lib/base/function.hpp @@ -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(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(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(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(sf)); \ + nsp->SetAttribute(#name, new EmbeddedNamespaceValue(sf)); \ }, 10) } diff --git a/lib/base/json-script.cpp b/lib/base/json-script.cpp index ee4221142..54d663177 100644 --- a/lib/base/json-script.cpp +++ b/lib/base/json-script.cpp @@ -25,5 +25,5 @@ INITIALIZE_ONCE([]() { jsonNSBehavior->Freeze(); Namespace::Ptr systemNS = ScriptGlobal::Get("System"); - systemNS->SetAttribute("Json", std::make_shared(jsonNS)); + systemNS->SetAttribute("Json", new ConstEmbeddedNamespaceValue(jsonNS)); }); diff --git a/lib/base/math-script.cpp b/lib/base/math-script.cpp index 21dbee411..0060513c2 100644 --- a/lib/base/math-script.cpp +++ b/lib/base/math-script.cpp @@ -181,5 +181,5 @@ INITIALIZE_ONCE([]() { mathNSBehavior->Freeze(); Namespace::Ptr systemNS = ScriptGlobal::Get("System"); - systemNS->SetAttribute("Math", std::make_shared(mathNS)); + systemNS->SetAttribute("Math", new ConstEmbeddedNamespaceValue(mathNS)); }); diff --git a/lib/base/namespace.cpp b/lib/base/namespace.cpp index c02ac95e6..33cca7d6a 100644 --- a/lib/base/namespace.cpp +++ b/lib/base/namespace.cpp @@ -75,7 +75,7 @@ void Namespace::RemoveAttribute(const String& field) m_Data.erase(it); } -std::shared_ptr Namespace::GetAttribute(const String& key) const +NamespaceValue::Ptr Namespace::GetAttribute(const String& key) const { ObjectLock olock(this); @@ -87,7 +87,7 @@ std::shared_ptr Namespace::GetAttribute(const String& key) const return it->second; } -void Namespace::SetAttribute(const String& key, const std::shared_ptr& 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(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(value)); + ns->SetAttribute(field, new ConstEmbeddedNamespaceValue(value)); } void ConstNamespaceBehavior::Remove(const Namespace::Ptr& ns, const String& field, bool overrideFrozen) diff --git a/lib/base/namespace.hpp b/lib/base/namespace.hpp index 6b2e92018..310dba7b0 100644 --- a/lib/base/namespace.hpp +++ b/lib/base/namespace.hpp @@ -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 @@ -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 >::iterator Iterator; + typedef std::map::iterator Iterator; - typedef std::map >::value_type Pair; + typedef std::map::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 GetAttribute(const String& field) const; - void SetAttribute(const String& field, const std::shared_ptr& 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 > m_Data; + std::map m_Data; std::unique_ptr m_Behavior; }; diff --git a/lib/base/scriptframe.cpp b/lib/base/scriptframe.cpp index 7510c8a11..8369e55e0 100644 --- a/lib/base/scriptframe.cpp +++ b/lib/base/scriptframe.cpp @@ -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(systemNS)); + globalNS->SetAttribute("System", new ConstEmbeddedNamespaceValue(systemNS)); - systemNS->SetAttribute("Configuration", std::make_shared(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(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(statsNS)); + globalNS->SetAttribute("StatsFunctions", new ConstEmbeddedNamespaceValue(statsNS)); Namespace::Ptr internalNS = new Namespace(l_InternalNSBehavior); - globalNS->SetAttribute("Internal", std::make_shared(internalNS)); + globalNS->SetAttribute("Internal", new ConstEmbeddedNamespaceValue(internalNS)); }, 1000); INITIALIZE_ONCE_WITH_PRIORITY([]() { diff --git a/lib/base/scriptglobal.cpp b/lib/base/scriptglobal.cpp index b567b79c2..545c09706 100644 --- a/lib/base/scriptglobal.cpp +++ b/lib/base/scriptglobal.cpp @@ -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(value)); + GetGlobals()->SetAttribute(name, new ConstEmbeddedNamespaceValue(value)); } bool ScriptGlobal::Exists(const String& name) diff --git a/lib/config/expression.cpp b/lib/config/expression.cpp index 1ae75fd3f..6a709ac6a 100644 --- a/lib/config/expression.cpp +++ b/lib/config/expression.cpp @@ -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(operand)); + globals->SetAttribute(m_Name, new ConstEmbeddedNamespaceValue(operand)); return Empty; } diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index 451f009da..5785b3358 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -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(icingaNS)); + globalNS->SetAttribute("Icinga", new ConstEmbeddedNamespaceValue(icingaNS)); } REGISTER_STATSFUNCTION(IcingaApplication, &IcingaApplication::StatsFunc);