]> granicus.if.org Git - icinga2/commitdiff
Replace std::shared_ptr<NamespaceValue> with NamespaceValue::Ptr 7364/head
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Fri, 26 Jul 2019 12:45:11 +0000 (14:45 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Mon, 21 Oct 2019 15:10:51 +0000 (17:10 +0200)
refs #7361

lib/base/function.hpp
lib/base/json-script.cpp
lib/base/math-script.cpp
lib/base/namespace.cpp
lib/base/namespace.hpp
lib/base/scriptframe.cpp
lib/base/scriptglobal.cpp
lib/config/expression.cpp
lib/icinga/icingaapplication.cpp

index d6f1d17e0ad92ce2f493f6cd36cfd22dc5726b7d..e0067d22617ce690181b4eb70ece31975706938e 100644 (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)
 
 }
index ee4221142712fb49465dfd47af885d398032afe4..54d66317713844cdc1d0582ef3ecf535927467a4 100644 (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));
 });
index 21dbee4114943fd955e18f66503313ddd5eb14b5..0060513c2a3c8b99c0342f3cd5ab5f7ced28e90f 100644 (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));
 });
index c02ac95e6c6180d035efff95b65c5a3d34c9e663..33cca7d6ad75ce27655c551864210da4f1b16e38 100644 (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)
index 6b2e9201860afc9eb1a3c6d6c6f3441738de0e46..310dba7b067ed556424cb02122a5f2ccf98316e3 100644 (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>
 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;
 };
 
index 7510c8a1138ffa2457306cb2e8d3704314e6d962..8369e55e0eb2827538b4888f5c6cc6947422802c 100644 (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([]() {
index b567b79c2188a332b05a2dffb31145822b21a766..545c097066fd18007199c402ef55ea437ac102fd 100644 (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)
index 1ae75fd3fba02c04704869af56e75acb6dd3e1ad..6a709ac6a5217ef3140c7d27989641ecdfbb3984 100644 (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;
 }
index 451f009da952694e770636ecbe8cc1efc3cd5448..5785b3358f5c094ccd3fa7bb54cc8fda006a8867 100644 (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);