From 72a7b08480005444fb67cc5704a96b9edb95b8cc Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 28 Mar 2015 11:04:42 +0100 Subject: [PATCH] Move implementation code from thpp files into separate files fixes #8890 --- lib/base/CMakeLists.txt | 14 +- lib/base/application.cpp | 1 + lib/base/dynamicobject.cpp | 1 + lib/base/dynamicobject.ti | 2 + lib/base/exception.cpp | 8 +- lib/base/exception.hpp | 10 +- lib/base/filelogger.cpp | 1 + lib/base/logger.cpp | 3 +- lib/base/streamlogger.cpp | 1 + lib/base/sysloglogger.cpp | 2 + lib/checker/CMakeLists.txt | 2 +- lib/checker/checkercomponent.cpp | 1 + lib/cli/repositoryutility.cpp | 1 + lib/compat/CMakeLists.txt | 8 +- lib/compat/checkresultreader.cpp | 1 + lib/compat/compatlogger.cpp | 1 + lib/compat/externalcommandlistener.cpp | 1 + lib/compat/statusdatawriter.cpp | 1 + lib/db_ido/CMakeLists.txt | 4 +- lib/db_ido/dbconnection.cpp | 1 + lib/db_ido_mysql/CMakeLists.txt | 2 +- lib/db_ido_mysql/idomysqlconnection.cpp | 1 + lib/db_ido_pgsql/CMakeLists.txt | 2 +- lib/db_ido_pgsql/idopgsqlconnection.cpp | 3 +- lib/demo/CMakeLists.txt | 2 +- lib/demo/demo.cpp | 1 + lib/hello/CMakeLists.txt | 2 +- lib/hello/hello.cpp | 1 + lib/icinga/CMakeLists.txt | 54 +- lib/icinga/checkable.cpp | 1 + lib/icinga/checkcommand.cpp | 1 + lib/icinga/checkresult.cpp | 1 + lib/icinga/command.cpp | 1 + lib/icinga/comment.cpp | 1 + lib/icinga/customvarobject.cpp | 1 + lib/icinga/dependency.cpp | 1 + lib/icinga/downtime.cpp | 1 + lib/icinga/eventcommand.cpp | 1 + lib/icinga/host.cpp | 1 + lib/icinga/hostgroup.cpp | 1 + lib/icinga/icingaapplication.cpp | 1 + lib/icinga/icingastatuswriter.cpp | 1 + lib/icinga/notification.cpp | 1 + lib/icinga/notificationcommand.cpp | 1 + lib/icinga/perfdatavalue.cpp | 1 + lib/icinga/scheduleddowntime.cpp | 1 + lib/icinga/service.cpp | 1 + lib/icinga/servicegroup.cpp | 1 + lib/icinga/timeperiod.cpp | 1 + lib/icinga/user.cpp | 1 + lib/icinga/usergroup.cpp | 1 + lib/livestatus/CMakeLists.txt | 2 +- lib/livestatus/livestatuslistener.cpp | 1 + lib/notification/CMakeLists.txt | 2 +- lib/notification/notificationcomponent.cpp | 1 + lib/perfdata/CMakeLists.txt | 8 +- lib/perfdata/gelfwriter.cpp | 1 + lib/perfdata/graphitewriter.cpp | 1 + lib/perfdata/opentsdbwriter.cpp | 1 + lib/perfdata/perfdatawriter.cpp | 1 + lib/remote/CMakeLists.txt | 10 +- lib/remote/apiclient-heartbeat.cpp | 1 + lib/remote/apilistener.cpp | 1 + lib/remote/endpoint.cpp | 1 + lib/remote/zone.cpp | 1 + tools/mkclass/CMakeLists.txt | 9 +- tools/mkclass/classcompiler.cpp | 704 +++++++++++---------- tools/mkclass/classcompiler.hpp | 22 +- tools/mkclass/mkclass.cpp | 6 +- 69 files changed, 529 insertions(+), 398 deletions(-) diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index fb7cea75e..726c490a9 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -15,15 +15,15 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -mkclass_target(application.ti application.thpp) -mkclass_target(dynamicobject.ti dynamicobject.thpp) -mkclass_target(filelogger.ti filelogger.thpp) -mkclass_target(logger.ti logger.thpp) -mkclass_target(streamlogger.ti streamlogger.thpp) -mkclass_target(sysloglogger.ti sysloglogger.thpp) +mkclass_target(application.ti application.tcpp application.thpp) +mkclass_target(dynamicobject.ti dynamicobject.tcpp dynamicobject.thpp) +mkclass_target(filelogger.ti filelogger.tcpp filelogger.thpp) +mkclass_target(logger.ti logger.tcpp logger.thpp) +mkclass_target(streamlogger.ti streamlogger.tcpp streamlogger.thpp) +mkclass_target(sysloglogger.ti sysloglogger.tcpp sysloglogger.thpp) set(base_SOURCES - application.cpp application-version.cpp application.thpp array.cpp array-script.cpp boolean.cpp boolean-script.cpp console.cpp context.cpp + application.cpp application.thpp application-version.cpp array.cpp array-script.cpp boolean.cpp boolean-script.cpp console.cpp context.cpp convert.cpp debuginfo.cpp dictionary.cpp dictionary-script.cpp dynamicobject.cpp dynamicobject.thpp dynamictype.cpp exception.cpp fifo.cpp filelogger.cpp filelogger.thpp initialize.cpp json.cpp json-script.cpp loader.cpp logger.cpp logger.thpp math-script.cpp netstring.cpp networkstream.cpp number.cpp number-script.cpp object.cpp object-script.cpp primitivetype.cpp process.cpp diff --git a/lib/base/application.cpp b/lib/base/application.cpp index bbf2135de..55d9f8367 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "base/application.hpp" +#include "base/application.tcpp" #include "base/stacktrace.hpp" #include "base/timer.hpp" #include "base/logger.hpp" diff --git a/lib/base/dynamicobject.cpp b/lib/base/dynamicobject.cpp index e29e51022..6c5006288 100644 --- a/lib/base/dynamicobject.cpp +++ b/lib/base/dynamicobject.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "base/dynamicobject.hpp" +#include "base/dynamicobject.tcpp" #include "base/dynamictype.hpp" #include "base/serializer.hpp" #include "base/netstring.hpp" diff --git a/lib/base/dynamicobject.ti b/lib/base/dynamicobject.ti index df8bdb154..4351c90ca 100644 --- a/lib/base/dynamicobject.ti +++ b/lib/base/dynamicobject.ti @@ -17,6 +17,8 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ +#include "base/debuginfo.hpp" + namespace icinga { diff --git a/lib/base/exception.cpp b/lib/base/exception.cpp index a68e0da59..a079837e5 100644 --- a/lib/base/exception.cpp +++ b/lib/base/exception.cpp @@ -18,8 +18,8 @@ ******************************************************************************/ #include "base/exception.hpp" -#include "base/dynamicobject.hpp" #include +#include #ifdef HAVE_CXXABI_H # include @@ -154,7 +154,7 @@ String icinga::DiagnosticInformation(const std::exception& ex, bool verbose, Sta if (vex) { DebugInfo di; - DynamicObject::Ptr dobj = dynamic_pointer_cast(vex->GetObject()); + DynamicObject::Ptr dobj = vex->GetObject(); if (dobj) di = dobj->GetDebugInfo(); @@ -313,7 +313,7 @@ const char *posix_error::what(void) const throw() return m_Message; } -ValidationError::ValidationError(const intrusive_ptr >& object, const std::vector& attributePath, const String& message) +ValidationError::ValidationError(const DynamicObject::Ptr& object, const std::vector& attributePath, const String& message) : m_Object(object), m_AttributePath(attributePath), m_Message(message) { String path; @@ -342,7 +342,7 @@ const char *ValidationError::what(void) const throw() return m_What.CStr(); } -intrusive_ptr > ValidationError::GetObject(void) const +DynamicObject::Ptr ValidationError::GetObject(void) const { return m_Object; } diff --git a/lib/base/exception.hpp b/lib/base/exception.hpp index 15f449f12..daeed9677 100644 --- a/lib/base/exception.hpp +++ b/lib/base/exception.hpp @@ -27,6 +27,7 @@ #include "base/utility.hpp" #include "base/debuginfo.hpp" #include "base/dictionary.hpp" +#include "base/dynamicobject.hpp" #include #include #include @@ -65,21 +66,18 @@ private: bool m_IncompleteExpr; }; -class DynamicObject; -template<> class ObjectImpl; - /* * @ingroup base */ class I2_BASE_API ValidationError : virtual public user_error { public: - ValidationError(const intrusive_ptr >& object, const std::vector& attributePath, const String& message); + ValidationError(const DynamicObject::Ptr& object, const std::vector& attributePath, const String& message); ~ValidationError(void) throw(); virtual const char *what(void) const throw(); - intrusive_ptr > GetObject(void) const; + DynamicObject::Ptr GetObject(void) const; std::vector GetAttributePath(void) const; String GetMessage(void) const; @@ -87,7 +85,7 @@ public: Dictionary::Ptr GetDebugHint(void) const; private: - intrusive_ptr > m_Object; + DynamicObject::Ptr m_Object; std::vector m_AttributePath; String m_Message; String m_What; diff --git a/lib/base/filelogger.cpp b/lib/base/filelogger.cpp index b15234f70..ab981bb76 100644 --- a/lib/base/filelogger.cpp +++ b/lib/base/filelogger.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "base/filelogger.hpp" +#include "base/filelogger.tcpp" #include "base/dynamictype.hpp" #include "base/statsfunction.hpp" #include "base/application.hpp" diff --git a/lib/base/logger.cpp b/lib/base/logger.cpp index 4c15c5d3d..4ffe3ef2b 100644 --- a/lib/base/logger.cpp +++ b/lib/base/logger.cpp @@ -17,9 +17,10 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ +#include "base/logger.hpp" +#include "base/logger.tcpp" #include "base/application.hpp" #include "base/streamlogger.hpp" -#include "base/logger.hpp" #include "base/dynamictype.hpp" #include "base/utility.hpp" #include "base/objectlock.hpp" diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index d3b0ca8a9..63ac98f6a 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "base/streamlogger.hpp" +#include "base/streamlogger.tcpp" #include "base/utility.hpp" #include "base/objectlock.hpp" #include "base/console.hpp" diff --git a/lib/base/sysloglogger.cpp b/lib/base/sysloglogger.cpp index f806cf6b0..34cffbcdd 100644 --- a/lib/base/sysloglogger.cpp +++ b/lib/base/sysloglogger.cpp @@ -22,6 +22,8 @@ #include "base/statsfunction.hpp" #ifndef _WIN32 +#include "base/sysloglogger.tcpp" + using namespace icinga; REGISTER_TYPE(SyslogLogger); diff --git a/lib/checker/CMakeLists.txt b/lib/checker/CMakeLists.txt index d8f422dfb..3a7b5a742 100644 --- a/lib/checker/CMakeLists.txt +++ b/lib/checker/CMakeLists.txt @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -mkclass_target(checkercomponent.ti checkercomponent.thpp) +mkclass_target(checkercomponent.ti checkercomponent.tcpp checkercomponent.thpp) set(checker_SOURCES checkercomponent.cpp checkercomponent.thpp diff --git a/lib/checker/checkercomponent.cpp b/lib/checker/checkercomponent.cpp index 89e5b015b..7bb5eef1c 100644 --- a/lib/checker/checkercomponent.cpp +++ b/lib/checker/checkercomponent.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "checker/checkercomponent.hpp" +#include "checker/checkercomponent.tcpp" #include "icinga/icingaapplication.hpp" #include "icinga/cib.hpp" #include "icinga/perfdatavalue.hpp" diff --git a/lib/cli/repositoryutility.cpp b/lib/cli/repositoryutility.cpp index d7b0e0ecd..d1fa88b3a 100644 --- a/lib/cli/repositoryutility.cpp +++ b/lib/cli/repositoryutility.cpp @@ -31,6 +31,7 @@ #include "base/objectlock.hpp" #include "base/console.hpp" #include "base/serializer.hpp" +#include "base/exception.hpp" #include #include #include diff --git a/lib/compat/CMakeLists.txt b/lib/compat/CMakeLists.txt index 60a4d9a1e..eef148eec 100644 --- a/lib/compat/CMakeLists.txt +++ b/lib/compat/CMakeLists.txt @@ -15,10 +15,10 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -mkclass_target(checkresultreader.ti checkresultreader.thpp) -mkclass_target(compatlogger.ti compatlogger.thpp) -mkclass_target(externalcommandlistener.ti externalcommandlistener.thpp) -mkclass_target(statusdatawriter.ti statusdatawriter.thpp) +mkclass_target(checkresultreader.ti checkresultreader.tcpp checkresultreader.thpp) +mkclass_target(compatlogger.ti compatlogger.tcpp compatlogger.thpp) +mkclass_target(externalcommandlistener.ti externalcommandlistener.tcpp externalcommandlistener.thpp) +mkclass_target(statusdatawriter.ti statusdatawriter.tcpp statusdatawriter.thpp) set(compat_SOURCES checkresultreader.cpp checkresultreader.thpp compatlogger.cpp diff --git a/lib/compat/checkresultreader.cpp b/lib/compat/checkresultreader.cpp index ac2b30c15..6433d055a 100644 --- a/lib/compat/checkresultreader.cpp +++ b/lib/compat/checkresultreader.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "compat/checkresultreader.hpp" +#include "compat/checkresultreader.tcpp" #include "icinga/service.hpp" #include "icinga/pluginutility.hpp" #include "icinga/icingaapplication.hpp" diff --git a/lib/compat/compatlogger.cpp b/lib/compat/compatlogger.cpp index c5cc9b424..90dd2aafe 100644 --- a/lib/compat/compatlogger.cpp +++ b/lib/compat/compatlogger.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "compat/compatlogger.hpp" +#include "compat/compatlogger.tcpp" #include "icinga/service.hpp" #include "icinga/checkcommand.hpp" #include "icinga/eventcommand.hpp" diff --git a/lib/compat/externalcommandlistener.cpp b/lib/compat/externalcommandlistener.cpp index 95c6fc603..6c96a4c74 100644 --- a/lib/compat/externalcommandlistener.cpp +++ b/lib/compat/externalcommandlistener.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "compat/externalcommandlistener.hpp" +#include "compat/externalcommandlistener.tcpp" #include "icinga/externalcommandprocessor.hpp" #include "base/dynamictype.hpp" #include "base/logger.hpp" diff --git a/lib/compat/statusdatawriter.cpp b/lib/compat/statusdatawriter.cpp index 699f0b605..e5e5f24ba 100644 --- a/lib/compat/statusdatawriter.cpp +++ b/lib/compat/statusdatawriter.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "compat/statusdatawriter.hpp" +#include "compat/statusdatawriter.tcpp" #include "icinga/icingaapplication.hpp" #include "icinga/cib.hpp" #include "icinga/hostgroup.hpp" diff --git a/lib/db_ido/CMakeLists.txt b/lib/db_ido/CMakeLists.txt index 0cec9ea02..9a7baa361 100644 --- a/lib/db_ido/CMakeLists.txt +++ b/lib/db_ido/CMakeLists.txt @@ -15,12 +15,12 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -mkclass_target(dbconnection.ti dbconnection.thpp) +mkclass_target(dbconnection.ti dbconnection.tcpp dbconnection.thpp) mkembedconfig_target(db_ido-itl.conf db_ido-itl.cpp) set(db_ido_SOURCES - commanddbobject.cpp dbconnection.cpp dbconnection.thpp dbconnection.thpp + commanddbobject.cpp dbconnection.cpp dbconnection.thpp db_ido-itl.cpp dbevents.cpp dbobject.cpp dbquery.cpp dbreference.cpp dbtype.cpp dbvalue.cpp endpointdbobject.cpp hostdbobject.cpp hostgroupdbobject.cpp idochecktask.cpp servicedbobject.cpp diff --git a/lib/db_ido/dbconnection.cpp b/lib/db_ido/dbconnection.cpp index fe8e011b1..8c91fe7c8 100644 --- a/lib/db_ido/dbconnection.cpp +++ b/lib/db_ido/dbconnection.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "db_ido/dbconnection.hpp" +#include "db_ido/dbconnection.tcpp" #include "db_ido/dbvalue.hpp" #include "icinga/icingaapplication.hpp" #include "icinga/host.hpp" diff --git a/lib/db_ido_mysql/CMakeLists.txt b/lib/db_ido_mysql/CMakeLists.txt index 61d57232a..d4e2bb921 100644 --- a/lib/db_ido_mysql/CMakeLists.txt +++ b/lib/db_ido_mysql/CMakeLists.txt @@ -18,7 +18,7 @@ find_package(MySQL) if(MYSQL_FOUND) - mkclass_target(idomysqlconnection.ti idomysqlconnection.thpp) + mkclass_target(idomysqlconnection.ti idomysqlconnection.tcpp idomysqlconnection.thpp) set(db_ido_mysql_SOURCES idomysqlconnection.cpp idomysqlconnection.thpp diff --git a/lib/db_ido_mysql/idomysqlconnection.cpp b/lib/db_ido_mysql/idomysqlconnection.cpp index c74d62fa2..b6532dcc7 100644 --- a/lib/db_ido_mysql/idomysqlconnection.cpp +++ b/lib/db_ido_mysql/idomysqlconnection.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/perfdatavalue.hpp" +#include "icinga/perfdatavalue.tcpp" #include "db_ido/dbtype.hpp" #include "db_ido/dbvalue.hpp" #include "db_ido_mysql/idomysqlconnection.hpp" diff --git a/lib/db_ido_pgsql/CMakeLists.txt b/lib/db_ido_pgsql/CMakeLists.txt index 06da5143d..0d7d52a0c 100644 --- a/lib/db_ido_pgsql/CMakeLists.txt +++ b/lib/db_ido_pgsql/CMakeLists.txt @@ -18,7 +18,7 @@ find_package(PostgreSQL) if(PostgreSQL_FOUND) - mkclass_target(idopgsqlconnection.ti idopgsqlconnection.thpp) + mkclass_target(idopgsqlconnection.ti idopgsqlconnection.tcpp idopgsqlconnection.thpp) link_directories(${PostgreSQL_LIBRARY_DIRS}) include_directories(${PostgreSQL_INCLUDE_DIRS}) diff --git a/lib/db_ido_pgsql/idopgsqlconnection.cpp b/lib/db_ido_pgsql/idopgsqlconnection.cpp index dd8884736..ab9333133 100644 --- a/lib/db_ido_pgsql/idopgsqlconnection.cpp +++ b/lib/db_ido_pgsql/idopgsqlconnection.cpp @@ -17,9 +17,10 @@ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ +#include "db_ido_pgsql/idopgsqlconnection.hpp" +#include "db_ido_pgsql/idopgsqlconnection.tcpp" #include "db_ido/dbtype.hpp" #include "db_ido/dbvalue.hpp" -#include "db_ido_pgsql/idopgsqlconnection.hpp" #include "icinga/perfdatavalue.hpp" #include "base/logger.hpp" #include "base/objectlock.hpp" diff --git a/lib/demo/CMakeLists.txt b/lib/demo/CMakeLists.txt index 2484d356a..92fa2bd22 100644 --- a/lib/demo/CMakeLists.txt +++ b/lib/demo/CMakeLists.txt @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -mkclass_target(demo.ti demo.thpp) +mkclass_target(demo.ti demo.tcpp) set(demo_SOURCES demo.cpp demo.thpp diff --git a/lib/demo/demo.cpp b/lib/demo/demo.cpp index 598aacdd8..1b076f602 100644 --- a/lib/demo/demo.cpp +++ b/lib/demo/demo.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "demo/demo.hpp" +#include "demo/demo.tcpp" #include "remote/apilistener.hpp" #include "remote/apifunction.hpp" #include "base/dynamictype.hpp" diff --git a/lib/hello/CMakeLists.txt b/lib/hello/CMakeLists.txt index d9ff7017a..cbfa8746a 100644 --- a/lib/hello/CMakeLists.txt +++ b/lib/hello/CMakeLists.txt @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -mkclass_target(hello.ti hello.thpp) +mkclass_target(hello.ti hello.tcpp hello.thpp) mkembedconfig_target(hello-app.conf hello-app.cpp) diff --git a/lib/hello/hello.cpp b/lib/hello/hello.cpp index 56da13a24..b273d523c 100644 --- a/lib/hello/hello.cpp +++ b/lib/hello/hello.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "hello/hello.hpp" +#include "hello/hello.tcpp" #include "base/logger.hpp" using namespace icinga; diff --git a/lib/icinga/CMakeLists.txt b/lib/icinga/CMakeLists.txt index 10648c885..65801a1a2 100644 --- a/lib/icinga/CMakeLists.txt +++ b/lib/icinga/CMakeLists.txt @@ -15,28 +15,28 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -mkclass_target(checkable.ti checkable.thpp) -mkclass_target(checkcommand.ti checkcommand.thpp) -mkclass_target(checkresult.ti checkresult.thpp) -mkclass_target(command.ti command.thpp) -mkclass_target(comment.ti comment.thpp) -mkclass_target(dependency.ti dependency.thpp) -mkclass_target(downtime.ti downtime.thpp) -mkclass_target(eventcommand.ti eventcommand.thpp) -mkclass_target(hostgroup.ti hostgroup.thpp) -mkclass_target(host.ti host.thpp) -mkclass_target(icingaapplication.ti icingaapplication.thpp) -mkclass_target(customvarobject.ti customvarobject.thpp) -mkclass_target(icingastatuswriter.ti icingastatuswriter.thpp) -mkclass_target(notificationcommand.ti notificationcommand.thpp) -mkclass_target(notification.ti notification.thpp) -mkclass_target(perfdatavalue.ti perfdatavalue.thpp) -mkclass_target(scheduleddowntime.ti scheduleddowntime.thpp) -mkclass_target(servicegroup.ti servicegroup.thpp) -mkclass_target(service.ti service.thpp) -mkclass_target(timeperiod.ti timeperiod.thpp) -mkclass_target(usergroup.ti usergroup.thpp) -mkclass_target(user.ti user.thpp) +mkclass_target(checkable.ti checkable.tcpp checkable.thpp) +mkclass_target(checkcommand.ti checkcommand.tcpp checkcommand.thpp) +mkclass_target(checkresult.ti checkresult.tcpp checkresult.thpp) +mkclass_target(command.ti command.tcpp command.thpp) +mkclass_target(comment.ti comment.tcpp comment.thpp) +mkclass_target(dependency.ti dependency.tcpp dependency.thpp) +mkclass_target(downtime.ti downtime.tcpp downtime.thpp) +mkclass_target(eventcommand.ti eventcommand.tcpp eventcommand.thpp) +mkclass_target(hostgroup.ti hostgroup.tcpp hostgroup.thpp) +mkclass_target(host.ti host.tcpp host.thpp) +mkclass_target(icingaapplication.ti icingaapplication.tcpp icingaapplication.thpp) +mkclass_target(customvarobject.ti customvarobject.tcpp customvarobject.thpp) +mkclass_target(icingastatuswriter.ti icingastatuswriter.tcpp icingastatuswriter.thpp) +mkclass_target(notificationcommand.ti notificationcommand.tcpp notificationcommand.thpp) +mkclass_target(notification.ti notification.tcpp notification.thpp) +mkclass_target(perfdatavalue.ti perfdatavalue.tcpp perfdatavalue.thpp) +mkclass_target(scheduleddowntime.ti scheduleddowntime.tcpp scheduleddowntime.thpp) +mkclass_target(servicegroup.ti servicegroup.tcpp servicegroup.thpp) +mkclass_target(service.ti service.tcpp service.thpp) +mkclass_target(timeperiod.ti timeperiod.tcpp timeperiod.thpp) +mkclass_target(usergroup.ti usergroup.tcpp usergroup.thpp) +mkclass_target(user.ti user.tcpp user.thpp) mkembedconfig_target(icinga-app.conf icinga-app.cpp) @@ -45,11 +45,11 @@ set(icinga_SOURCES checkable-flapping.cpp checkcommand.cpp checkcommand.thpp checkresult.cpp checkresult.thpp cib.cpp command.cpp command.thpp comment.cpp comment.thpp compatutility.cpp dependency.cpp dependency.thpp dependency-apply.cpp downtime.cpp downtime.thpp eventcommand.cpp eventcommand.thpp - externalcommandprocessor.cpp host.cpp host.thpp hostgroup.cpp hostgroup.thpp icingaapplication.cpp - icingaapplication.thpp customvarobject.cpp customvarobject.thpp icingastatuswriter.cpp icingastatuswriter.thpp - legacytimeperiod.cpp macroprocessor.cpp notificationcommand.cpp notificationcommand.thpp notification.cpp - notification.thpp notification-apply.cpp objectutils.cpp perfdatavalue.cpp perfdatavalue.thpp pluginutility.cpp scheduleddowntime.cpp - scheduleddowntime.thpp scheduleddowntime-apply.cpp service-apply.cpp checkable-check.cpp checkable-comment.cpp + externalcommandprocessor.cpp host.cpp host.thpp hostgroup.cpp hostgroup.thpp icingaapplication.cpp icingaapplication.thpp + customvarobject.cpp customvarobject.thpp icingastatuswriter.cpp icingastatuswriter.thpp + legacytimeperiod.cpp macroprocessor.cpp notificationcommand.cpp notificationcommand.thpp notification.cpp notification.thpp + notification-apply.cpp objectutils.cpp perfdatavalue.cpp perfdatavalue.thpp pluginutility.cpp scheduleddowntime.cpp scheduleddowntime.thpp + scheduleddowntime-apply.cpp service-apply.cpp checkable-check.cpp checkable-comment.cpp service.cpp service.thpp servicegroup.cpp servicegroup.thpp checkable-notification.cpp timeperiod.cpp timeperiod.thpp user.cpp user.thpp usergroup.cpp usergroup.thpp icinga-app.cpp ) diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp index 27b5c3628..75561bed1 100644 --- a/lib/icinga/checkable.cpp +++ b/lib/icinga/checkable.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/checkable.hpp" +#include "icinga/checkable.tcpp" #include "base/objectlock.hpp" #include "base/utility.hpp" #include "base/exception.hpp" diff --git a/lib/icinga/checkcommand.cpp b/lib/icinga/checkcommand.cpp index 849a37141..26e39984e 100644 --- a/lib/icinga/checkcommand.cpp +++ b/lib/icinga/checkcommand.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/checkcommand.hpp" +#include "icinga/checkcommand.tcpp" #include "base/dynamictype.hpp" using namespace icinga; diff --git a/lib/icinga/checkresult.cpp b/lib/icinga/checkresult.cpp index c6798b5b7..d1f2933d9 100644 --- a/lib/icinga/checkresult.cpp +++ b/lib/icinga/checkresult.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/checkresult.hpp" +#include "icinga/checkresult.tcpp" using namespace icinga; diff --git a/lib/icinga/command.cpp b/lib/icinga/command.cpp index 0641e1d57..4741467cb 100644 --- a/lib/icinga/command.cpp +++ b/lib/icinga/command.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/command.hpp" +#include "icinga/command.tcpp" #include "icinga/macroprocessor.hpp" #include "base/exception.hpp" #include "base/objectlock.hpp" diff --git a/lib/icinga/comment.cpp b/lib/icinga/comment.cpp index d39e6dae2..ce6f8576e 100644 --- a/lib/icinga/comment.cpp +++ b/lib/icinga/comment.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/comment.hpp" +#include "icinga/comment.tcpp" #include "base/utility.hpp" #include "base/dynamictype.hpp" diff --git a/lib/icinga/customvarobject.cpp b/lib/icinga/customvarobject.cpp index 8388cea29..48facf14b 100644 --- a/lib/icinga/customvarobject.cpp +++ b/lib/icinga/customvarobject.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/customvarobject.hpp" +#include "icinga/customvarobject.tcpp" #include "icinga/macroprocessor.hpp" #include "base/logger.hpp" #include "base/function.hpp" diff --git a/lib/icinga/dependency.cpp b/lib/icinga/dependency.cpp index d935a8f03..28de23d02 100644 --- a/lib/icinga/dependency.cpp +++ b/lib/icinga/dependency.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/dependency.hpp" +#include "icinga/dependency.tcpp" #include "icinga/service.hpp" #include "base/logger.hpp" #include "base/exception.hpp" diff --git a/lib/icinga/downtime.cpp b/lib/icinga/downtime.cpp index ffabab7b5..8c37a3d03 100644 --- a/lib/icinga/downtime.cpp +++ b/lib/icinga/downtime.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/downtime.hpp" +#include "icinga/downtime.tcpp" #include "base/utility.hpp" using namespace icinga; diff --git a/lib/icinga/eventcommand.cpp b/lib/icinga/eventcommand.cpp index e2714eb83..55c97b246 100644 --- a/lib/icinga/eventcommand.cpp +++ b/lib/icinga/eventcommand.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/eventcommand.hpp" +#include "icinga/eventcommand.tcpp" using namespace icinga; diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 4e7083a20..db0530471 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/host.hpp" +#include "icinga/host.tcpp" #include "icinga/service.hpp" #include "icinga/hostgroup.hpp" #include "icinga/pluginutility.hpp" diff --git a/lib/icinga/hostgroup.cpp b/lib/icinga/hostgroup.cpp index 586ab6227..c6e009628 100644 --- a/lib/icinga/hostgroup.cpp +++ b/lib/icinga/hostgroup.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/hostgroup.hpp" +#include "icinga/hostgroup.tcpp" #include "config/objectrule.hpp" #include "config/configitem.hpp" #include "base/dynamictype.hpp" diff --git a/lib/icinga/icingaapplication.cpp b/lib/icinga/icingaapplication.cpp index 2a5edc8f7..d9a333362 100644 --- a/lib/icinga/icingaapplication.cpp +++ b/lib/icinga/icingaapplication.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/icingaapplication.hpp" +#include "icinga/icingaapplication.tcpp" #include "icinga/cib.hpp" #include "base/dynamictype.hpp" #include "base/logger.hpp" diff --git a/lib/icinga/icingastatuswriter.cpp b/lib/icinga/icingastatuswriter.cpp index 105d6a180..f01ec4754 100644 --- a/lib/icinga/icingastatuswriter.cpp +++ b/lib/icinga/icingastatuswriter.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/icingastatuswriter.hpp" +#include "icinga/icingastatuswriter.tcpp" #include "icinga/cib.hpp" #include "base/dynamictype.hpp" #include "base/logger.hpp" diff --git a/lib/icinga/notification.cpp b/lib/icinga/notification.cpp index af2732d00..7289df566 100644 --- a/lib/icinga/notification.cpp +++ b/lib/icinga/notification.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/notification.hpp" +#include "icinga/notification.tcpp" #include "icinga/notificationcommand.hpp" #include "icinga/service.hpp" #include "base/objectlock.hpp" diff --git a/lib/icinga/notificationcommand.cpp b/lib/icinga/notificationcommand.cpp index 67076fb3a..fd324b90d 100644 --- a/lib/icinga/notificationcommand.cpp +++ b/lib/icinga/notificationcommand.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/notificationcommand.hpp" +#include "icinga/notificationcommand.tcpp" using namespace icinga; diff --git a/lib/icinga/perfdatavalue.cpp b/lib/icinga/perfdatavalue.cpp index b3e0ae1be..37f7904ec 100644 --- a/lib/icinga/perfdatavalue.cpp +++ b/lib/icinga/perfdatavalue.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/perfdatavalue.hpp" +#include "icinga/perfdatavalue.tcpp" #include "base/convert.hpp" #include "base/exception.hpp" #include "base/logger.hpp" diff --git a/lib/icinga/scheduleddowntime.cpp b/lib/icinga/scheduleddowntime.cpp index 4deacdd9a..c5cb01247 100644 --- a/lib/icinga/scheduleddowntime.cpp +++ b/lib/icinga/scheduleddowntime.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/scheduleddowntime.hpp" +#include "icinga/scheduleddowntime.tcpp" #include "icinga/legacytimeperiod.hpp" #include "icinga/downtime.hpp" #include "icinga/service.hpp" diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index b1cc8e36b..f9e7e915e 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/service.hpp" +#include "icinga/service.tcpp" #include "icinga/servicegroup.hpp" #include "icinga/scheduleddowntime.hpp" #include "icinga/pluginutility.hpp" diff --git a/lib/icinga/servicegroup.cpp b/lib/icinga/servicegroup.cpp index ee07360bd..5513889dc 100644 --- a/lib/icinga/servicegroup.cpp +++ b/lib/icinga/servicegroup.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/servicegroup.hpp" +#include "icinga/servicegroup.tcpp" #include "config/objectrule.hpp" #include "config/configitem.hpp" #include "base/dynamictype.hpp" diff --git a/lib/icinga/timeperiod.cpp b/lib/icinga/timeperiod.cpp index 07dcbe399..8cd0acd52 100644 --- a/lib/icinga/timeperiod.cpp +++ b/lib/icinga/timeperiod.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/timeperiod.hpp" +#include "icinga/timeperiod.tcpp" #include "icinga/legacytimeperiod.hpp" #include "base/dynamictype.hpp" #include "base/objectlock.hpp" diff --git a/lib/icinga/user.cpp b/lib/icinga/user.cpp index cb68b6cf5..299d6bf74 100644 --- a/lib/icinga/user.cpp +++ b/lib/icinga/user.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/user.hpp" +#include "icinga/user.tcpp" #include "icinga/usergroup.hpp" #include "icinga/notification.hpp" #include "icinga/usergroup.hpp" diff --git a/lib/icinga/usergroup.cpp b/lib/icinga/usergroup.cpp index fbaa545f3..82bc4b518 100644 --- a/lib/icinga/usergroup.cpp +++ b/lib/icinga/usergroup.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "icinga/usergroup.hpp" +#include "icinga/usergroup.tcpp" #include "config/objectrule.hpp" #include "config/configitem.hpp" #include "base/dynamictype.hpp" diff --git a/lib/livestatus/CMakeLists.txt b/lib/livestatus/CMakeLists.txt index fb7033b72..2913c4ffa 100644 --- a/lib/livestatus/CMakeLists.txt +++ b/lib/livestatus/CMakeLists.txt @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -mkclass_target(livestatuslistener.ti livestatuslistener.thpp) +mkclass_target(livestatuslistener.ti livestatuslistener.tcpp livestatuslistener.thpp) set(livestatus_SOURCES aggregator.cpp andfilter.cpp attributefilter.cpp diff --git a/lib/livestatus/livestatuslistener.cpp b/lib/livestatus/livestatuslistener.cpp index 800fa2713..10a46d4d9 100644 --- a/lib/livestatus/livestatuslistener.cpp +++ b/lib/livestatus/livestatuslistener.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "livestatus/livestatuslistener.hpp" +#include "livestatus/livestatuslistener.tcpp" #include "icinga/perfdatavalue.hpp" #include "base/utility.hpp" #include "base/objectlock.hpp" diff --git a/lib/notification/CMakeLists.txt b/lib/notification/CMakeLists.txt index dca75ba54..deaa07545 100644 --- a/lib/notification/CMakeLists.txt +++ b/lib/notification/CMakeLists.txt @@ -15,7 +15,7 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -mkclass_target(notificationcomponent.ti notificationcomponent.thpp) +mkclass_target(notificationcomponent.ti notificationcomponent.tcpp notificationcomponent.thpp) set(notification_SOURCES notificationcomponent.cpp notificationcomponent.thpp diff --git a/lib/notification/notificationcomponent.cpp b/lib/notification/notificationcomponent.cpp index 7b65a69cd..bc0011694 100644 --- a/lib/notification/notificationcomponent.cpp +++ b/lib/notification/notificationcomponent.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "notification/notificationcomponent.hpp" +#include "notification/notificationcomponent.tcpp" #include "icinga/service.hpp" #include "icinga/icingaapplication.hpp" #include "base/dynamictype.hpp" diff --git a/lib/perfdata/CMakeLists.txt b/lib/perfdata/CMakeLists.txt index b6c2cd918..846aefd6c 100644 --- a/lib/perfdata/CMakeLists.txt +++ b/lib/perfdata/CMakeLists.txt @@ -15,10 +15,10 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -mkclass_target(gelfwriter.ti gelfwriter.thpp) -mkclass_target(graphitewriter.ti graphitewriter.thpp) -mkclass_target(opentsdbwriter.ti opentsdbwriter.thpp) -mkclass_target(perfdatawriter.ti perfdatawriter.thpp) +mkclass_target(gelfwriter.ti gelfwriter.tcpp gelfwriter.thpp) +mkclass_target(graphitewriter.ti graphitewriter.tcpp graphitewriter.thpp) +mkclass_target(opentsdbwriter.ti opentsdbwriter.tcpp opentsdbwriter.thpp) +mkclass_target(perfdatawriter.ti perfdatawriter.tcpp perfdatawriter.thpp) set(perfdata_SOURCES gelfwriter.cpp gelfwriter.thpp graphitewriter.cpp graphitewriter.thpp opentsdbwriter.cpp opentsdbwriter.thpp perfdatawriter.cpp perfdatawriter.thpp diff --git a/lib/perfdata/gelfwriter.cpp b/lib/perfdata/gelfwriter.cpp index f05af5553..1efec3ec6 100644 --- a/lib/perfdata/gelfwriter.cpp +++ b/lib/perfdata/gelfwriter.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "perfdata/gelfwriter.hpp" +#include "perfdata/gelfwriter.tcpp" #include "icinga/service.hpp" #include "icinga/notification.hpp" #include "icinga/macroprocessor.hpp" diff --git a/lib/perfdata/graphitewriter.cpp b/lib/perfdata/graphitewriter.cpp index 7304e6225..ef717116f 100644 --- a/lib/perfdata/graphitewriter.cpp +++ b/lib/perfdata/graphitewriter.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "perfdata/graphitewriter.hpp" +#include "perfdata/graphitewriter.tcpp" #include "icinga/service.hpp" #include "icinga/macroprocessor.hpp" #include "icinga/icingaapplication.hpp" diff --git a/lib/perfdata/opentsdbwriter.cpp b/lib/perfdata/opentsdbwriter.cpp index 20248af95..acbd71807 100644 --- a/lib/perfdata/opentsdbwriter.cpp +++ b/lib/perfdata/opentsdbwriter.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "perfdata/opentsdbwriter.hpp" +#include "perfdata/opentsdbwriter.tcpp" #include "icinga/service.hpp" #include "icinga/macroprocessor.hpp" #include "icinga/icingaapplication.hpp" diff --git a/lib/perfdata/perfdatawriter.cpp b/lib/perfdata/perfdatawriter.cpp index 368889fcb..94a5c5090 100644 --- a/lib/perfdata/perfdatawriter.cpp +++ b/lib/perfdata/perfdatawriter.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "perfdata/perfdatawriter.hpp" +#include "perfdata/perfdatawriter.tcpp" #include "icinga/service.hpp" #include "icinga/macroprocessor.hpp" #include "icinga/icingaapplication.hpp" diff --git a/lib/remote/CMakeLists.txt b/lib/remote/CMakeLists.txt index 9965474aa..e7e96e190 100644 --- a/lib/remote/CMakeLists.txt +++ b/lib/remote/CMakeLists.txt @@ -15,13 +15,13 @@ # along with this program; if not, write to the Free Software Foundation # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. -mkclass_target(apilistener.ti apilistener.thpp) -mkclass_target(endpoint.ti endpoint.thpp) -mkclass_target(zone.ti zone.thpp) +mkclass_target(apilistener.ti apilistener.tcpp apilistener.thpp) +mkclass_target(endpoint.ti endpoint.tcpp endpoint.thpp) +mkclass_target(zone.ti zone.tcpp zone.thpp) set(remote_SOURCES - apiclient.cpp apiclient-heartbeat.cpp apifunction.cpp apilistener.cpp apilistener-sync.cpp - apilistener.thpp authority.cpp endpoint.cpp endpoint.thpp jsonrpc.cpp + apiclient.cpp apiclient-heartbeat.cpp apifunction.cpp apilistener.cpp apilistener.thpp apilistener-sync.cpp + authority.cpp endpoint.cpp endpoint.thpp jsonrpc.cpp messageorigin.cpp zone.cpp zone.thpp ) diff --git a/lib/remote/apiclient-heartbeat.cpp b/lib/remote/apiclient-heartbeat.cpp index bd7aad9f8..4bd224e1c 100644 --- a/lib/remote/apiclient-heartbeat.cpp +++ b/lib/remote/apiclient-heartbeat.cpp @@ -23,6 +23,7 @@ #include "base/initialize.hpp" #include "base/dynamictype.hpp" #include "base/logger.hpp" +#include "base/utility.hpp" #include using namespace icinga; diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 42042270a..de96f97bf 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "remote/apilistener.hpp" +#include "remote/apilistener.tcpp" #include "remote/apiclient.hpp" #include "remote/endpoint.hpp" #include "remote/jsonrpc.hpp" diff --git a/lib/remote/endpoint.cpp b/lib/remote/endpoint.cpp index a7a9e7afe..4dca3970b 100644 --- a/lib/remote/endpoint.cpp +++ b/lib/remote/endpoint.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "remote/endpoint.hpp" +#include "remote/endpoint.tcpp" #include "remote/apilistener.hpp" #include "remote/apiclient.hpp" #include "remote/zone.hpp" diff --git a/lib/remote/zone.cpp b/lib/remote/zone.cpp index 194292cdb..a5a21a63a 100644 --- a/lib/remote/zone.cpp +++ b/lib/remote/zone.cpp @@ -18,6 +18,7 @@ ******************************************************************************/ #include "remote/zone.hpp" +#include "remote/zone.tcpp" #include "remote/apiclient.hpp" #include "base/objectlock.hpp" #include diff --git a/tools/mkclass/CMakeLists.txt b/tools/mkclass/CMakeLists.txt index f49ed9eb3..7f16402dc 100644 --- a/tools/mkclass/CMakeLists.txt +++ b/tools/mkclass/CMakeLists.txt @@ -40,15 +40,12 @@ set_target_properties ( FOLDER Bin ) -macro(MKCLASS_TARGET ClassInput ClassOutput) +macro(MKCLASS_TARGET ClassInput ClassImplOutput ClassHeaderOutput) add_custom_command( - OUTPUT ${ClassOutput} + OUTPUT ${ClassImplOutput} ${ClassHeaderOutput} COMMAND mkclass - ARGS ${ClassInput} > ${CMAKE_CURRENT_BINARY_DIR}/${ClassOutput}.tmp - COMMAND ${CMAKE_COMMAND} - ARGS -E copy ${CMAKE_CURRENT_BINARY_DIR}/${ClassOutput}.tmp ${CMAKE_CURRENT_BINARY_DIR}/${ClassOutput} + ARGS ${ClassInput} ${CMAKE_CURRENT_BINARY_DIR}/${ClassImplOutput} ${CMAKE_CURRENT_BINARY_DIR}/${ClassHeaderOutput} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS mkclass ${ClassInput} ) - set_property(SOURCE ${ClassOutput} PROPERTY EXCLUDE_UNITY_BUILD) endmacro() diff --git a/tools/mkclass/classcompiler.cpp b/tools/mkclass/classcompiler.cpp index d700cfd52..1dd24623a 100644 --- a/tools/mkclass/classcompiler.cpp +++ b/tools/mkclass/classcompiler.cpp @@ -34,8 +34,9 @@ using namespace icinga; -ClassCompiler::ClassCompiler(const std::string& path, std::istream *input) - : m_Path(path), m_Input(input) +ClassCompiler::ClassCompiler(const std::string& path, std::istream& input, + std::ostream& oimpl, std::ostream& oheader) + : m_Path(path), m_Input(input), m_Impl(oimpl), m_Header(oheader) { InitializeScanner(); } @@ -57,36 +58,41 @@ void *ClassCompiler::GetScanner(void) size_t ClassCompiler::ReadInput(char *buffer, size_t max_size) { - m_Input->read(buffer, max_size); - return static_cast(m_Input->gcount()); + m_Input.read(buffer, max_size); + return static_cast(m_Input.gcount()); } void ClassCompiler::HandleInclude(const std::string& path, const ClassDebugInfo&) { - std::cout << "#include \"" << path << "\"" << std::endl << std::endl; + m_Header << "#include \"" << path << "\"" << std::endl << std::endl; } void ClassCompiler::HandleAngleInclude(const std::string& path, const ClassDebugInfo&) { - std::cout << "#include <" << path << ">" << std::endl << std::endl; + m_Header << "#include <" << path << ">" << std::endl << std::endl; } void ClassCompiler::HandleNamespaceBegin(const std::string& name, const ClassDebugInfo&) { - std::cout << "namespace " << name << std::endl - << "{" << std::endl << std::endl; + m_Header << "namespace " << name << std::endl + << "{" << std::endl << std::endl; + + m_Impl << "namespace " << name << std::endl + << "{" << std::endl << std::endl; } void ClassCompiler::HandleNamespaceEnd(const ClassDebugInfo&) { HandleMissingValidators(); - std::cout << "}" << std::endl; + m_Header << "}" << std::endl; + + m_Impl << "}" << std::endl; } void ClassCompiler::HandleCode(const std::string& code, const ClassDebugInfo&) { - std::cout << code << std::endl; + m_Header << code << std::endl; } unsigned long ClassCompiler::SDBM(const std::string& str, size_t len = std::string::npos) @@ -148,77 +154,78 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) /* forward declaration */ if (klass.Name.find_first_of(':') == std::string::npos) - std::cout << "class " << klass.Name << ";" << std::endl << std::endl; + m_Header << "class " << klass.Name << ";" << std::endl << std::endl; /* TypeHelper */ if (klass.Attributes & TAAbstract) { - std::cout << "template<>" << std::endl - << "struct TypeHelper<" << klass.Name << ">" << std::endl - << "{" << std::endl - << "\t" << "static ObjectFactory GetFactory(void)" << std::endl - << "\t" << "{" << std::endl - << "\t\t" << "return NULL;" << std::endl - << "\t" << "}" << std::endl - << "};" << std::endl << std::endl; + m_Header << "template<>" << std::endl + << "struct TypeHelper<" << klass.Name << ">" << std::endl + << "{" << std::endl + << "\t" << "static ObjectFactory GetFactory(void)" << std::endl + << "\t" << "{" << std::endl + << "\t\t" << "return NULL;" << std::endl + << "\t" << "}" << std::endl + << "};" << std::endl << std::endl; } /* TypeImpl */ - std::cout << "template<>" << std::endl - << "class TypeImpl<" << klass.Name << ">" - << " : public Type"; + m_Header << "template<>" << std::endl + << "class TypeImpl<" << klass.Name << ">" + << " : public Type"; if (!klass.TypeBase.empty()) - std::cout << ", public " + klass.TypeBase; + m_Header << ", public " + klass.TypeBase; - std::cout << std::endl - << " {" << std::endl - << "public:" << std::endl; + m_Header << std::endl + << "{" << std::endl + << "public:" << std::endl; /* GetName */ - std::cout << "\t" << "virtual String GetName(void) const" << std::endl - << "\t" << "{" << std::endl - << "\t\t" << "return \"" << klass.Name << "\";" << std::endl - << "\t" << "}" << std::endl << std::endl; + m_Header << "\t" << "virtual String GetName(void) const;" << std::endl; + + m_Impl << "String TypeImpl<" << klass.Name << ">::GetName(void) const" << std::endl + << "{" << std::endl + << "\t" << "return \"" << klass.Name << "\";" << std::endl + << "}" << std::endl << std::endl; /* GetAttributes */ - std::cout << "\t" << "virtual int GetAttributes(void) const" << std::endl - << "\t" << "{" << std::endl - << "\t\t" << "return " << klass.Attributes << ";" << std::endl - << "\t" << "}" << std::endl << std::endl; + m_Header << "\t" << "virtual int GetAttributes(void) const;" << std::endl; + + m_Impl << "int TypeImpl<" << klass.Name << ">::GetAttributes(void) const" << std::endl + << "{" << std::endl + << "\t" << "return " << klass.Attributes << ";" << std::endl + << "}" << std::endl << std::endl; /* GetBaseType */ - std::cout << "\t" << "virtual Type::Ptr GetBaseType(void) const" << std::endl - << "\t" << "{" << std::endl; + m_Header << "\t" << "virtual Type::Ptr GetBaseType(void) const;" << std::endl; - std::cout << "\t\t" << "return "; + m_Impl << "Type::Ptr TypeImpl<" << klass.Name << ">::GetBaseType(void) const" << std::endl + << "{" << std::endl + << "\t" << "return "; if (!klass.Parent.empty()) - std::cout << "Type::GetByName(\"" << klass.Parent << "\")"; + m_Impl << "Type::GetByName(\"" << klass.Parent << "\")"; else - std::cout << "Type::Ptr()"; + m_Impl << "Type::Ptr()"; - std::cout << ";" << std::endl - << "\t" << "}" << std::endl << std::endl; + m_Impl << ";" << std::endl + << "}" << std::endl << std::endl; /* GetFieldId */ - std::cout << "\t" << "virtual int GetFieldId(const String& name) const" << std::endl - << "\t" << "{" << std::endl - << "\t\t" << "return StaticGetFieldId(name);" << std::endl - << "\t" << "}" << std::endl << std::endl; + m_Header << "\t" << "virtual int GetFieldId(const String& name) const;" << std::endl; - /* StaticGetFieldId */ - std::cout << "\t" << "static int StaticGetFieldId(const String& name)" << std::endl - << "\t" << "{" << std::endl; + m_Impl << "int TypeImpl<" << klass.Name << ">::GetFieldId(const String& name) const" << std::endl + << "{" << std::endl; if (!klass.Fields.empty()) { - std::cout << "\t\t" << "int offset = "; + m_Impl << "\t" << "int offset = "; if (!klass.Parent.empty()) - std::cout << "TypeImpl<" << klass.Parent << ">::StaticGetFieldCount()"; + m_Impl << klass.Parent << "::TypeInstance->GetFieldCount()"; else - std::cout << "0"; + m_Impl << "0"; - std::cout << ";" << std::endl << std::endl; + m_Impl << ";" << std::endl << std::endl; } std::map > > jumptable; @@ -243,61 +250,57 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) } while (collisions >= 5 && hlen < 8); if (!klass.Fields.empty()) { - std::cout << "\t\tswitch (static_cast(Utility::SDBM(name, " << hlen << "))) {" << std::endl; + m_Impl << "\tswitch (static_cast(Utility::SDBM(name, " << hlen << "))) {" << std::endl; std::map > >::const_iterator itj; for (itj = jumptable.begin(); itj != jumptable.end(); itj++) { - std::cout << "\t\t\tcase " << itj->first << ":" << std::endl; + m_Impl << "\t\tcase " << itj->first << ":" << std::endl; std::vector >::const_iterator itf; for (itf = itj->second.begin(); itf != itj->second.end(); itf++) { - std::cout << "\t\t\t\t" << "if (name == \"" << itf->second << "\")" << std::endl - << "\t\t\t\t\t" << "return offset + " << itf->first << ";" << std::endl; + m_Impl << "\t\t\t" << "if (name == \"" << itf->second << "\")" << std::endl + << "\t\t\t\t" << "return offset + " << itf->first << ";" << std::endl; } - std::cout << std::endl - << "\t\t\t\tbreak;" << std::endl; + m_Impl << std::endl + << "\t\t\t\tbreak;" << std::endl; } - std::cout << "\t\t}" << std::endl; + m_Impl << "\t}" << std::endl; } - std::cout << std::endl - << "\t\t" << "return "; + m_Impl << std::endl + << "\t" << "return "; if (!klass.Parent.empty()) - std::cout << "TypeImpl<" << klass.Parent << ">::StaticGetFieldId(name)"; + m_Impl << klass.Parent << "::TypeInstance->GetFieldId(name)"; else - std::cout << "-1"; + m_Impl << "-1"; - std::cout << ";" << std::endl - << "\t" << "}" << std::endl << std::endl; + m_Impl << ";" << std::endl + << "}" << std::endl << std::endl; /* GetFieldInfo */ - std::cout << "\t" << "virtual Field GetFieldInfo(int id) const" << std::endl - << "\t" << "{" << std::endl - << "\t\t" << "return StaticGetFieldInfo(id);" << std::endl - << "\t" << "}" << std::endl << std::endl; + m_Header << "\t" << "virtual Field GetFieldInfo(int id) const;" << std::endl; - /* StaticGetFieldInfo */ - std::cout << "\t" << "static Field StaticGetFieldInfo(int id)" << std::endl - << "\t" << "{" << std::endl; + m_Impl << "Field TypeImpl<" << klass.Name << ">::GetFieldInfo(int id) const" << std::endl + << "{" << std::endl; if (!klass.Parent.empty()) - std::cout << "\t\t" << "int real_id = id - " << "TypeImpl<" << klass.Parent << ">::StaticGetFieldCount();" << std::endl - << "\t\t" << "if (real_id < 0) { return " << "TypeImpl<" << klass.Parent << ">::StaticGetFieldInfo(id); }" << std::endl; + m_Impl << "\t" << "int real_id = id - " << klass.Parent << "::TypeInstance->GetFieldCount();" << std::endl + << "\t" << "if (real_id < 0) { return " << klass.Parent << "::TypeInstance->GetFieldInfo(id); }" << std::endl; if (klass.Fields.size() > 0) { - std::cout << "\t\t" << "switch ("; + m_Impl << "\t" << "switch ("; if (!klass.Parent.empty()) - std::cout << "real_id"; + m_Impl << "real_id"; else - std::cout << "id"; + m_Impl << "id"; - std::cout << ") {" << std::endl; + m_Impl << ") {" << std::endl; size_t num = 0; for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { @@ -324,193 +327,210 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) else nameref = "NULL"; - std::cout << "\t\t\t" << "case " << num << ":" << std::endl - << "\t\t\t\t" << "return Field(" << num << ", \"" << ftype << "\", \"" << it->Name << "\", " << nameref << ", " << it->Attributes << ");" << std::endl; + m_Impl << "\t\t" << "case " << num << ":" << std::endl + << "\t\t\t\t" << "return Field(" << num << ", \"" << ftype << "\", \"" << it->Name << "\", " << nameref << ", " << it->Attributes << ");" << std::endl; num++; } - std::cout << "\t\t\t" << "default:" << std::endl - << "\t\t"; + m_Impl << "\t\t" << "default:" << std::endl + << "\t\t"; } - std::cout << "\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl; + m_Impl << "\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl; if (klass.Fields.size() > 0) - std::cout << "\t\t" << "}" << std::endl; + m_Impl << "\t" << "}" << std::endl; - std::cout << "\t" << "}" << std::endl << std::endl; + m_Impl << "}" << std::endl << std::endl; /* GetFieldCount */ - std::cout << "\t" << "virtual int GetFieldCount(void) const" << std::endl - << "\t" << "{" << std::endl - << "\t\t" << "return StaticGetFieldCount();" << std::endl - << "\t" << "}" << std::endl << std::endl; + m_Header << "\t" << "virtual int GetFieldCount(void) const;" << std::endl; - /* StaticGetFieldCount */ - std::cout << "\t" << "static int StaticGetFieldCount(void)" << std::endl - << "\t" << "{" << std::endl - << "\t\t" << "return " << klass.Fields.size(); + m_Impl << "int TypeImpl<" << klass.Name << ">::GetFieldCount(void) const" << std::endl + << "{" << std::endl + << "\t" << "return " << klass.Fields.size(); if (!klass.Parent.empty()) - std::cout << " + " << "TypeImpl<" << klass.Parent << ">::StaticGetFieldCount()"; + m_Impl << " + " << klass.Parent << "::TypeInstance->GetFieldCount()"; - std::cout << ";" << std::endl - << "\t" << "}" << std::endl << std::endl; + m_Impl << ";" << std::endl + << "}" << std::endl << std::endl; /* GetFactory */ - std::cout << "\t" << "virtual ObjectFactory GetFactory(void) const" << std::endl - << "\t" << "{" << std::endl - << "\t\t" << "return TypeHelper<" << klass.Name << ">::GetFactory();" << std::endl - << "\t" << "}" << std::endl << std::endl; + m_Header << "\t" << "virtual ObjectFactory GetFactory(void) const;" << std::endl; + + m_Impl << "ObjectFactory TypeImpl<" << klass.Name << ">::GetFactory(void) const" << std::endl + << "{" << std::endl + << "\t" << "return TypeHelper<" << klass.Name << ">::GetFactory();" << std::endl + << "}" << std::endl << std::endl; /* GetLoadDependencies */ - std::cout << "\t" << "virtual std::vector GetLoadDependencies(void) const" << std::endl - << "\t" << "{" << std::endl - << "\t\t" << "std::vector deps;" << std::endl; + m_Header << "\t" << "virtual std::vector GetLoadDependencies(void) const;" << std::endl; + + m_Impl << "std::vector TypeImpl<" << klass.Name << ">::GetLoadDependencies(void) const" << std::endl + << "{" << std::endl + << "\t" << "std::vector deps;" << std::endl; for (std::vector::const_iterator itd = klass.LoadDependencies.begin(); itd != klass.LoadDependencies.end(); itd++) - std::cout << "\t\t" << "deps.push_back(\"" << *itd << "\");" << std::endl; + m_Impl << "\t" << "deps.push_back(\"" << *itd << "\");" << std::endl; - std::cout << "\t\t" << "return deps;" << std::endl - << "\t" << "}" << std::endl; + m_Impl << "\t" << "return deps;" << std::endl + << "}" << std::endl; - std::cout << "};" << std::endl << std::endl; + m_Header << "};" << std::endl << std::endl; - std::cout << std::endl; + m_Header << std::endl; /* ObjectImpl */ - std::cout << "template<>" << std::endl - << "class ObjectImpl<" << klass.Name << ">" - << " : public " << (klass.Parent.empty() ? "Object" : klass.Parent) << std::endl - << "{" << std::endl - << "public:" << std::endl - << "\t" << "DECLARE_PTR_TYPEDEFS(ObjectImpl<" << klass.Name << ">);" << std::endl << std::endl; + m_Header << "template<>" << std::endl + << "class ObjectImpl<" << klass.Name << ">" + << " : public " << (klass.Parent.empty() ? "Object" : klass.Parent) << std::endl + << "{" << std::endl + << "public:" << std::endl + << "\t" << "DECLARE_PTR_TYPEDEFS(ObjectImpl<" << klass.Name << ">);" << std::endl << std::endl; /* Validate */ - std::cout << "\t" << "virtual void Validate(int types, const ValidationUtils& utils)" << std::endl - << "\t" << "{" << std::endl; + m_Header << "\t" << "virtual void Validate(int types, const ValidationUtils& utils);" << std::endl; + + m_Impl << "void ObjectImpl<" << klass.Name << ">::Validate(int types, const ValidationUtils& utils)" << std::endl + << "{" << std::endl; if (!klass.Parent.empty()) - std::cout << "\t\t" << klass.Parent << "::Validate(types, utils);" << std::endl << std::endl; + m_Impl << "\t" << klass.Parent << "::Validate(types, utils);" << std::endl << std::endl; for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { - std::cout << "\t\t" << "if (" << (it->Attributes & (FAEphemeral|FAConfig|FAState)) << " & types)" << std::endl - << "\t\t\t" << "Validate" << it->GetFriendlyName() << "(Get" << it->GetFriendlyName() << "(), utils);" << std::endl; + m_Impl << "\t" << "if (" << (it->Attributes & (FAEphemeral|FAConfig|FAState)) << " & types)" << std::endl + << "\t\t" << "Validate" << it->GetFriendlyName() << "(Get" << it->GetFriendlyName() << "(), utils);" << std::endl; } - std::cout << "\t" << "}" << std::endl << std::endl; + m_Impl << "}" << std::endl << std::endl; for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { - std::cout << "\t" << "inline void SimpleValidate" << it->GetFriendlyName() << "(" << it->Type.GetArgumentType() << " value, const ValidationUtils& utils)" << std::endl - << "\t" << "{" << std::endl; + m_Header << "\t" << "void SimpleValidate" << it->GetFriendlyName() << "(" << it->Type.GetArgumentType() << " value, const ValidationUtils& utils);" << std::endl; + + m_Impl << "void ObjectImpl<" << klass.Name << ">::SimpleValidate" << it->GetFriendlyName() << "(" << it->Type.GetArgumentType() << " value, const ValidationUtils& utils)" << std::endl + << "{" << std::endl; const Field& field = *it; if ((field.Attributes & (FARequired)) || field.Type.IsName) { if (field.Attributes & FARequired) { if (field.Type.GetRealType().find("::Ptr") != std::string::npos) - std::cout << "\t\t" << "if (!value)" << std::endl; + m_Impl << "\t" << "if (!value)" << std::endl; else - std::cout << "\t\t" << "if (value.IsEmpty())" << std::endl; + m_Impl << "\t" << "if (value.IsEmpty())" << std::endl; - std::cout << "\t\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of(\"" << field.Name << "\"), \"Attribute must not be empty.\"));" << std::endl << std::endl; + m_Impl << "\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_cast(this), boost::assign::list_of(\"" << field.Name << "\"), \"Attribute must not be empty.\"));" << std::endl << std::endl; } if (field.Type.IsName) { - std::cout << "\t\t" << "String ref = value;" << std::endl - << "\t\t" << "if (!ref.IsEmpty() && !utils.ValidateName(\"" << field.Type.TypeName << "\", ref))" << std::endl - << "\t\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of(\"" << field.Name << "\"), \"Object '\" + ref + \"' of type '" << field.Type.TypeName - << "' does not exist.\"));" << std::endl; + m_Impl << "\t" << "String ref = value;" << std::endl + << "\t" << "if (!ref.IsEmpty() && !utils.ValidateName(\"" << field.Type.TypeName << "\", ref))" << std::endl + << "\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_cast(this), boost::assign::list_of(\"" << field.Name << "\"), \"Object '\" + ref + \"' of type '" << field.Type.TypeName + << "' does not exist.\"));" << std::endl; } } - std::cout << "\t" << "}" << std::endl << std::endl; + m_Impl << "}" << std::endl << std::endl; } if (!klass.Fields.empty()) { /* constructor */ - std::cout << "public:" << std::endl - << "\t" << "ObjectImpl<" << klass.Name << ">(void)" << std::endl - << "\t" << "{" << std::endl; + m_Header << "public:" << std::endl + << "\t" << "ObjectImpl<" << klass.Name << ">(void);" << std::endl; + + m_Impl << "ObjectImpl<" << klass.Name << ">::ObjectImpl(void)" << std::endl + << "{" << std::endl; for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { - std::cout << "\t\t" << "Set" << it->GetFriendlyName() << "(" << "GetDefault" << it->GetFriendlyName() << "());" << std::endl; + m_Impl << "\t\t" << "Set" << it->GetFriendlyName() << "(" << "GetDefault" << it->GetFriendlyName() << "());" << std::endl; } - std::cout << "\t" << "}" << std::endl << std::endl; + m_Impl << "}" << std::endl << std::endl; + + /* destructor */ + m_Header << "public:" << std::endl + << "\t" << "~ObjectImpl<" << klass.Name << ">(void);" << std::endl; + + m_Impl << "ObjectImpl<" << klass.Name << ">::~ObjectImpl(void)" << std::endl + << "{ }" << std::endl << std::endl; /* SetField */ - std::cout << "protected:" << std::endl - << "\t" << "virtual void SetField(int id, const Value& value)" << std::endl - << "\t" << "{" << std::endl; + m_Header << "protected:" << std::endl + << "\t" << "virtual void SetField(int id, const Value& value);" << std::endl; + + m_Impl << "void ObjectImpl<" << klass.Name << ">::SetField(int id, const Value& value)" << std::endl + << "{" << std::endl; if (!klass.Parent.empty()) - std::cout << "\t\t" << "int real_id = id - TypeImpl<" << klass.Parent << ">::StaticGetFieldCount(); " << std::endl - << "\t\t" << "if (real_id < 0) { " << klass.Parent << "::SetField(id, value); return; }" << std::endl; + m_Impl << "\t" << "int real_id = id - " << klass.Parent << "::TypeInstance->GetFieldCount(); " << std::endl + << "\t" << "if (real_id < 0) { " << klass.Parent << "::SetField(id, value); return; }" << std::endl; - std::cout << "\t\t" << "switch ("; + m_Impl << "\t" << "switch ("; if (!klass.Parent.empty()) - std::cout << "real_id"; + m_Impl << "real_id"; else - std::cout << "id"; + m_Impl << "id"; - std::cout << ") {" << std::endl; + m_Impl << ") {" << std::endl; size_t num = 0; for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { - std::cout << "\t\t\t" << "case " << num << ":" << std::endl - << "\t\t\t\t" << "Set" << it->GetFriendlyName() << "("; + m_Impl << "\t\t" << "case " << num << ":" << std::endl + << "\t\t\t" << "Set" << it->GetFriendlyName() << "("; if (it->Attributes & FAEnum) - std::cout << "static_cast<" << it->Type.GetRealType() << ">(static_cast("; + m_Impl << "static_cast<" << it->Type.GetRealType() << ">(static_cast("; - std::cout << "value"; + m_Impl << "value"; if (it->Attributes & FAEnum) - std::cout << "))"; + m_Impl << "))"; - std::cout << ");" << std::endl - << "\t\t\t\t" << "break;" << std::endl; + m_Impl << ");" << std::endl + << "\t\t\t" << "break;" << std::endl; num++; } - std::cout << "\t\t\t" << "default:" << std::endl - << "\t\t\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl - << "\t\t" << "}" << std::endl; + m_Impl << "\t\t" << "default:" << std::endl + << "\t\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl + << "\t" << "}" << std::endl; - std::cout << "\t" << "}" << std::endl << std::endl; + m_Impl << "}" << std::endl << std::endl; /* GetField */ - std::cout << "protected:" << std::endl - << "\t" << "virtual Value GetField(int id) const" << std::endl - << "\t" << "{" << std::endl; + m_Header << "protected:" << std::endl + << "\t" << "virtual Value GetField(int id) const;" << std::endl; + + m_Impl << "Value ObjectImpl<" << klass.Name << ">::GetField(int id) const" << std::endl + << "{" << std::endl; if (!klass.Parent.empty()) - std::cout << "\t\t" << "int real_id = id - TypeImpl<" << klass.Parent << ">::StaticGetFieldCount(); " << std::endl - << "\t\t" << "if (real_id < 0) { return " << klass.Parent << "::GetField(id); }" << std::endl; + m_Impl << "\t" << "int real_id = id - " << klass.Parent << "::TypeInstance->GetFieldCount(); " << std::endl + << "\t" << "if (real_id < 0) { return " << klass.Parent << "::GetField(id); }" << std::endl; - std::cout << "\t\t" << "switch ("; + m_Impl << "\t" << "switch ("; if (!klass.Parent.empty()) - std::cout << "real_id"; + m_Impl << "real_id"; else - std::cout << "id"; + m_Impl << "id"; - std::cout << ") {" << std::endl; + m_Impl << ") {" << std::endl; num = 0; for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { - std::cout << "\t\t\t" << "case " << num << ":" << std::endl - << "\t\t\t\t" << "return Get" << it->GetFriendlyName() << "();" << std::endl; + m_Impl << "\t\t" << "case " << num << ":" << std::endl + << "\t\t\t" << "return Get" << it->GetFriendlyName() << "();" << std::endl; num++; } - std::cout << "\t\t\t" << "default:" << std::endl - << "\t\t\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl - << "\t\t" << "}" << std::endl; + m_Impl << "\t\t" << "default:" << std::endl + << "\t\t\t" << "throw std::runtime_error(\"Invalid field ID.\");" << std::endl + << "\t" << "}" << std::endl; - std::cout << "\t" << "}" << std::endl << std::endl; + m_Impl << "}" << std::endl << std::endl; /* getters */ for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { @@ -521,21 +541,23 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) else prot = "public"; - std::cout << prot << ":" << std::endl - << "\t" << "virtual " << it->Type.GetRealType() << " Get" << it->GetFriendlyName() << "(void) const"; + m_Header << prot << ":" << std::endl + << "\t" << "virtual " << it->Type.GetRealType() << " Get" << it->GetFriendlyName() << "(void) const"; if (it->PureGetAccessor) { - std::cout << " = 0;" << std::endl; + m_Header << " = 0;" << std::endl; } else { - std::cout << std::endl - << "\t" << "{" << std::endl; + m_Header << ";" << std::endl; + + m_Impl << it->Type.GetRealType() << " ObjectImpl<" << klass.Name << ">::Get" << it->GetFriendlyName() << "(void) const" << std::endl + << "{" << std::endl; if (it->GetAccessor.empty() && !(it->Attributes & FANoStorage)) - std::cout << "\t\t" << "return m_" << it->GetFriendlyName() << ";" << std::endl; + m_Impl << "\t" << "return m_" << it->GetFriendlyName() << ";" << std::endl; else - std::cout << it->GetAccessor << std::endl; + m_Impl << it->GetAccessor << std::endl; - std::cout << "\t" << "}" << std::endl << std::endl; + m_Impl << "}" << std::endl << std::endl; } } @@ -550,20 +572,23 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) else prot = "public"; - std::cout << prot << ":" << std::endl - << "\t" << "virtual void Set" << it->GetFriendlyName() << "(" << it->Type.GetArgumentType() << " value)" << std::endl; + m_Header << prot << ":" << std::endl + << "\t" << "virtual void Set" << it->GetFriendlyName() << "(" << it->Type.GetArgumentType() << " value)"; if (it->PureSetAccessor) { - std::cout << " = 0;" << std::endl; + m_Header << " = 0;" << std::endl; } else { - std::cout << "\t" << "{" << std::endl; + m_Header << ";" << std::endl; + + m_Impl << "void ObjectImpl<" << klass.Name << ">::Set" << it->GetFriendlyName() << "(" << it->Type.GetArgumentType() << " value)" << std::endl + << "{" << std::endl; if (it->SetAccessor.empty() && !(it->Attributes & FANoStorage)) - std::cout << "\t\t" << "m_" << it->GetFriendlyName() << " = value;" << std::endl; + m_Impl << "\t\t" << "m_" << it->GetFriendlyName() << " = value;" << std::endl; else - std::cout << it->SetAccessor << std::endl; + m_Impl << it->SetAccessor << std::endl; - std::cout << "\t" << "}" << std::endl << std::endl; + m_Impl << "}" << std::endl << std::endl; } } @@ -571,64 +596,64 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&) for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { std::string realType = it->Type.GetRealType(); - std::cout << "private:" << std::endl - << "\t" << realType << " GetDefault" << it->GetFriendlyName() << "(void) const" << std::endl - << "\t" << "{" << std::endl; + m_Header << "private:" << std::endl + << "\t" << realType << " GetDefault" << it->GetFriendlyName() << "(void) const;" << std::endl; + + m_Impl << realType << " ObjectImpl<" << klass.Name << ">::GetDefault" << it->GetFriendlyName() << "(void) const" << std::endl + << "{" << std::endl; if (it->DefaultAccessor.empty()) - std::cout << "\t\t" << "return " << realType << "();" << std::endl; + m_Impl << "\t" << "return " << realType << "();" << std::endl; else - std::cout << it->DefaultAccessor << std::endl; + m_Impl << it->DefaultAccessor << std::endl; - std::cout << "\t" << "}" << std::endl; + m_Impl << "}" << std::endl; } /* validators */ for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { - std::cout << "protected:" << std::endl - << "\t" << "virtual void Validate" << it->GetFriendlyName() << "(" << it->Type.GetArgumentType() << " value, const ValidationUtils& utils);" << std::endl; + m_Header << "protected:" << std::endl + << "\t" << "virtual void Validate" << it->GetFriendlyName() << "(" << it->Type.GetArgumentType() << " value, const ValidationUtils& utils);" << std::endl; } /* instance variables */ - std::cout << "private:" << std::endl; + m_Header << "private:" << std::endl; for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { if (!(it->Attributes & FANoStorage)) - std::cout << "\t" << it->Type.GetRealType() << " m_" << it->GetFriendlyName() << ";" << std::endl; + m_Header << "\t" << it->Type.GetRealType() << " m_" << it->GetFriendlyName() << ";" << std::endl; } } if (klass.Name == "DynamicObject") - std::cout << "\t" << "friend class ConfigItem;" << std::endl; + m_Header << "\t" << "friend class ConfigItem;" << std::endl; if (!klass.TypeBase.empty()) - std::cout << "\t" << "friend class " << klass.TypeBase << ";" << std::endl; + m_Header << "\t" << "friend class " << klass.TypeBase << ";" << std::endl; - std::cout << "};" << std::endl << std::endl; + m_Header << "};" << std::endl << std::endl; for (it = klass.Fields.begin(); it != klass.Fields.end(); it++) { m_MissingValidators[std::make_pair(klass.Name, it->GetFriendlyName())] = *it; } } -enum ValidatorType -{ - ValidatorField, - ValidatorArray, - ValidatorDictionary -}; - -static void CodeGenValidator(const std::string& name, const std::string& klass, const std::vector& rules, const std::string& field, const FieldType& fieldType, ValidatorType validatorType) +void ClassCompiler::CodeGenValidator(const std::string& name, const std::string& klass, const std::vector& rules, const std::string& field, const FieldType& fieldType, ValidatorType validatorType) { - std::cout << "inline void TIValidate" << name << "(const intrusive_ptr >& object, "; + m_Header << "void TIValidate" << name << "(const intrusive_ptr >& object, "; + m_Impl << "void TIValidate" << name << "(const intrusive_ptr >& object, "; - if (validatorType != ValidatorField) - std::cout << "const String& key, "; + if (validatorType != ValidatorField) { + m_Header << "const String& key, "; + m_Impl << "const String& key, "; + } bool static_known_attribute = false; - std::cout << fieldType.GetArgumentType() << " value, std::vector& location, const ValidationUtils& utils)" << std::endl - << "{" << std::endl; + m_Header << fieldType.GetArgumentType() << " value, std::vector& location, const ValidationUtils& utils);" << std::endl; + + m_Impl << fieldType.GetArgumentType() << " value, std::vector& location, const ValidationUtils& utils)" << std::endl + << "{" << std::endl; if (validatorType == ValidatorField) { static_known_attribute = true; @@ -646,21 +671,21 @@ static void CodeGenValidator(const std::string& name, const std::string& klass, if (fieldType.GetRealType() != "int" && fieldType.GetRealType() != "double") { if (fieldType.GetRealType() == "Value" || fieldType.GetRealType() == "String") - std::cout << "\t" << "if (value.IsEmpty())" << std::endl; + m_Impl << "\t" << "if (value.IsEmpty())" << std::endl; else - std::cout << "\t" << "if (!value)" << std::endl; + m_Impl << "\t" << "if (!value)" << std::endl; if (required) - std::cout << "BOOST_THROW_EXCEPTION(ValidationError(this, location, \"This attribute must not be empty.\"));" << std::endl; + m_Impl << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_cast(this), location, \"This attribute must not be empty.\"));" << std::endl; else - std::cout << "\t\t" << "return;" << std::endl; + m_Impl << "\t\t" << "return;" << std::endl; - std::cout << std::endl; + m_Impl << std::endl; } } if (!static_known_attribute) - std::cout << "\t" << "bool known_attribute = false;" << std::endl; + m_Impl << "\t" << "bool known_attribute = false;" << std::endl; bool type_check = false; @@ -673,50 +698,50 @@ static void CodeGenValidator(const std::string& name, const std::string& klass, if (validatorType == ValidatorField && rule.Pattern != field) continue; - std::cout << "\t" << "do {" << std::endl; + m_Impl << "\t" << "do {" << std::endl; if (validatorType != ValidatorField) { if (rule.Pattern != "*") { if (rule.Pattern.find_first_of("*?") != std::string::npos) - std::cout << "\t\t" << "if (!Utility::Match(\"" << rule.Pattern << "\", key))" << std::endl; + m_Impl << "\t\t" << "if (!Utility::Match(\"" << rule.Pattern << "\", key))" << std::endl; else - std::cout << "\t\t" << "if (key != \"" << rule.Pattern << "\")" << std::endl; + m_Impl << "\t\t" << "if (key != \"" << rule.Pattern << "\")" << std::endl; - std::cout << "\t\t\t" << "break;" << std::endl; + m_Impl << "\t\t\t" << "break;" << std::endl; } else static_known_attribute = true; if (!static_known_attribute) - std::cout << "\t\t" << "known_attribute = true;" << std::endl; + m_Impl << "\t\t" << "known_attribute = true;" << std::endl; } if (rule.IsName) { - std::cout << "\t\t" << "if (value.IsScalar()) {" << std::endl - << "\t\t\t" << "if (utils.ValidateName(\"" << rule.Type << "\", value))" << std::endl - << "\t\t\t\t" << "return;" << std::endl - << "\t\t\t" << "else" << std::endl - << "\t\t\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(object, location, \"Object '\" + value + \"' of type '" << rule.Type << "' does not exist.\"));" << std::endl - << "\t\t" << "}" << std::endl; + m_Impl << "\t\t" << "if (value.IsScalar()) {" << std::endl + << "\t\t\t" << "if (utils.ValidateName(\"" << rule.Type << "\", value))" << std::endl + << "\t\t\t\t" << "return;" << std::endl + << "\t\t\t" << "else" << std::endl + << "\t\t\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_pointer_cast(object), location, \"Object '\" + value + \"' of type '" << rule.Type << "' does not exist.\"));" << std::endl + << "\t\t" << "}" << std::endl; } if (fieldType.GetRealType() == "Value") { if (rule.Type == "String") - std::cout << "\t\t" << "if (value.IsScalar())" << std::endl - << "\t\t\t" << "return;" << std::endl; + m_Impl << "\t\t" << "if (value.IsScalar())" << std::endl + << "\t\t\t" << "return;" << std::endl; else if (rule.Type == "Number") { - std::cout << "\t\t" << "try {" << std::endl - << "\t\t\t" << "Convert::ToDouble(value);" << std::endl - << "\t\t\t" << "return;" << std::endl - << "\t\t" << "} catch (...) { }" << std::endl; + m_Impl << "\t\t" << "try {" << std::endl + << "\t\t\t" << "Convert::ToDouble(value);" << std::endl + << "\t\t\t" << "return;" << std::endl + << "\t\t" << "} catch (...) { }" << std::endl; } } if (rule.Type == "Dictionary" || rule.Type == "Array" || rule.Type == "Function") { if (fieldType.GetRealType() == "Value") { - std::cout << "\t\t" << "if (value.IsObjectType<" << rule.Type << ">()) {" << std::endl; + m_Impl << "\t\t" << "if (value.IsObjectType<" << rule.Type << ">()) {" << std::endl; type_check = true; } else if (fieldType.GetRealType() != rule.Type + "::Ptr") { - std::cout << "\t\t" << "if (dynamic_pointer_cast<" << rule.Type << ">(value)) {" << std::endl; + m_Impl << "\t\t" << "if (dynamic_pointer_cast<" << rule.Type << ">(value)) {" << std::endl; type_check = true; } @@ -725,29 +750,29 @@ static void CodeGenValidator(const std::string& name, const std::string& klass, if (rule.Type == "Dictionary") { if (type_check) - std::cout << "\t\t\t" << "Dictionary::Ptr dict = value;" << std::endl; + m_Impl << "\t\t\t" << "Dictionary::Ptr dict = value;" << std::endl; else - std::cout << "\t\t" << "const Dictionary::Ptr& dict = value;" << std::endl; + m_Impl << "\t\t" << "const Dictionary::Ptr& dict = value;" << std::endl; - std::cout << (type_check ? "\t" : "") << "\t\t" << "ObjectLock olock(dict);" << std::endl - << (type_check ? "\t" : "") << "\t\t" << "BOOST_FOREACH(const Dictionary::Pair& kv, dict) {" << std::endl - << (type_check ? "\t" : "") << "\t\t\t" << "const String& akey = kv.first;" << std::endl - << (type_check ? "\t" : "") << "\t\t\t" << "const Value& avalue = kv.second;" << std::endl; + m_Impl << (type_check ? "\t" : "") << "\t\t" << "ObjectLock olock(dict);" << std::endl + << (type_check ? "\t" : "") << "\t\t" << "BOOST_FOREACH(const Dictionary::Pair& kv, dict) {" << std::endl + << (type_check ? "\t" : "") << "\t\t\t" << "const String& akey = kv.first;" << std::endl + << (type_check ? "\t" : "") << "\t\t\t" << "const Value& avalue = kv.second;" << std::endl; indent = true; } else if (rule.Type == "Array") { if (type_check) - std::cout << "\t\t\t" << "Array::Ptr arr = value;" << std::endl; + m_Impl << "\t\t\t" << "Array::Ptr arr = value;" << std::endl; else - std::cout << "\t\t" << "const Array::Ptr& arr = value;" << std::endl; + m_Impl << "\t\t" << "const Array::Ptr& arr = value;" << std::endl; - std::cout << (type_check ? "\t" : "") << "\t\t" << "Array::SizeType anum = 0;" << std::endl - << (type_check ? "\t" : "") << "\t\t" << "ObjectLock olock(arr);" << std::endl - << (type_check ? "\t" : "") << "\t\t" << "BOOST_FOREACH(const Value& avalue, arr) {" << std::endl - << (type_check ? "\t" : "") << "\t\t\t" << "String akey = Convert::ToString(anum);" << std::endl; + m_Impl << (type_check ? "\t" : "") << "\t\t" << "Array::SizeType anum = 0;" << std::endl + << (type_check ? "\t" : "") << "\t\t" << "ObjectLock olock(arr);" << std::endl + << (type_check ? "\t" : "") << "\t\t" << "BOOST_FOREACH(const Value& avalue, arr) {" << std::endl + << (type_check ? "\t" : "") << "\t\t\t" << "String akey = Convert::ToString(anum);" << std::endl; indent = true; } else { - std::cout << (type_check ? "\t" : "") << "\t\t" << "String akey = \"\";" << std::endl - << (type_check ? "\t" : "") << "\t\t" << "const Value& avalue = value;" << std::endl; + m_Impl << (type_check ? "\t" : "") << "\t\t" << "String akey = \"\";" << std::endl + << (type_check ? "\t" : "") << "\t\t" << "const Value& avalue = value;" << std::endl; } std::string subvalidator_prefix; @@ -757,14 +782,14 @@ static void CodeGenValidator(const std::string& name, const std::string& klass, else subvalidator_prefix = name; - std::cout << (type_check ? "\t" : "") << (indent ? "\t" : "") << "\t\t" << "location.push_back(akey);" << std::endl - << (type_check ? "\t" : "") << (indent ? "\t" : "") << "\t\t" << "TIValidate" << subvalidator_prefix << "_" << i << "(object, akey, avalue, location, utils);" << std::endl; + m_Impl << (type_check ? "\t" : "") << (indent ? "\t" : "") << "\t\t" << "location.push_back(akey);" << std::endl + << (type_check ? "\t" : "") << (indent ? "\t" : "") << "\t\t" << "TIValidate" << subvalidator_prefix << "_" << i << "(object, akey, avalue, location, utils);" << std::endl; if (rule.Type == "Array") - std::cout << (type_check ? "\t" : "") << "\t\t\t" << "anum++;" << std::endl; + m_Impl << (type_check ? "\t" : "") << "\t\t\t" << "anum++;" << std::endl; if (rule.Type == "Dictionary" || rule.Type == "Array") - std::cout << (type_check ? "\t" : "") << "\t\t" << "}" << std::endl; + m_Impl << (type_check ? "\t" : "") << "\t\t" << "}" << std::endl; for (std::vector::size_type i = 0; i < rule.Rules.size(); i++) { const Rule& srule = rule.Rules[i]; @@ -773,8 +798,8 @@ static void CodeGenValidator(const std::string& name, const std::string& klass, continue; if (rule.Type == "Dictionary") { - std::cout << (type_check ? "\t" : "") << "\t\t" << "if (dict.Get(\"" << srule.Pattern << "\").IsEmpty())" << std::endl - << (type_check ? "\t" : "") << "\t\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(this, location, \"Required dictionary item '" << srule.Pattern << "' is not set.\"));" << std::endl; + m_Impl << (type_check ? "\t" : "") << "\t\t" << "if (dict.Get(\"" << srule.Pattern << "\").IsEmpty())" << std::endl + << (type_check ? "\t" : "") << "\t\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_cast(this), location, \"Required dictionary item '" << srule.Pattern << "' is not set.\"));" << std::endl; } else if (rule.Type == "Array") { int index = -1; std::stringstream idxbuf; @@ -786,43 +811,43 @@ static void CodeGenValidator(const std::string& name, const std::string& klass, std::exit(1); } - std::cout << (type_check ? "\t" : "") << "\t\t" << "if (arr.GetLength() < " << (index + 1) << ")" << std::endl - << (type_check ? "\t" : "") << "\t\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(this, location, \"Required index '" << index << "' is not set.\"));" << std::endl; + m_Impl << (type_check ? "\t" : "") << "\t\t" << "if (arr.GetLength() < " << (index + 1) << ")" << std::endl + << (type_check ? "\t" : "") << "\t\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_cast(this), location, \"Required index '" << index << "' is not set.\"));" << std::endl; } } - std::cout << (type_check ? "\t" : "") << (indent ? "\t" : "") << "\t\t" << "location.pop_back();" << std::endl; + m_Impl << (type_check ? "\t" : "") << (indent ? "\t" : "") << "\t\t" << "location.pop_back();" << std::endl; } - std::cout << (type_check ? "\t" : "") << "\t\t" << "return;" << std::endl; + m_Impl << (type_check ? "\t" : "") << "\t\t" << "return;" << std::endl; if (fieldType.GetRealType() == "Value" || fieldType.GetRealType() != rule.Type + "::Ptr") - std::cout << "\t\t" << "}" << std::endl; + m_Impl << "\t\t" << "}" << std::endl; } - std::cout << "\t" << "} while (0);" << std::endl << std::endl; + m_Impl << "\t" << "} while (0);" << std::endl << std::endl; } if (type_check || validatorType != ValidatorField) { if (!static_known_attribute) - std::cout << "\t" << "if (!known_attribute)" << std::endl - << "\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(object, location, \"Invalid attribute: \" + key));" << std::endl - << "\t" << "else" << std::endl; + m_Impl << "\t" << "if (!known_attribute)" << std::endl + << "\t\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_pointer_cast(object), location, \"Invalid attribute: \" + key));" << std::endl + << "\t" << "else" << std::endl; - std::cout << (!static_known_attribute ? "\t" : "") << "\t" << "BOOST_THROW_EXCEPTION(ValidationError(object, boost::assign::list_of("; + m_Impl << (!static_known_attribute ? "\t" : "") << "\t" << "BOOST_THROW_EXCEPTION(ValidationError(dynamic_pointer_cast(object), boost::assign::list_of("; if (validatorType == ValidatorField) - std::cout << "\"" << field << "\""; + m_Impl << "\"" << field << "\""; else - std::cout << "key"; + m_Impl << "key"; - std::cout << "), \"Invalid type.\"));" << std::endl; + m_Impl << "), \"Invalid type.\"));" << std::endl; } - std::cout << "}" << std::endl << std::endl; + m_Impl << "}" << std::endl << std::endl; } -static void CodeGenValidatorSubrules(const std::string& name, const std::string& klass, const std::vector& rules) +void ClassCompiler::CodeGenValidatorSubrules(const std::string& name, const std::string& klass, const std::vector& rules) { for (std::vector::size_type i = 0; i < rules.size(); i++) { const Rule& rule = rules[i]; @@ -863,13 +888,13 @@ void ClassCompiler::HandleValidator(const Validator& validator, const ClassDebug CodeGenValidator(it->first.first + it->first.second, it->first.first, validator.Rules, it->second.Name, it->second.Type, ValidatorField); for (std::map, Field>::const_iterator it = m_MissingValidators.begin(); it != m_MissingValidators.end(); it++) { - std::cout << "inline void ObjectImpl<" << it->first.first << ">::Validate" << it->first.second << "(" << it->second.Type.GetArgumentType() << " value, const ValidationUtils& utils)" << std::endl - << "{" << std::endl - << "\t" << "SimpleValidate" << it->first.second << "(value, utils);" << std::endl - << "\t" << "std::vector location;" << std::endl - << "\t" << "location.push_back(\"" << it->second.Name << "\");" << std::endl - << "\t" << "TIValidate" << it->first.first << it->first.second << "(this, value, location, utils);" << std::endl - << "}" << std::endl << std::endl; + m_Impl << "void ObjectImpl<" << it->first.first << ">::Validate" << it->first.second << "(" << it->second.Type.GetArgumentType() << " value, const ValidationUtils& utils)" << std::endl + << "{" << std::endl + << "\t" << "SimpleValidate" << it->first.second << "(value, utils);" << std::endl + << "\t" << "std::vector location;" << std::endl + << "\t" << "location.push_back(\"" << it->second.Name << "\");" << std::endl + << "\t" << "TIValidate" << it->first.first << it->first.second << "(this, value, location, utils);" << std::endl + << "}" << std::endl << std::endl; } m_MissingValidators.clear(); @@ -878,24 +903,67 @@ void ClassCompiler::HandleValidator(const Validator& validator, const ClassDebug void ClassCompiler::HandleMissingValidators(void) { for (std::map, Field>::const_iterator it = m_MissingValidators.begin(); it != m_MissingValidators.end(); it++) { - std::cout << "inline void ObjectImpl<" << it->first.first << ">::Validate" << it->first.second << "(" << it->second.Type.GetArgumentType() << " value, const ValidationUtils& utils)" << std::endl - << "{" << std::endl - << "\t" << "SimpleValidate" << it->first.second << "(value, utils);" << std::endl - << "}" << std::endl << std::endl; + m_Impl << "void ObjectImpl<" << it->first.first << ">::Validate" << it->first.second << "(" << it->second.Type.GetArgumentType() << " value, const ValidationUtils& utils)" << std::endl + << "{" << std::endl + << "\t" << "SimpleValidate" << it->first.second << "(value, utils);" << std::endl + << "}" << std::endl << std::endl; } m_MissingValidators.clear(); } -void ClassCompiler::CompileFile(const std::string& path) +void ClassCompiler::CompileFile(const std::string& inputpath, + const std::string& implpath, const std::string& headerpath) { - std::ifstream stream; - stream.open(path.c_str(), std::ifstream::in); + std::ifstream input; + input.open(inputpath.c_str(), std::ifstream::in); + + if (!input) { + std::cerr << "Could not open input file: " << inputpath << std::endl; + std::exit(EXIT_FAILURE); + } + + std::string tmpheaderpath = headerpath + ".tmp"; + std::ofstream oheader; + oheader.open(tmpheaderpath.c_str(), std::ofstream::out); + + if (!oheader) { + std::cerr << "Could not open header file: " << tmpheaderpath << std::endl; + std::exit(EXIT_FAILURE); + } + + std::string tmpimplpath = implpath + ".tmp"; + std::ofstream oimpl; + oimpl.open(tmpimplpath.c_str(), std::ofstream::out); + + if (!oimpl) { + std::cerr << "Could not open implementation file: " << tmpimplpath << std::endl; + std::exit(EXIT_FAILURE); + } + + CompileStream(inputpath, input, oimpl, oheader); - if (!stream) - throw std::invalid_argument("Could not open config file: " + path); + input.close(); + oimpl.close(); + oheader.close(); - return CompileStream(path, &stream); +#ifdef _WIN32 + _unlink(headerpath.c_str()); +#endif /* _WIN32 */ + + if (rename(tmpheaderpath.c_str(), headerpath.c_str()) < 0) { + std::cerr << "Could not rename header file: " << tmpheaderpath << " -> " << headerpath << std::endl; + std::exit(EXIT_FAILURE); + } + +#ifdef _WIN32 + _unlink(implpath.c_str()); +#endif /* _WIN32 */ + + if (rename(tmpimplpath.c_str(), implpath.c_str()) < 0) { + std::cerr << "Could not rename implementation file: " << tmpimplpath << " -> " << implpath << std::endl; + std::exit(EXIT_FAILURE); + } } std::string ClassCompiler::BaseName(const std::string& path) @@ -921,7 +989,7 @@ std::string ClassCompiler::FileNameToGuardName(const std::string& fname) { std::string result = fname; - for (int i = 0; i < result.size(); i++) { + for (std::string::size_type i = 0; i < result.size(); i++) { result[i] = toupper(result[i]); if (result[i] == '.') @@ -931,39 +999,41 @@ std::string ClassCompiler::FileNameToGuardName(const std::string& fname) return result; } -void ClassCompiler::CompileStream(const std::string& path, std::istream *stream) +void ClassCompiler::CompileStream(const std::string& path, std::istream& input, + std::ostream& oimpl, std::ostream& oheader) { - stream->exceptions(std::istream::badbit); + input.exceptions(std::istream::badbit); std::string guard_name = FileNameToGuardName(BaseName(path)); - std::cout << "#ifndef " << guard_name << std::endl - << "#define " << guard_name << std::endl << std::endl; - - std::cout << "#include \"base/object.hpp\"" << std::endl - << "#include \"base/type.hpp\"" << std::endl - << "#include \"base/debug.hpp\"" << std::endl - << "#include \"base/value.hpp\"" << std::endl - << "#include \"base/array.hpp\"" << std::endl - << "#include \"base/dictionary.hpp\"" << std::endl - << "#include \"base/convert.hpp\"" << std::endl - << "#include \"base/exception.hpp\"" << std::endl - << "#include \"base/objectlock.hpp\"" << std::endl - << "#include \"base/utility.hpp\"" << std::endl << std::endl - << "#include " << std::endl - << "#include " << std::endl - << "#ifdef _MSC_VER" << std::endl - << "#pragma warning( push )" << std::endl - << "#pragma warning( disable : 4244 )" << std::endl - << "#pragma warning( disable : 4800 )" << std::endl - << "#endif /* _MSC_VER */" << std::endl << std::endl; - - ClassCompiler ctx(path, stream); + oheader << "#ifndef " << guard_name << std::endl + << "#define " << guard_name << std::endl << std::endl; + + oheader << "#include \"base/object.hpp\"" << std::endl + << "#include \"base/type.hpp\"" << std::endl + << "#include \"base/value.hpp\"" << std::endl + << "#include \"base/array.hpp\"" << std::endl + << "#include \"base/dictionary.hpp\"" << std::endl << std::endl; + + oimpl << "#include \"base/exception.hpp\"" << std::endl + << "#include \"base/objectlock.hpp\"" << std::endl + << "#include \"base/utility.hpp\"" << std::endl + << "#include \"base/convert.hpp\"" << std::endl + << "#include " << std::endl + << "#include " << std::endl + << "#ifdef _MSC_VER" << std::endl + << "#pragma warning( push )" << std::endl + << "#pragma warning( disable : 4244 )" << std::endl + << "#pragma warning( disable : 4800 )" << std::endl + << "#endif /* _MSC_VER */" << std::endl << std::endl; + + + ClassCompiler ctx(path, input, oimpl, oheader); ctx.Compile(); - std::cout << "#ifdef _MSC_VER" << std::endl - << "#pragma warning ( pop )" << std::endl - << "#endif /* _MSC_VER */" << std::endl; + oheader << "#endif /* " << guard_name << " */" << std::endl; - std::cout << "#endif /* " << guard_name << " */" << std::endl; + oimpl << "#ifdef _MSC_VER" << std::endl + << "#pragma warning ( pop )" << std::endl + << "#endif /* _MSC_VER */" << std::endl; } diff --git a/tools/mkclass/classcompiler.hpp b/tools/mkclass/classcompiler.hpp index 697f32f49..96b48b57d 100644 --- a/tools/mkclass/classcompiler.hpp +++ b/tools/mkclass/classcompiler.hpp @@ -171,6 +171,13 @@ struct Rule std::vector Rules; }; +enum ValidatorType +{ + ValidatorField, + ValidatorArray, + ValidatorDictionary +}; + struct Validator { std::string Name; @@ -180,7 +187,7 @@ struct Validator class ClassCompiler { public: - ClassCompiler(const std::string& path, std::istream *input); + ClassCompiler(const std::string& path, std::istream& input, std::ostream& oimpl, std::ostream& oheader); ~ClassCompiler(void); void Compile(void); @@ -203,14 +210,21 @@ public: void HandleCode(const std::string& code, const ClassDebugInfo& locp); void HandleMissingValidators(void); - static void CompileFile(const std::string& path); - static void CompileStream(const std::string& path, std::istream *stream); + void CodeGenValidator(const std::string& name, const std::string& klass, const std::vector& rules, const std::string& field, const FieldType& fieldType, ValidatorType validatorType); + void CodeGenValidatorSubrules(const std::string& name, const std::string& klass, const std::vector& rules); + + static void CompileFile(const std::string& inputpath, const std::string& implpath, + const std::string& headerpath); + static void CompileStream(const std::string& path, std::istream& input, + std::ostream& oimpl, std::ostream& oheader); static void OptimizeStructLayout(std::vector& fields); private: std::string m_Path; - std::istream *m_Input; + std::istream& m_Input; + std::ostream& m_Impl; + std::ostream& m_Header; void *m_Scanner; std::map, Field> m_MissingValidators; diff --git a/tools/mkclass/mkclass.cpp b/tools/mkclass/mkclass.cpp index db5ddee41..655773db0 100644 --- a/tools/mkclass/mkclass.cpp +++ b/tools/mkclass/mkclass.cpp @@ -24,10 +24,10 @@ using namespace icinga; int main(int argc, char **argv) { - if (argc < 2) { - std::cerr << "Syntax: " << argv[0] << " " << std::endl; + if (argc < 4) { + std::cerr << "Syntax: " << argv[0] << " " << std::endl; return 1; } - ClassCompiler::CompileFile(argv[1]); + ClassCompiler::CompileFile(argv[1], argv[2], argv[3]); } -- 2.40.0