]> granicus.if.org Git - icinga2/blob - lib/base/primitivetype.cpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / base / primitivetype.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "base/primitivetype.hpp"
4 #include "base/dictionary.hpp"
5
6 using namespace icinga;
7
8 PrimitiveType::PrimitiveType(String name, String base, const ObjectFactory& factory)
9         : m_Name(std::move(name)), m_Base(std::move(base)), m_Factory(factory)
10 { }
11
12 String PrimitiveType::GetName() const
13 {
14         return m_Name;
15 }
16
17 Type::Ptr PrimitiveType::GetBaseType() const
18 {
19         if (m_Base == "None")
20                 return nullptr;
21         else
22                 return Type::GetByName(m_Base);
23 }
24
25 int PrimitiveType::GetAttributes() const
26 {
27         return 0;
28 }
29
30 int PrimitiveType::GetFieldId(const String& name) const
31 {
32         Type::Ptr base = GetBaseType();
33
34         if (base)
35                 return base->GetFieldId(name);
36         else
37                 return -1;
38 }
39
40 Field PrimitiveType::GetFieldInfo(int id) const
41 {
42         Type::Ptr base = GetBaseType();
43
44         if (base)
45                 return base->GetFieldInfo(id);
46         else
47                 throw std::runtime_error("Invalid field ID.");
48 }
49
50 int PrimitiveType::GetFieldCount() const
51 {
52         Type::Ptr base = GetBaseType();
53
54         if (base)
55                 return Object::TypeInstance->GetFieldCount();
56         else
57                 return 0;
58 }
59
60 ObjectFactory PrimitiveType::GetFactory() const
61 {
62         return m_Factory;
63 }
64