2014-10-31 08:49:14 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2018-01-02 12:06:00 +01:00
|
|
|
* Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
|
2014-10-31 08:49:14 +01:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#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
|
|
|
};
|
|
|
|
|
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 */
|