From 0915b3ef56dfac3113cce55a59a5765dc94976be Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:34:54 +0200 Subject: Adding upstream version 2.13.6. Signed-off-by: Daniel Baumann --- lib/base/configtype.hpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 lib/base/configtype.hpp (limited to 'lib/base/configtype.hpp') diff --git a/lib/base/configtype.hpp b/lib/base/configtype.hpp new file mode 100644 index 0000000..5008cd7 --- /dev/null +++ b/lib/base/configtype.hpp @@ -0,0 +1,63 @@ +/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ + +#ifndef CONFIGTYPE_H +#define CONFIGTYPE_H + +#include "base/i2-base.hpp" +#include "base/object.hpp" +#include "base/type.hpp" +#include "base/dictionary.hpp" +#include + +namespace icinga +{ + +class ConfigObject; + +class ConfigType +{ +public: + virtual ~ConfigType(); + + intrusive_ptr GetObject(const String& name) const; + + void RegisterObject(const intrusive_ptr& object); + void UnregisterObject(const intrusive_ptr& object); + + std::vector > GetObjects() const; + + template + static TypeImpl *Get() + { + typedef TypeImpl ObjType; + return static_cast(T::TypeInstance.get()); + } + + template + static std::vector > GetObjectsByType() + { + std::vector > objects = GetObjectsHelper(T::TypeInstance.get()); + std::vector > result; + result.reserve(objects.size()); +for (const auto& object : objects) { + result.push_back(static_pointer_cast(object)); + } + return result; + } + + int GetObjectCount() const; + +private: + typedef std::map > ObjectMap; + typedef std::vector > ObjectVector; + + mutable std::mutex m_Mutex; + ObjectMap m_ObjectMap; + ObjectVector m_ObjectVector; + + static std::vector > GetObjectsHelper(Type *type); +}; + +} + +#endif /* CONFIGTYPE_H */ -- cgit v1.2.3