2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2014-10-31 08:49:14 +01:00
|
|
|
|
|
|
|
#include "base/primitivetype.hpp"
|
2014-12-12 15:19:23 +01:00
|
|
|
#include "base/dictionary.hpp"
|
2014-10-31 08:49:14 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2018-01-04 08:54:18 +01:00
|
|
|
PrimitiveType::PrimitiveType(String name, String base, const ObjectFactory& factory)
|
|
|
|
: m_Name(std::move(name)), m_Base(std::move(base)), m_Factory(factory)
|
2014-10-31 08:49:14 +01:00
|
|
|
{ }
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
String PrimitiveType::GetName() const
|
2014-10-31 08:49:14 +01:00
|
|
|
{
|
|
|
|
return m_Name;
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
Type::Ptr PrimitiveType::GetBaseType() const
|
2014-10-31 08:49:14 +01:00
|
|
|
{
|
2015-08-17 08:14:04 +02:00
|
|
|
if (m_Base == "None")
|
2017-11-30 08:36:35 +01:00
|
|
|
return nullptr;
|
2015-08-17 08:14:04 +02:00
|
|
|
else
|
|
|
|
return Type::GetByName(m_Base);
|
2014-10-31 08:49:14 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
int PrimitiveType::GetAttributes() const
|
2014-10-31 08:49:14 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PrimitiveType::GetFieldId(const String& name) const
|
|
|
|
{
|
2015-11-05 10:52:25 +01:00
|
|
|
Type::Ptr base = GetBaseType();
|
|
|
|
|
|
|
|
if (base)
|
|
|
|
return base->GetFieldId(name);
|
|
|
|
else
|
|
|
|
return -1;
|
2014-10-31 08:49:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Field PrimitiveType::GetFieldInfo(int id) const
|
|
|
|
{
|
2015-11-05 10:52:25 +01:00
|
|
|
Type::Ptr base = GetBaseType();
|
|
|
|
|
|
|
|
if (base)
|
|
|
|
return base->GetFieldInfo(id);
|
|
|
|
else
|
|
|
|
throw std::runtime_error("Invalid field ID.");
|
2014-10-31 08:49:14 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
int PrimitiveType::GetFieldCount() const
|
2014-10-31 08:49:14 +01:00
|
|
|
{
|
2015-11-05 10:52:25 +01:00
|
|
|
Type::Ptr base = GetBaseType();
|
|
|
|
|
|
|
|
if (base)
|
|
|
|
return Object::TypeInstance->GetFieldCount();
|
|
|
|
else
|
|
|
|
return 0;
|
2014-10-31 08:49:14 +01:00
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
ObjectFactory PrimitiveType::GetFactory() const
|
2014-11-07 12:32:25 +01:00
|
|
|
{
|
2015-03-21 22:48:23 +01:00
|
|
|
return m_Factory;
|
2014-11-07 12:32:25 +01:00
|
|
|
}
|