2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2014-10-31 08:49:14 +01:00
|
|
|
|
|
|
|
#ifndef PRIMITIVETYPE_H
|
|
|
|
#define PRIMITIVETYPE_H
|
|
|
|
|
|
|
|
#include "base/i2-base.hpp"
|
|
|
|
#include "base/type.hpp"
|
|
|
|
#include "base/initialize.hpp"
|
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2018-01-04 06:11:04 +01:00
|
|
|
class PrimitiveType final : public Type
|
2014-10-31 08:49:14 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-01-04 08:54:18 +01:00
|
|
|
PrimitiveType(String name, String base, const ObjectFactory& factory = ObjectFactory());
|
2014-10-31 08:49:14 +01:00
|
|
|
|
2018-01-04 05:12:56 +01:00
|
|
|
String GetName() const override;
|
|
|
|
Type::Ptr GetBaseType() const override;
|
|
|
|
int GetAttributes() const override;
|
|
|
|
int GetFieldId(const String& name) const override;
|
|
|
|
Field GetFieldInfo(int id) const override;
|
|
|
|
int GetFieldCount() const override;
|
2014-10-31 08:49:14 +01:00
|
|
|
|
2014-11-07 12:32:25 +01:00
|
|
|
protected:
|
2018-01-04 05:12:56 +01:00
|
|
|
ObjectFactory GetFactory() const override;
|
2014-11-07 12:32:25 +01:00
|
|
|
|
2014-10-31 08:49:14 +01:00
|
|
|
private:
|
|
|
|
String m_Name;
|
2015-08-17 08:14:04 +02:00
|
|
|
String m_Base;
|
2015-03-21 22:48:23 +01:00
|
|
|
ObjectFactory m_Factory;
|
2014-10-31 08:49:14 +01:00
|
|
|
};
|
|
|
|
|
2018-09-04 15:17:34 +02:00
|
|
|
/* Ensure that the priority is lower than the basic namespace initialization in scriptframe.cpp. */
|
2014-12-12 15:19:23 +01:00
|
|
|
#define REGISTER_BUILTIN_TYPE(type, prototype) \
|
2016-08-27 09:35:08 +02:00
|
|
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
|
|
|
icinga::Type::Ptr t = new PrimitiveType(#type, "None"); \
|
|
|
|
t->SetPrototype(prototype); \
|
|
|
|
icinga::Type::Register(t); \
|
|
|
|
}, 15)
|
2014-10-31 08:49:14 +01:00
|
|
|
|
2015-08-17 08:14:04 +02:00
|
|
|
#define REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, factory) \
|
2016-08-27 09:35:08 +02:00
|
|
|
INITIALIZE_ONCE_WITH_PRIORITY([]() { \
|
|
|
|
icinga::Type::Ptr t = new PrimitiveType(#type, #base, factory); \
|
|
|
|
t->SetPrototype(prototype); \
|
|
|
|
icinga::Type::Register(t); \
|
|
|
|
type::TypeInstance = t; \
|
|
|
|
}, 15); \
|
2014-11-07 12:32:25 +01:00
|
|
|
DEFINE_TYPE_INSTANCE(type)
|
|
|
|
|
2015-08-17 08:14:04 +02:00
|
|
|
#define REGISTER_PRIMITIVE_TYPE(type, base, prototype) \
|
|
|
|
REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, DefaultObjectFactory<type>)
|
2015-03-21 22:48:23 +01:00
|
|
|
|
2016-03-29 12:45:22 +02:00
|
|
|
#define REGISTER_PRIMITIVE_TYPE_VA(type, base, prototype) \
|
|
|
|
REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, DefaultObjectFactoryVA<type>)
|
|
|
|
|
2015-08-17 08:14:04 +02:00
|
|
|
#define REGISTER_PRIMITIVE_TYPE_NOINST(type, base, prototype) \
|
2017-12-14 15:37:20 +01:00
|
|
|
REGISTER_PRIMITIVE_TYPE_FACTORY(type, base, prototype, nullptr)
|
2015-03-21 22:48:23 +01:00
|
|
|
|
2014-10-31 08:49:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* PRIMITIVETYPE_H */
|