]> granicus.if.org Git - icinga2/blobdiff - lib/base/type.hpp
Remove unused #includes
[icinga2] / lib / base / type.hpp
index d8ebf804694191aa6a4ac91b58d3af7f5873578a..b825b440d6ec089b19e67610374c70253c48765a 100644 (file)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * Icinga 2                                                                   *
- * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)    *
+ * Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org)    *
  *                                                                            *
  * This program is free software; you can redistribute it and/or              *
  * modify it under the terms of the GNU General Public License                *
 #include "base/string.hpp"
 #include "base/object.hpp"
 #include "base/initialize.hpp"
-#include "base/utility.hpp"
-#include <boost/function.hpp>
+#include <vector>
 
 namespace icinga
 {
 
+/* keep this in sync with tools/mkclass/classcompiler.hpp */
 enum FieldAttribute
 {
-       FAConfig = 1,
-       FAState = 2
+       FAEphemeral = 1,
+       FAConfig = 2,
+       FAState = 4,
+       FAInternal = 64,
+       FARequired = 512
 }; 
 
 class Type;
@@ -41,12 +44,13 @@ class Type;
 struct Field
 {
        int ID;
-       const Type *FType;
+       const char *TypeName;
        const char *Name;
+       const char *RefTypeName;
        int Attributes;
 
-       Field(int id, const Type *type, const char *name, int attributes)
-               : ID(id), FType(type), Name(name), Attributes(attributes)
+       Field(int id, const char *type, const char *name, const char *reftype, int attributes)
+               : ID(id), TypeName(type), Name(name), RefTypeName(reftype), Attributes(attributes)
        { }
 };
 
@@ -55,13 +59,21 @@ enum TypeAttribute
        TAAbstract = 1
 };
 
-class I2_BASE_API Type
+class ValidationUtils
 {
 public:
-       typedef boost::function<Object::Ptr (void)> Factory;
+       virtual bool ValidateName(const String& type, const String& name) const = 0;
+};
+
+class I2_BASE_API Type : public Object
+{
+public:
+       DECLARE_PTR_TYPEDEFS(Type);
+
+       virtual String ToString(void) const;
 
        virtual String GetName(void) const = 0;
-       virtual const Type *GetBaseType(void) const = 0;
+       virtual Type::Ptr GetBaseType(void) const = 0;
        virtual int GetAttributes(void) const = 0;
        virtual int GetFieldId(const String& name) const = 0;
        virtual Field GetFieldInfo(int id) const = 0;
@@ -69,54 +81,64 @@ public:
 
        Object::Ptr Instantiate(void) const;
 
-       bool IsAssignableFrom(const Type *other) const;
+       bool IsAssignableFrom(const Type::Ptr& other) const;
 
        bool IsAbstract(void) const;
 
-       static void Register(const Type *type);
-       static const Type *GetByName(const String& name);
+       Object::Ptr GetPrototype(void) const;
+       void SetPrototype(const Object::Ptr& object);
 
-       void SetFactory(const Factory& factory);
+       static void Register(const Type::Ptr& type);
+       static Type::Ptr GetByName(const String& name);
 
-private:
-       typedef std::map<String, const Type *> TypeMap;
+       virtual void SetField(int id, const Value& value);
+       virtual Value GetField(int id) const;
 
-       static TypeMap& GetTypes(void);
+       virtual std::vector<String> GetLoadDependencies(void) const;
 
-       Factory m_Factory;
-};
+protected:
+       virtual ObjectFactory GetFactory(void) const = 0;
 
-template<typename T>
-class TypeImpl
-{
+private:
+       Object::Ptr m_Prototype;
 };
 
-template<typename T>
-shared_ptr<T> ObjectFactory(void)
+class I2_BASE_API TypeType : public Type
 {
-       return make_shared<T>();
-}
+public:
+       DECLARE_PTR_TYPEDEFS(Type);
+
+       virtual String GetName(void) const;
+       virtual Type::Ptr GetBaseType(void) const;
+       virtual int GetAttributes(void) const;
+       virtual int GetFieldId(const String& name) const;
+       virtual Field GetFieldInfo(int id) const;
+       virtual int GetFieldCount(void) const;
+
+protected:
+       virtual ObjectFactory GetFactory(void) const;
+};
 
 template<typename T>
-struct FactoryHelper
+class TypeImpl
 {
-       Type::Factory GetFactory(void)
-       {
-               return ObjectFactory<T>;
-       }
 };
 
 #define REGISTER_TYPE(type) \
        namespace { namespace UNIQUE_NAME(rt) { \
                void RegisterType ## type(void) \
                { \
-                       icinga::Type *t = new TypeImpl<type>(); \
-                       t->SetFactory(FactoryHelper<type>().GetFactory()); \
+                       icinga::Type::Ptr t = new TypeImpl<type>(); \
+                       type::TypeInstance = t; \
                        icinga::Type::Register(t); \
                } \
                \
-               INITIALIZE_ONCE(RegisterType ## type); \
-       } }
+               INITIALIZE_ONCE_WITH_PRIORITY(RegisterType ## type, 10); \
+       } } \
+       DEFINE_TYPE_INSTANCE(type)
+
+#define DEFINE_TYPE_INSTANCE(type) \
+       Type::Ptr type::TypeInstance
 
 }