]> granicus.if.org Git - icinga2/blob - lib/base/objecttype.cpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / base / objecttype.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "base/objecttype.hpp"
4 #include "base/initialize.hpp"
5 #include <boost/throw_exception.hpp>
6
7 using namespace icinga;
8
9 /* Ensure that the priority is lower than the basic namespace initialization in scriptframe.cpp. */
10 INITIALIZE_ONCE_WITH_PRIORITY([]() {
11         Type::Ptr type = new ObjectType();
12         type->SetPrototype(Object::GetPrototype());
13         Type::Register(type);
14         Object::TypeInstance = type;
15 }, 20);
16
17 String ObjectType::GetName() const
18 {
19         return "Object";
20 }
21
22 Type::Ptr ObjectType::GetBaseType() const
23 {
24         return nullptr;
25 }
26
27 int ObjectType::GetAttributes() const
28 {
29         return 0;
30 }
31
32 int ObjectType::GetFieldId(const String& name) const
33 {
34         if (name == "type")
35                 return 0;
36         else
37                 return -1;
38 }
39
40 Field ObjectType::GetFieldInfo(int id) const
41 {
42         if (id == 0)
43                 return {1, "String", "type", nullptr, nullptr, 0, 0};
44         else
45                 BOOST_THROW_EXCEPTION(std::runtime_error("Invalid field ID."));
46 }
47
48 int ObjectType::GetFieldCount() const
49 {
50         return 1;
51 }
52
53 ObjectFactory ObjectType::GetFactory() const
54 {
55         return DefaultObjectFactory<Object>;
56 }
57