1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #ifndef PRIMITIVETYPE_H
4 #define PRIMITIVETYPE_H
6 #include "base/i2-base.hpp"
7 #include "base/type.hpp"
8 #include "base/initialize.hpp"
13 class PrimitiveType final : public Type
16 PrimitiveType(String name, String base, const ObjectFactory& factory = ObjectFactory());
18 String GetName() const override;
19 Type::Ptr GetBaseType() const override;
20 int GetAttributes() const override;
21 int GetFieldId(const String& name) const override;
22 Field GetFieldInfo(int id) const override;
23 int GetFieldCount() const override;
26 ObjectFactory GetFactory() const override;
31 ObjectFactory m_Factory;
34 /* Ensure that the priority is lower than the basic namespace initialization in scriptframe.cpp. */
35 #define REGISTER_BUILTIN_TYPE(type, prototype) \
36 INITIALIZE_ONCE_WITH_PRIORITY([]() { \
37 icinga::Type::Ptr t = new PrimitiveType(#type, "None"); \
38 t->SetPrototype(prototype); \
39 icinga::Type::Register(t); \
42 #define REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, factory) \
43 INITIALIZE_ONCE_WITH_PRIORITY([]() { \
44 icinga::Type::Ptr t = new PrimitiveType(#type, #base, factory); \
45 t->SetPrototype(prototype); \
46 icinga::Type::Register(t); \
47 type::TypeInstance = t; \
49 DEFINE_TYPE_INSTANCE(type)
51 #define REGISTER_PRIMITIVE_TYPE(type, base, prototype) \
52 REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, DefaultObjectFactory<type>)
54 #define REGISTER_PRIMITIVE_TYPE_VA(type, base, prototype) \
55 REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, DefaultObjectFactoryVA<type>)
57 #define REGISTER_PRIMITIVE_TYPE_NOINST(type, base, prototype) \
58 REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, nullptr)
62 #endif /* PRIMITIVETYPE_H */