application.cpp application.thpp array.cpp configerror.cpp console.cpp context.cpp
convert.cpp debuginfo.cpp dictionary.cpp dynamicobject.cpp dynamicobject.thpp dynamictype.cpp
exception.cpp fifo.cpp filelogger.cpp filelogger.thpp json.cpp logger.cpp logger.thpp
- netstring.cpp networkstream.cpp object.cpp objectlock.cpp process.cpp
+ netstring.cpp networkstream.cpp object.cpp objectlock.cpp primitivetype.cpp process.cpp
ringbuffer.cpp scriptfunction.cpp scriptfunctionwrapper.cpp
scriptutils.cpp scriptvariable.cpp serializer.cpp socket.cpp stacktrace.cpp
statsfunction.cpp stdiostream.cpp stream.cpp streamlogger.cpp streamlogger.thpp string.cpp
#include "base/array.hpp"
#include "base/objectlock.hpp"
#include "base/debug.hpp"
+#include "base/primitivetype.hpp"
#include <boost/foreach.hpp>
using namespace icinga;
+REGISTER_PRIMITIVE_TYPE(Array);
+
/**
* Restrieves a value from an array.
*
#include "base/dictionary.hpp"
#include "base/objectlock.hpp"
#include "base/debug.hpp"
+#include "base/primitivetype.hpp"
#include <boost/foreach.hpp>
using namespace icinga;
+REGISTER_PRIMITIVE_TYPE(Dictionary);
+
/**
* Compares dictionary keys using the less operator.
*/
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
+ * *
+ * 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. *
+ ******************************************************************************/
+
+#include "base/primitivetype.hpp"
+
+using namespace icinga;
+
+REGISTER_PRIMITIVE_TYPE(int);
+REGISTER_PRIMITIVE_TYPE(double);
+REGISTER_PRIMITIVE_TYPE(bool);
+
+PrimitiveType::PrimitiveType(const String& name)
+ : m_Name(name)
+{ }
+
+String PrimitiveType::GetName(void) const
+{
+ return m_Name;
+}
+
+const Type *PrimitiveType::GetBaseType(void) const
+{
+ return NULL;
+}
+
+int PrimitiveType::GetAttributes(void) const
+{
+ return 0;
+}
+
+int PrimitiveType::GetFieldId(const String& name) const
+{
+ return -1;
+}
+
+Field PrimitiveType::GetFieldInfo(int id) const
+{
+ throw std::runtime_error("Invalid field ID.");
+}
+
+int PrimitiveType::GetFieldCount(void) const
+{
+ return 0;
+}
+
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
+ * *
+ * 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
+{
+
+class I2_BASE_API PrimitiveType : public Type
+{
+public:
+ PrimitiveType(const String& name);
+
+ virtual String GetName(void) const;
+ virtual const Type *GetBaseType(void) const;
+ virtual int GetAttributes(void) const;
+ virtual int GetFieldId(const String& name) const;
+ virtual Field GetFieldInfo(int id) const;
+ virtual int GetFieldCount(void) const;
+
+private:
+ String m_Name;
+};
+
+#define REGISTER_PRIMITIVE_TYPE(type) \
+ namespace { namespace UNIQUE_NAME(prt) { \
+ void RegisterPrimitiveType ## type(void) \
+ { \
+ icinga::Type *t = new PrimitiveType(#type); \
+ icinga::Type::Register(t); \
+ } \
+ \
+ INITIALIZE_ONCE(RegisterPrimitiveType ## type); \
+ } }
+
+}
+
+#endif /* PRIMITIVETYPE_H */
#include "base/string.hpp"
#include "base/value.hpp"
+#include "base/primitivetype.hpp"
#include <boost/algorithm/string/trim.hpp>
#include <ostream>
using namespace icinga;
+REGISTER_PRIMITIVE_TYPE(String);
+
const String::SizeType String::NPos = std::string::npos;
String::String(void)
FAConfig = 1,
FAState = 2
};
-
+
+class Type;
+
struct Field
{
int ID;
+ const Type *FType;
const char *Name;
int Attributes;
- Field(int id, const char *name, int attributes)
- : ID(id), Name(name), Attributes(attributes)
+ Field(int id, const Type *type, const char *name, int attributes)
+ : ID(id), FType(type), Name(name), Attributes(attributes)
{ }
};
#define REGISTER_TYPE(type) \
namespace { namespace UNIQUE_NAME(rt) { \
- void RegisterType(void) \
+ void RegisterType ## type(void) \
{ \
icinga::Type *t = new TypeImpl<type>(); \
t->SetFactory(FactoryHelper<type>().GetFactory()); \
icinga::Type::Register(t); \
} \
\
- INITIALIZE_ONCE(RegisterType); \
+ INITIALIZE_ONCE(RegisterType ## type); \
} }
}
if (!(field.Attributes & FAConfig))
continue;
+ if (field.FType != Type::GetByName("int") && field.FType != Type::GetByName("double")
+ && field.FType != Type::GetByName("bool") && field.FType != Type::GetByName("String"))
+ continue;
+
String fname = field.Name;
if (fname == "__name" || fname == "templates" || fname == "type")
size_t num = 0;
for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) {
+ std::string ftype = it->Type;
+
+ if (ftype.find("::Ptr") == ftype.size() - strlen("::Ptr"))
+ ftype = ftype.substr(0, ftype.size() - strlen("::Ptr"));
+
+ if (it->Attributes & FAEnum)
+ ftype = "int";
+
std::cout << "\t\t\t" << "case " << num << ":" << std::endl
- << "\t\t\t\t" << "return Field(" << num << ", \"" << it->Name << "\", " << it->Attributes << ");" << std::endl;
+ << "\t\t\t\t" << "return Field(" << num << ", Type::GetByName(\"" << ftype << "\"), \"" << it->Name << "\", " << it->Attributes << ");" << std::endl;
num++;
}