diff --git a/lib/base/dynamictype.hpp b/lib/base/dynamictype.hpp index 824d04e67..fd5271f59 100644 --- a/lib/base/dynamictype.hpp +++ b/lib/base/dynamictype.hpp @@ -36,7 +36,7 @@ class DynamicTypeIterator; class I2_BASE_API DynamicType : public Object { public: - DECLARE_OBJECT(DynamicType); + DECLARE_PTR_TYPEDEFS(DynamicType); DynamicType(const String& name); diff --git a/lib/base/fifo.hpp b/lib/base/fifo.hpp index 4fffc0126..5534e5e4f 100644 --- a/lib/base/fifo.hpp +++ b/lib/base/fifo.hpp @@ -34,7 +34,7 @@ namespace icinga class I2_BASE_API FIFO : public Stream { public: - DECLARE_OBJECT(FIFO); + DECLARE_PTR_TYPEDEFS(FIFO); static const size_t BlockSize = 16 * 1024; diff --git a/lib/base/networkstream.hpp b/lib/base/networkstream.hpp index c123063a0..aae07edf5 100644 --- a/lib/base/networkstream.hpp +++ b/lib/base/networkstream.hpp @@ -35,7 +35,7 @@ namespace icinga class I2_BASE_API NetworkStream : public Stream { public: - DECLARE_OBJECT(NetworkStream); + DECLARE_PTR_TYPEDEFS(NetworkStream); NetworkStream(const Socket::Ptr& socket); diff --git a/lib/base/object.cpp b/lib/base/object.cpp index da9ab49f3..ad8ffa0f9 100644 --- a/lib/base/object.cpp +++ b/lib/base/object.cpp @@ -83,8 +83,3 @@ Value Object::GetField(int) const BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID.")); } -Type::Ptr icinga::LookupType(const char *name) -{ - return Type::GetByName(name); -} - diff --git a/lib/base/object.hpp b/lib/base/object.hpp index 9becb5b5a..673f58dc7 100644 --- a/lib/base/object.hpp +++ b/lib/base/object.hpp @@ -60,24 +60,40 @@ namespace icinga { class Value; +class Object; +class Type; #define DECLARE_PTR_TYPEDEFS(klass) \ typedef shared_ptr Ptr; \ typedef weak_ptr WeakPtr #define IMPL_TYPE_LOOKUP(klass) \ + static shared_ptr TypeInstance; \ inline virtual shared_ptr GetReflectionType(void) const \ { \ - return LookupType(#klass); \ + return TypeInstance; \ } #define DECLARE_OBJECT(klass) \ DECLARE_PTR_TYPEDEFS(klass); \ IMPL_TYPE_LOOKUP(klass); -class Type; +template +shared_ptr DefaultObjectFactory(void) +{ + return make_shared(); +} -I2_BASE_API shared_ptr LookupType(const char *name); +typedef shared_ptr (*ObjectFactory)(void); + +template +struct TypeHelper +{ + static ObjectFactory GetFactory(void) + { + return DefaultObjectFactory; + } +}; /** * Base class for all heap-allocated objects. At least one of its methods diff --git a/lib/base/primitivetype.cpp b/lib/base/primitivetype.cpp index 161b889bb..b47cc7f87 100644 --- a/lib/base/primitivetype.cpp +++ b/lib/base/primitivetype.cpp @@ -21,9 +21,9 @@ using namespace icinga; -REGISTER_PRIMITIVE_TYPE(int); -REGISTER_PRIMITIVE_TYPE(double); -REGISTER_PRIMITIVE_TYPE(bool); +REGISTER_BUILTIN_TYPE(int); +REGISTER_BUILTIN_TYPE(double); +REGISTER_BUILTIN_TYPE(bool); PrimitiveType::PrimitiveType(const String& name) : m_Name(name) @@ -59,3 +59,8 @@ int PrimitiveType::GetFieldCount(void) const return 0; } +ObjectFactory PrimitiveType::GetFactory(void) const +{ + return NULL; +} + diff --git a/lib/base/primitivetype.hpp b/lib/base/primitivetype.hpp index c91e4f5c6..0420331fc 100644 --- a/lib/base/primitivetype.hpp +++ b/lib/base/primitivetype.hpp @@ -39,11 +39,14 @@ public: virtual Field GetFieldInfo(int id) const; virtual int GetFieldCount(void) const; +protected: + virtual ObjectFactory GetFactory(void) const; + private: String m_Name; }; -#define REGISTER_PRIMITIVE_TYPE(type) \ +#define REGISTER_BUILTIN_TYPE(type) \ namespace { namespace UNIQUE_NAME(prt) { namespace prt ## type { \ void RegisterPrimitiveType(void) \ { \ @@ -54,6 +57,10 @@ private: INITIALIZE_ONCE(RegisterPrimitiveType); \ } } } +#define REGISTER_PRIMITIVE_TYPE(type) \ + REGISTER_BUILTIN_TYPE(type); \ + DEFINE_TYPE_INSTANCE(type) + } #endif /* PRIMITIVETYPE_H */ diff --git a/lib/base/process.hpp b/lib/base/process.hpp index 2ccda78f6..a23942ba2 100644 --- a/lib/base/process.hpp +++ b/lib/base/process.hpp @@ -53,7 +53,7 @@ struct ProcessResult class I2_BASE_API Process : public Object { public: - DECLARE_OBJECT(Process); + DECLARE_PTR_TYPEDEFS(Process); #ifdef _WIN32 typedef String Arguments; diff --git a/lib/base/ringbuffer.hpp b/lib/base/ringbuffer.hpp index 3ca2b821d..cb8d96950 100644 --- a/lib/base/ringbuffer.hpp +++ b/lib/base/ringbuffer.hpp @@ -35,7 +35,7 @@ namespace icinga class I2_BASE_API RingBuffer : public Object { public: - DECLARE_OBJECT(RingBuffer); + DECLARE_PTR_TYPEDEFS(RingBuffer); typedef std::vector::size_type SizeType; diff --git a/lib/base/scriptfunction.hpp b/lib/base/scriptfunction.hpp index 99055b2ee..aa50d7f7c 100644 --- a/lib/base/scriptfunction.hpp +++ b/lib/base/scriptfunction.hpp @@ -37,7 +37,7 @@ namespace icinga class I2_BASE_API ScriptFunction : public Object { public: - DECLARE_OBJECT(ScriptFunction); + DECLARE_PTR_TYPEDEFS(ScriptFunction); typedef boost::function& arguments)> Callback; diff --git a/lib/base/scriptvariable.hpp b/lib/base/scriptvariable.hpp index a0a80b0d2..602c524c0 100644 --- a/lib/base/scriptvariable.hpp +++ b/lib/base/scriptvariable.hpp @@ -43,7 +43,7 @@ public: class I2_BASE_API ScriptVariable : public Object { public: - DECLARE_OBJECT(ScriptVariable); + DECLARE_PTR_TYPEDEFS(ScriptVariable); ScriptVariable(const Value& data); diff --git a/lib/base/socket.hpp b/lib/base/socket.hpp index a118d85f8..429b7f24e 100644 --- a/lib/base/socket.hpp +++ b/lib/base/socket.hpp @@ -38,7 +38,7 @@ namespace icinga class I2_BASE_API Socket : public Object { public: - DECLARE_OBJECT(Socket); + DECLARE_PTR_TYPEDEFS(Socket); Socket(void); Socket(SOCKET fd); diff --git a/lib/base/statsfunction.hpp b/lib/base/statsfunction.hpp index 3dd2ddb75..3f08565de 100644 --- a/lib/base/statsfunction.hpp +++ b/lib/base/statsfunction.hpp @@ -38,7 +38,7 @@ namespace icinga class I2_BASE_API StatsFunction : public Object { public: - DECLARE_OBJECT(StatsFunction); + DECLARE_PTR_TYPEDEFS(StatsFunction); typedef boost::function Callback; diff --git a/lib/base/stdiostream.hpp b/lib/base/stdiostream.hpp index 937d6b5be..b79fcceff 100644 --- a/lib/base/stdiostream.hpp +++ b/lib/base/stdiostream.hpp @@ -29,7 +29,7 @@ namespace icinga { class I2_BASE_API StdioStream : public Stream { public: - DECLARE_OBJECT(StdioStream); + DECLARE_PTR_TYPEDEFS(StdioStream); StdioStream(std::iostream *innerStream, bool ownsStream); ~StdioStream(void); diff --git a/lib/base/stream.hpp b/lib/base/stream.hpp index c8a7d272f..8a6120b08 100644 --- a/lib/base/stream.hpp +++ b/lib/base/stream.hpp @@ -54,7 +54,7 @@ struct ReadLineContext class I2_BASE_API Stream : public Object { public: - DECLARE_OBJECT(Stream); + DECLARE_PTR_TYPEDEFS(Stream); /** * Reads data from the stream. diff --git a/lib/base/string.cpp b/lib/base/string.cpp index a11a901aa..f4fca2c1f 100644 --- a/lib/base/string.cpp +++ b/lib/base/string.cpp @@ -25,7 +25,7 @@ using namespace icinga; -REGISTER_PRIMITIVE_TYPE(String); +REGISTER_BUILTIN_TYPE(String); const String::SizeType String::NPos = std::string::npos; diff --git a/lib/base/tcpsocket.hpp b/lib/base/tcpsocket.hpp index c250e53c9..902874eaf 100644 --- a/lib/base/tcpsocket.hpp +++ b/lib/base/tcpsocket.hpp @@ -34,7 +34,7 @@ namespace icinga class I2_BASE_API TcpSocket : public Socket { public: - DECLARE_OBJECT(TcpSocket); + DECLARE_PTR_TYPEDEFS(TcpSocket); void Bind(const String& service, int family); void Bind(const String& node, const String& service, int family); diff --git a/lib/base/timer.hpp b/lib/base/timer.hpp index bb70d5173..8c8550715 100644 --- a/lib/base/timer.hpp +++ b/lib/base/timer.hpp @@ -34,7 +34,7 @@ namespace icinga { class I2_BASE_API Timer : public Object { public: - DECLARE_OBJECT(Timer); + DECLARE_PTR_TYPEDEFS(Timer); Timer(void); ~Timer(void); diff --git a/lib/base/tlsstream.hpp b/lib/base/tlsstream.hpp index 6303a17f6..00b24ce3b 100644 --- a/lib/base/tlsstream.hpp +++ b/lib/base/tlsstream.hpp @@ -36,7 +36,7 @@ namespace icinga class I2_BASE_API TlsStream : public Stream { public: - DECLARE_OBJECT(TlsStream); + DECLARE_PTR_TYPEDEFS(TlsStream); TlsStream(const Socket::Ptr& socket, ConnectionRole role, const shared_ptr& sslContext); diff --git a/lib/base/type.cpp b/lib/base/type.cpp index f14102a68..e1e933678 100644 --- a/lib/base/type.cpp +++ b/lib/base/type.cpp @@ -49,7 +49,12 @@ Type::Ptr Type::GetByName(const String& name) Object::Ptr Type::Instantiate(void) const { - return m_Factory(); + ObjectFactory factory = GetFactory(); + + if (!factory) + return Object::Ptr(); + + return factory(); } bool Type::IsAbstract(void) const @@ -67,7 +72,3 @@ bool Type::IsAssignableFrom(const Type::Ptr& other) const return false; } -void Type::SetFactory(const Type::Factory& factory) -{ - m_Factory = factory; -} diff --git a/lib/base/type.hpp b/lib/base/type.hpp index b4ab7b6ff..47c3899ff 100644 --- a/lib/base/type.hpp +++ b/lib/base/type.hpp @@ -59,9 +59,7 @@ enum TypeAttribute class I2_BASE_API Type : public Object { public: - DECLARE_OBJECT(Type); - - typedef boost::function Factory; + DECLARE_PTR_TYPEDEFS(Type); virtual String GetName(void) const = 0; virtual Type::Ptr GetBaseType(void) const = 0; @@ -79,14 +77,13 @@ public: static void Register(const Type::Ptr& type); static Type::Ptr GetByName(const String& name); - void SetFactory(const Factory& factory); +protected: + virtual ObjectFactory GetFactory(void) const = 0; private: typedef std::map TypeMap; static TypeMap& GetTypes(void); - - Factory m_Factory; }; template @@ -94,32 +91,21 @@ class TypeImpl { }; -template -shared_ptr ObjectFactory(void) -{ - return make_shared(); -} - -template -struct FactoryHelper -{ - Type::Factory GetFactory(void) - { - return ObjectFactory; - } -}; - #define REGISTER_TYPE(type) \ namespace { namespace UNIQUE_NAME(rt) { \ void RegisterType ## type(void) \ { \ icinga::Type::Ptr t = make_shared >(); \ - t->SetFactory(FactoryHelper().GetFactory()); \ + type::TypeInstance = t; \ icinga::Type::Register(t); \ } \ \ INITIALIZE_ONCE(RegisterType ## type); \ - } } + } } \ + DEFINE_TYPE_INSTANCE(type) + +#define DEFINE_TYPE_INSTANCE(type) \ + Type::Ptr type::TypeInstance; } diff --git a/lib/base/unixsocket.hpp b/lib/base/unixsocket.hpp index 1d120133a..f72ac9a93 100644 --- a/lib/base/unixsocket.hpp +++ b/lib/base/unixsocket.hpp @@ -29,7 +29,7 @@ namespace icinga class I2_BASE_API UnixSocket : public Socket { public: - DECLARE_OBJECT(UnixSocket); + DECLARE_PTR_TYPEDEFS(UnixSocket); UnixSocket(void); diff --git a/lib/cli/clicommand.hpp b/lib/cli/clicommand.hpp index a4362f48d..985d5d4c9 100644 --- a/lib/cli/clicommand.hpp +++ b/lib/cli/clicommand.hpp @@ -48,7 +48,7 @@ enum ImpersonationLevel class I2_CLI_API CLICommand : public Object { public: - DECLARE_OBJECT(CLICommand); + DECLARE_PTR_TYPEDEFS(CLICommand); typedef std::vector(*ArgumentCompletionCallback)(const String&, const String&); diff --git a/lib/cli/daemoncommand.hpp b/lib/cli/daemoncommand.hpp index 8674a5546..5a95d218d 100644 --- a/lib/cli/daemoncommand.hpp +++ b/lib/cli/daemoncommand.hpp @@ -33,7 +33,7 @@ namespace icinga class DaemonCommand : public CLICommand { public: - DECLARE_OBJECT(DaemonCommand); + DECLARE_PTR_TYPEDEFS(DaemonCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/featuredisablecommand.hpp b/lib/cli/featuredisablecommand.hpp index 21960fa7e..722d89abb 100644 --- a/lib/cli/featuredisablecommand.hpp +++ b/lib/cli/featuredisablecommand.hpp @@ -33,7 +33,7 @@ namespace icinga class FeatureDisableCommand : public CLICommand { public: - DECLARE_OBJECT(FeatureDisableCommand); + DECLARE_PTR_TYPEDEFS(FeatureDisableCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/featureenablecommand.hpp b/lib/cli/featureenablecommand.hpp index b0a0d16f6..4a94aa019 100644 --- a/lib/cli/featureenablecommand.hpp +++ b/lib/cli/featureenablecommand.hpp @@ -33,7 +33,7 @@ namespace icinga class FeatureEnableCommand : public CLICommand { public: - DECLARE_OBJECT(FeatureEnableCommand); + DECLARE_PTR_TYPEDEFS(FeatureEnableCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/featurelistcommand.hpp b/lib/cli/featurelistcommand.hpp index 0894dc2d1..df9f8d3a3 100644 --- a/lib/cli/featurelistcommand.hpp +++ b/lib/cli/featurelistcommand.hpp @@ -33,7 +33,7 @@ namespace icinga class FeatureListCommand : public CLICommand { public: - DECLARE_OBJECT(FeatureListCommand); + DECLARE_PTR_TYPEDEFS(FeatureListCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/nodeaddcommand.hpp b/lib/cli/nodeaddcommand.hpp index 504f1b522..d791fe24e 100644 --- a/lib/cli/nodeaddcommand.hpp +++ b/lib/cli/nodeaddcommand.hpp @@ -33,7 +33,7 @@ namespace icinga class NodeAddCommand : public CLICommand { public: - DECLARE_OBJECT(NodeAddCommand); + DECLARE_PTR_TYPEDEFS(NodeAddCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/nodeblackandwhitelistcommand.hpp b/lib/cli/nodeblackandwhitelistcommand.hpp index b061353e6..cd103660e 100644 --- a/lib/cli/nodeblackandwhitelistcommand.hpp +++ b/lib/cli/nodeblackandwhitelistcommand.hpp @@ -40,7 +40,7 @@ enum BlackAndWhitelistCommandType class I2_CLI_API BlackAndWhitelistCommand : public CLICommand { public: - DECLARE_OBJECT(BlackAndWhitelistCommand); + DECLARE_PTR_TYPEDEFS(BlackAndWhitelistCommand); BlackAndWhitelistCommand(const String& type, BlackAndWhitelistCommandType command); diff --git a/lib/cli/nodelistcommand.hpp b/lib/cli/nodelistcommand.hpp index fb30ad3ee..e194c7824 100644 --- a/lib/cli/nodelistcommand.hpp +++ b/lib/cli/nodelistcommand.hpp @@ -33,7 +33,7 @@ namespace icinga class NodeListCommand : public CLICommand { public: - DECLARE_OBJECT(NodeListCommand); + DECLARE_PTR_TYPEDEFS(NodeListCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/noderemovecommand.hpp b/lib/cli/noderemovecommand.hpp index 3f183eb7c..b41a6244f 100644 --- a/lib/cli/noderemovecommand.hpp +++ b/lib/cli/noderemovecommand.hpp @@ -33,7 +33,7 @@ namespace icinga class NodeRemoveCommand : public CLICommand { public: - DECLARE_OBJECT(NodeRemoveCommand); + DECLARE_PTR_TYPEDEFS(NodeRemoveCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/nodesetcommand.hpp b/lib/cli/nodesetcommand.hpp index d13634a00..a8c2434fa 100644 --- a/lib/cli/nodesetcommand.hpp +++ b/lib/cli/nodesetcommand.hpp @@ -33,7 +33,7 @@ namespace icinga class NodeSetCommand : public CLICommand { public: - DECLARE_OBJECT(NodeSetCommand); + DECLARE_PTR_TYPEDEFS(NodeSetCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/nodesetupcommand.hpp b/lib/cli/nodesetupcommand.hpp index cf7c13238..47d094e31 100644 --- a/lib/cli/nodesetupcommand.hpp +++ b/lib/cli/nodesetupcommand.hpp @@ -33,7 +33,7 @@ namespace icinga class NodeSetupCommand : public CLICommand { public: - DECLARE_OBJECT(NodeSetupCommand); + DECLARE_PTR_TYPEDEFS(NodeSetupCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/nodeupdateconfigcommand.hpp b/lib/cli/nodeupdateconfigcommand.hpp index 1ff2ba852..b35f252d3 100644 --- a/lib/cli/nodeupdateconfigcommand.hpp +++ b/lib/cli/nodeupdateconfigcommand.hpp @@ -33,7 +33,7 @@ namespace icinga class NodeUpdateConfigCommand : public CLICommand { public: - DECLARE_OBJECT(NodeUpdateConfigCommand); + DECLARE_PTR_TYPEDEFS(NodeUpdateConfigCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/nodewizardcommand.hpp b/lib/cli/nodewizardcommand.hpp index 077425714..daf257dc2 100644 --- a/lib/cli/nodewizardcommand.hpp +++ b/lib/cli/nodewizardcommand.hpp @@ -33,7 +33,7 @@ namespace icinga class NodeWizardCommand : public CLICommand { public: - DECLARE_OBJECT(NodeWizardCommand); + DECLARE_PTR_TYPEDEFS(NodeWizardCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/objectlistcommand.hpp b/lib/cli/objectlistcommand.hpp index e3cfc7fe7..324cdbe8d 100644 --- a/lib/cli/objectlistcommand.hpp +++ b/lib/cli/objectlistcommand.hpp @@ -36,7 +36,7 @@ namespace icinga class ObjectListCommand : public CLICommand { public: - DECLARE_OBJECT(ObjectListCommand); + DECLARE_PTR_TYPEDEFS(ObjectListCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/pkinewcacommand.hpp b/lib/cli/pkinewcacommand.hpp index 7c5c411e8..e1a3ff57c 100644 --- a/lib/cli/pkinewcacommand.hpp +++ b/lib/cli/pkinewcacommand.hpp @@ -33,7 +33,7 @@ namespace icinga class PKINewCACommand : public CLICommand { public: - DECLARE_OBJECT(PKINewCACommand); + DECLARE_PTR_TYPEDEFS(PKINewCACommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/pkinewcertcommand.hpp b/lib/cli/pkinewcertcommand.hpp index c1ee23efc..770f19c5a 100644 --- a/lib/cli/pkinewcertcommand.hpp +++ b/lib/cli/pkinewcertcommand.hpp @@ -33,7 +33,7 @@ namespace icinga class PKINewCertCommand : public CLICommand { public: - DECLARE_OBJECT(PKINewCertCommand); + DECLARE_PTR_TYPEDEFS(PKINewCertCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/pkirequestcommand.hpp b/lib/cli/pkirequestcommand.hpp index c61cb8de7..225237725 100644 --- a/lib/cli/pkirequestcommand.hpp +++ b/lib/cli/pkirequestcommand.hpp @@ -33,7 +33,7 @@ namespace icinga class PKIRequestCommand : public CLICommand { public: - DECLARE_OBJECT(PKIRequestCommand); + DECLARE_PTR_TYPEDEFS(PKIRequestCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/pkisavecertcommand.hpp b/lib/cli/pkisavecertcommand.hpp index a12fbca02..9ed935abb 100644 --- a/lib/cli/pkisavecertcommand.hpp +++ b/lib/cli/pkisavecertcommand.hpp @@ -33,7 +33,7 @@ namespace icinga class PKISaveCertCommand : public CLICommand { public: - DECLARE_OBJECT(PKISaveCertCommand); + DECLARE_PTR_TYPEDEFS(PKISaveCertCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/pkisigncsrcommand.hpp b/lib/cli/pkisigncsrcommand.hpp index 77d165eec..8a2789f12 100644 --- a/lib/cli/pkisigncsrcommand.hpp +++ b/lib/cli/pkisigncsrcommand.hpp @@ -33,7 +33,7 @@ namespace icinga class PKISignCSRCommand : public CLICommand { public: - DECLARE_OBJECT(PKISignCSRCommand); + DECLARE_PTR_TYPEDEFS(PKISignCSRCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/pkiticketcommand.hpp b/lib/cli/pkiticketcommand.hpp index 92bee25cd..d8009030a 100644 --- a/lib/cli/pkiticketcommand.hpp +++ b/lib/cli/pkiticketcommand.hpp @@ -33,7 +33,7 @@ namespace icinga class PKITicketCommand : public CLICommand { public: - DECLARE_OBJECT(PKITicketCommand); + DECLARE_PTR_TYPEDEFS(PKITicketCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/repositoryclearchangescommand.hpp b/lib/cli/repositoryclearchangescommand.hpp index 4e64e1219..ac4332e48 100644 --- a/lib/cli/repositoryclearchangescommand.hpp +++ b/lib/cli/repositoryclearchangescommand.hpp @@ -36,7 +36,7 @@ namespace icinga class RepositoryClearChangesCommand : public CLICommand { public: - DECLARE_OBJECT(RepositoryClearChangesCommand); + DECLARE_PTR_TYPEDEFS(RepositoryClearChangesCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/repositorycommitcommand.hpp b/lib/cli/repositorycommitcommand.hpp index d63c9e9bd..d853d25e1 100644 --- a/lib/cli/repositorycommitcommand.hpp +++ b/lib/cli/repositorycommitcommand.hpp @@ -36,7 +36,7 @@ namespace icinga class RepositoryCommitCommand : public CLICommand { public: - DECLARE_OBJECT(RepositoryCommitCommand); + DECLARE_PTR_TYPEDEFS(RepositoryCommitCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/repositoryobjectcommand.hpp b/lib/cli/repositoryobjectcommand.hpp index 9aafad5f3..9472f5e86 100644 --- a/lib/cli/repositoryobjectcommand.hpp +++ b/lib/cli/repositoryobjectcommand.hpp @@ -41,7 +41,7 @@ enum RepositoryCommandType class I2_CLI_API RepositoryObjectCommand : public CLICommand { public: - DECLARE_OBJECT(RepositoryObjectCommand); + DECLARE_PTR_TYPEDEFS(RepositoryObjectCommand); RepositoryObjectCommand(const String& type, RepositoryCommandType command); diff --git a/lib/cli/variablegetcommand.hpp b/lib/cli/variablegetcommand.hpp index 3273c8f85..da72618e2 100644 --- a/lib/cli/variablegetcommand.hpp +++ b/lib/cli/variablegetcommand.hpp @@ -36,7 +36,7 @@ namespace icinga class VariableGetCommand : public CLICommand { public: - DECLARE_OBJECT(VariableGetCommand); + DECLARE_PTR_TYPEDEFS(VariableGetCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/cli/variablelistcommand.hpp b/lib/cli/variablelistcommand.hpp index 825bac9ef..566f2e49c 100644 --- a/lib/cli/variablelistcommand.hpp +++ b/lib/cli/variablelistcommand.hpp @@ -36,7 +36,7 @@ namespace icinga class VariableListCommand : public CLICommand { public: - DECLARE_OBJECT(VariableListCommand); + DECLARE_PTR_TYPEDEFS(VariableListCommand); virtual String GetDescription(void) const; virtual String GetShortDescription(void) const; diff --git a/lib/config/configitem.hpp b/lib/config/configitem.hpp index 0694cb9a7..a267b79d6 100644 --- a/lib/config/configitem.hpp +++ b/lib/config/configitem.hpp @@ -35,7 +35,7 @@ namespace icinga */ class I2_CONFIG_API ConfigItem : public Object { public: - DECLARE_OBJECT(ConfigItem); + DECLARE_PTR_TYPEDEFS(ConfigItem); ConfigItem(const String& type, const String& name, bool abstract, const Expression::Ptr& exprl, const DebugInfo& debuginfo, diff --git a/lib/config/configitembuilder.hpp b/lib/config/configitembuilder.hpp index 53a5970f8..30b16f0c9 100644 --- a/lib/config/configitembuilder.hpp +++ b/lib/config/configitembuilder.hpp @@ -37,7 +37,7 @@ namespace icinga class I2_CONFIG_API ConfigItemBuilder : public Object { public: - DECLARE_OBJECT(ConfigItemBuilder); + DECLARE_PTR_TYPEDEFS(ConfigItemBuilder); ConfigItemBuilder(void); explicit ConfigItemBuilder(const DebugInfo& debugInfo); diff --git a/lib/config/configtype.hpp b/lib/config/configtype.hpp index 5c8332c9e..aa8b770ad 100644 --- a/lib/config/configtype.hpp +++ b/lib/config/configtype.hpp @@ -37,7 +37,7 @@ namespace icinga */ class I2_CONFIG_API ConfigType : public Object { public: - DECLARE_OBJECT(ConfigType); + DECLARE_PTR_TYPEDEFS(ConfigType); ConfigType(const String& name, const DebugInfo& debuginfo); diff --git a/lib/config/expression.hpp b/lib/config/expression.hpp index f47663162..3ef66761d 100644 --- a/lib/config/expression.hpp +++ b/lib/config/expression.hpp @@ -61,7 +61,7 @@ enum CombinedSetOp class I2_CONFIG_API Expression : public Object { public: - DECLARE_OBJECT(Expression); + DECLARE_PTR_TYPEDEFS(Expression); typedef Value (*OpCallback)(const Expression *, const Dictionary::Ptr&, DebugHint *dhint); diff --git a/lib/config/typerulelist.hpp b/lib/config/typerulelist.hpp index 4e5f9c68c..a131b4960 100644 --- a/lib/config/typerulelist.hpp +++ b/lib/config/typerulelist.hpp @@ -48,7 +48,7 @@ enum TypeValidationResult class I2_CONFIG_API TypeRuleList : public Object { public: - DECLARE_OBJECT(TypeRuleList); + DECLARE_PTR_TYPEDEFS(TypeRuleList); void SetValidator(const String& validator); String GetValidator(void) const; diff --git a/lib/icinga/macroresolver.hpp b/lib/icinga/macroresolver.hpp index 91631d4d7..300145f2b 100644 --- a/lib/icinga/macroresolver.hpp +++ b/lib/icinga/macroresolver.hpp @@ -36,7 +36,7 @@ namespace icinga class I2_ICINGA_API MacroResolver { public: - DECLARE_OBJECT(MacroResolver); + DECLARE_PTR_TYPEDEFS(MacroResolver); virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const = 0; }; diff --git a/lib/remote/apiclient.hpp b/lib/remote/apiclient.hpp index eca972f2b..9c05a4f1e 100644 --- a/lib/remote/apiclient.hpp +++ b/lib/remote/apiclient.hpp @@ -43,7 +43,7 @@ enum ClientRole class I2_REMOTE_API ApiClient : public Object { public: - DECLARE_OBJECT(ApiClient); + DECLARE_PTR_TYPEDEFS(ApiClient); ApiClient(const String& identity, bool authenticated, const TlsStream::Ptr& stream, ConnectionRole role); diff --git a/lib/remote/apifunction.hpp b/lib/remote/apifunction.hpp index 30abb9e83..72da522d4 100644 --- a/lib/remote/apifunction.hpp +++ b/lib/remote/apifunction.hpp @@ -39,7 +39,7 @@ namespace icinga class I2_REMOTE_API ApiFunction : public Object { public: - DECLARE_OBJECT(ApiFunction); + DECLARE_PTR_TYPEDEFS(ApiFunction); typedef boost::function Callback; diff --git a/test/base-object.cpp b/test/base-object.cpp index 985ae0dcd..8be052703 100644 --- a/test/base-object.cpp +++ b/test/base-object.cpp @@ -26,7 +26,7 @@ using namespace icinga; class TestObject : public Object { public: - DECLARE_OBJECT(TestObject); + DECLARE_PTR_TYPEDEFS(TestObject); TestObject::Ptr GetTestRef(void) { diff --git a/tools/mkclass/classcompiler.cpp b/tools/mkclass/classcompiler.cpp index 808b7a329..e4be9d825 100644 --- a/tools/mkclass/classcompiler.cpp +++ b/tools/mkclass/classcompiler.cpp @@ -114,6 +114,18 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) if (klass.Name.find_first_of(':') == std::string::npos) std::cout << "class " << klass.Name << ";" << std::endl << std::endl; + /* TypeHelper */ + if (klass.Attributes & TAAbstract) { + std::cout << "template<>" << std::endl + << "struct TypeHelper<" << klass.Name << ">" << std::endl + << "{" << std::endl + << "\t" << "static ObjectFactory GetFactory(void)" << std::endl + << "\t" << "{" << std::endl + << "\t\t" << "return NULL;" << std::endl + << "\t" << "}" << std::endl + << "};" << std::endl << std::endl; + } + /* TypeImpl */ std::cout << "template<>" << std::endl << "class TypeImpl<" << klass.Name << ">" @@ -294,6 +306,12 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) std::cout << ";" << std::endl << "\t" << "}" << std::endl << std::endl; + /* GetFactory */ + std::cout << "\t" << "virtual ObjectFactory GetFactory(void) const" << std::endl + << "\t" << "{" << std::endl + << "\t\t" << "return TypeHelper<" << klass.Name << ">::GetFactory();" << std::endl + << "\t" << "}" << std::endl << std::endl; + std::cout << "};" << std::endl << std::endl; /* ObjectImpl */ @@ -302,8 +320,7 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) << " : public " << (klass.Parent.empty() ? "Object" : klass.Parent) << std::endl << "{" << std::endl << "public:" << std::endl - << "\t" << "DECLARE_PTR_TYPEDEFS(ObjectImpl<" << klass.Name << ">);" << std::endl - << "\t" << "IMPL_TYPE_LOOKUP(" << klass.Name << ");" << std::endl << std::endl; + << "\t" << "DECLARE_PTR_TYPEDEFS(ObjectImpl<" << klass.Name << ">);" << std::endl; if (!klass.Fields.empty()) { /* constructor */ @@ -466,18 +483,6 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) } std::cout << "};" << std::endl << std::endl; - - /* FactoryHelper */ - if (klass.Attributes & TAAbstract) { - std::cout << "template<>" << std::endl - << "struct FactoryHelper<" << klass.Name << ">" << std::endl - << "{" << std::endl - << "\t" << "Type::Factory GetFactory(void)" << std::endl - << "\t" << "{" << std::endl - << "\t\t" << "return Type::Factory();" << std::endl - << "\t" << "}" << std::endl - << "};" << std::endl << std::endl; - } } void ClassCompiler::CompileFile(const std::string& path)