]> granicus.if.org Git - icinga2/blob - lib/base/primitivetype.hpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / base / primitivetype.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef PRIMITIVETYPE_H
4 #define PRIMITIVETYPE_H
5
6 #include "base/i2-base.hpp"
7 #include "base/type.hpp"
8 #include "base/initialize.hpp"
9
10 namespace icinga
11 {
12
13 class PrimitiveType final : public Type
14 {
15 public:
16         PrimitiveType(String name, String base, const ObjectFactory& factory = ObjectFactory());
17
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;
24
25 protected:
26         ObjectFactory GetFactory() const override;
27
28 private:
29         String m_Name;
30         String m_Base;
31         ObjectFactory m_Factory;
32 };
33
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);                                      \
40         }, 15)
41
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;                                         \
48         }, 15);                                                                 \
49         DEFINE_TYPE_INSTANCE(type)
50
51 #define REGISTER_PRIMITIVE_TYPE(type, base, prototype)                          \
52         REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, DefaultObjectFactory<type>)
53
54 #define REGISTER_PRIMITIVE_TYPE_VA(type, base, prototype)                               \
55         REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, DefaultObjectFactoryVA<type>)
56
57 #define REGISTER_PRIMITIVE_TYPE_NOINST(type, base, prototype)                   \
58         REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, nullptr)
59
60 }
61
62 #endif /* PRIMITIVETYPE_H */