diff options
59 files changed, 2248 insertions, 2163 deletions
diff --git a/Jamroot.jam b/Jamroot.jam index 98e8e4c..9d1aa16 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -23,26 +23,33 @@ project  			<variant>coverage:<coverage>on  			<toolset>tidy:<checkxx>boost-*  			<toolset>tidy:<checkxx>bugprone-* +			<toolset>tidy:<xcheckxx>bugprone-macro-parentheses  			<toolset>tidy:<checkxx>clang-* +			<toolset>tidy:<xcheckxx>clang-analyzer-cplusplus.NewDeleteLeaks  			<toolset>tidy:<checkxx>misc-* +			<toolset>tidy:<xcheckxx>misc-non-private-member-variables-in-classes  			<toolset>tidy:<checkxx>modernize-*  			<toolset>tidy:<xcheckxx>modernize-use-trailing-return-type  			<toolset>tidy:<checkxx>hicpp-* +			<toolset>tidy:<xcheckxx>hicpp-no-array-decay +			<toolset>tidy:<xcheckxx>hicpp-vararg  			<toolset>tidy:<checkxx>performance-* -			<toolset>tidy:<exclude>test/bin/tidy/debug/classes.h -			<toolset>tidy:<exclude>test/bin/tidy/debug/classtype.h -			<toolset>tidy:<exclude>test/bin/tidy/debug/collections.h -			<toolset>tidy:<exclude>test/bin/tidy/debug/enums.h -			<toolset>tidy:<exclude>test/bin/tidy/debug/inheritance.h -			<toolset>tidy:<exclude>test/bin/tidy/debug/interfaces.h -			<toolset>tidy:<exclude>test/bin/tidy/debug/json.h -			<toolset>tidy:<exclude>test/bin/tidy/debug/locals.h -			<toolset>tidy:<exclude>test/bin/tidy/debug/optionals.h -			<toolset>tidy:<exclude>test/bin/tidy/debug/structs.h -			<toolset>tidy:<exclude>test/bin/tidy/debug/types.h -			<toolset>tidy:<exclude>test/bin/tidy/debug/xml.h +			<toolset>tidy:<exclude>test/bin/tidy/debug/cxxstd-17-iso/classes.h +			<toolset>tidy:<exclude>test/bin/tidy/debug/cxxstd-17-iso/classtype.h +			<toolset>tidy:<exclude>test/bin/tidy/debug/cxxstd-17-iso/collections.h +			<toolset>tidy:<exclude>test/bin/tidy/debug/cxxstd-17-iso/enums.h +			<toolset>tidy:<exclude>test/bin/tidy/debug/cxxstd-17-iso/inheritance.h +			<toolset>tidy:<exclude>test/bin/tidy/debug/cxxstd-17-iso/interfaces.h +			<toolset>tidy:<exclude>test/bin/tidy/debug/cxxstd-17-iso/json.h +			<toolset>tidy:<exclude>test/bin/tidy/debug/cxxstd-17-iso/locals.h +			<toolset>tidy:<exclude>test/bin/tidy/debug/cxxstd-17-iso/optionals.h +			<toolset>tidy:<exclude>test/bin/tidy/debug/cxxstd-17-iso/structs.h +			<toolset>tidy:<exclude>test/bin/tidy/debug/cxxstd-17-iso/types.h +			<toolset>tidy:<exclude>test/bin/tidy/debug/cxxstd-17-iso/xml.h  			<toolset>tidy:<exclude>slicer/bin/common.h  			<toolset>tidy:<exclude>xml/bin/tidy/debug/cxxstd-17-iso/xmlExceptions.h +			<toolset>tidy:<exclude>db/bin/tidy/debug/cxxstd-17-iso/sqlExceptions.h +			<toolset>tidy:<exclude>db/bin/tidy/debug/cxxstd-17-iso/testModels.h  			;  build-project slicer ; diff --git a/slicer/Jamfile.jam b/slicer/Jamfile.jam index d6f47ff..387a313 100644 --- a/slicer/Jamfile.jam +++ b/slicer/Jamfile.jam @@ -8,8 +8,7 @@ build-project db ;  build-project ice ;  build-project test ; -lib boost_utf : : <name>boost_unit_test_framework : : -	<toolset>tidy:<xcheckxx>hicpp-* ; +lib boost_utf : : <name>boost_unit_test_framework ;  lib adhocutil : : : : <include>/usr/include/adhocutil ;  lib Ice++11 ;  lib pthread ; diff --git a/slicer/db/Jamfile.jam b/slicer/db/Jamfile.jam index fcfa4d3..7a5de7e 100644 --- a/slicer/db/Jamfile.jam +++ b/slicer/db/Jamfile.jam @@ -39,7 +39,6 @@ lib testCommon :  	:  	<dependency>../tool//slicer  	<slicer>pure -	<slicerbin>../tool//slicer  	<implicit-dependency>../test//types  	<library>../test//types  	<library>../test//common @@ -48,6 +47,12 @@ lib testCommon :  	<library>..//adhocutil  	<library>dbicetypes  	<implicit-dependency>dbicetypes +	<toolset>gcc:<dependency>../tool//slicer/<toolset>gcc +	<toolset>clang:<dependency>../tool//slicer/<toolset>clang +	<toolset>tidy:<dependency>../tool//slicer/<toolset>gcc +	<toolset>gcc:<slicerbin>../tool//slicer/<toolset>gcc +	<toolset>clang:<slicerbin>../tool//slicer/<toolset>clang +	<toolset>tidy:<slicerbin>../tool//slicer/<toolset>gcc  	: :  	<library>..//adhocutil  	<library>dbicetypes diff --git a/slicer/db/sqlBinder.cpp b/slicer/db/sqlBinder.cpp index 6969749..8245217 100644 --- a/slicer/db/sqlBinder.cpp +++ b/slicer/db/sqlBinder.cpp @@ -1,11 +1,7 @@  #include "sqlBinder.h"  namespace Slicer { -	SqlBinder::SqlBinder(DB::Command & c, unsigned int i) : -		command(c), -		idx(i) -	{ -	} +	SqlBinder::SqlBinder(DB::Command & c, unsigned int i) : command(c), idx(i) { }  	void  	SqlBinder::get(const boost::posix_time::ptime & b) const @@ -67,4 +63,3 @@ namespace Slicer {  		command.bindParamS(idx, b);  	}  } - diff --git a/slicer/db/sqlBinder.h b/slicer/db/sqlBinder.h index f7a0be6..8c1ce80 100644 --- a/slicer/db/sqlBinder.h +++ b/slicer/db/sqlBinder.h @@ -1,36 +1,34 @@  #ifndef SLICER_DB_SQLBINDER_H  #define SLICER_DB_SQLBINDER_H -#include <slicer/modelParts.h> -#include <command.h>  #include <boost/date_time/posix_time/ptime.hpp> +#include <command.h> +#include <slicer/modelParts.h>  namespace Slicer { -	class SqlBinder : public Slicer::ValueTarget, -			public Slicer::TValueTarget<boost::posix_time::time_duration>, -			public Slicer::TValueTarget<boost::posix_time::ptime> -	{ -		public: -			SqlBinder(DB::Command & c, unsigned int idx); +	class SqlBinder : +		public Slicer::ValueTarget, +		public Slicer::TValueTarget<boost::posix_time::time_duration>, +		public Slicer::TValueTarget<boost::posix_time::ptime> { +	public: +		SqlBinder(DB::Command & c, unsigned int idx); -			void get(const boost::posix_time::ptime & b) const override; -			void get(const boost::posix_time::time_duration & b) const override; -			void get(const bool & b) const override; -			void get(const Ice::Byte & b) const override; -			void get(const Ice::Short & b) const override; -			void get(const Ice::Int & b) const override; -			void get(const Ice::Long & b) const override; -			void get(const Ice::Float & b) const override; -			void get(const Ice::Double & b) const override; -			void get(const std::string & b) const override; +		void get(const boost::posix_time::ptime & b) const override; +		void get(const boost::posix_time::time_duration & b) const override; +		void get(const bool & b) const override; +		void get(const Ice::Byte & b) const override; +		void get(const Ice::Short & b) const override; +		void get(const Ice::Int & b) const override; +		void get(const Ice::Long & b) const override; +		void get(const Ice::Float & b) const override; +		void get(const Ice::Double & b) const override; +		void get(const std::string & b) const override; -		private: -			DB::Command & command; -			const unsigned int idx; +	private: +		DB::Command & command; +		const unsigned int idx;  	};  	typedef std::shared_ptr<SqlBinder> SqlBinderPtr;  }  #endif - - diff --git a/slicer/db/sqlCommon.cpp b/slicer/db/sqlCommon.cpp index 193285e..ecce6cc 100644 --- a/slicer/db/sqlCommon.cpp +++ b/slicer/db/sqlCommon.cpp @@ -1,7 +1,7 @@ -#include <sqlExceptions.h> -#include <compileTimeFormatter.h>  #include "sqlCommon.h" +#include <compileTimeFormatter.h>  #include <metadata.h> +#include <sqlExceptions.h>  namespace Slicer {  	const std::string md_pkey = "db:pkey"; @@ -9,53 +9,61 @@ namespace Slicer {  	const std::string md_ignore = "db:ignore";  	const std::string md_global_ignore = "ignore"; -	bool isPKey(const HookCommon * h) +	bool +	isPKey(const HookCommon * h)  	{  		return metaDataFlagSet(h->GetMetadata(), md_pkey) && isBind(h);  	} -	bool isAuto(const HookCommon * h) +	bool +	isAuto(const HookCommon * h)  	{  		return metaDataFlagSet(h->GetMetadata(), md_auto) && isBind(h);  	} -	bool isNotAuto(const HookCommon * h) +	bool +	isNotAuto(const HookCommon * h)  	{  		return metaDataFlagNotSet(h->GetMetadata(), md_auto) && isBind(h);  	} -	bool isBind(const HookCommon * h) +	bool +	isBind(const HookCommon * h)  	{ -		return metaDataFlagNotSet(h->GetMetadata(), md_global_ignore) && -			metaDataFlagNotSet(h->GetMetadata(), md_ignore); +		return metaDataFlagNotSet(h->GetMetadata(), md_global_ignore) +				&& metaDataFlagNotSet(h->GetMetadata(), md_ignore);  	} -	bool isValue(const HookCommon * h) +	bool +	isValue(const HookCommon * h)  	{ -		return metaDataFlagNotSet(h->GetMetadata(), md_auto) && -			metaDataFlagNotSet(h->GetMetadata(), md_pkey) && isBind(h); +		return metaDataFlagNotSet(h->GetMetadata(), md_auto) && metaDataFlagNotSet(h->GetMetadata(), md_pkey) +				&& isBind(h);  	} -	void TooManyRowsReturned::ice_print(std::ostream & s) const +	void +	TooManyRowsReturned::ice_print(std::ostream & s) const  	{  		s << "Too many rows returned";  	} -	void NoRowsReturned::ice_print(std::ostream & s) const +	void +	NoRowsReturned::ice_print(std::ostream & s) const  	{  		s << "No rows returned";  	} -	void NoRowsFound::ice_print(std::ostream & s) const +	void +	NoRowsFound::ice_print(std::ostream & s) const  	{  		s << "No rows found";  	}  	AdHocFormatter(UnsuitableIdFieldTypeMsg, "Unsuitable id field type [%?]"); -	void UnsuitableIdFieldType::ice_print(std::ostream & s) const +	void +	UnsuitableIdFieldType::ice_print(std::ostream & s) const  	{  		UnsuitableIdFieldTypeMsg::write(s, type);  	}  } - diff --git a/slicer/db/sqlCommon.h b/slicer/db/sqlCommon.h index 954800a..32afd87 100644 --- a/slicer/db/sqlCommon.h +++ b/slicer/db/sqlCommon.h @@ -1,8 +1,8 @@  #ifndef SLICER_DB_SQLCOMMON_H  #define SLICER_DB_SQLCOMMON_H -#include <string>  #include <modelParts.h> +#include <string>  namespace Slicer {  	bool isPKey(const HookCommon *); @@ -13,4 +13,3 @@ namespace Slicer {  }  #endif - diff --git a/slicer/db/sqlInsertSerializer.cpp b/slicer/db/sqlInsertSerializer.cpp index dde8f1f..4061b17 100644 --- a/slicer/db/sqlInsertSerializer.cpp +++ b/slicer/db/sqlInsertSerializer.cpp @@ -1,20 +1,20 @@ -#include "sqlInsertSerializer.h" -#include <common.h> -#include <sqlExceptions.h>  #include "sqlBinder.h"  #include "sqlCommon.h" +#include "sqlInsertSerializer.h" +#include <boost/numeric/conversion/cast.hpp> +#include <common.h>  #include <compileTimeFormatter.h> +#include <functional>  #include <modifycommand.h>  #include <slicer/metadata.h> -#include <boost/numeric/conversion/cast.hpp> -#include <functional> +#include <sqlExceptions.h> +#include <type_traits>  namespace Slicer {  	using namespace std::placeholders;  	SqlInsertSerializer::SqlInsertSerializer(DB::Connection * const c, std::string t) : -		connection(c), -		tableName(std::move(t)) +		connection(c), tableName(std::move(t))  	{  	} @@ -22,11 +22,15 @@ namespace Slicer {  	SqlInsertSerializer::Serialize(Slicer::ModelPartForRootPtr mp)  	{  		switch (mp->GetType()) { -			case Slicer::mpt_Sequence: -				mp->OnEachChild(std::bind(&SqlInsertSerializer::SerializeSequence, this, _2)); +			case Slicer::ModelPartType::Sequence: +				mp->OnEachChild([this](auto &&, auto && PH2, auto &&) { +					SerializeSequence(PH2); +				});  				return; -			case Slicer::mpt_Complex: -				mp->OnEachChild(std::bind(&SqlInsertSerializer::SerializeObject, this, _2)); +			case Slicer::ModelPartType::Complex: +				mp->OnEachChild([this](auto &&, auto && PH2, auto &&) { +					SerializeObject(PH2); +				});  				return;  			default:  				throw UnsupportedModelType(); @@ -45,45 +49,52 @@ namespace Slicer {  	{  		auto ins = createInsert(mp->GetContainedModelPart());  		mp->OnEachChild([&ins, this](const std::string &, const ModelPartPtr & cmp, const HookCommon *) { -				bindObjectAndExecute(cmp, ins.get()); -			}); +			bindObjectAndExecute(cmp, ins.get()); +		});  	}  	void  	SqlInsertSerializer::bindObjectAndExecute(const Slicer::ModelPartPtr & cmp, DB::ModifyCommand * ins) const  	{  		int paramNo = 0; -		cmp->OnEachChild(std::bind(&SqlInsertSerializer::bindObjectAndExecuteField, this, std::ref(paramNo), ins, _2, _3)); +		cmp->OnEachChild([this, ¶mNo, ins](auto &&, auto && PH2, auto && PH3) { +			bindObjectAndExecuteField(paramNo, ins, PH2, PH3); +		});  		ins->execute();  	}  	class IdSave : public Slicer::ValueSource { -		public: -			explicit IdSave(DB::Connection * const c) : -				connection(c) -			{ -			} - -#define NonNumType(T) \ -			/* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \ -			void set(T &) const override { throw UnsuitableIdFieldType(#T); } +	public: +		explicit IdSave(DB::Connection * const c) : connection(c) { }  #define NumType(T) \ -			/* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \ -			void set(T & v) const override { v = boost::numeric_cast<T>(connection->insertId()); } - -			NonNumType(bool); -			NonNumType(std::string); - -			NumType(Ice::Byte); -			NumType(Ice::Short); -			NumType(Ice::Int); -			NumType(Ice::Long); -			NumType(Ice::Float); -			NumType(Ice::Double); +	void set(T & v) const override \ +	{ \ +		doSet(v, #T); \ +	} -		private: -			DB::Connection * const connection; +		NumType(bool); +		NumType(std::string); +		NumType(Ice::Byte); +		NumType(Ice::Short); +		NumType(Ice::Int); +		NumType(Ice::Long); +		NumType(Ice::Float); +		NumType(Ice::Double); + +	private: +		DB::Connection * const connection; +		template<typename T> +		inline void +		doSet([[maybe_unused]] T & v, [[maybe_unused]] const char * Tname) const +		{ +			if constexpr (std::is_integral_v<T>) { +				v = boost::numeric_cast<T>(connection->insertId()); +			} +			else { +				throw UnsuitableIdFieldType(Tname); +			} +		}  	};  	void @@ -98,7 +109,8 @@ namespace Slicer {  	}  	void -	SqlInsertSerializer::bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand * ins, const Slicer::ModelPartPtr & cmp, const HookCommon * h) const +	SqlInsertSerializer::bindObjectAndExecuteField( +			int & paramNo, DB::ModifyCommand * ins, const Slicer::ModelPartPtr & cmp, const HookCommon * h) const  	{  		if (isBind(h)) {  			if (!cmp->GetValue(SqlBinder(*ins, paramNo))) { @@ -109,7 +121,8 @@ namespace Slicer {  	}  	void -	SqlAutoIdInsertSerializer::bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand * ins, const Slicer::ModelPartPtr & cmp, const HookCommon * h) const +	SqlAutoIdInsertSerializer::bindObjectAndExecuteField( +			int & paramNo, DB::ModifyCommand * ins, const Slicer::ModelPartPtr & cmp, const HookCommon * h) const  	{  		if (isNotAuto(h)) {  			SqlInsertSerializer::bindObjectAndExecuteField(paramNo, ins, cmp, h); @@ -123,7 +136,9 @@ namespace Slicer {  		std::stringstream insert;  		"INSERT INTO %?("_fmt(insert, tableName);  		int fieldNo = 0; -		mp->OnEachChild(std::bind(&SqlInsertSerializer::createInsertField, this, std::ref(fieldNo), std::ref(insert), _1, _3)); +		mp->OnEachChild([this, &fieldNo, &insert](auto && PH1, auto &&, auto && PH3) { +			createInsertField(fieldNo, insert, PH1, PH3); +		});  		insert << ") VALUES (";  		for (; fieldNo > 1; --fieldNo) {  			insert << "?, "; @@ -133,7 +148,8 @@ namespace Slicer {  	}  	void -	SqlInsertSerializer::createInsertField(int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const +	SqlInsertSerializer::createInsertField( +			int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const  	{  		if (isBind(h)) {  			if (fieldNo++) { @@ -144,7 +160,8 @@ namespace Slicer {  	}  	void -	SqlAutoIdInsertSerializer::createInsertField(int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const +	SqlAutoIdInsertSerializer::createInsertField( +			int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const  	{  		if (isNotAuto(h)) {  			if (fieldNo++) { @@ -154,4 +171,3 @@ namespace Slicer {  		}  	}  } - diff --git a/slicer/db/sqlInsertSerializer.h b/slicer/db/sqlInsertSerializer.h index 175706f..6150d66 100644 --- a/slicer/db/sqlInsertSerializer.h +++ b/slicer/db/sqlInsertSerializer.h @@ -1,49 +1,50 @@  #ifndef SLICER_DB_SQLINSERTSERIALIZER_H  #define SLICER_DB_SQLINSERTSERIALIZER_H -#include <slicer/serializer.h>  #include <connection.h> -#include <visibility.h>  #include <ostream> +#include <slicer/serializer.h> +#include <visibility.h>  namespace Slicer {  	class DLL_PUBLIC SqlInsertSerializer : public Slicer::Serializer { -		public: -			SqlInsertSerializer(DB::Connection * const, std::string tableName); - -			void Serialize(Slicer::ModelPartForRootPtr) override; - -		protected: -			void SerializeObject(const Slicer::ModelPartPtr &) const; -			void SerializeSequence(const Slicer::ModelPartPtr &) const; -			DB::ModifyCommandPtr createInsert(const Slicer::ModelPartPtr &) const; -			virtual void createInsertField(int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const; -			virtual void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *) const; -			virtual void bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const; - -			DB::Connection * const connection; -			const std::string tableName; +	public: +		SqlInsertSerializer(DB::Connection * const, std::string tableName); + +		void Serialize(Slicer::ModelPartForRootPtr) override; + +	protected: +		void SerializeObject(const Slicer::ModelPartPtr &) const; +		void SerializeSequence(const Slicer::ModelPartPtr &) const; +		DB::ModifyCommandPtr createInsert(const Slicer::ModelPartPtr &) const; +		virtual void createInsertField( +				int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const; +		virtual void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *) const; +		virtual void bindObjectAndExecuteField( +				int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const; + +		DB::Connection * const connection; +		const std::string tableName;  	};  	class DLL_PUBLIC SqlAutoIdInsertSerializer : public SqlInsertSerializer { -		public: -			template <typename ... P> -			SqlAutoIdInsertSerializer(const P & ... p) : SqlInsertSerializer(p...) { } - -		protected: -			virtual void createInsertField(int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const; -			virtual void bindObjectAndExecuteField(int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const; +	public: +		template<typename... P> SqlAutoIdInsertSerializer(const P &... p) : SqlInsertSerializer(p...) { } + +	protected: +		virtual void createInsertField( +				int & fieldNo, std::ostream & insert, const std::string & name, const HookCommon * h) const; +		virtual void bindObjectAndExecuteField( +				int & paramNo, DB::ModifyCommand *, const Slicer::ModelPartPtr &, const HookCommon *) const;  	};  	class DLL_PUBLIC SqlFetchIdInsertSerializer : public SqlAutoIdInsertSerializer { -		public: -			template <typename ... P> -			SqlFetchIdInsertSerializer(const P & ... p) : SqlAutoIdInsertSerializer(p...) { } +	public: +		template<typename... P> SqlFetchIdInsertSerializer(const P &... p) : SqlAutoIdInsertSerializer(p...) { } -		protected: -			virtual void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *) const; +	protected: +		virtual void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *) const;  	};  }  #endif - diff --git a/slicer/db/sqlSelectDeserializer.cpp b/slicer/db/sqlSelectDeserializer.cpp index ff16c43..8982958 100644 --- a/slicer/db/sqlSelectDeserializer.cpp +++ b/slicer/db/sqlSelectDeserializer.cpp @@ -1,13 +1,11 @@  #include "sqlSelectDeserializer.h"  #include "sqlSource.h" -#include <sqlExceptions.h>  #include <common.h> +#include <sqlExceptions.h>  namespace Slicer {  	SqlSelectDeserializer::SqlSelectDeserializer(DB::SelectCommand * c, Ice::optional<std::string> tc) : -		cmd(c), -		columnCount(0), -		typeIdColName(std::move(tc)) +		cmd(c), columnCount(0), typeIdColName(std::move(tc))  	{  	} @@ -20,13 +18,13 @@ namespace Slicer {  			typeIdColIdx = cmd->getOrdinal(*typeIdColName);  		}  		switch (mp->GetType()) { -			case Slicer::mpt_Sequence: +			case Slicer::ModelPartType::Sequence:  				DeserializeSequence(mp);  				return; -			case Slicer::mpt_Complex: +			case Slicer::ModelPartType::Complex:  				DeserializeObject(mp);  				return; -			case Slicer::mpt_Simple: +			case Slicer::ModelPartType::Simple:  				DeserializeSimple(mp);  				return;  			default: @@ -74,7 +72,7 @@ namespace Slicer {  		}  		DeserializeRow(mp);  		if (cmd->fetch()) { -			while (cmd->fetch()) {} +			while (cmd->fetch()) { }  			throw TooManyRowsReturned();  		}  	} @@ -85,43 +83,38 @@ namespace Slicer {  		auto rmp = mp->GetAnonChild();  		if (rmp) {  			switch (rmp->GetType()) { -				case Slicer::mpt_Complex: -					{ -						if (typeIdColIdx) { -							std::string subclass; -							(*cmd)[*typeIdColIdx] >> subclass; -							rmp = rmp->GetSubclassModelPart(subclass); -						} -						rmp->Create(); -						for (auto col = 0U; col < columnCount; col += 1) { -							const DB::Column & c = (*cmd)[col]; -							if (!c.isNull()) { -								auto fmpr = rmp->GetChildRef(c.name, nullptr, false); -								if (fmpr) { -									auto fmp = fmpr.Child(); -									fmp->Create(); -									fmp->SetValue(SqlSource(c)); -									fmp->Complete(); -								} -							} -						} -						rmp->Complete(); +				case Slicer::ModelPartType::Complex: { +					if (typeIdColIdx) { +						std::string subclass; +						(*cmd)[*typeIdColIdx] >> subclass; +						rmp = rmp->GetSubclassModelPart(subclass);  					} -					break; -				case Slicer::mpt_Simple: -					{ -						rmp->Create(); -						const DB::Column & c = (*cmd)[0]; +					rmp->Create(); +					for (auto col = 0U; col < columnCount; col += 1) { +						const DB::Column & c = (*cmd)[col];  						if (!c.isNull()) { -							rmp->SetValue(SqlSource(c)); +							auto fmpr = rmp->GetChildRef(c.name, nullptr, false); +							if (fmpr) { +								auto fmp = fmpr.Child(); +								fmp->Create(); +								fmp->SetValue(SqlSource(c)); +								fmp->Complete(); +							}  						} -						rmp->Complete();  					} -					break; +					rmp->Complete(); +				} break; +				case Slicer::ModelPartType::Simple: { +					rmp->Create(); +					const DB::Column & c = (*cmd)[0]; +					if (!c.isNull()) { +						rmp->SetValue(SqlSource(c)); +					} +					rmp->Complete(); +				} break;  				default:  					throw UnsupportedModelType();  			}  		}  	}  } - diff --git a/slicer/db/sqlSelectDeserializer.h b/slicer/db/sqlSelectDeserializer.h index e9afd1d..5f34ef4 100644 --- a/slicer/db/sqlSelectDeserializer.h +++ b/slicer/db/sqlSelectDeserializer.h @@ -1,29 +1,28 @@  #ifndef SLICER_DB_SQLSELECTDESERIALIZER_H  #define SLICER_DB_SQLSELECTDESERIALIZER_H -#include <slicer/serializer.h>  #include <selectcommand.h> +#include <slicer/serializer.h>  #include <visibility.h>  namespace Slicer {  	class DLL_PUBLIC SqlSelectDeserializer : public Slicer::Deserializer { -		public: -			SqlSelectDeserializer(DB::SelectCommand *, Ice::optional<std::string> typeIdCol = Ice::optional<std::string>()); +	public: +		SqlSelectDeserializer(DB::SelectCommand *, Ice::optional<std::string> typeIdCol = Ice::optional<std::string>()); -			void Deserialize(Slicer::ModelPartForRootPtr) override; +		void Deserialize(Slicer::ModelPartForRootPtr) override; -		protected: -			void DLL_PRIVATE DeserializeSimple(const Slicer::ModelPartPtr &); -			void DLL_PRIVATE DeserializeObject(const Slicer::ModelPartPtr &); -			void DLL_PRIVATE DeserializeSequence(const Slicer::ModelPartPtr &); -			void DLL_PRIVATE DeserializeRow(const Slicer::ModelPartPtr &); +	protected: +		void DLL_PRIVATE DeserializeSimple(const Slicer::ModelPartPtr &); +		void DLL_PRIVATE DeserializeObject(const Slicer::ModelPartPtr &); +		void DLL_PRIVATE DeserializeSequence(const Slicer::ModelPartPtr &); +		void DLL_PRIVATE DeserializeRow(const Slicer::ModelPartPtr &); -			DB::SelectCommand * cmd; -			unsigned int columnCount; -			Ice::optional<std::string> typeIdColName; -			Ice::optional<unsigned int> typeIdColIdx; +		DB::SelectCommand * cmd; +		unsigned int columnCount; +		Ice::optional<std::string> typeIdColName; +		Ice::optional<unsigned int> typeIdColIdx;  	};  }  #endif - diff --git a/slicer/db/sqlSource.cpp b/slicer/db/sqlSource.cpp index eeea99c..84964f2 100644 --- a/slicer/db/sqlSource.cpp +++ b/slicer/db/sqlSource.cpp @@ -2,10 +2,7 @@  #include <boost/numeric/conversion/cast.hpp>  namespace Slicer { -	SqlSource::SqlSource(const DB::Column & c) : -		column(c) -	{ -	} +	SqlSource::SqlSource(const DB::Column & c) : column(c) { }  	bool  	SqlSource::isNull() const @@ -83,4 +80,3 @@ namespace Slicer {  		column >> b;  	}  } - diff --git a/slicer/db/sqlSource.h b/slicer/db/sqlSource.h index 99ffabb..548f35e 100644 --- a/slicer/db/sqlSource.h +++ b/slicer/db/sqlSource.h @@ -1,35 +1,34 @@  #ifndef SLICER_DB_SQLSOURCE_H  #define SLICER_DB_SQLSOURCE_H -#include <slicer/modelParts.h> -#include <column.h>  #include <boost/date_time/posix_time/ptime.hpp> +#include <column.h> +#include <slicer/modelParts.h>  namespace Slicer { -	class SqlSource : public Slicer::ValueSource, -			public Slicer::TValueSource<boost::posix_time::time_duration>, -			public Slicer::TValueSource<boost::posix_time::ptime> -	{ -		public: -			SqlSource(const DB::Column & c); +	class SqlSource : +		public Slicer::ValueSource, +		public Slicer::TValueSource<boost::posix_time::time_duration>, +		public Slicer::TValueSource<boost::posix_time::ptime> { +	public: +		SqlSource(const DB::Column & c); -			bool isNull() const; -			void set(boost::posix_time::ptime & b) const override; -			void set(boost::posix_time::time_duration & b) const override; -			void set(bool & b) const override; -			void set(Ice::Byte & b) const override; -			void set(Ice::Short & b) const override; -			void set(Ice::Int & b) const override; -			void set(Ice::Long & b) const override; -			void set(Ice::Float & b) const override; -			void set(Ice::Double & b) const override; -			void set(std::string & b) const override; +		bool isNull() const; +		void set(boost::posix_time::ptime & b) const override; +		void set(boost::posix_time::time_duration & b) const override; +		void set(bool & b) const override; +		void set(Ice::Byte & b) const override; +		void set(Ice::Short & b) const override; +		void set(Ice::Int & b) const override; +		void set(Ice::Long & b) const override; +		void set(Ice::Float & b) const override; +		void set(Ice::Double & b) const override; +		void set(std::string & b) const override; -		private: -			const DB::Column & column; +	private: +		const DB::Column & column;  	};  	typedef std::shared_ptr<SqlSource> SqlSourcePtr;  }  #endif - diff --git a/slicer/db/sqlTablePatchSerializer.cpp b/slicer/db/sqlTablePatchSerializer.cpp index ec5b59b..7c29be5 100644 --- a/slicer/db/sqlTablePatchSerializer.cpp +++ b/slicer/db/sqlTablePatchSerializer.cpp @@ -1,16 +1,15 @@ -#include "sqlTablePatchSerializer.h" -#include "sqlInsertSerializer.h"  #include "sqlCommon.h" -#include <slicer/metadata.h> +#include "sqlInsertSerializer.h" +#include "sqlTablePatchSerializer.h"  #include <compileTimeFormatter.h> -#include <scopeExit.h>  #include <functional> +#include <scopeExit.h> +#include <slicer/metadata.h>  namespace Slicer {  	AdHocFormatter(ttname, "slicer_tmp_%?");  	SqlTablePatchSerializer::SqlTablePatchSerializer(DB::Connection * const db, DB::TablePatch & tp) : -		db(db), -		tablePatch(tp) +		db(db), tablePatch(tp)  	{  		tablePatch.src = ttname::get(this);  	} @@ -22,7 +21,9 @@ namespace Slicer {  		tablePatch.cols.clear();  		createTemporaryTable(); -		AdHoc::ScopeExit tidy(std::bind(&SqlTablePatchSerializer::dropTemporaryTable, this)); +		AdHoc::ScopeExit tidy([this] { +			dropTemporaryTable(); +		});  		SqlInsertSerializer ins(db, tablePatch.src);  		ins.Serialize(mpr); @@ -56,4 +57,3 @@ namespace Slicer {  		db->execute(dropTmpTable::get(tablePatch.src));  	}  } - diff --git a/slicer/db/sqlTablePatchSerializer.h b/slicer/db/sqlTablePatchSerializer.h index 00ea328..9a82f85 100644 --- a/slicer/db/sqlTablePatchSerializer.h +++ b/slicer/db/sqlTablePatchSerializer.h @@ -6,19 +6,18 @@  namespace Slicer {  	class DLL_PUBLIC SqlTablePatchSerializer : public Slicer::Serializer { -		public: -			SqlTablePatchSerializer(DB::Connection * const, DB::TablePatch &); +	public: +		SqlTablePatchSerializer(DB::Connection * const, DB::TablePatch &); -			void Serialize(Slicer::ModelPartForRootPtr) override; +		void Serialize(Slicer::ModelPartForRootPtr) override; -		private: -			void createTemporaryTable(); -			void dropTemporaryTable(); +	private: +		void createTemporaryTable(); +		void dropTemporaryTable(); -			DB::Connection * const db; -			DB::TablePatch & tablePatch; +		DB::Connection * const db; +		DB::TablePatch & tablePatch;  	};  }  #endif - diff --git a/slicer/db/sqlUpdateSerializer.cpp b/slicer/db/sqlUpdateSerializer.cpp index 64ff1a0..29d9da7 100644 --- a/slicer/db/sqlUpdateSerializer.cpp +++ b/slicer/db/sqlUpdateSerializer.cpp @@ -1,19 +1,18 @@ -#include "sqlUpdateSerializer.h" -#include <sqlExceptions.h> -#include <common.h>  #include "sqlBinder.h"  #include "sqlCommon.h" +#include "sqlUpdateSerializer.h" +#include <common.h>  #include <compileTimeFormatter.h> +#include <functional>  #include <modifycommand.h>  #include <slicer/metadata.h> -#include <functional> +#include <sqlExceptions.h>  namespace Slicer {  	using namespace std::placeholders;  	SqlUpdateSerializer::SqlUpdateSerializer(DB::Connection * const c, std::string t) : -		connection(c), -		tableName(std::move(t)) +		connection(c), tableName(std::move(t))  	{  	} @@ -21,11 +20,15 @@ namespace Slicer {  	SqlUpdateSerializer::Serialize(Slicer::ModelPartForRootPtr mp)  	{  		switch (mp->GetType()) { -			case Slicer::mpt_Sequence: -				mp->OnEachChild(std::bind(&SqlUpdateSerializer::SerializeSequence, this, _2)); +			case Slicer::ModelPartType::Sequence: +				mp->OnEachChild([this](auto &&, auto && PH2, auto &&) { +					SerializeSequence(PH2); +				});  				return; -			case Slicer::mpt_Complex: -				mp->OnEachChild(std::bind(&SqlUpdateSerializer::SerializeObject, this, _2)); +			case Slicer::ModelPartType::Complex: +				mp->OnEachChild([this](auto &&, auto && PH2, auto &&) { +					SerializeObject(PH2); +				});  				return;  			default:  				throw UnsupportedModelType(); @@ -44,8 +47,8 @@ namespace Slicer {  	{  		auto ins = createUpdate(mp->GetContainedModelPart());  		mp->OnEachChild([&ins](const std::string &, const ModelPartPtr & cmp, const HookCommon *) { -				bindObjectAndExecute(cmp, ins.get()); -			}); +			bindObjectAndExecute(cmp, ins.get()); +		});  	}  	void @@ -77,7 +80,7 @@ namespace Slicer {  		std::stringstream update;  		"UPDATE %? SET "_fmt(update, tableName);  		int fieldNo = 0; -		mp->OnEachChild([&update, &fieldNo]( const std::string & name, const ModelPartPtr &, const HookCommon * h) { +		mp->OnEachChild([&update, &fieldNo](const std::string & name, const ModelPartPtr &, const HookCommon * h) {  			if (isValue(h)) {  				if (fieldNo++) {  					update << ", "; @@ -87,7 +90,7 @@ namespace Slicer {  		});  		update << " WHERE ";  		fieldNo = 0; -		mp->OnEachChild([&update, &fieldNo]( const std::string & name, const ModelPartPtr &, const HookCommon * h) { +		mp->OnEachChild([&update, &fieldNo](const std::string & name, const ModelPartPtr &, const HookCommon * h) {  			if (isPKey(h)) {  				if (fieldNo++) {  					update << " AND "; @@ -98,4 +101,3 @@ namespace Slicer {  		return connection->modify(update.str());  	}  } - diff --git a/slicer/db/sqlUpdateSerializer.h b/slicer/db/sqlUpdateSerializer.h index a3462f8..e82015b 100644 --- a/slicer/db/sqlUpdateSerializer.h +++ b/slicer/db/sqlUpdateSerializer.h @@ -1,27 +1,26 @@  #ifndef SLICER_DB_SQLUPDATESERIALIZER_H  #define SLICER_DB_SQLUPDATESERIALIZER_H -#include <slicer/serializer.h>  #include <connection.h> +#include <slicer/serializer.h>  #include <visibility.h>  namespace Slicer {  	class DLL_PUBLIC SqlUpdateSerializer : public Slicer::Serializer { -		public: -			SqlUpdateSerializer(DB::Connection * const, std::string tableName); +	public: +		SqlUpdateSerializer(DB::Connection * const, std::string tableName); -			void Serialize(Slicer::ModelPartForRootPtr) override; +		void Serialize(Slicer::ModelPartForRootPtr) override; -		protected: -			void SerializeObject(const Slicer::ModelPartPtr &) const; -			void SerializeSequence(const Slicer::ModelPartPtr &) const; -			DB::ModifyCommandPtr createUpdate(const Slicer::ModelPartPtr &) const; -			static void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *); +	protected: +		void SerializeObject(const Slicer::ModelPartPtr &) const; +		void SerializeSequence(const Slicer::ModelPartPtr &) const; +		DB::ModifyCommandPtr createUpdate(const Slicer::ModelPartPtr &) const; +		static void bindObjectAndExecute(const Slicer::ModelPartPtr &, DB::ModifyCommand *); -			DB::Connection * const connection; -			const std::string tableName; +		DB::Connection * const connection; +		const std::string tableName;  	};  }  #endif - diff --git a/slicer/db/testConversions.cpp b/slicer/db/testConversions.cpp index d19f309..68de17a 100644 --- a/slicer/db/testConversions.cpp +++ b/slicer/db/testConversions.cpp @@ -1,16 +1,17 @@ -#include <testModels.h>  #include <boost/date_time/posix_time/posix_time_types.hpp>  #include <boost/numeric/conversion/cast.hpp> +#include <testModels.h>  #include <visibility.h> -#define SHORT(x) boost::numeric_cast< ::Ice::Short , int64_t >(x) +#define SHORT(x) boost::numeric_cast<::Ice::Short, int64_t>(x)  namespace Slicer {  	DLL_PUBLIC  	::TestDatabase::TimespanPtr  	timedurationToTimespan(const boost::posix_time::time_duration & td)  	{ -		return std::make_shared<::TestDatabase::Timespan>(SHORT(td.hours() / 24), SHORT(td.hours() % 24), SHORT(td.minutes()), SHORT(td.seconds())); +		return std::make_shared<::TestDatabase::Timespan>( +				SHORT(td.hours() / 24), SHORT(td.hours() % 24), SHORT(td.minutes()), SHORT(td.seconds()));  	}  	DLL_PUBLIC @@ -20,4 +21,3 @@ namespace Slicer {  		return boost::posix_time::time_duration((ts->days * 24) + ts->hours, ts->minutes, ts->seconds);  	}  } - diff --git a/slicer/db/testInsert.cpp b/slicer/db/testInsert.cpp index 3724679..6bc6acd 100644 --- a/slicer/db/testInsert.cpp +++ b/slicer/db/testInsert.cpp @@ -1,13 +1,13 @@  #define BOOST_TEST_MODULE db_insert -#include <boost/test/unit_test.hpp> -#include <boost/date_time/posix_time/posix_time_io.hpp> -#include "testMockCommon.h" -#include <slicer/slicer.h>  #include "sqlInsertSerializer.h"  #include "sqlSelectDeserializer.h" -#include <types.h> +#include "testMockCommon.h" +#include <boost/date_time/posix_time/posix_time_io.hpp> +#include <boost/test/unit_test.hpp>  #include <common.h> +#include <slicer/slicer.h>  #include <testModels.h> +#include <types.h>  using namespace std::literals; @@ -19,16 +19,18 @@ BOOST_TEST_DONT_PRINT_LOG_VALUE(TestDatabase::Timespan);  namespace std {  	template<typename T> -	ostream & operator<<(ostream & s, const Ice::optional<T> &) { +	ostream & +	operator<<(ostream & s, const Ice::optional<T> &) +	{  		return s;  	}  } -BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); +BOOST_GLOBAL_FIXTURE(StandardMockDatabase);  BOOST_FIXTURE_TEST_SUITE(db, ConnectionFixture); -BOOST_AUTO_TEST_CASE( insert_builtins ) +BOOST_AUTO_TEST_CASE(insert_builtins)  {  	TestModule::BuiltInsPtr bi = std::make_shared<TestModule::BuiltIns>(true, 4, 16, 64, 128, 1.2, 3.4, "text");  	Slicer::SerializeAny<Slicer::SqlInsertSerializer>(bi, db, "builtins"); @@ -44,12 +46,10 @@ BOOST_AUTO_TEST_CASE( insert_builtins )  	BOOST_REQUIRE_EQUAL(bi->mstring, bi2->mstring);  } -BOOST_AUTO_TEST_CASE( insert_seq_builtins ) +BOOST_AUTO_TEST_CASE(insert_seq_builtins)  { -	TestModule::BuiltInSeq bis = { -		std::make_shared<TestModule::BuiltIns>(true, 5, 17, 65, 129, 2.3, 4.5, "more text"), -		std::make_shared<TestModule::BuiltIns>(true, 6, 18, 66, 130, 3.4, 5.6, "even more text") -	}; +	TestModule::BuiltInSeq bis = {std::make_shared<TestModule::BuiltIns>(true, 5, 17, 65, 129, 2.3, 4.5, "more text"), +			std::make_shared<TestModule::BuiltIns>(true, 6, 18, 66, 130, 3.4, 5.6, "even more text")};  	Slicer::SerializeAny<Slicer::SqlInsertSerializer>(bis, db, "builtins");  	auto sel = db->select("SELECT * FROM builtins ORDER BY mint");  	auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(sel.get()); @@ -64,12 +64,10 @@ BOOST_AUTO_TEST_CASE( insert_seq_builtins )  	BOOST_REQUIRE_EQUAL(bis.back()->mstring, bis2.back()->mstring);  } -BOOST_AUTO_TEST_CASE( autoinsert_seq_builtins ) +BOOST_AUTO_TEST_CASE(autoinsert_seq_builtins)  { -	TestModule::BuiltInSeq bis = { -		std::make_shared<TestModule::BuiltIns>(true, 5, 17, 0, 129, 2.3, 4.5, "more text"), -		std::make_shared<TestModule::BuiltIns>(true, 6, 18, 0, 130, 3.4, 5.6, "even more text") -	}; +	TestModule::BuiltInSeq bis = {std::make_shared<TestModule::BuiltIns>(true, 5, 17, 0, 129, 2.3, 4.5, "more text"), +			std::make_shared<TestModule::BuiltIns>(true, 6, 18, 0, 130, 3.4, 5.6, "even more text")};  	Slicer::SerializeAny<Slicer::SqlAutoIdInsertSerializer>(bis, db, "builtins");  	auto sel = db->select("SELECT * FROM builtins WHERE mint IN (1, 2) ORDER BY mint");  	auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(sel.get()); @@ -87,12 +85,10 @@ BOOST_AUTO_TEST_CASE( autoinsert_seq_builtins )  	BOOST_REQUIRE_EQUAL(bis.back()->mstring, bis2.back()->mstring);  } -BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtins ) +BOOST_AUTO_TEST_CASE(fetchinsert_seq_builtins)  { -	TestModule::BuiltInSeq bis = { -		std::make_shared<TestModule::BuiltIns>(true, 5, 17, 0, 129, 2.3, 4.5, "more text"), -		std::make_shared<TestModule::BuiltIns>(true, 6, 18, 0, 130, 3.4, 5.6, "even more text") -	}; +	TestModule::BuiltInSeq bis = {std::make_shared<TestModule::BuiltIns>(true, 5, 17, 0, 129, 2.3, 4.5, "more text"), +			std::make_shared<TestModule::BuiltIns>(true, 6, 18, 0, 130, 3.4, 5.6, "even more text")};  	Slicer::SerializeAny<Slicer::SqlFetchIdInsertSerializer>(bis, db, "builtins");  	auto sel = db->select("SELECT * FROM builtins WHERE mint IN (3, 4) ORDER BY mint");  	auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BuiltInSeq>(sel.get()); @@ -110,12 +106,11 @@ BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtins )  	BOOST_REQUIRE_EQUAL(bis.back()->mstring, bis2.back()->mstring);  } -BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtinsWithNulls ) +BOOST_AUTO_TEST_CASE(fetchinsert_seq_builtinsWithNulls)  {  	TestDatabase::BuiltInSeq bis = { -		std::make_shared<TestDatabase::BuiltIns>(true, IceUtil::None, 17, 0, 129, 2.3, 4.5, "more text"s), -		std::make_shared<TestDatabase::BuiltIns>(true, 6, 18, 0, 130, 3.4, IceUtil::None, "even more text"s) -	}; +			std::make_shared<TestDatabase::BuiltIns>(true, IceUtil::None, 17, 0, 129, 2.3, 4.5, "more text"s), +			std::make_shared<TestDatabase::BuiltIns>(true, 6, 18, 0, 130, 3.4, IceUtil::None, "even more text"s)};  	Slicer::SerializeAny<Slicer::SqlFetchIdInsertSerializer>(bis, db, "builtins");  	auto sel = db->select("SELECT * FROM builtins WHERE mint IN (5, 6) ORDER BY mint");  	auto bis2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(sel.get()); @@ -133,13 +128,11 @@ BOOST_AUTO_TEST_CASE( fetchinsert_seq_builtinsWithNulls )  	BOOST_REQUIRE_EQUAL(bis.back()->mstring, bis2.back()->mstring);  } -BOOST_AUTO_TEST_CASE( insert_converted ) +BOOST_AUTO_TEST_CASE(insert_converted)  { -	TestDatabase::SpecificTypesPtr st = std::make_shared<TestDatabase::SpecificTypes>( -		TestModule::DateTime {2015, 10, 16, 19, 12, 34}, -		TestModule::IsoDate {2015, 10, 16}, -		std::make_shared<TestDatabase::Timespan>(1, 2, 3, 4) -	); +	TestDatabase::SpecificTypesPtr st +			= std::make_shared<TestDatabase::SpecificTypes>(TestModule::DateTime {2015, 10, 16, 19, 12, 34}, +					TestModule::IsoDate {2015, 10, 16}, std::make_shared<TestDatabase::Timespan>(1, 2, 3, 4));  	Slicer::SerializeAny<Slicer::SqlInsertSerializer>(st, db, "converted");  	auto sel = db->select("SELECT * FROM converted");  	auto st2 = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::SpecificTypesPtr>(sel.get()); @@ -151,11 +144,11 @@ BOOST_AUTO_TEST_CASE( insert_converted )  	BOOST_REQUIRE_EQUAL(st->ts->seconds, st2->ts->seconds);  } -BOOST_AUTO_TEST_CASE( insert_unsupportedModel ) +BOOST_AUTO_TEST_CASE(insert_unsupportedModel)  {  	TestModule::ClassMap cm; -	BOOST_REQUIRE_THROW(Slicer::SerializeAny<Slicer::SqlInsertSerializer>(cm, db, "converted"), Slicer::UnsupportedModelType); +	BOOST_REQUIRE_THROW( +			Slicer::SerializeAny<Slicer::SqlInsertSerializer>(cm, db, "converted"), Slicer::UnsupportedModelType);  }  BOOST_AUTO_TEST_SUITE_END(); - diff --git a/slicer/db/testMockCommon.cpp b/slicer/db/testMockCommon.cpp index ed18563..0d8c2c9 100644 --- a/slicer/db/testMockCommon.cpp +++ b/slicer/db/testMockCommon.cpp @@ -2,15 +2,8 @@  #include <definedDirs.h>  StandardMockDatabase::StandardMockDatabase() : -DB::PluginMock<PQ::Mock>("pqmock", { -		rootDir.parent_path() / "db" / "slicer.sql" }, -		"user=postgres dbname=postgres") -{ -} - -ConnectionFixture::ConnectionFixture() : -	_db(DB::MockDatabase::openConnectionTo("pqmock")), -	db(_db.get()) +	DB::PluginMock<PQ::Mock>("pqmock", {rootDir.parent_path() / "db" / "slicer.sql"}, "user=postgres dbname=postgres")  {  } +ConnectionFixture::ConnectionFixture() : _db(DB::MockDatabase::openConnectionTo("pqmock")), db(_db.get()) { } diff --git a/slicer/db/testMockCommon.h b/slicer/db/testMockCommon.h index bd9b11f..c775ae0 100644 --- a/slicer/db/testMockCommon.h +++ b/slicer/db/testMockCommon.h @@ -6,17 +6,16 @@  #include <visibility.h>  class DLL_PUBLIC StandardMockDatabase : public DB::PluginMock<PQ::Mock> { -	public: -		StandardMockDatabase(); +public: +	StandardMockDatabase();  };  class DLL_PUBLIC ConnectionFixture { -	public: -		ConnectionFixture(); +public: +	ConnectionFixture(); -		DB::ConnectionPtr _db; -		DB::Connection * const db; +	DB::ConnectionPtr _db; +	DB::Connection * const db;  };  #endif - diff --git a/slicer/db/testPatch.cpp b/slicer/db/testPatch.cpp index 2af60b4..70068e2 100644 --- a/slicer/db/testPatch.cpp +++ b/slicer/db/testPatch.cpp @@ -1,13 +1,13 @@  #define BOOST_TEST_MODULE db_patch -#include <boost/test/unit_test.hpp> -#include <boost/date_time/posix_time/posix_time_io.hpp> -#include "testMockCommon.h" -#include <slicer/slicer.h> -#include "sqlTablePatchSerializer.h"  #include "sqlSelectDeserializer.h" -#include <types.h> +#include "sqlTablePatchSerializer.h" +#include "testMockCommon.h" +#include <boost/date_time/posix_time/posix_time_io.hpp> +#include <boost/test/unit_test.hpp>  #include <common.h> +#include <slicer/slicer.h>  #include <testModels.h> +#include <types.h>  // LCOV_EXCL_START  BOOST_TEST_DONT_PRINT_LOG_VALUE(TestModule::DateTime); @@ -16,16 +16,14 @@ BOOST_TEST_DONT_PRINT_LOG_VALUE(TestDatabase::Timespan);  BOOST_TEST_DONT_PRINT_LOG_VALUE(DB::PrimaryKey);  // LCOV_EXCL_STOP -BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); +BOOST_GLOBAL_FIXTURE(StandardMockDatabase);  BOOST_FIXTURE_TEST_SUITE(db, ConnectionFixture); -BOOST_AUTO_TEST_CASE( insert_builtins ) +BOOST_AUTO_TEST_CASE(insert_builtins)  { -	TestModule::BuiltInSeq bis = { -		std::make_shared<TestModule::BuiltIns>(true, 5, 17, 0, 129, 2.3, 4.5, "more text"), -		std::make_shared<TestModule::BuiltIns>(true, 6, 18, 0, 130, 3.4, 5.6, "even more text") -	}; +	TestModule::BuiltInSeq bis = {std::make_shared<TestModule::BuiltIns>(true, 5, 17, 0, 129, 2.3, 4.5, "more text"), +			std::make_shared<TestModule::BuiltIns>(true, 6, 18, 0, 130, 3.4, 5.6, "even more text")};  	DB::TablePatch tp;  	DB::TransactionScope tx(*db);  	tp.dest = "builtins"; @@ -42,4 +40,3 @@ BOOST_AUTO_TEST_CASE( insert_builtins )  }  BOOST_AUTO_TEST_SUITE_END(); - diff --git a/slicer/db/testSelect.cpp b/slicer/db/testSelect.cpp index ce7821c..0e765f2 100644 --- a/slicer/db/testSelect.cpp +++ b/slicer/db/testSelect.cpp @@ -1,59 +1,58 @@  #define BOOST_TEST_MODULE db_select -#include <boost/test/unit_test.hpp> -#include <boost/date_time/posix_time/posix_time_io.hpp> -#include "testMockCommon.h" -#include <slicer/slicer.h>  #include "sqlSelectDeserializer.h" -#include <types.h> +#include "testMockCommon.h" +#include <boost/date_time/posix_time/posix_time_io.hpp> +#include <boost/test/unit_test.hpp>  #include <common.h> -#include <testModels.h> +#include <slicer/slicer.h>  #include <sqlExceptions.h> +#include <testModels.h> +#include <types.h>  using namespace std::literals; -BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); +BOOST_GLOBAL_FIXTURE(StandardMockDatabase);  BOOST_FIXTURE_TEST_SUITE(db, ConnectionFixture); -BOOST_AUTO_TEST_CASE( select_simple_int ) +BOOST_AUTO_TEST_CASE(select_simple_int)  {  	auto sel = db->select("SELECT MAX(id) FROM test");  	auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Ice::Int>(sel.get());  	BOOST_REQUIRE_EQUAL(4, bi);  } -BOOST_AUTO_TEST_CASE( select_simple_double ) +BOOST_AUTO_TEST_CASE(select_simple_double)  {  	auto sel = db->select("SELECT MAX(fl) FROM test");  	auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Ice::Double>(sel.get());  	BOOST_REQUIRE_CLOSE(1234.1234, bi, 0.0001);  } -BOOST_AUTO_TEST_CASE( select_simple_string ) +BOOST_AUTO_TEST_CASE(select_simple_string)  {  	auto sel = db->select("SELECT MAX(string) FROM test");  	auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, std::string>(sel.get());  	BOOST_REQUIRE_EQUAL("text two", bi);  } -BOOST_AUTO_TEST_CASE( select_simple_true ) +BOOST_AUTO_TEST_CASE(select_simple_true)  {  	auto sel = db->select("SELECT true");  	auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, bool>(sel.get());  	BOOST_REQUIRE_EQUAL(true, bi);  } -BOOST_AUTO_TEST_CASE( select_simple_false ) +BOOST_AUTO_TEST_CASE(select_simple_false)  {  	auto sel = db->select("SELECT NOT(true)");  	auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, bool>(sel.get());  	BOOST_REQUIRE_EQUAL(false, bi);  } -BOOST_AUTO_TEST_CASE( select_single ) +BOOST_AUTO_TEST_CASE(select_single)  { -	auto sel = db->select( -				"SELECT boolean mbool, \ +	auto sel = db->select("SELECT boolean mbool, \  				id mbyte, id mshort, id mint, id mlong, \  				fl mdouble, fl mfloat, \  				string mstring \ @@ -72,10 +71,9 @@ BOOST_AUTO_TEST_CASE( select_single )  	BOOST_REQUIRE_EQUAL("text one", bi->mstring);  } -BOOST_AUTO_TEST_CASE( select_inherit_single ) +BOOST_AUTO_TEST_CASE(select_inherit_single)  { -	auto sel = db->select( -				"SELECT id a, '::TestModule::D' || CAST(id AS TEXT) tc, 200 b, 300 c, 400 d \ +	auto sel = db->select("SELECT id a, '::TestModule::D' || CAST(id AS TEXT) tc, 200 b, 300 c, 400 d \  				FROM test \  				WHERE id = 2");  	auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BasePtr>(sel.get(), "tc"s); @@ -86,10 +84,9 @@ BOOST_AUTO_TEST_CASE( select_inherit_single )  	BOOST_REQUIRE_EQUAL(300, d2->c);  } -BOOST_AUTO_TEST_CASE( select_simple_sequence ) +BOOST_AUTO_TEST_CASE(select_simple_sequence)  { -	auto sel = db->select( -				"SELECT string \ +	auto sel = db->select("SELECT string \  				FROM test \  				ORDER BY id DESC");  	auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::SimpleSeq>(sel.get()); @@ -100,10 +97,9 @@ BOOST_AUTO_TEST_CASE( select_simple_sequence )  	BOOST_REQUIRE_EQUAL("text one", bi[3]);  } -BOOST_AUTO_TEST_CASE( select_inherit_sequence ) +BOOST_AUTO_TEST_CASE(select_inherit_sequence)  { -	auto sel = db->select( -				"SELECT id a, '::TestModule::D' || CAST(id AS TEXT) tc, 200 b, 300 c, 400 d \ +	auto sel = db->select("SELECT id a, '::TestModule::D' || CAST(id AS TEXT) tc, 200 b, 300 c, 400 d \  				FROM test \  				WHERE id < 4 \  				ORDER BY id DESC"); @@ -124,13 +120,13 @@ BOOST_AUTO_TEST_CASE( select_inherit_sequence )  	BOOST_REQUIRE_EQUAL(200, d1->b);  } -BOOST_AUTO_TEST_CASE( select_inherit_datetime ) +BOOST_AUTO_TEST_CASE(select_inherit_datetime)  { -	auto sel = db->select( -				"SELECT dt, to_char(dt, 'YYYY-MM-DD') date, ts \ +	auto sel = db->select("SELECT dt, to_char(dt, 'YYYY-MM-DD') date, ts \  				FROM test \  				WHERE id = 3"); -	TestDatabase::SpecificTypesPtr bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::SpecificTypesPtr>(sel.get()); +	TestDatabase::SpecificTypesPtr bi +			= Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::SpecificTypesPtr>(sel.get());  	BOOST_REQUIRE_EQUAL(2015, bi->dt.year);  	BOOST_REQUIRE_EQUAL(3, bi->dt.month);  	BOOST_REQUIRE_EQUAL(27, bi->dt.day); @@ -146,45 +142,45 @@ BOOST_AUTO_TEST_CASE( select_inherit_datetime )  	BOOST_REQUIRE_EQUAL(12, bi->ts->seconds);  } -template <typename T, typename ... P> +template<typename T, typename... P>  T -BoostThrowWrapperHelper(P && ... p) +BoostThrowWrapperHelper(P &&... p)  {  	return Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, T>(p...);  } -BOOST_AUTO_TEST_CASE( select_unsupportedModel ) +BOOST_AUTO_TEST_CASE(select_unsupportedModel)  {  	auto sel = db->select("SELECT id FROM test");  	BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<TestModule::ClassMap>(sel.get()), Slicer::UnsupportedModelType);  } -BOOST_AUTO_TEST_CASE( select_tooManyRowsSimple ) +BOOST_AUTO_TEST_CASE(select_tooManyRowsSimple)  {  	auto sel = db->select("SELECT id FROM test");  	BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::Int>(sel.get()), Slicer::TooManyRowsReturned);  } -BOOST_AUTO_TEST_CASE( select_noRowsSimple ) +BOOST_AUTO_TEST_CASE(select_noRowsSimple)  {  	auto sel = db->select("SELECT id FROM test WHERE false");  	BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::Int>(sel.get()), Slicer::NoRowsReturned);  } -BOOST_AUTO_TEST_CASE( select_noRowsSimpleOptional ) +BOOST_AUTO_TEST_CASE(select_noRowsSimpleOptional)  {  	auto sel = db->select("SELECT id FROM test WHERE false");  	auto v = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Ice::optional<Ice::Int>>(sel.get());  	BOOST_REQUIRE(!v);  } -BOOST_AUTO_TEST_CASE( select_tooManyRowsSimpleOptional ) +BOOST_AUTO_TEST_CASE(select_tooManyRowsSimpleOptional)  {  	auto sel = db->select("SELECT id FROM test");  	BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::optional<Ice::Int>>(sel.get()), Slicer::TooManyRowsReturned);  } -BOOST_AUTO_TEST_CASE( select_simpleOptional ) +BOOST_AUTO_TEST_CASE(select_simpleOptional)  {  	auto sel = db->select("SELECT MAX(id) FROM test");  	auto v = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Ice::optional<Ice::Int>>(sel.get()); @@ -192,10 +188,9 @@ BOOST_AUTO_TEST_CASE( select_simpleOptional )  	BOOST_REQUIRE_EQUAL(4, *v);  } -BOOST_AUTO_TEST_CASE( select_noRowsComplexOptional ) +BOOST_AUTO_TEST_CASE(select_noRowsComplexOptional)  { -	auto sel = db->select( -				"SELECT boolean mbool, \ +	auto sel = db->select("SELECT boolean mbool, \  				id mbyte, id mshort, id mint, id mlong, \  				fl mdouble, fl mfloat, \  				string mstring \ @@ -205,26 +200,26 @@ BOOST_AUTO_TEST_CASE( select_noRowsComplexOptional )  	BOOST_REQUIRE(!v);  } -BOOST_AUTO_TEST_CASE( select_tooManyRowsComplex ) +BOOST_AUTO_TEST_CASE(select_tooManyRowsComplex)  {  	auto sel = db->select("SELECT id FROM test");  	BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<TestModule::BuiltInsPtr>(sel.get()), Slicer::TooManyRowsReturned);  } -BOOST_AUTO_TEST_CASE( select_noRowsComplex ) +BOOST_AUTO_TEST_CASE(select_noRowsComplex)  {  	auto sel = db->select("SELECT id FROM test WHERE false");  	BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<TestModule::BuiltInsPtr>(sel.get()), Slicer::NoRowsReturned);  } -BOOST_AUTO_TEST_CASE( select_emptySequence ) +BOOST_AUTO_TEST_CASE(select_emptySequence)  {  	auto sel = db->select("SELECT id FROM test WHERE false");  	auto bi = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestModule::BaseSeq>(sel.get());  	BOOST_REQUIRE_EQUAL(0, bi.size());  } -BOOST_AUTO_TEST_CASE( select_null ) +BOOST_AUTO_TEST_CASE(select_null)  {  	db->execute("INSERT INTO test(id) VALUES(NULL)"); @@ -242,12 +237,12 @@ BOOST_AUTO_TEST_CASE( select_null )  	BOOST_REQUIRE(!v);  } -BOOST_AUTO_TEST_CASE( bulkSelectTest ) +BOOST_AUTO_TEST_CASE(bulkSelectTest)  { -	auto sel = db->select(R"SQL(select s mint, cast(s as numeric(7,1)) mdouble, cast(s as text) mstring, s % 2 = 0 mbool from generate_series(1, 10000) s)SQL"); +	auto sel = db->select( +			R"SQL(select s mint, cast(s as numeric(7,1)) mdouble, cast(s as text) mstring, s % 2 = 0 mbool from generate_series(1, 10000) s)SQL");  	auto vec = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(sel.get());  	BOOST_REQUIRE_EQUAL(10000, vec.size());  }  BOOST_AUTO_TEST_SUITE_END(); - diff --git a/slicer/db/testUpdate.cpp b/slicer/db/testUpdate.cpp index 48ea903..7dbcba3 100644 --- a/slicer/db/testUpdate.cpp +++ b/slicer/db/testUpdate.cpp @@ -1,29 +1,29 @@  #define BOOST_TEST_MODULE db_update -#include <boost/test/unit_test.hpp> -#include <boost/date_time/posix_time/posix_time_io.hpp> -#include "testMockCommon.h" -#include <slicer/slicer.h>  #include "sqlInsertSerializer.h"  #include "sqlSelectDeserializer.h"  #include "sqlUpdateSerializer.h" -#include <types.h> +#include "testMockCommon.h" +#include <boost/date_time/posix_time/posix_time_io.hpp> +#include <boost/test/unit_test.hpp>  #include <common.h> -#include <testModels.h> +#include <slicer/slicer.h>  #include <sqlExceptions.h> +#include <testModels.h> +#include <types.h>  using namespace std::literals; -BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); +BOOST_GLOBAL_FIXTURE(StandardMockDatabase);  BOOST_FIXTURE_TEST_SUITE(db, ConnectionFixture); -BOOST_AUTO_TEST_CASE( update_builtinsNotFound ) +BOOST_AUTO_TEST_CASE(update_builtinsNotFound)  {  	TestModule::BuiltInsPtr ubi = std::make_shared<TestModule::BuiltIns>(false, 5, 17, 64, 129, -1.2, -1.4, "string");  	BOOST_REQUIRE_THROW(Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(ubi, db, "builtins"), Slicer::NoRowsFound);  } -BOOST_AUTO_TEST_CASE( update_builtins ) +BOOST_AUTO_TEST_CASE(update_builtins)  {  	TestModule::BuiltInsPtr bi1 = std::make_shared<TestModule::BuiltIns>(true, 4, 16, 64, 128, 1.2, 3.4, "text1");  	TestModule::BuiltInsPtr bi2 = std::make_shared<TestModule::BuiltIns>(true, 3, 15, 63, 127, 5.2, 5.4, "text2"); @@ -54,12 +54,10 @@ BOOST_AUTO_TEST_CASE( update_builtins )  	BOOST_REQUIRE_EQUAL(bis.back()->mstring, bi2->mstring);  } -BOOST_AUTO_TEST_CASE( update_builtins_seq ) +BOOST_AUTO_TEST_CASE(update_builtins_seq)  { -	TestModule::BuiltInSeq ubis { -		TestModule::BuiltInsPtr(std::make_shared<TestModule::BuiltIns>(false, 5, 17, 64, 128, -1.2, -1.4, "string")), -		TestModule::BuiltInsPtr(std::make_shared<TestModule::BuiltIns>(false, 5, 21, 63, 127, -4.2, -5.4, "string updated")) -	}; +	TestModule::BuiltInSeq ubis {std::make_shared<TestModule::BuiltIns>(false, 5, 17, 64, 128, -1.2, -1.4, "string"), +			std::make_shared<TestModule::BuiltIns>(false, 5, 21, 63, 127, -4.2, -5.4, "string updated")};  	Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(ubis, db, "builtins");  	auto sel = db->select("SELECT * FROM builtins ORDER BY mint"); @@ -83,7 +81,7 @@ BOOST_AUTO_TEST_CASE( update_builtins_seq )  	BOOST_REQUIRE_EQUAL(ubis.back()->mstring, ubis2.front()->mstring);  } -BOOST_AUTO_TEST_CASE( update_withNulls ) +BOOST_AUTO_TEST_CASE(update_withNulls)  {  	auto sel = db->select("SELECT * FROM builtins ORDER BY mint");  	auto bis = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, TestDatabase::BuiltInSeq>(sel.get()); @@ -107,11 +105,11 @@ BOOST_AUTO_TEST_CASE( update_withNulls )  	BOOST_REQUIRE(bis2[1]->mfloat);  } -BOOST_AUTO_TEST_CASE( update_unsupportedModel ) +BOOST_AUTO_TEST_CASE(update_unsupportedModel)  {  	TestModule::ClassMap cm; -	BOOST_REQUIRE_THROW(Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(cm, db, "converted"), Slicer::UnsupportedModelType); +	BOOST_REQUIRE_THROW( +			Slicer::SerializeAny<Slicer::SqlUpdateSerializer>(cm, db, "converted"), Slicer::UnsupportedModelType);  }  BOOST_AUTO_TEST_SUITE_END(); - diff --git a/slicer/ice/serializer.cpp b/slicer/ice/serializer.cpp index a2e6f4a..877f531 100644 --- a/slicer/ice/serializer.cpp +++ b/slicer/ice/serializer.cpp @@ -1,6 +1,6 @@  #include "serializer.h" -#include "Ice/Initialize.h"  #include "Ice/Communicator.h" +#include "Ice/Initialize.h"  NAMEDFACTORY("application/ice", Slicer::IceStreamSerializer, Slicer::StreamSerializerFactory);  NAMEDFACTORY("application/ice", Slicer::IceStreamDeserializer, Slicer::StreamDeserializerFactory); @@ -8,19 +8,13 @@ NAMEDFACTORY("application/ice", Slicer::IceStreamDeserializer, Slicer::StreamDes  namespace Slicer {  	Ice::StringSeq empty; -	IceBase::IceBase() : -		ic(Ice::initialize(empty)) -	{ -	} +	IceBase::IceBase() : ic(Ice::initialize(empty)) { }  	IceBase::~IceBase()  	{  		ic->destroy();  	} -	IceBlobSerializer::IceBlobSerializer(Ice::ByteSeq & b) : -		blob(b) -	{ -	} +	IceBlobSerializer::IceBlobSerializer(Ice::ByteSeq & b) : blob(b) { }  	void  	IceBlobSerializer::Serialize(ModelPartForRootPtr mp) @@ -30,11 +24,7 @@ namespace Slicer {  		s.finished(blob);  	} -	IceStreamSerializer::IceStreamSerializer(std::ostream & os) : -		IceBlobSerializer(blob), -		strm(os) -	{ -	} +	IceStreamSerializer::IceStreamSerializer(std::ostream & os) : IceBlobSerializer(blob), strm(os) { }  	void  	IceStreamSerializer::Serialize(ModelPartForRootPtr mp) @@ -43,10 +33,7 @@ namespace Slicer {  		strm.write((const char *)&blob.front(), blob.size());  	} -	IceBlobDeserializer::IceBlobDeserializer(const Ice::ByteSeq & b) : -		blob(b) -	{ -	} +	IceBlobDeserializer::IceBlobDeserializer(const Ice::ByteSeq & b) : blob(b) { }  	void  	IceBlobDeserializer::Deserialize(ModelPartForRootPtr mp) @@ -55,11 +42,7 @@ namespace Slicer {  		mp->Read(s);  	} -	IceStreamDeserializer::IceStreamDeserializer(std::istream & is) : -		IceBlobDeserializer(blob), -		strm(is) -	{ -	} +	IceStreamDeserializer::IceStreamDeserializer(std::istream & is) : IceBlobDeserializer(blob), strm(is) { }  	void  	IceStreamDeserializer::Deserialize(ModelPartForRootPtr mp) @@ -68,4 +51,3 @@ namespace Slicer {  		IceBlobDeserializer::Deserialize(mp);  	}  } - diff --git a/slicer/ice/serializer.h b/slicer/ice/serializer.h index c1768c0..05a7752 100644 --- a/slicer/ice/serializer.h +++ b/slicer/ice/serializer.h @@ -1,65 +1,63 @@  #ifndef SLICER_ICE_H  #define SLICER_ICE_H +#include <Ice/BuiltinSequences.h> +#include <Ice/CommunicatorF.h>  #include <slicer/serializer.h>  #include <visibility.h> -#include <Ice/CommunicatorF.h> -#include <Ice/BuiltinSequences.h>  namespace Slicer {  	class IceBase { -		public: -			virtual ~IceBase(); +	public: +		virtual ~IceBase(); -		protected: -			IceBase(); +	protected: +		IceBase(); -			Ice::CommunicatorPtr ic; +		Ice::CommunicatorPtr ic;  	};  	class DLL_PUBLIC IceBlobSerializer : public Serializer, protected IceBase { -		public: -			IceBlobSerializer(Ice::ByteSeq &); +	public: +		IceBlobSerializer(Ice::ByteSeq &); -			void Serialize(ModelPartForRootPtr) override; +		void Serialize(ModelPartForRootPtr) override; -		private: -			Ice::ByteSeq & blob; +	private: +		Ice::ByteSeq & blob;  	};  	class DLL_PUBLIC IceStreamSerializer : public IceBlobSerializer { -		public: -			IceStreamSerializer(std::ostream &); +	public: +		IceStreamSerializer(std::ostream &); -			void Serialize(ModelPartForRootPtr) override; +		void Serialize(ModelPartForRootPtr) override; -		protected: -			std::ostream & strm; -			Ice::ByteSeq blob; +	protected: +		std::ostream & strm; +		Ice::ByteSeq blob;  	};  	class DLL_PUBLIC IceBlobDeserializer : public Deserializer, protected IceBase { -		public: -			IceBlobDeserializer(const Ice::ByteSeq &); +	public: +		IceBlobDeserializer(const Ice::ByteSeq &); -			void Deserialize(ModelPartForRootPtr) override; +		void Deserialize(ModelPartForRootPtr) override; -		protected: -			const Ice::ByteSeq & blob; +	protected: +		const Ice::ByteSeq & blob;  	};  	class DLL_PUBLIC IceStreamDeserializer : public IceBlobDeserializer { -		public: -			IceStreamDeserializer(std::istream &); +	public: +		IceStreamDeserializer(std::istream &); -			void Deserialize(ModelPartForRootPtr) override; +		void Deserialize(ModelPartForRootPtr) override; -		protected: -			std::istream & strm; -			Ice::ByteSeq blob; +	protected: +		std::istream & strm; +		Ice::ByteSeq blob;  	};  }  #endif - - diff --git a/slicer/ice/testSpecifics.cpp b/slicer/ice/testSpecifics.cpp index 9832352..3a4be15 100644 --- a/slicer/ice/testSpecifics.cpp +++ b/slicer/ice/testSpecifics.cpp @@ -1,7 +1,7 @@  #define BOOST_TEST_MODULE ice_specifics +#include "serializer.h"  #include <boost/test/unit_test.hpp>  #include <slicer.h> -#include "serializer.h"  #include <types.h>  // LCOV_EXCL_START @@ -30,7 +30,7 @@ testCompare(const X & x, const std::function<bool(const X &, const X &)> & cmp)  	BOOST_REQUIRE(cmp(x, x2));  } -BOOST_AUTO_TEST_CASE( builtins ) +BOOST_AUTO_TEST_CASE(builtins)  {  	testCompare<std::string>("some string value");  	testCompare<bool>(true); @@ -65,7 +65,7 @@ testCompareOptional(const X & d)  	BOOST_REQUIRE_EQUAL(d, *x3);  } -BOOST_AUTO_TEST_CASE( optionalBuiltins ) +BOOST_AUTO_TEST_CASE(optionalBuiltins)  {  	testCompareOptional<std::string>("some string value");  	testCompareOptional<bool>(true); @@ -84,9 +84,7 @@ BOOST_AUTO_TEST_CASE( optionalBuiltins )  	testCompareOptional<Ice::Double>(3.14159);  } - - -BOOST_AUTO_TEST_CASE( classes ) +BOOST_AUTO_TEST_CASE(classes)  {  	TestModule::BuiltInsPtr x = std::make_shared<TestModule::BuiltIns>();  	x->mbool = true; @@ -98,21 +96,15 @@ BOOST_AUTO_TEST_CASE( classes )  	x->mdouble = 3423423423.42342342343;  	x->mstring = "sdfsf432423";  	testCompare<TestModule::BuiltInsPtr>(x, [](const auto & a, const auto & b) { -		return a->mbool == b->mbool -			&& a->mbyte == b->mbyte -			&& a->mshort == b->mshort -			&& a->mint == b->mint -			&& a->mlong == b->mlong -			&& a->mfloat == b->mfloat -			&& a->mdouble == b->mdouble -			&& a->mstring == b->mstring; +		return a->mbool == b->mbool && a->mbyte == b->mbyte && a->mshort == b->mshort && a->mint == b->mint +				&& a->mlong == b->mlong && a->mfloat == b->mfloat && a->mdouble == b->mdouble +				&& a->mstring == b->mstring;  	});  } -BOOST_AUTO_TEST_CASE( structes ) +BOOST_AUTO_TEST_CASE(structes)  { -	TestModule::IsoDate date({ 2016, 10, 3 }); +	TestModule::IsoDate date({2016, 10, 3});  	testCompare(date);  	testCompareOptional(date);  } - diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp index b9b0c69..b94ae2e 100644 --- a/slicer/json/serializer.cpp +++ b/slicer/json/serializer.cpp @@ -1,11 +1,11 @@  #include "serializer.h" -#include <slicer/metadata.h> -#include <jsonpp.h>  #include <boost/numeric/conversion/cast.hpp> -#include <functional> -#include <stdexcept>  #include <fstream> +#include <functional>  #include <glibmm/ustring.h> +#include <jsonpp.h> +#include <slicer/metadata.h> +#include <stdexcept>  NAMEDFACTORY(".js", Slicer::JsonFileSerializer, Slicer::FileSerializerFactory);  NAMEDFACTORY(".js", Slicer::JsonFileDeserializer, Slicer::FileDeserializerFactory); @@ -24,173 +24,188 @@ namespace Slicer {  	using namespace std::placeholders;  	class JsonValueSource : public ValueSource { -		public: -			explicit JsonValueSource(const json::Value & s) : -				value(s) -			{ -			} +	public: +		explicit JsonValueSource(const json::Value & s) : value(s) { } -			void set(bool & v) const override -			{ -				v = std::get<bool>(value); -			} +		void +		set(bool & v) const override +		{ +			v = std::get<bool>(value); +		} -			void set(Ice::Byte & v) const override -			{ -				v = boost::numeric_cast<Ice::Byte>(std::get<json::Number>(value)); -			} +		void +		set(Ice::Byte & v) const override +		{ +			v = boost::numeric_cast<Ice::Byte>(std::get<json::Number>(value)); +		} -			void set(Ice::Short & v) const override -			{ -				v = boost::numeric_cast<Ice::Short>(std::get<json::Number>(value)); -			} +		void +		set(Ice::Short & v) const override +		{ +			v = boost::numeric_cast<Ice::Short>(std::get<json::Number>(value)); +		} -			void set(Ice::Int & v) const override -			{ -				v = boost::numeric_cast<Ice::Int>(std::get<json::Number>(value)); -			} +		void +		set(Ice::Int & v) const override +		{ +			v = boost::numeric_cast<Ice::Int>(std::get<json::Number>(value)); +		} -			void set(Ice::Long & v) const override -			{ -				v = boost::numeric_cast<Ice::Long>(std::get<json::Number>(value)); -			} +		void +		set(Ice::Long & v) const override +		{ +			v = boost::numeric_cast<Ice::Long>(std::get<json::Number>(value)); +		} -			void set(Ice::Float & v) const override -			{ -				v = boost::numeric_cast<Ice::Float>(std::get<json::Number>(value)); -			} +		void +		set(Ice::Float & v) const override +		{ +			v = boost::numeric_cast<Ice::Float>(std::get<json::Number>(value)); +		} -			void set(Ice::Double & v) const override -			{ -				v = boost::numeric_cast<Ice::Double>(std::get<json::Number>(value)); -			} +		void +		set(Ice::Double & v) const override +		{ +			v = boost::numeric_cast<Ice::Double>(std::get<json::Number>(value)); +		} -			void set(std::string & v) const override -			{ -				v = std::get<json::String>(value); -			} +		void +		set(std::string & v) const override +		{ +			v = std::get<json::String>(value); +		} -		private: -			const json::Value & value; +	private: +		const json::Value & value;  	};  	class JsonValueTarget : public ValueTarget { -		public: -			explicit JsonValueTarget(json::Value & t) : -				target(t) -			{ -				target = json::Null(); -			} +	public: +		explicit JsonValueTarget(json::Value & t) : target(t) +		{ +			target = json::Null(); +		} -			void get(const bool & value) const override -			{ -				target = value; -			} +		void +		get(const bool & value) const override +		{ +			target = value; +		} -			void get(const Ice::Byte & value) const override -			{ -				target = boost::numeric_cast<json::Number>(value); -			} +		void +		get(const Ice::Byte & value) const override +		{ +			target = boost::numeric_cast<json::Number>(value); +		} -			void get(const Ice::Short & value) const override -			{ -				target = boost::numeric_cast<json::Number>(value); -			} +		void +		get(const Ice::Short & value) const override +		{ +			target = boost::numeric_cast<json::Number>(value); +		} -			void get(const Ice::Int & value) const override -			{ -				target = boost::numeric_cast<json::Number>(value); -			} +		void +		get(const Ice::Int & value) const override +		{ +			target = boost::numeric_cast<json::Number>(value); +		} -			void get(const Ice::Long & value) const override -			{ -				target = boost::numeric_cast<json::Number>(value); -			} +		void +		get(const Ice::Long & value) const override +		{ +			target = boost::numeric_cast<json::Number>(value); +		} -			void get(const Ice::Float & value) const override -			{ -				target = boost::numeric_cast<json::Number>(value); -			} +		void +		get(const Ice::Float & value) const override +		{ +			target = boost::numeric_cast<json::Number>(value); +		} -			void get(const Ice::Double & value) const override -			{ -				target = boost::numeric_cast<json::Number>(value); -			} +		void +		get(const Ice::Double & value) const override +		{ +			target = boost::numeric_cast<json::Number>(value); +		} -			void get(const std::string & value) const override -			{ -				target = value; -			} +		void +		get(const std::string & value) const override +		{ +			target = value; +		} -		private: -			json::Value & target; +	private: +		json::Value & target;  	};  	class DocumentTreeIterate { -		public: -			explicit DocumentTreeIterate(ModelPartPtr & mp) : modelPart(mp) -			{ -			} -			template<typename SimpleT> -			void operator()(const SimpleT & v) const -			{ -				modelPart->Create(); -				modelPart->SetValue(JsonValueSource(v)); -				modelPart->Complete(); -			} -			void operator()(const json::Null &) const -			{ -				modelPart->Complete(); -			} -			void operator()(const json::Object & o) const -			{ -				if (auto typeIdName = modelPart->GetTypeIdProperty()) { -					auto typeAttrItr = o.find(*typeIdName); -					if (typeAttrItr != o.end() && std::holds_alternative<json::String>(typeAttrItr->second)) { -						modelPart = modelPart->GetSubclassModelPart(std::get<json::String>(typeAttrItr->second)); -					} -				} -				modelPart->Create(); -				if (metaDataFlagSet(modelPart->GetMetadata(), md_object)) { -					for (const auto & element : o) { -						auto emp = modelPart->GetAnonChild(); -						emp->Create(); -						auto key = emp->GetChild(keyName); -						auto value = emp->GetChild(valueName); -						key->Create(); -						key->SetValue(JsonValueSource(element.first)); -						key->Complete(); -						std::visit(DocumentTreeIterate(value), element.second); -						emp->Complete(); -					} -				} -				else { -					for (const auto & element : o) { -						auto emp = modelPart->GetChild(element.first); -						if (emp) { -							emp->Create(); -							std::visit(DocumentTreeIterate(emp), element.second); -							emp->Complete(); -						} -					} -					modelPart->Complete(); +	public: +		explicit DocumentTreeIterate(ModelPartPtr & mp) : modelPart(mp) { } +		template<typename SimpleT> +		void +		operator()(const SimpleT & v) const +		{ +			modelPart->Create(); +			modelPart->SetValue(JsonValueSource(v)); +			modelPart->Complete(); +		} +		void +		operator()(const json::Null &) const +		{ +			modelPart->Complete(); +		} +		void +		operator()(const json::Object & o) const +		{ +			if (auto typeIdName = modelPart->GetTypeIdProperty()) { +				auto typeAttrItr = o.find(*typeIdName); +				if (typeAttrItr != o.end() && std::holds_alternative<json::String>(typeAttrItr->second)) { +					modelPart = modelPart->GetSubclassModelPart(std::get<json::String>(typeAttrItr->second));  				}  			} -			void operator()(const json::Array & a) const -			{ -				modelPart->Create(); -				for (const auto & element : a) { +			modelPart->Create(); +			if (metaDataFlagSet(modelPart->GetMetadata(), md_object)) { +				for (const auto & element : o) {  					auto emp = modelPart->GetAnonChild(); +					emp->Create(); +					auto key = emp->GetChild(keyName); +					auto value = emp->GetChild(valueName); +					key->Create(); +					key->SetValue(JsonValueSource(element.first)); +					key->Complete(); +					std::visit(DocumentTreeIterate(value), element.second); +					emp->Complete(); +				} +			} +			else { +				for (const auto & element : o) { +					auto emp = modelPart->GetChild(element.first);  					if (emp) {  						emp->Create(); -						std::visit(DocumentTreeIterate(emp), element); +						std::visit(DocumentTreeIterate(emp), element.second);  						emp->Complete();  					}  				}  				modelPart->Complete();  			} -		private: -			ModelPartPtr & modelPart; +		} +		void +		operator()(const json::Array & a) const +		{ +			modelPart->Create(); +			for (const auto & element : a) { +				auto emp = modelPart->GetAnonChild(); +				if (emp) { +					emp->Create(); +					std::visit(DocumentTreeIterate(emp), element); +					emp->Complete(); +				} +			} +			modelPart->Complete(); +		} + +	private: +		ModelPartPtr & modelPart;  	};  	void @@ -218,7 +233,7 @@ namespace Slicer {  		JsonValueSource s(kv);  		s.set(k);  		ModelTreeIterateRoot(&v, mp->GetChild(valueName)); -		obj->insert({ k, v }); +		obj->insert({k, v});  	}  	void @@ -228,18 +243,17 @@ namespace Slicer {  			return;  		}  		switch (mp->GetType()) { -			case mpt_Null: +			case ModelPartType::Null:  				std::get<json::Object>(*n).insert({name, json::Null()});  				return; -			case mpt_Simple: -				{ -					json::Value v; -					if (mp->GetValue(JsonValueTarget(v))) { -						std::get<json::Object>(*n).insert({ name, v }); -					} -					break; +			case ModelPartType::Simple: { +				json::Value v; +				if (mp->GetValue(JsonValueTarget(v))) { +					std::get<json::Object>(*n).insert({name, v});  				} -			case mpt_Complex: +				break; +			} +			case ModelPartType::Complex:  				if (mp->HasValue()) {  					json::Object nn;  					if (auto typeIdName = mp->GetTypeIdProperty()) { @@ -248,35 +262,34 @@ namespace Slicer {  							mp = mp->GetSubclassModelPart(*typeId);  						}  					} -					mp->OnEachChild( -							[capture0 = &std::get<json::Object>(*n).insert({name, nn}).first->second] -							(auto && PH1, auto && PH2, auto &&) { -								return JsonSerializer::ModelTreeIterate(capture0, PH1, PH2); -							}); +					mp->OnEachChild([capture0 = &std::get<json::Object>(*n).insert({name, nn}).first->second]( +											auto && PH1, auto && PH2, auto &&) { +						return JsonSerializer::ModelTreeIterate(capture0, PH1, PH2); +					});  				}  				break; -			case mpt_Sequence: +			case ModelPartType::Sequence:  				if (mp->HasValue()) {  					mp->OnEachChild( -							[capture0 = &std::get<json::Object>(*n).insert({name, json::Array()}).first->second] -							(auto &&, auto && PH2, auto &&) { +							[capture0 = &std::get<json::Object>(*n).insert({name, json::Array()}).first->second]( +									auto &&, auto && PH2, auto &&) {  								return JsonSerializer::ModelTreeIterateSeq(capture0, PH2);  							});  				}  				break; -			case mpt_Dictionary: +			case ModelPartType::Dictionary:  				if (mp->HasValue()) {  					if (metaDataFlagSet(mp->GetMetadata(), md_object)) {  						mp->OnEachChild( -								[capture0 = &std::get<json::Object>(*n).insert({name, json::Object()}).first->second] -								(auto &&, auto && PH2, auto &&) { +								[capture0 = &std::get<json::Object>(*n).insert({name, json::Object()}).first->second]( +										auto &&, auto && PH2, auto &&) {  									return JsonSerializer::ModelTreeIterateDictObj(capture0, PH2);  								});  					}  					else {  						mp->OnEachChild( -								[capture0 = &std::get<json::Object>(*n).insert({name, json::Array()}).first->second] -								(auto &&, auto && PH2, auto &&) { +								[capture0 = &std::get<json::Object>(*n).insert({name, json::Array()}).first->second]( +										auto &&, auto && PH2, auto &&) {  									return JsonSerializer::ModelTreeIterateSeq(capture0, PH2);  								});  					} @@ -290,13 +303,13 @@ namespace Slicer {  	{  		if (mp) {  			switch (mp->GetType()) { -				case mpt_Null: +				case ModelPartType::Null:  					*n = json::Null();  					return; -				case mpt_Simple: +				case ModelPartType::Simple:  					mp->GetValue(JsonValueTarget(*n));  					break; -				case mpt_Complex: +				case ModelPartType::Complex:  					*n = json::Object();  					if (auto typeIdName = mp->GetTypeIdProperty()) {  						if (auto typeId = mp->GetTypeId()) { @@ -308,13 +321,13 @@ namespace Slicer {  						return JsonSerializer::ModelTreeIterate(n, PH1, PH2);  					});  					break; -				case mpt_Sequence: +				case ModelPartType::Sequence:  					*n = json::Array();  					mp->OnEachChild([n](auto &&, auto && PH2, auto &&) {  						return JsonSerializer::ModelTreeIterateSeq(n, PH2);  					});  					break; -				case mpt_Dictionary: +				case ModelPartType::Dictionary:  					if (metaDataFlagSet(mp->GetMetadata(), md_object)) {  						*n = json::Object();  						mp->OnEachChild([n](auto &&, auto && PH2, auto &&) { @@ -332,15 +345,9 @@ namespace Slicer {  		}  	} -	JsonStreamSerializer::JsonStreamSerializer(std::ostream & s) : -		strm(s) -	{ -	} +	JsonStreamSerializer::JsonStreamSerializer(std::ostream & s) : strm(s) { } -	JsonStreamDeserializer::JsonStreamDeserializer(std::istream & s) : -		strm(s) -	{ -	} +	JsonStreamDeserializer::JsonStreamDeserializer(std::istream & s) : strm(s) { }  	void  	JsonStreamDeserializer::Deserialize(ModelPartForRootPtr modelRoot) @@ -360,15 +367,9 @@ namespace Slicer {  		json::serializeValue(doc, strm, "utf-8");  	} -	JsonFileSerializer::JsonFileSerializer(std::filesystem::path p) : -		path(std::move(p)) -	{ -	} +	JsonFileSerializer::JsonFileSerializer(std::filesystem::path p) : path(std::move(p)) { } -	JsonFileDeserializer::JsonFileDeserializer(std::filesystem::path p) : -		path(std::move(p)) -	{ -	} +	JsonFileDeserializer::JsonFileDeserializer(std::filesystem::path p) : path(std::move(p)) { }  	void  	JsonFileDeserializer::Deserialize(ModelPartForRootPtr modelRoot) @@ -390,15 +391,9 @@ namespace Slicer {  		json::serializeValue(doc, outFile, "utf-8");  	} -	JsonValueSerializer::JsonValueSerializer(json::Value & v) : -		value(v) -	{ -	} +	JsonValueSerializer::JsonValueSerializer(json::Value & v) : value(v) { } -	JsonValueDeserializer::JsonValueDeserializer(const json::Value & v) : -		value(v) -	{ -	} +	JsonValueDeserializer::JsonValueDeserializer(const json::Value & v) : value(v) { }  	void  	JsonValueDeserializer::Deserialize(ModelPartForRootPtr modelRoot) @@ -415,5 +410,3 @@ namespace Slicer {  		});  	}  } - - diff --git a/slicer/json/serializer.h b/slicer/json/serializer.h index ed666aa..c23121b 100644 --- a/slicer/json/serializer.h +++ b/slicer/json/serializer.h @@ -1,80 +1,78 @@  #ifndef SLICER_JSON_H  #define SLICER_JSON_H -#include <slicer/serializer.h>  #include <jsonpp.h> +#include <slicer/serializer.h>  #include <visibility.h>  namespace Slicer {  	class JsonSerializer : public Serializer { -		protected: -			static void ModelTreeIterate(json::Value *, const std::string &, ModelPartPtr mp); -			static void ModelTreeIterateDictObj(json::Value *, const ModelPartPtr & mp); -			static void ModelTreeIterateSeq(json::Value *, const ModelPartPtr & mp); -			static void ModelTreeIterateRoot(json::Value *, ModelPartPtr mp); +	protected: +		static void ModelTreeIterate(json::Value *, const std::string &, ModelPartPtr mp); +		static void ModelTreeIterateDictObj(json::Value *, const ModelPartPtr & mp); +		static void ModelTreeIterateSeq(json::Value *, const ModelPartPtr & mp); +		static void ModelTreeIterateRoot(json::Value *, ModelPartPtr mp);  	};  	class DLL_PUBLIC JsonStreamSerializer : public JsonSerializer { -		public: -			JsonStreamSerializer(std::ostream &); +	public: +		explicit JsonStreamSerializer(std::ostream &); -			void Serialize(ModelPartForRootPtr) override; +		void Serialize(ModelPartForRootPtr) override; -		protected: -			std::ostream & strm; +	protected: +		std::ostream & strm;  	};  	class DLL_PUBLIC JsonFileSerializer : public JsonSerializer { -		public: -			JsonFileSerializer(std::filesystem::path); +	public: +		explicit JsonFileSerializer(std::filesystem::path); -			void Serialize(ModelPartForRootPtr) override; +		void Serialize(ModelPartForRootPtr) override; -		protected: -			const std::filesystem::path path; +	protected: +		const std::filesystem::path path;  	};  	class DLL_PUBLIC JsonValueSerializer : public JsonSerializer { -		public: -			JsonValueSerializer(json::Value &); +	public: +		explicit JsonValueSerializer(json::Value &); -			void Serialize(ModelPartForRootPtr) override; +		void Serialize(ModelPartForRootPtr) override; -		protected: -			json::Value & value; +	protected: +		json::Value & value;  	};  	class DLL_PUBLIC JsonStreamDeserializer : public Deserializer { -		public: -			JsonStreamDeserializer(std::istream &); +	public: +		explicit JsonStreamDeserializer(std::istream &); -			void Deserialize(ModelPartForRootPtr) override; +		void Deserialize(ModelPartForRootPtr) override; -		protected: -			std::istream & strm; +	protected: +		std::istream & strm;  	};  	class DLL_PUBLIC JsonFileDeserializer : public Deserializer { -		public: -			JsonFileDeserializer(std::filesystem::path); +	public: +		explicit JsonFileDeserializer(std::filesystem::path); -			void Deserialize(ModelPartForRootPtr) override; +		void Deserialize(ModelPartForRootPtr) override; -		protected: -			const std::filesystem::path path; +	protected: +		const std::filesystem::path path;  	};  	class DLL_PUBLIC JsonValueDeserializer : public Deserializer { -		public: -			JsonValueDeserializer(const json::Value &); +	public: +		explicit JsonValueDeserializer(const json::Value &); -			void Deserialize(ModelPartForRootPtr) override; +		void Deserialize(ModelPartForRootPtr) override; -		protected: -			const json::Value & value; +	protected: +		const json::Value & value;  	};  }  #endif - - diff --git a/slicer/json/testSpecifics.cpp b/slicer/json/testSpecifics.cpp index c0a54d4..6bfc9d4 100644 --- a/slicer/json/testSpecifics.cpp +++ b/slicer/json/testSpecifics.cpp @@ -1,18 +1,21 @@  #define BOOST_TEST_MODULE json_specifics +#include "serializer.h"  #include <boost/test/unit_test.hpp>  #include <slicer/slicer.h> -#include "serializer.h"  #include <types.h> -BOOST_AUTO_TEST_CASE( factories ) +BOOST_AUTO_TEST_CASE(factories)  {  	BOOST_REQUIRE(Slicer::SerializerPtr(Slicer::FileSerializerFactory::createNew(".json", "/some.json")));  	BOOST_REQUIRE(Slicer::DeserializerPtr(Slicer::FileDeserializerFactory::createNew(".json", "/some.json")));  	BOOST_REQUIRE(Slicer::SerializerPtr(Slicer::FileSerializerFactory::createNew(".js", "/some.js")));  	BOOST_REQUIRE(Slicer::DeserializerPtr(Slicer::FileDeserializerFactory::createNew(".js", "/some.js"))); -	BOOST_REQUIRE(Slicer::SerializerPtr(Slicer::StreamSerializerFactory::createNew("application/javascript", std::cout))); -	BOOST_REQUIRE(Slicer::DeserializerPtr(Slicer::StreamDeserializerFactory::createNew("application/javascript", std::cin))); -	BOOST_REQUIRE(Slicer::SerializerPtr(Slicer::StreamSerializerFactory::createNew("application/javascript", std::cout))); -	BOOST_REQUIRE(Slicer::DeserializerPtr(Slicer::StreamDeserializerFactory::createNew("application/javascript", std::cin))); +	BOOST_REQUIRE( +			Slicer::SerializerPtr(Slicer::StreamSerializerFactory::createNew("application/javascript", std::cout))); +	BOOST_REQUIRE( +			Slicer::DeserializerPtr(Slicer::StreamDeserializerFactory::createNew("application/javascript", std::cin))); +	BOOST_REQUIRE( +			Slicer::SerializerPtr(Slicer::StreamSerializerFactory::createNew("application/javascript", std::cout))); +	BOOST_REQUIRE( +			Slicer::DeserializerPtr(Slicer::StreamDeserializerFactory::createNew("application/javascript", std::cin)));  } - diff --git a/slicer/slicer/metadata.cpp b/slicer/slicer/metadata.cpp index 4f794fc..6429cc8 100644 --- a/slicer/slicer/metadata.cpp +++ b/slicer/slicer/metadata.cpp @@ -1,7 +1,7 @@  #include "metadata.h" +#include <boost/algorithm/string/classification.hpp>  #include <boost/algorithm/string/predicate.hpp>  #include <boost/algorithm/string/split.hpp> -#include <boost/algorithm/string/classification.hpp>  bool  Slicer::metaDataFlagSet(const std::list<std::string> & md, const std::string & flag) @@ -46,4 +46,3 @@ Slicer::metaDataValue(const std::string & prefix, const std::list<std::string> &  	}  	return std::optional<std::string>();  } - diff --git a/slicer/slicer/metadata.h b/slicer/slicer/metadata.h index 79baf13..e604658 100644 --- a/slicer/slicer/metadata.h +++ b/slicer/slicer/metadata.h @@ -1,10 +1,10 @@  #ifndef SLICER_METADATA_H  #define SLICER_METADATA_H -#include <string>  #include <list> -#include <vector>  #include <optional> +#include <string> +#include <vector>  namespace Slicer {  #pragma GCC visibility push(default) @@ -19,4 +19,3 @@ namespace Slicer {  }  #endif - diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp index 61cbd25..a6e191a 100644 --- a/slicer/slicer/modelParts.cpp +++ b/slicer/slicer/modelParts.cpp @@ -73,10 +73,7 @@ namespace Slicer {  		return shared_from_this();  	} -	HookCommon::HookCommon(std::string n) : -		name(std::move(n)) -	{ -	} +	HookCommon::HookCommon(std::string n) : name(std::move(n)) { }  	bool  	HookCommon::filter(const HookFilter & flt) @@ -90,4 +87,3 @@ namespace Slicer {  		ch(this->name, modelPart, this);  	}  } - diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index f31a8c0..50ae427 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -1,64 +1,62 @@  #ifndef SLICER_MODELPARTS_H  #define SLICER_MODELPARTS_H -#include <Ice/Optional.h>  #include <Ice/InputStream.h> +#include <Ice/Optional.h>  #include <Ice/OutputStream.h> -#include <stdexcept>  #include <functional> -#include <vector>  #include <list> +#include <stdexcept> +#include <vector>  #include <visibility.h>  namespace Slicer { -	template <typename T> -	class TValueTarget { -		public: -			virtual void get(const T &) const = 0; +	template<typename T> class TValueTarget { +	public: +		virtual void get(const T &) const = 0;  	};  	class ValueTarget : -			public TValueTarget<bool>, -			public TValueTarget<Ice::Byte>, -			public TValueTarget<Ice::Short>, -			public TValueTarget<Ice::Int>, -			public TValueTarget<Ice::Long>, -			public TValueTarget<Ice::Float>, -			public TValueTarget<Ice::Double>, -			public TValueTarget<std::string> { -		public: -			using TValueTarget<bool>::get; -			using TValueTarget<Ice::Byte>::get; -			using TValueTarget<Ice::Short>::get; -			using TValueTarget<Ice::Int>::get; -			using TValueTarget<Ice::Long>::get; -			using TValueTarget<Ice::Float>::get; -			using TValueTarget<Ice::Double>::get; -			using TValueTarget<std::string>::get; +		public TValueTarget<bool>, +		public TValueTarget<Ice::Byte>, +		public TValueTarget<Ice::Short>, +		public TValueTarget<Ice::Int>, +		public TValueTarget<Ice::Long>, +		public TValueTarget<Ice::Float>, +		public TValueTarget<Ice::Double>, +		public TValueTarget<std::string> { +	public: +		using TValueTarget<bool>::get; +		using TValueTarget<Ice::Byte>::get; +		using TValueTarget<Ice::Short>::get; +		using TValueTarget<Ice::Int>::get; +		using TValueTarget<Ice::Long>::get; +		using TValueTarget<Ice::Float>::get; +		using TValueTarget<Ice::Double>::get; +		using TValueTarget<std::string>::get;  	}; -	template <typename T> -	class TValueSource { -		public: -			virtual void set(T &) const = 0; +	template<typename T> class TValueSource { +	public: +		virtual void set(T &) const = 0;  	};  	class ValueSource : -			public TValueSource<bool>, -			public TValueSource<Ice::Byte>, -			public TValueSource<Ice::Short>, -			public TValueSource<Ice::Int>, -			public TValueSource<Ice::Long>, -			public TValueSource<Ice::Float>, -			public TValueSource<Ice::Double>, -			public TValueSource<std::string> { -		public: -			using TValueSource<bool>::set; -			using TValueSource<Ice::Byte>::set; -			using TValueSource<Ice::Short>::set; -			using TValueSource<Ice::Int>::set; -			using TValueSource<Ice::Long>::set; -			using TValueSource<Ice::Float>::set; -			using TValueSource<Ice::Double>::set; -			using TValueSource<std::string>::set; +		public TValueSource<bool>, +		public TValueSource<Ice::Byte>, +		public TValueSource<Ice::Short>, +		public TValueSource<Ice::Int>, +		public TValueSource<Ice::Long>, +		public TValueSource<Ice::Float>, +		public TValueSource<Ice::Double>, +		public TValueSource<std::string> { +	public: +		using TValueSource<bool>::set; +		using TValueSource<Ice::Byte>::set; +		using TValueSource<Ice::Short>::set; +		using TValueSource<Ice::Int>::set; +		using TValueSource<Ice::Long>::set; +		using TValueSource<Ice::Float>::set; +		using TValueSource<Ice::Double>::set; +		using TValueSource<std::string>::set;  	};  	class ModelPart; @@ -75,51 +73,51 @@ namespace Slicer {  	using Metadata = std::list<std::string>;  	DLL_PUBLIC extern const Metadata emptyMetadata; -	enum ModelPartType { -		mpt_Null, -		mpt_Simple, -		mpt_Complex, -		mpt_Sequence, -		mpt_Dictionary, +	enum class ModelPartType { +		Null, +		Simple, +		Complex, +		Sequence, +		Dictionary,  	}; -	enum TryConvertResult { -		tcr_NoAction = 0, -		tcr_NoValue, -		tcr_Value, +	enum class TryConvertResult { +		NoAction, +		NoValue, +		Value,  	};  	class DLL_PUBLIC ChildRef { -		public: -			explicit ChildRef(); -			explicit ChildRef(ModelPartPtr); -			explicit ChildRef(ModelPartPtr, const Metadata &); - -			[[nodiscard]] ModelPartPtr Child() const; -			[[nodiscard]] const Metadata & ChildMetaData() const; -			explicit operator bool() const; - -		private: -			ModelPartPtr mpp; -			const Metadata & mdr; +	public: +		explicit ChildRef(); +		explicit ChildRef(ModelPartPtr); +		explicit ChildRef(ModelPartPtr, const Metadata &); + +		[[nodiscard]] ModelPartPtr Child() const; +		[[nodiscard]] const Metadata & ChildMetaData() const; +		explicit operator bool() const; + +	private: +		ModelPartPtr mpp; +		const Metadata & mdr;  	};  	class DLL_PUBLIC HookCommon { -		public: -			explicit HookCommon(std::string); +	public: +		explicit HookCommon(std::string); -			bool filter(const HookFilter & flt); -			void apply(const ChildHandler & ch, const ModelPartPtr & modelPart); +		bool filter(const HookFilter & flt); +		void apply(const ChildHandler & ch, const ModelPartPtr & modelPart); -			[[nodiscard]] virtual const Metadata & GetMetadata() const = 0; +		[[nodiscard]] virtual const Metadata & GetMetadata() const = 0; -			// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -			const std::string name; +		const std::string name;  	};  	struct case_less {  		template<typename A, typename B> -		inline bool operator()(const A & a, const B & b) const +		inline bool +		operator()(const A & a, const B & b) const  		{  			const auto cmp = strncasecmp(a.data(), b.data(), std::min(a.length(), b.length()));  			return (cmp < 0) || (!cmp && a.length() < b.length()); @@ -127,69 +125,64 @@ namespace Slicer {  	};  	class DLL_PUBLIC ModelPart : public std::enable_shared_from_this<ModelPart> { -		public: -			ModelPart() = default; -			ModelPart(const ModelPart &) = delete; -			ModelPart(ModelPart &&) = delete; - -			virtual ~ModelPart() = default; - -			ModelPart & operator=(const ModelPart &) = delete; -			ModelPart & operator=(ModelPart &&) = delete; - -			template<typename T> -			static ModelPartPtr CreateFor(); -			template<typename T> -			static ModelPartPtr CreateFor(T & t); -			template<typename T> -			static ModelPartForRootPtr CreateRootFor(T & t); - -			virtual void OnEachChild(const ChildHandler &) = 0; -			ModelPartPtr GetAnonChild(const HookFilter & = HookFilter()); -			ModelPartPtr GetChild(const std::string & memberName, const HookFilter & = HookFilter()); -			virtual ChildRef GetAnonChildRef(const HookFilter & = HookFilter()) = 0; -			virtual ChildRef GetChildRef(const std::string & memberName, const HookFilter & = HookFilter(), bool matchCase = true) = 0; -			virtual ModelPartPtr GetSubclassModelPart(const std::string &); -			virtual TypeId GetTypeId() const; -			virtual Ice::optional<std::string> GetTypeIdProperty() const; -			virtual ModelPartType GetType() const = 0; -			virtual void Create(); -			virtual void Complete(); -			virtual void SetValue(ValueSource &&); -			virtual bool GetValue(ValueTarget &&); -			virtual bool HasValue() const = 0; -			virtual const Metadata & GetMetadata() const; -			virtual bool IsOptional() const; -			virtual ModelPartPtr GetContainedModelPart(); +	public: +		ModelPart() = default; +		ModelPart(const ModelPart &) = delete; +		ModelPart(ModelPart &&) = delete; + +		virtual ~ModelPart() = default; + +		ModelPart & operator=(const ModelPart &) = delete; +		ModelPart & operator=(ModelPart &&) = delete; + +		template<typename T> static ModelPartPtr CreateFor(); +		template<typename T> static ModelPartPtr CreateFor(T & t); +		template<typename T> static ModelPartForRootPtr CreateRootFor(T & t); + +		virtual void OnEachChild(const ChildHandler &) = 0; +		ModelPartPtr GetAnonChild(const HookFilter & = HookFilter()); +		ModelPartPtr GetChild(const std::string & memberName, const HookFilter & = HookFilter()); +		virtual ChildRef GetAnonChildRef(const HookFilter & = HookFilter()) = 0; +		virtual ChildRef GetChildRef( +				const std::string & memberName, const HookFilter & = HookFilter(), bool matchCase = true) +				= 0; +		virtual ModelPartPtr GetSubclassModelPart(const std::string &); +		virtual TypeId GetTypeId() const; +		virtual Ice::optional<std::string> GetTypeIdProperty() const; +		virtual ModelPartType GetType() const = 0; +		virtual void Create(); +		virtual void Complete(); +		virtual void SetValue(ValueSource &&); +		virtual bool GetValue(ValueTarget &&); +		virtual bool HasValue() const = 0; +		virtual const Metadata & GetMetadata() const; +		virtual bool IsOptional() const; +		virtual ModelPartPtr GetContainedModelPart();  	}; -	template<typename T> -	class DLL_PUBLIC ModelPartModel { -		protected: -			explicit ModelPartModel() : Model(nullptr) { } -			explicit ModelPartModel(T * m) : Model(m) { } -			// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -			T * Model; +	template<typename T> class DLL_PUBLIC ModelPartModel { +	protected: +		explicit ModelPartModel() : Model(nullptr) { } +		explicit ModelPartModel(T * m) : Model(m) { } +		T * Model;  	};  	class DLL_PUBLIC ModelPartForRootBase : public ModelPart { -		public: -			explicit ModelPartForRootBase(ModelPartPtr mp); - -			virtual const std::string & GetRootName() const = 0; -			ChildRef GetAnonChildRef(const HookFilter &) override; -			ChildRef GetChildRef(const std::string & name, const HookFilter &, bool matchCase = true) override; -			void OnEachChild(const ChildHandler & ch) override; -			ModelPartType GetType() const override; -			bool IsOptional() const override; -			virtual void Write(::Ice::OutputStream &) const = 0; -			virtual void Read(::Ice::InputStream &) = 0; -			ModelPartPtr GetContainedModelPart() override; - -			// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -			ModelPartPtr mp; +	public: +		explicit ModelPartForRootBase(ModelPartPtr mp); + +		virtual const std::string & GetRootName() const = 0; +		ChildRef GetAnonChildRef(const HookFilter &) override; +		ChildRef GetChildRef(const std::string & name, const HookFilter &, bool matchCase = true) override; +		void OnEachChild(const ChildHandler & ch) override; +		ModelPartType GetType() const override; +		bool IsOptional() const override; +		virtual void Write(::Ice::OutputStream &) const = 0; +		virtual void Read(::Ice::InputStream &) = 0; +		ModelPartPtr GetContainedModelPart() override; + +		ModelPartPtr mp;  	};  }  #endif - diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp index 7d9ea54..73e13bf 100644 --- a/slicer/slicer/modelPartsTypes.cpp +++ b/slicer/slicer/modelPartsTypes.cpp @@ -6,25 +6,29 @@  namespace Slicer {  	using ClassRefMap = std::map<std::string, ClassRef, std::less<>>;  	using ClassNamePair = std::pair<std::string, std::string>; -	using ClassNameMap = boost::multi_index_container< -		ClassNamePair, -		boost::multi_index::indexed_by< -			boost::multi_index::ordered_unique<boost::multi_index::member<ClassNamePair, const std::string, &ClassNamePair::first>, std::less<>>, -			boost::multi_index::ordered_unique<boost::multi_index::member<ClassNamePair, const std::string, &ClassNamePair::second>, std::less<>> -		>>; +	using ClassNameMap = boost::multi_index_container<ClassNamePair, +			boost::multi_index::indexed_by< +					boost::multi_index::ordered_unique< +							boost::multi_index::member<ClassNamePair, const std::string, &ClassNamePair::first>, +							std::less<>>, +					boost::multi_index::ordered_unique< +							boost::multi_index::member<ClassNamePair, const std::string, &ClassNamePair::second>, +							std::less<>>>>;  	static void createClassMaps() __attribute__((constructor(208)));  	static void deleteClassMaps() __attribute__((destructor(208)));  	static ClassNameMap * names;  	static ClassRefMap * refs; -	void createClassMaps() +	void +	createClassMaps()  	{  		names = new ClassNameMap();  		refs = new ClassRefMap();  	} -	static void deleteClassMaps() +	static void +	deleteClassMaps()  	{  		delete names;  		delete refs; @@ -100,10 +104,7 @@ namespace Slicer {  	}  	// ModelPartForRootBase -	ModelPartForRootBase::ModelPartForRootBase(ModelPartPtr m) : -		mp(std::move(m)) -	{ -	} +	ModelPartForRootBase::ModelPartForRootBase(ModelPartPtr m) : mp(std::move(m)) { }  	ChildRef  	ModelPartForRootBase::GetAnonChildRef(const HookFilter &) @@ -121,7 +122,8 @@ namespace Slicer {  		return GetAnonChildRef(hf);  	} -	void ModelPartForRootBase::OnEachChild(const ChildHandler & ch) +	void +	ModelPartForRootBase::OnEachChild(const ChildHandler & ch)  	{  		ch(GetRootName(), mp, nullptr);  	} @@ -144,37 +146,83 @@ namespace Slicer {  		return mp->GetContainedModelPart();  	} -	void ModelPartForSimpleBase::OnEachChild(const ChildHandler &) { } -	ChildRef ModelPartForSimpleBase::GetAnonChildRef(const HookFilter &) { return ChildRef(); } -	ChildRef ModelPartForSimpleBase::GetChildRef(const std::string &, const HookFilter &, bool) { return ChildRef(); } -	bool ModelPartForSimpleBase::HasValue() const { return true; } -	ModelPartType ModelPartForSimpleBase::GetType() const { return type; } -	const ModelPartType ModelPartForSimpleBase::type = mpt_Simple; +	void +	ModelPartForSimpleBase::OnEachChild(const ChildHandler &) +	{ +	} +	ChildRef +	ModelPartForSimpleBase::GetAnonChildRef(const HookFilter &) +	{ +		return ChildRef(); +	} +	ChildRef +	ModelPartForSimpleBase::GetChildRef(const std::string &, const HookFilter &, bool) +	{ +		return ChildRef(); +	} +	bool +	ModelPartForSimpleBase::HasValue() const +	{ +		return true; +	} +	ModelPartType +	ModelPartForSimpleBase::GetType() const +	{ +		return type; +	} +	const ModelPartType ModelPartForSimpleBase::type = ModelPartType::Simple; -	void ModelPartForConvertedBase::OnEachChild(const ChildHandler &) { } -	ChildRef ModelPartForConvertedBase::GetAnonChildRef(const HookFilter &) { return ChildRef(); } -	ChildRef ModelPartForConvertedBase::GetChildRef(const std::string &, const HookFilter &, bool) { return ChildRef(); } -	bool ModelPartForConvertedBase::HasValue() const { return true; } -	ModelPartType ModelPartForConvertedBase::GetType() const { return type; } -	const ModelPartType ModelPartForConvertedBase::type = mpt_Simple; +	void +	ModelPartForConvertedBase::OnEachChild(const ChildHandler &) +	{ +	} +	ChildRef +	ModelPartForConvertedBase::GetAnonChildRef(const HookFilter &) +	{ +		return ChildRef(); +	} +	ChildRef +	ModelPartForConvertedBase::GetChildRef(const std::string &, const HookFilter &, bool) +	{ +		return ChildRef(); +	} +	bool +	ModelPartForConvertedBase::HasValue() const +	{ +		return true; +	} +	ModelPartType +	ModelPartForConvertedBase::GetType() const +	{ +		return type; +	} +	const ModelPartType ModelPartForConvertedBase::type = ModelPartType::Simple; -	ModelPartType ModelPartForComplexBase::GetType() const { return type; } -	const ModelPartType ModelPartForComplexBase::type = mpt_Complex; -	void ModelPartForComplexBase::registerClass(const std::string & className, const std::string * typeName, const ClassRef & cr) +	ModelPartType +	ModelPartForComplexBase::GetType() const  	{ -		Slicer::classRefMap()->insert({ className, cr }); +		return type; +	} +	const ModelPartType ModelPartForComplexBase::type = ModelPartType::Complex; +	void +	ModelPartForComplexBase::registerClass( +			const std::string & className, const std::string * typeName, const ClassRef & cr) +	{ +		Slicer::classRefMap()->insert({className, cr});  		if (typeName) { -			Slicer::classNameMap()->insert({ className, *typeName }); +			Slicer::classNameMap()->insert({className, *typeName});  		}  	} -	void ModelPartForComplexBase::unregisterClass(const std::string & className, const std::string * typeName) +	void +	ModelPartForComplexBase::unregisterClass(const std::string & className, const std::string * typeName)  	{  		Slicer::classRefMap()->erase(className);  		if (typeName) {  			classNameMap()->get<0>().erase(className);  		}  	} -	ModelPartPtr ModelPartForComplexBase::getSubclassModelPart(const std::string & name, void * m) +	ModelPartPtr +	ModelPartForComplexBase::getSubclassModelPart(const std::string & name, void * m)  	{  		auto ref = classRefMap()->find(ToModelTypeName(name));  		if (ref == classRefMap()->end()) { @@ -182,32 +230,38 @@ namespace Slicer {  		}  		return ref->second(m);  	} -	TypeId ModelPartForComplexBase::GetTypeId(const std::string & id, const std::string & className) +	TypeId +	ModelPartForComplexBase::GetTypeId(const std::string & id, const std::string & className)  	{  		return (id == className) ? TypeId() : ToExchangeTypeName(id);  	} -	std::string ModelPartForComplexBase::demangle(const char * mangled) +	std::string +	ModelPartForComplexBase::demangle(const char * mangled)  	{ -		auto buf = std::unique_ptr<char, decltype(free)*>(abi::__cxa_demangle(mangled, nullptr, nullptr, nullptr), std::free); +		auto buf = std::unique_ptr<char, decltype(free) *>( +				abi::__cxa_demangle(mangled, nullptr, nullptr, nullptr), std::free);  		return "::" + std::string(buf.get());  	} -	void ModelPartForOptionalBase::OnEachChild(const ChildHandler & ch) +	void +	ModelPartForOptionalBase::OnEachChild(const ChildHandler & ch)  	{  		if (this->hasModel()) {  			modelPart->OnEachChild(ch);  		}  	} -	void ModelPartForOptionalBase::Complete() +	void +	ModelPartForOptionalBase::Complete()  	{  		if (this->hasModel()) {  			modelPart->Complete();  		}  	} -	ChildRef ModelPartForOptionalBase::GetAnonChildRef(const HookFilter & flt) +	ChildRef +	ModelPartForOptionalBase::GetAnonChildRef(const HookFilter & flt)  	{  		if (this->hasModel()) {  			return modelPart->GetAnonChildRef(flt); @@ -215,7 +269,8 @@ namespace Slicer {  		return ChildRef();  	} -	ChildRef ModelPartForOptionalBase::GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase) +	ChildRef +	ModelPartForOptionalBase::GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase)  	{  		if (this->hasModel()) {  			return modelPart->GetChildRef(name, flt, matchCase); @@ -223,57 +278,127 @@ namespace Slicer {  		return ChildRef();  	} -	void ModelPartForOptionalBase::SetValue(ValueSource && s) +	void +	ModelPartForOptionalBase::SetValue(ValueSource && s)  	{  		if (this->hasModel()) {  			modelPart->SetValue(std::move(s));  		}  	} -	bool ModelPartForOptionalBase::HasValue() const +	bool +	ModelPartForOptionalBase::HasValue() const  	{  		return this->hasModel() && modelPart->HasValue();  	} -	bool ModelPartForOptionalBase::IsOptional() const +	bool +	ModelPartForOptionalBase::IsOptional() const  	{  		return true;  	}; -	const Metadata & ModelPartForOptionalBase::GetMetadata() const +	const Metadata & +	ModelPartForOptionalBase::GetMetadata() const  	{  		return modelPart->GetMetadata();  	} -	void ModelPartForEnumBase::OnEachChild(const ChildHandler &) { } -	ChildRef ModelPartForEnumBase::GetAnonChildRef(const HookFilter &) { return ChildRef(); } -	ChildRef ModelPartForEnumBase::GetChildRef(const std::string &, const HookFilter &, bool) { return ChildRef(); } -	bool ModelPartForEnumBase::HasValue() const { return true; } -	ModelPartType ModelPartForEnumBase::GetType() const { return type; } -	const ModelPartType ModelPartForEnumBase::type = mpt_Simple; +	void +	ModelPartForEnumBase::OnEachChild(const ChildHandler &) +	{ +	} +	ChildRef +	ModelPartForEnumBase::GetAnonChildRef(const HookFilter &) +	{ +		return ChildRef(); +	} +	ChildRef +	ModelPartForEnumBase::GetChildRef(const std::string &, const HookFilter &, bool) +	{ +		return ChildRef(); +	} +	bool +	ModelPartForEnumBase::HasValue() const +	{ +		return true; +	} +	ModelPartType +	ModelPartForEnumBase::GetType() const +	{ +		return type; +	} +	const ModelPartType ModelPartForEnumBase::type = ModelPartType::Simple; -	bool ModelPartForSequenceBase::HasValue() const { return true; } -	ModelPartType ModelPartForSequenceBase::GetType() const { return type; } -	const ModelPartType ModelPartForSequenceBase::type = mpt_Sequence; +	bool +	ModelPartForSequenceBase::HasValue() const +	{ +		return true; +	} +	ModelPartType +	ModelPartForSequenceBase::GetType() const +	{ +		return type; +	} +	const ModelPartType ModelPartForSequenceBase::type = ModelPartType::Sequence; -	bool ModelPartForDictionaryBase::HasValue() const { return true; } -	ModelPartType ModelPartForDictionaryBase::GetType() const { return type; } -	const ModelPartType ModelPartForDictionaryBase::type = mpt_Dictionary; +	bool +	ModelPartForDictionaryBase::HasValue() const +	{ +		return true; +	} +	ModelPartType +	ModelPartForDictionaryBase::GetType() const +	{ +		return type; +	} +	const ModelPartType ModelPartForDictionaryBase::type = ModelPartType::Dictionary;  	// Streams  	// NOLINTNEXTLINE(hicpp-no-array-decay) -	ChildRef ModelPartForStreamBase::GetAnonChildRef(const Slicer::HookFilter &) { throw InvalidStreamOperation(__FUNCTION__); } +	ChildRef +	ModelPartForStreamBase::GetAnonChildRef(const Slicer::HookFilter &) +	{ +		throw InvalidStreamOperation(__FUNCTION__); +	}  	// NOLINTNEXTLINE(hicpp-no-array-decay) -	ChildRef ModelPartForStreamBase::GetChildRef(const std::string &, const Slicer::HookFilter &, bool) { throw InvalidStreamOperation(__FUNCTION__); } -	ModelPartType ModelPartForStreamBase::GetType() const { return mpt_Sequence; } -	bool ModelPartForStreamBase::HasValue() const { return true; } +	ChildRef +	ModelPartForStreamBase::GetChildRef(const std::string &, const Slicer::HookFilter &, bool) +	{ +		throw InvalidStreamOperation(__FUNCTION__); +	} +	ModelPartType +	ModelPartForStreamBase::GetType() const +	{ +		return ModelPartType::Sequence; +	} +	bool +	ModelPartForStreamBase::HasValue() const +	{ +		return true; +	}  	// Stream Roots  	ModelPartForStreamRootBase::ModelPartForStreamRootBase(const ModelPartPtr & mp) : ModelPartForRootBase(mp) { }  	// NOLINTNEXTLINE(hicpp-no-array-decay) -	void ModelPartForStreamRootBase::Write(Ice::OutputStream&) const { throw InvalidStreamOperation(__FUNCTION__); } +	void +	ModelPartForStreamRootBase::Write(Ice::OutputStream &) const +	{ +		throw InvalidStreamOperation(__FUNCTION__); +	}  	// NOLINTNEXTLINE(hicpp-no-array-decay) -	void ModelPartForStreamRootBase::Read(Ice::InputStream&) { throw InvalidStreamOperation(__FUNCTION__); } -	bool ModelPartForStreamRootBase::HasValue() const { return mp->HasValue(); } -	void ModelPartForStreamRootBase::OnEachChild(const ChildHandler & ch) { ch(GetRootName(), mp, NULL); } +	void +	ModelPartForStreamRootBase::Read(Ice::InputStream &) +	{ +		throw InvalidStreamOperation(__FUNCTION__); +	} +	bool +	ModelPartForStreamRootBase::HasValue() const +	{ +		return mp->HasValue(); +	} +	void +	ModelPartForStreamRootBase::OnEachChild(const ChildHandler & ch) +	{ +		ch(GetRootName(), mp, NULL); +	}  } - diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index 99ccb81..b47353b 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -4,376 +4,367 @@  #include "modelParts.h"  namespace Slicer { -	template<typename T> -	struct isLocal { +	template<typename T> struct isLocal {  		static constexpr bool value = false;  	};  	DLL_PUBLIC bool optionalCaseEq(const std::string & a, const std::string & b, bool matchCase); -	template<typename T> -	class DLL_PUBLIC ModelPartForRoot : public ModelPartForRootBase { -		public: -			ModelPartForRoot(T * o); +	template<typename T> class DLL_PUBLIC ModelPartForRoot : public ModelPartForRootBase { +	public: +		explicit ModelPartForRoot(T * o); -			const std::string & GetRootName() const override; -			bool HasValue() const override; -			void Write(::Ice::OutputStream &) const override; -			void Read(::Ice::InputStream &) override; +		const std::string & GetRootName() const override; +		bool HasValue() const override; +		void Write(::Ice::OutputStream &) const override; +		void Read(::Ice::InputStream &) override; -			static const std::string rootName; +		static const std::string rootName; -		private: -			T * ModelObject; +	private: +		T * ModelObject;  	};  	class DLL_PUBLIC ModelPartForSimpleBase : public ModelPart { -		public: -			void OnEachChild(const ChildHandler &) override; -			ChildRef GetAnonChildRef(const HookFilter &) override; -			ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; -			bool HasValue() const override; -			ModelPartType GetType() const override; -			static const ModelPartType type; +	public: +		void OnEachChild(const ChildHandler &) override; +		ChildRef GetAnonChildRef(const HookFilter &) override; +		ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; +		bool HasValue() const override; +		ModelPartType GetType() const override; +		static const ModelPartType type;  	};  	template<typename T>  	class DLL_PUBLIC ModelPartForSimple : public ModelPartForSimpleBase, protected ModelPartModel<T> { -		public: -			using element_type = T; +	public: +		using element_type = T; -			ModelPartForSimple(T * h); +		explicit ModelPartForSimple(T * h); -			void SetValue(ValueSource && s) override; -			bool GetValue(ValueTarget && s) override; +		void SetValue(ValueSource && s) override; +		bool GetValue(ValueTarget && s) override;  	};  	class DLL_PUBLIC ModelPartForConvertedBase : public ModelPart { -		public: -			void OnEachChild(const ChildHandler &) override; -			ChildRef GetAnonChildRef(const HookFilter &) override; -			ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; -			bool HasValue() const override; -			ModelPartType GetType() const override; -			static const ModelPartType type; - -		protected: -			template<typename ET, typename MT, typename Conv> -			inline static bool tryConvertFrom(ValueSource & vsp, MT * model, const Conv & conv); -			template<typename ET, typename MT> -			inline static bool tryConvertFrom(ValueSource & vsp, MT * model); -			template<typename ET, typename MT, typename Conv> -			inline static TryConvertResult tryConvertTo(ValueTarget & vsp, const MT * model, const Conv & conv); -			template<typename ET, typename MT> -			inline static TryConvertResult tryConvertTo(ValueTarget & vsp, const MT * model); +	public: +		void OnEachChild(const ChildHandler &) override; +		ChildRef GetAnonChildRef(const HookFilter &) override; +		ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; +		bool HasValue() const override; +		ModelPartType GetType() const override; +		static const ModelPartType type; + +	protected: +		template<typename ET, typename MT, typename Conv> +		inline static bool tryConvertFrom(ValueSource & vsp, MT * model, const Conv & conv); +		template<typename ET, typename MT> inline static bool tryConvertFrom(ValueSource & vsp, MT * model); +		template<typename ET, typename MT, typename Conv> +		inline static TryConvertResult tryConvertTo(ValueTarget & vsp, const MT * model, const Conv & conv); +		template<typename ET, typename MT> +		inline static TryConvertResult tryConvertTo(ValueTarget & vsp, const MT * model);  	}; -	template<typename T, typename M, T M::* MV> +	template<typename T, typename M, T M::*MV>  	class DLL_PUBLIC ModelPartForConverted : public ModelPartForConvertedBase, protected ModelPartModel<T> { -		public: -			using element_type = T; +	public: +		using element_type = T; -			ModelPartForConverted(T * h); +		explicit ModelPartForConverted(T * h); -			void SetValue(ValueSource && s) override; -			bool GetValue(ValueTarget && s) override; +		void SetValue(ValueSource && s) override; +		bool GetValue(ValueTarget && s) override;  	}; -	template<typename T, typename M, Ice::optional<T> M::* MV> -	class DLL_PUBLIC ModelPartForConverted<Ice::optional<T>, M, MV> : public ModelPartForConvertedBase, protected ModelPartModel<Ice::optional<T>> { -		public: -			using element_type = Ice::optional<T>; +	template<typename T, typename M, Ice::optional<T> M::*MV> +	class DLL_PUBLIC ModelPartForConverted<Ice::optional<T>, M, MV> : +		public ModelPartForConvertedBase, +		protected ModelPartModel<Ice::optional<T>> { +	public: +		using element_type = Ice::optional<T>; -			ModelPartForConverted(Ice::optional<T> * h); +		explicit ModelPartForConverted(Ice::optional<T> * h); -			void SetValue(ValueSource && s) override; -			bool GetValue(ValueTarget && s) override; -			bool HasValue() const override; +		void SetValue(ValueSource && s) override; +		bool GetValue(ValueTarget && s) override; +		bool HasValue() const override;  	};  	class DLL_PUBLIC ModelPartForOptionalBase : public ModelPart { -		public: -			void OnEachChild(const ChildHandler & ch) override; -			void Complete() override; -			ChildRef GetAnonChildRef(const HookFilter & flt) override; -			ChildRef GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase = true) override; -			void SetValue(ValueSource && s) override; -			bool HasValue() const override; -			bool IsOptional() const override; -			const Metadata & GetMetadata() const override; - -		protected: -			virtual bool hasModel() const = 0; -			// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -			ModelPartPtr modelPart; +	public: +		void OnEachChild(const ChildHandler & ch) override; +		void Complete() override; +		ChildRef GetAnonChildRef(const HookFilter & flt) override; +		ChildRef GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase = true) override; +		void SetValue(ValueSource && s) override; +		bool HasValue() const override; +		bool IsOptional() const override; +		const Metadata & GetMetadata() const override; + +	protected: +		virtual bool hasModel() const = 0; +		ModelPartPtr modelPart;  	};  	template<typename T> -	class DLL_PUBLIC ModelPartForOptional : public ModelPartForOptionalBase, protected ModelPartModel<Ice::optional<typename T::element_type> > { -		public: -			ModelPartForOptional(Ice::optional< typename T::element_type > * h); -			void Create() override; -			bool GetValue(ValueTarget && s) override; -			ModelPartType GetType() const override; - -		protected: -			bool hasModel() const override; +	class DLL_PUBLIC ModelPartForOptional : +		public ModelPartForOptionalBase, +		protected ModelPartModel<Ice::optional<typename T::element_type>> { +	public: +		explicit ModelPartForOptional(Ice::optional<typename T::element_type> * h); +		void Create() override; +		bool GetValue(ValueTarget && s) override; +		ModelPartType GetType() const override; + +	protected: +		bool hasModel() const override;  	};  	class DLL_PUBLIC ModelPartForComplexBase : public ModelPart { -		public: -			ModelPartType GetType() const override; -			static const ModelPartType type; +	public: +		ModelPartType GetType() const override; +		static const ModelPartType type; -		protected: -			ModelPartPtr getSubclassModelPart(const std::string & name, void * m); +	protected: +		ModelPartPtr getSubclassModelPart(const std::string & name, void * m); -			static void registerClass(const std::string & className, const std::string * typeName, const ClassRef &); -			static void unregisterClass(const std::string & className, const std::string * typeName); -			static TypeId GetTypeId(const std::string & id, const std::string & className); -			static std::string demangle(const char * mangled); +		static void registerClass(const std::string & className, const std::string * typeName, const ClassRef &); +		static void unregisterClass(const std::string & className, const std::string * typeName); +		static TypeId GetTypeId(const std::string & id, const std::string & className); +		static std::string demangle(const char * mangled); -			static const std::string & ToExchangeTypeName(const std::string &); -			static const std::string & ToModelTypeName(const std::string &); +		static const std::string & ToExchangeTypeName(const std::string &); +		static const std::string & ToModelTypeName(const std::string &);  	}; -	template<typename T> -	class DLL_PUBLIC ModelPartForComplex : public ModelPartForComplexBase { -		public: -			class DLL_PRIVATE HookBase; -			using HookPtr = std::unique_ptr<HookBase>; +	template<typename T> class DLL_PUBLIC ModelPartForComplex : public ModelPartForComplexBase { +	public: +		class DLL_PRIVATE HookBase; +		using HookPtr = std::unique_ptr<HookBase>; -			template <typename MT, typename MP> -			class DLL_PRIVATE Hook; +		template<typename MT, typename MP> class DLL_PRIVATE Hook; -			template <typename MT, typename MP> -			class DLL_PRIVATE HookMetadata; +		template<typename MT, typename MP> class DLL_PRIVATE HookMetadata; -			void OnEachChild(const ChildHandler & ch) override; +		void OnEachChild(const ChildHandler & ch) override; -			ChildRef GetAnonChildRef(const HookFilter & flt) override; -			ChildRef GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase = true) override; +		ChildRef GetAnonChildRef(const HookFilter & flt) override; +		ChildRef GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase = true) override; -			const Metadata & GetMetadata() const override; +		const Metadata & GetMetadata() const override; -			virtual T * GetModel() = 0; +		virtual T * GetModel() = 0; -		protected: -			template<typename R> -			DLL_PRIVATE ChildRef GetChildRefFromRange(const R & range, const HookFilter & flt); +	protected: +		template<typename R> DLL_PRIVATE ChildRef GetChildRefFromRange(const R & range, const HookFilter & flt); -			class DLL_PRIVATE Hooks; +		class DLL_PRIVATE Hooks; -			template<typename H, typename ... P> -			static void addHook(Hooks &, const P & ...); +		template<typename H, typename... P> static void addHook(Hooks &, const P &...); -			static const Hooks hooks; -			static const Metadata metadata; +		static const Hooks hooks; +		static const Metadata metadata;  	};  	template<typename T> -	class DLL_PUBLIC ModelPartForClass : public ModelPartForComplex<T>, protected ModelPartModel<std::shared_ptr<T> > { -		public: -			using element_type = std::shared_ptr<T>; +	class DLL_PUBLIC ModelPartForClass : public ModelPartForComplex<T>, protected ModelPartModel<std::shared_ptr<T>> { +	public: +		using element_type = std::shared_ptr<T>; -			ModelPartForClass(element_type * h); +		explicit ModelPartForClass(element_type * h); -			void Create() override; +		void Create() override; -			T * GetModel() override; +		T * GetModel() override; -			ModelPartPtr GetSubclassModelPart(const std::string & name) override; +		ModelPartPtr GetSubclassModelPart(const std::string & name) override; -			[[nodiscard]] bool HasValue() const override; +		[[nodiscard]] bool HasValue() const override; -			[[nodiscard]] TypeId GetTypeId() const override; -			template<typename dummy = T> -			const std::string & getTypeId(typename std::enable_if<std::is_base_of<Ice::Object, dummy>::value>::type * = nullptr) const; -			template<typename dummy = T> -			std::string getTypeId(typename std::enable_if<!std::is_base_of<Ice::Object, dummy>::value>::type * = nullptr) const; +		[[nodiscard]] TypeId GetTypeId() const override; +		template<typename dummy = T> +		const std::string & getTypeId( +				typename std::enable_if<std::is_base_of<Ice::Object, dummy>::value>::type * = nullptr) const; +		template<typename dummy = T> +		std::string getTypeId( +				typename std::enable_if<!std::is_base_of<Ice::Object, dummy>::value>::type * = nullptr) const; -			[[nodiscard]] Ice::optional<std::string> GetTypeIdProperty() const override; +		[[nodiscard]] Ice::optional<std::string> GetTypeIdProperty() const override; -			static const std::string typeIdProperty; -			static const std::string * className; -			static const std::string * typeName; +		static const std::string typeIdProperty; +		static const std::string * className; +		static const std::string * typeName; -			static ModelPartPtr CreateModelPart(void *); +		static ModelPartPtr CreateModelPart(void *); -		private: -			static void initClassName(); -			static void deleteClassName(); -			static void registerClass() __attribute__ ((constructor(210))); -			static void unregisterClass() __attribute__ ((destructor(210))); +	private: +		static void initClassName(); +		static void deleteClassName(); +		static void registerClass() __attribute__((constructor(210))); +		static void unregisterClass() __attribute__((destructor(210)));  	};  	template<typename T>  	class DLL_PUBLIC ModelPartForStruct : public ModelPartForComplex<T>, protected ModelPartModel<T> { -		public: -			using element_type = T; +	public: +		using element_type = T; -			ModelPartForStruct(T * o); +		explicit ModelPartForStruct(T * o); -			T * GetModel() override; +		T * GetModel() override; -			[[nodiscard]] bool HasValue() const override; +		[[nodiscard]] bool HasValue() const override;  	};  	class DLL_PUBLIC ModelPartForEnumBase : public ModelPart { -		public: -			void OnEachChild(const ChildHandler &) override; -			ChildRef GetAnonChildRef(const HookFilter &) override; -			ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; -			bool HasValue() const override; -			ModelPartType GetType() const override; -			static const ModelPartType type; +	public: +		void OnEachChild(const ChildHandler &) override; +		ChildRef GetAnonChildRef(const HookFilter &) override; +		ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; +		bool HasValue() const override; +		ModelPartType GetType() const override; +		static const ModelPartType type;  	}; -	template<typename T> -	class DLL_PUBLIC ModelPartForEnum : public ModelPartForEnumBase, protected ModelPartModel<T> { -		public: -			using element_type = T; -			class DLL_PRIVATE Enumerations; +	template<typename T> class DLL_PUBLIC ModelPartForEnum : public ModelPartForEnumBase, protected ModelPartModel<T> { +	public: +		using element_type = T; +		class DLL_PRIVATE Enumerations; -			ModelPartForEnum(T * s); +		explicit ModelPartForEnum(T * s); -			const Metadata & GetMetadata() const override; +		const Metadata & GetMetadata() const override; -			void SetValue(ValueSource && s) override; +		void SetValue(ValueSource && s) override; -			bool GetValue(ValueTarget && s) override; +		bool GetValue(ValueTarget && s) override; -			static const Metadata metadata; -			static const Enumerations enumerations; -			DLL_PUBLIC static const std::string & lookup(T); -			DLL_PUBLIC static T lookup(const std::string_view &); +		static const Metadata metadata; +		static const Enumerations enumerations; +		DLL_PUBLIC static const std::string & lookup(T); +		DLL_PUBLIC static T lookup(const std::string_view &);  	};  	class DLL_PUBLIC ModelPartForSequenceBase : public ModelPart { -		public: -			bool HasValue() const override; -			ModelPartType GetType() const override; -			static const ModelPartType type; +	public: +		bool HasValue() const override; +		ModelPartType GetType() const override; +		static const ModelPartType type;  	};  	template<typename T>  	class DLL_PUBLIC ModelPartForSequence : public ModelPartForSequenceBase, protected ModelPartModel<T> { -		public: -			using element_type = T; +	public: +		using element_type = T; -			ModelPartForSequence(T * s); +		explicit ModelPartForSequence(T * s); -			void OnEachChild(const ChildHandler & ch) override; +		void OnEachChild(const ChildHandler & ch) override; -			ChildRef GetAnonChildRef(const HookFilter &) override; +		ChildRef GetAnonChildRef(const HookFilter &) override; -			ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; +		ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; -			const Metadata & GetMetadata() const override; +		const Metadata & GetMetadata() const override; -			ModelPartPtr GetContainedModelPart() override; +		ModelPartPtr GetContainedModelPart() override; -			static const Metadata metadata; -			static const std::string elementName; +		static const Metadata metadata; +		static const std::string elementName; -		private: -			ModelPartPtr elementModelPart(typename T::value_type &) const; +	private: +		ModelPartPtr elementModelPart(typename T::value_type &) const;  	};  	template<typename T>  	class DLL_PUBLIC ModelPartForDictionaryElementInserter : public ModelPartForStruct<typename T::value_type> { -		public: -			ModelPartForDictionaryElementInserter(T * d); +	public: +		explicit ModelPartForDictionaryElementInserter(T * d); -			void Complete() override; +		void Complete() override; -			// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -			typename T::value_type value; +		typename T::value_type value; -		private: -			T * dictionary; +	private: +		T * dictionary;  	};  	class DLL_PUBLIC ModelPartForDictionaryBase : public ModelPart { -		public: -			bool HasValue() const override; -			ModelPartType GetType() const override; -			static const ModelPartType type; +	public: +		bool HasValue() const override; +		ModelPartType GetType() const override; +		static const ModelPartType type;  	};  	template<typename T>  	class DLL_PUBLIC ModelPartForDictionary : public ModelPartForDictionaryBase, protected ModelPartModel<T> { -		public: -			using element_type = T; +	public: +		using element_type = T; -			ModelPartForDictionary(T * d); +		explicit ModelPartForDictionary(T * d); -			void OnEachChild(const ChildHandler & ch) override; +		void OnEachChild(const ChildHandler & ch) override; -			ChildRef GetAnonChildRef(const HookFilter &) override; +		ChildRef GetAnonChildRef(const HookFilter &) override; -			ChildRef GetChildRef(const std::string & name, const HookFilter &, bool matchCase = true) override; +		ChildRef GetChildRef(const std::string & name, const HookFilter &, bool matchCase = true) override; -			const Metadata & GetMetadata() const override; +		const Metadata & GetMetadata() const override; -			ModelPartPtr GetContainedModelPart() override; +		ModelPartPtr GetContainedModelPart() override; -			static const Metadata metadata; -			static const std::string pairName; +		static const Metadata metadata; +		static const std::string pairName;  	}; -	template<typename T> -	class DLL_PUBLIC Stream { -		public: -			using Consumer = std::function<void(const T &)>; -			using element_type = T; +	template<typename T> class DLL_PUBLIC Stream { +	public: +		using Consumer = std::function<void(const T &)>; +		using element_type = T; -			virtual void Produce(const Consumer & c) = 0; +		virtual void Produce(const Consumer & c) = 0;  	};  	class DLL_PUBLIC ModelPartForStreamBase : public ModelPart { -		public: -			ModelPartType GetType() const override; -			bool HasValue() const override; -			ChildRef GetAnonChildRef(const HookFilter &) override; -			ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; - -			ModelPartPtr GetContainedModelPart() override = 0; -			void OnEachChild(const ChildHandler & ch) override = 0; +	public: +		ModelPartType GetType() const override; +		bool HasValue() const override; +		ChildRef GetAnonChildRef(const HookFilter &) override; +		ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; + +		ModelPartPtr GetContainedModelPart() override = 0; +		void OnEachChild(const ChildHandler & ch) override = 0;  	};  	template<typename T>  	class DLL_PUBLIC ModelPartForStream : public ModelPartForStreamBase, ModelPartModel<Stream<T>> { -		public: -			ModelPartForStream(Stream<T> * s); +	public: +		explicit ModelPartForStream(Stream<T> * s); -			ModelPartPtr GetContainedModelPart() override; -			void OnEachChild(const ChildHandler & ch) override; +		ModelPartPtr GetContainedModelPart() override; +		void OnEachChild(const ChildHandler & ch) override;  	};  	class DLL_PUBLIC ModelPartForStreamRootBase : public ModelPartForRootBase { -		public: -			ModelPartForStreamRootBase(const ModelPartPtr & mp); - -			void Write(Ice::OutputStream&) const override; -			void Read(Ice::InputStream&) override; -			bool HasValue() const override; -			void OnEachChild(const ChildHandler & ch) override; -			const std::string & GetRootName() const override = 0; +	public: +		explicit ModelPartForStreamRootBase(const ModelPartPtr & mp); + +		void Write(Ice::OutputStream &) const override; +		void Read(Ice::InputStream &) override; +		bool HasValue() const override; +		void OnEachChild(const ChildHandler & ch) override; +		const std::string & GetRootName() const override = 0;  	}; -	template<typename T> -	class DLL_PUBLIC ModelPartForStreamRoot : public ModelPartForStreamRootBase { -		public: -			ModelPartForStreamRoot(Stream<T> * s); +	template<typename T> class DLL_PUBLIC ModelPartForStreamRoot : public ModelPartForStreamRootBase { +	public: +		explicit ModelPartForStreamRoot(Stream<T> * s); -			const std::string & GetRootName() const override; +		const std::string & GetRootName() const override; -		private: -			Stream<T> * stream; +	private: +		Stream<T> * stream;  	};  }  #endif - - diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 872304b..be464d1 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -1,67 +1,98 @@  #ifndef SLICER_MODELPARTSTYPES_IMPL_H  #define SLICER_MODELPARTSTYPES_IMPL_H -#include "modelPartsTypes.h"  #include "common.h" +#include "modelPartsTypes.h"  #include <Ice/StreamHelpers.h>  #include <IceUtil/Optional.h> -#include <boost/multi_index_container.hpp> -#include <boost/multi_index/sequenced_index.hpp> -#include <boost/multi_index/ordered_index.hpp> +#include <boost/algorithm/string/case_conv.hpp>  #include <boost/multi_index/global_fun.hpp>  #include <boost/multi_index/member.hpp> -#include <boost/algorithm/string/case_conv.hpp> +#include <boost/multi_index/ordered_index.hpp> +#include <boost/multi_index/sequenced_index.hpp> +#include <boost/multi_index_container.hpp> +#include <c++11Helpers.h>  #ifdef __clang__ -#define FINALVISMODELPARTS DLL_PUBLIC +#	define FINALVISMODELPARTS DLL_PUBLIC  #else -#define FINALVISMODELPARTS +#	define FINALVISMODELPARTS  #endif  #define CUSTOMMODELPARTFOR(Type, BaseModelPart, ModelPartType) \ -	template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor<Type>() { return std::make_shared<ModelPartType>(nullptr); } \ -	template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(Type & s) { return std::make_shared<ModelPartType>(&s); } \ -	template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(const Type & s) { return CreateFor(const_cast<Type &>(s)); } \ -	template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(Ice::optional<Type> & s) { return std::make_shared<ModelPartForOptional<ModelPartType>>(&s); } \ -	template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(const Ice::optional<Type> & s) { return CreateFor(const_cast<Ice::optional<Type> &>(s)); } \ -	template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(Type & s) { return std::make_shared<ModelPartForRoot<Type>>(&s); } \ -	template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(Ice::optional<Type> & s) { return std::make_shared<ModelPartForRoot<Ice::optional<Type>>>(&s); } \ -	template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(const Type & s) { return CreateRootFor(const_cast<Type &>(s)); } \ -	template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(const Ice::optional<Type> & s) { return CreateRootFor(const_cast<Ice::optional<Type> &>(s)); } \ +	template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor<Type>() \ +	{ \ +		return std::make_shared<ModelPartType>(nullptr); \ +	} \ +	template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(Type & s) \ +	{ \ +		return std::make_shared<ModelPartType>(&s); \ +	} \ +	template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(const Type & s) \ +	{ \ +		return CreateFor(const_cast<Type &>(s)); \ +	} \ +	template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(Ice::optional<Type> & s) \ +	{ \ +		return std::make_shared<ModelPartForOptional<ModelPartType>>(&s); \ +	} \ +	template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(const Ice::optional<Type> & s) \ +	{ \ +		return CreateFor(const_cast<Ice::optional<Type> &>(s)); \ +	} \ +	template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(Type & s) \ +	{ \ +		return std::make_shared<ModelPartForRoot<Type>>(&s); \ +	} \ +	template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(Ice::optional<Type> & s) \ +	{ \ +		return std::make_shared<ModelPartForRoot<Ice::optional<Type>>>(&s); \ +	} \ +	template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(const Type & s) \ +	{ \ +		return CreateRootFor(const_cast<Type &>(s)); \ +	} \ +	template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(const Ice::optional<Type> & s) \ +	{ \ +		return CreateRootFor(const_cast<Ice::optional<Type> &>(s)); \ +	} \  	template class FINALVISMODELPARTS BaseModelPart; \  	template class ModelPartForRoot<Type>; \ -	template class ModelPartForRoot< Ice::optional<Type> >; \ +	template class ModelPartForRoot<Ice::optional<Type>>; -#define MODELPARTFOR(Type, ModelPartType) \ -	CUSTOMMODELPARTFOR(Type, ModelPartType<Type>, ModelPartType<Type>) +#define MODELPARTFOR(Type, ModelPartType) CUSTOMMODELPARTFOR(Type, ModelPartType<Type>, ModelPartType<Type>)  #define MODELPARTFORSTREAM(StreamImpl) \  	namespace Slicer { \ -		template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(const StreamImpl & stream) { \ -			return std::make_shared<ModelPartForStreamRoot<typename StreamImpl::element_type>>(const_cast<StreamImpl *>(&stream)); \ +		template<> \ +		DLL_PUBLIC ModelPartForRootPtr \ +		ModelPart::CreateRootFor(const StreamImpl & stream) \ +		{ \ +			return std::make_shared<ModelPartForStreamRoot<typename StreamImpl::element_type>>( \ +					const_cast<StreamImpl *>(&stream)); \  		} \  	}  #ifdef __clang__ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wundefined-var-template" +#	pragma clang diagnostic push +#	pragma clang diagnostic ignored "-Wundefined-var-template"  #endif  namespace Slicer {  	// ModelPartForRoot  	template<typename T> -	ModelPartForRoot<T>::ModelPartForRoot(T * o) : -		ModelPartForRootBase(ModelPart::CreateFor(*o)), -		ModelObject(o) +	ModelPartForRoot<T>::ModelPartForRoot(T * o) : ModelPartForRootBase(ModelPart::CreateFor(*o)), ModelObject(o)  	{  	}  	template<typename T> -	const std::string & ModelPartForRoot<T>::GetRootName() const +	const std::string & +	ModelPartForRoot<T>::GetRootName() const  	{  		return rootName;  	}  	template<typename T> -	bool ModelPartForRoot<T>::HasValue() const +	bool +	ModelPartForRoot<T>::HasValue() const  	{  		return ModelObject && mp->HasValue();  	} @@ -131,100 +162,144 @@ namespace Slicer {  	}  	template<typename T> -	void ModelPartForRoot<T>::Write(::Ice::OutputStream & s) const +	void +	ModelPartForRoot<T>::Write(::Ice::OutputStream & s) const  	{  		typeWrite(s, *ModelObject);  	}  	template<typename T> -	void ModelPartForRoot<T>::Read(::Ice::InputStream & s) +	void +	ModelPartForRoot<T>::Read(::Ice::InputStream & s)  	{  		typeRead(s, *ModelObject);  	}  	// ModelPartForSimple -	template<typename T> -	ModelPartForSimple<T>::ModelPartForSimple(T * h) : -		ModelPartModel<T>(h) -	{ -	} +	template<typename T> ModelPartForSimple<T>::ModelPartForSimple(T * h) : ModelPartModel<T>(h) { }  	template<typename T> -	void ModelPartForSimple<T>::SetValue(ValueSource && s) +	void +	ModelPartForSimple<T>::SetValue(ValueSource && s)  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		s.set(*this->Model);  	}  	template<typename T> -	bool ModelPartForSimple<T>::GetValue(ValueTarget && s) +	bool +	ModelPartForSimple<T>::GetValue(ValueTarget && s)  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		s.get(*this->Model);  		return true;  	}  	// ModelPartForConverted -	template<typename T, typename M, T M::* MV> -	ModelPartForConverted<T, M, MV>::ModelPartForConverted(T * h) : -		ModelPartModel<T>(h) +	template<typename T, typename M, T M::*MV> +	ModelPartForConverted<T, M, MV>::ModelPartForConverted(T * h) : ModelPartModel<T>(h)  	{  	} -	template<typename T, typename M, Ice::optional<T> M::* MV> +	template<typename T, typename M, Ice::optional<T> M::*MV>  	ModelPartForConverted<Ice::optional<T>, M, MV>::ModelPartForConverted(Ice::optional<T> * h) :  		ModelPartModel<Ice::optional<T>>(h)  	{  	} -	template<typename T, typename M, Ice::optional<T> M::* MV> -	bool ModelPartForConverted<Ice::optional<T>, M, MV>::HasValue() const +	template<typename T, typename M, Ice::optional<T> M::*MV> +	bool +	ModelPartForConverted<Ice::optional<T>, M, MV>::HasValue() const  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		return (bool)*this->Model;  	}  	// Function traits helpers -	template <typename R, typename ... Args> struct function_traits; -	template <typename R, typename ... Args> struct function_traits<std::function<R(Args...)>> { +	template<typename R, typename... Args> struct function_traits; +	template<typename R, typename... Args> struct function_traits<std::function<R(Args...)>> {  		template<int A> struct arg {  			using type = typename std::tuple_element<A, std::tuple<Args...>>::type;  		};  	}; -	template <typename F> struct callable_traits : public function_traits<std::function<typename std::remove_pointer<F>::type>> { }; +	template<typename F> +	struct callable_traits : public function_traits<std::function<typename std::remove_pointer<F>::type>> { +	};  	// Converters that remove "optionalness". -	template <typename X> -	struct Coerce { +	template<typename X> struct Coerce {  		using T = typename std::remove_const<typename std::remove_reference<X>::type>::type; -		T & operator()(T & x) const { return x; } -		const T & operator()(const T & x) const { return x; } -		template <typename Y> -		T & operator()(Ice::optional<Y> & x) const { if (!x) x = Y(); return *x; } -		template <typename Y> -		const T & operator()(const Ice::optional<Y> & x) const { return *x; } -		static bool valueExists(const T &) { return true; } -		static bool valueExists(const Ice::optional<T> & y) { return y.has_value(); } +		T & +		operator()(T & x) const +		{ +			return x; +		} +		const T & +		operator()(const T & x) const +		{ +			return x; +		} +		template<typename Y> +		T & +		operator()(Ice::optional<Y> & x) const +		{ +			if (!x) { +				x = Y(); +			} +			return *x; +		} +		template<typename Y> +		const T & +		operator()(const Ice::optional<Y> & x) const +		{ +			return *x; +		} +		static bool +		valueExists(const T &) +		{ +			return true; +		} +		static bool +		valueExists(const Ice::optional<T> & y) +		{ +			return y.has_value(); +		}  	}; -	template <typename X> -	struct Coerce<Ice::optional<X>> { +	template<typename X> struct Coerce<Ice::optional<X>> {  		using T = typename std::remove_const<typename std::remove_reference<X>::type>::type; -		Ice::optional<T> & operator()(Ice::optional<T> & x) const { return x; } -		const Ice::optional<T> & operator()(const Ice::optional<T> & x) const { return x; } -		template <typename Y> -		Ice::optional<T> operator()(Y & y) const { return y; } -		static bool valueExists(const T &) { return true; } -		static bool valueExists(const Ice::optional<T> &) { return true; } +		Ice::optional<T> & +		operator()(Ice::optional<T> & x) const +		{ +			return x; +		} +		const Ice::optional<T> & +		operator()(const Ice::optional<T> & x) const +		{ +			return x; +		} +		template<typename Y> +		Ice::optional<T> +		operator()(Y & y) const +		{ +			return y; +		} +		static bool +		valueExists(const T &) +		{ +			return true; +		} +		static bool +		valueExists(const Ice::optional<T> &) +		{ +			return true; +		}  	};  	template<typename ET, typename MT, typename Conv> -	inline -	bool ModelPartForConvertedBase::tryConvertFrom(ValueSource & vsp, MT * model, const Conv & conv) +	inline bool +	ModelPartForConvertedBase::tryConvertFrom(ValueSource & vsp, MT * model, const Conv & conv)  	{  		if (auto vspt = dynamic_cast<TValueSource<ET> *>(&vsp)) {  			using CA = typename callable_traits<Conv>::template arg<0>::type; @@ -240,8 +315,8 @@ namespace Slicer {  	}  	template<typename ET, typename MT> -	inline -	bool ModelPartForConvertedBase::tryConvertFrom(ValueSource & vsp, MT * model) +	inline bool +	ModelPartForConvertedBase::tryConvertFrom(ValueSource & vsp, MT * model)  	{  		if (auto vspt = dynamic_cast<TValueSource<ET> *>(&vsp)) {  			if (Coerce<ET>::valueExists(*model)) { @@ -253,8 +328,8 @@ namespace Slicer {  	}  	template<typename ET, typename MT, typename Conv> -	inline -	TryConvertResult ModelPartForConvertedBase::tryConvertTo(ValueTarget & vsp, const MT * model, const Conv & conv) +	inline TryConvertResult +	ModelPartForConvertedBase::tryConvertTo(ValueTarget & vsp, const MT * model, const Conv & conv)  	{  		if (auto vspt = dynamic_cast<TValueTarget<ET> *>(&vsp)) {  			using CA = typename callable_traits<Conv>::template arg<0>::type; @@ -263,32 +338,32 @@ namespace Slicer {  				auto converted = conv(Coerce<CA>()(*model));  				if (Coerce<ET>::valueExists(converted)) {  					vspt->get(Coerce<ET>()(converted)); -					return tcr_Value; +					return TryConvertResult::Value;  				}  			} -			return tcr_NoValue; +			return TryConvertResult::NoValue;  		} -		return tcr_NoAction; +		return TryConvertResult::NoAction;  	}  	template<typename ET, typename MT> -	inline -	TryConvertResult ModelPartForConvertedBase::tryConvertTo(ValueTarget & vsp, const MT * model) +	inline TryConvertResult +	ModelPartForConvertedBase::tryConvertTo(ValueTarget & vsp, const MT * model)  	{  		if (auto vspt = dynamic_cast<TValueTarget<ET> *>(&vsp)) {  			if (Coerce<ET>::valueExists(*model)) {  				vspt->get(Coerce<ET>()(*model)); -				return tcr_Value; +				return TryConvertResult::Value;  			} -			return tcr_NoValue; +			return TryConvertResult::NoValue;  		} -		return tcr_NoAction; +		return TryConvertResult::NoAction;  	}  	// ModelPartForOptional  	template<typename T> -	ModelPartForOptional<T>::ModelPartForOptional(Ice::optional< typename T::element_type > * h) : -		ModelPartModel<Ice::optional< typename T::element_type> >(h) +	ModelPartForOptional<T>::ModelPartForOptional(Ice::optional<typename T::element_type> * h) : +		ModelPartModel<Ice::optional<typename T::element_type>>(h)  	{  		if (this->Model && *this->Model) {  			modelPart = std::make_shared<T>(&**this->Model); @@ -296,17 +371,17 @@ namespace Slicer {  	}  	template<typename T> -	bool ModelPartForOptional<T>::hasModel() const +	bool +	ModelPartForOptional<T>::hasModel() const  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		return (bool)*this->Model;  	}  	template<typename T> -	void ModelPartForOptional<T>::Create() +	void +	ModelPartForOptional<T>::Create()  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		if (!*this->Model) {  			*this->Model = typename T::element_type(); @@ -316,9 +391,9 @@ namespace Slicer {  	}  	template<typename T> -	bool ModelPartForOptional<T>::GetValue(ValueTarget && s) +	bool +	ModelPartForOptional<T>::GetValue(ValueTarget && s)  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		if (*this->Model) {  			return modelPart->GetValue(std::move(s)); @@ -327,34 +402,50 @@ namespace Slicer {  	}  	template<typename T> -	ModelPartType ModelPartForOptional<T>::GetType() const +	ModelPartType +	ModelPartForOptional<T>::GetType() const  	{  		return T::type;  	}  	// ModelPartForComplex  	template<typename T> -	class ModelPartForComplex<T>::Hooks : public boost::multi_index_container< -		HookPtr, -		boost::multi_index::indexed_by< -			boost::multi_index::sequenced<>, -			boost::multi_index::ordered_non_unique<boost::multi_index::member<HookCommon, const std::string, &HookCommon::name>, std::less<>>, -			boost::multi_index::ordered_non_unique<boost::multi_index::member<HookCommon, const std::string, &HookCommon::name>, case_less>>> { +	class ModelPartForComplex<T>::Hooks : +		public boost::multi_index_container<HookPtr, +				boost::multi_index::indexed_by<boost::multi_index::sequenced<>, +						boost::multi_index::ordered_non_unique< +								boost::multi_index::member<HookCommon, const std::string, &HookCommon::name>, +								std::less<>>, +						boost::multi_index::ordered_non_unique< +								boost::multi_index::member<HookCommon, const std::string, &HookCommon::name>, +								case_less>>> {  	};  	template<typename T> -	void ModelPartForComplex<T>::OnEachChild(const ChildHandler & ch) +	void +	ModelPartForComplex<T>::OnEachChild(const ChildHandler & ch)  	{  		for (const auto & h : hooks) {  			h->apply(ch, h->Get(GetModel()));  		}  	} -	template<typename P> auto begin(const P & p) { return p.first; } -	template<typename P> auto end(const P & p) { return p.second; } +	template<typename P> +	auto +	begin(const P & p) +	{ +		return p.first; +	} +	template<typename P> +	auto +	end(const P & p) +	{ +		return p.second; +	}  	template<typename T>  	template<typename R> -	ChildRef ModelPartForComplex<T>::GetChildRefFromRange(const R & range, const HookFilter & flt) +	ChildRef +	ModelPartForComplex<T>::GetChildRefFromRange(const R & range, const HookFilter & flt)  	{  		auto model = GetModel();  		for (const auto & h : range) { @@ -366,13 +457,15 @@ namespace Slicer {  	}  	template<typename T> -	ChildRef ModelPartForComplex<T>::GetAnonChildRef(const HookFilter & flt) +	ChildRef +	ModelPartForComplex<T>::GetAnonChildRef(const HookFilter & flt)  	{  		return GetChildRefFromRange(hooks.template get<0>(), flt);  	}  	template<typename T> -	ChildRef ModelPartForComplex<T>::GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase) +	ChildRef +	ModelPartForComplex<T>::GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase)  	{  		if (matchCase) {  			return GetChildRefFromRange(hooks.template get<1>().equal_range(name), flt); @@ -383,138 +476,137 @@ namespace Slicer {  	}  	template<typename T> -	const Metadata & ModelPartForComplex<T>::GetMetadata() const +	const Metadata & +	ModelPartForComplex<T>::GetMetadata() const  	{  		return metadata;  	}  	template<typename T> -	template<typename H, typename ... P> -	void ModelPartForComplex<T>::addHook(Hooks & h, const P & ... p) +	template<typename H, typename... P> +	void +	ModelPartForComplex<T>::addHook(Hooks & h, const P &... p)  	{  		h.push_back(std::make_unique<H>(p...));  	} -	template<typename T> -	class DLL_PRIVATE ModelPartForComplex<T>::HookBase : public HookCommon { -		public: -			HookBase(const std::string & n) : -				HookCommon(n) -			{ -			} -			virtual ~HookBase() = default; +	template<typename T> class DLL_PRIVATE ModelPartForComplex<T>::HookBase : public HookCommon { +	public: +		explicit HookBase(const std::string & n) : HookCommon(n) { } +		SPECIAL_MEMBERS_DEFAULT(HookBase); +		virtual ~HookBase() = default; -			virtual ModelPartPtr Get(T * t) const = 0; -			const Metadata & GetMetadata() const override -			{ -				return emptyMetadata; -			} +		virtual ModelPartPtr Get(T * t) const = 0; +		[[nodiscard]] const Metadata & +		GetMetadata() const override +		{ +			return emptyMetadata; +		}  	};  	template<typename T>  	template<typename MT, typename MP>  	class DLL_PRIVATE ModelPartForComplex<T>::Hook : public ModelPartForComplex<T>::HookBase { -		public: -			Hook(MT T::* m, const std::string & n) : -				HookBase(n), -				member(m) -			{ -			} - -			ModelPartPtr Get(T * t) const override -			{ -				return std::make_shared<MP>(t ? const_cast<typename std::remove_const<MT>::type *>(&(t->*member)) : NULL); -			} +	public: +		Hook(MT T::*m, const std::string & n) : HookBase(n), member(m) { } + +		ModelPartPtr +		Get(T * t) const override +		{ +			return std::make_shared<MP>( +					t ? const_cast<typename std::remove_const<MT>::type *>(&(t->*member)) : nullptr); +		} -		private: -			const MT T::* member; +	private: +		const MT T::*member;  	};  	template<typename T>  	template<typename MT, typename MP>  	class DLL_PRIVATE ModelPartForComplex<T>::HookMetadata : public ModelPartForComplex<T>::template Hook<MT, MP> { -		public: -			HookMetadata(MT T::* member, const std::string & n, const Metadata & md) : -				Hook<MT, MP>(member, n), -				metadata(md) -			{ -			} +	public: +		HookMetadata(MT T::*member, const std::string & n, Metadata md) : +			Hook<MT, MP>(member, n), metadata(std::move(md)) +		{ +		} -			const Metadata & GetMetadata() const override -			{ -				return metadata; -			} +		[[nodiscard]] const Metadata & +		GetMetadata() const override +		{ +			return metadata; +		} -			const Metadata metadata; +		const Metadata metadata;  	};  	// ModelPartForClass -	template<typename T> -	ModelPartForClass<T>::ModelPartForClass(element_type * h) : -			ModelPartModel<element_type>(h) -	{ -	} +	template<typename T> ModelPartForClass<T>::ModelPartForClass(element_type * h) : ModelPartModel<element_type>(h) { }  	template<typename T> -	void ModelPartForClass<T>::Create() +	void +	ModelPartForClass<T>::Create()  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		*this->Model = std::make_shared<T>();  	}  	template<typename T> -	T * ModelPartForClass<T>::GetModel() +	T * +	ModelPartForClass<T>::GetModel()  	{  		return this->Model ? this->Model->get() : nullptr;  	}  	template<typename T> -	ModelPartPtr ModelPartForClass<T>::GetSubclassModelPart(const std::string & name) +	ModelPartPtr +	ModelPartForClass<T>::GetSubclassModelPart(const std::string & name)  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		return ModelPartForComplexBase::getSubclassModelPart(name, this->Model);  	}  	template<typename T> -	bool ModelPartForClass<T>::HasValue() const +	bool +	ModelPartForClass<T>::HasValue() const  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		return (bool)*this->Model;  	}  	template<typename T> -	Ice::optional<std::string> ModelPartForClass<T>::GetTypeIdProperty() const +	Ice::optional<std::string> +	ModelPartForClass<T>::GetTypeIdProperty() const  	{  		return typeIdProperty;  	}  	template<typename T> -	ModelPartPtr ModelPartForClass<T>::CreateModelPart(void * p) +	ModelPartPtr +	ModelPartForClass<T>::CreateModelPart(void * p)  	{  		return std::make_shared<ModelPartForClass<T>>(static_cast<element_type *>(p));  	}  	template<typename T> -	void ModelPartForClass<T>::deleteClassName() +	void +	ModelPartForClass<T>::deleteClassName()  	{  		delete className;  		delete typeName;  	}  	template<typename T> -	void ModelPartForClass<T>::registerClass() +	void +	ModelPartForClass<T>::registerClass()  	{  		initClassName();  		ModelPartForComplexBase::registerClass(*className, typeName, &ModelPartForClass<T>::CreateModelPart);  	}  	template<typename T> -	void ModelPartForClass<T>::unregisterClass() +	void +	ModelPartForClass<T>::unregisterClass()  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(className);  		ModelPartForComplexBase::unregisterClass(*className, typeName);  		deleteClassName(); @@ -524,78 +616,72 @@ namespace Slicer {  	TypeId  	ModelPartForClass<T>::GetTypeId() const  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model); -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(className);  		return ModelPartForComplexBase::GetTypeId(getTypeId(), *className);  	}  	template<typename T>  	template<typename dummy> -	const std::string & ModelPartForClass<T>::getTypeId(typename std::enable_if<std::is_base_of<Ice::Object, dummy>::value>::type *) const +	const std::string & +	ModelPartForClass<T>::getTypeId(typename std::enable_if<std::is_base_of<Ice::Object, dummy>::value>::type *) const  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		return (*this->Model)->ice_id();  	}  	template<typename T>  	template<typename dummy> -	std::string ModelPartForClass<T>::getTypeId(typename std::enable_if<!std::is_base_of<Ice::Object, dummy>::value>::type *) const +	std::string +	ModelPartForClass<T>::getTypeId(typename std::enable_if<!std::is_base_of<Ice::Object, dummy>::value>::type *) const  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		return ModelPartForComplexBase::demangle(typeid(*this->Model->get()).name());  	}  	// ModelPartForStruct -	template<typename T> -	ModelPartForStruct<T>::ModelPartForStruct(T * o) : -		ModelPartModel<T>(o) -	{ -	} +	template<typename T> ModelPartForStruct<T>::ModelPartForStruct(T * o) : ModelPartModel<T>(o) { }  	template<typename T> -	T * ModelPartForStruct<T>::GetModel() +	T * +	ModelPartForStruct<T>::GetModel()  	{  		return this->Model;  	}  	template<typename T> -	bool ModelPartForStruct<T>::HasValue() const +	bool +	ModelPartForStruct<T>::HasValue() const  	{  		return true;  	}  	// ModelPartForEnum -	template<typename T> -	using EnumPair = std::pair<T, std::string>; +	template<typename T> using EnumPair = std::pair<T, std::string>;  	template<typename T> -	class ModelPartForEnum<T>::Enumerations : public boost::multi_index_container< -		EnumPair<T>, -		boost::multi_index::indexed_by< -			boost::multi_index::ordered_unique<boost::multi_index::member<EnumPair<T>, const T, &EnumPair<T>::first>>, -			boost::multi_index::ordered_unique<boost::multi_index::member<EnumPair<T>, const std::string, &EnumPair<T>::second>, std::less<>> -			>> { +	class ModelPartForEnum<T>::Enumerations : +		public boost::multi_index_container<EnumPair<T>, +				boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::member< +													   EnumPair<T>, const T, &EnumPair<T>::first>>, +						boost::multi_index::ordered_unique< +								boost::multi_index::member<EnumPair<T>, const std::string, &EnumPair<T>::second>, +								std::less<>>>> {  	}; -	template<typename T> -	ModelPartForEnum<T>::ModelPartForEnum(T * s) : -		ModelPartModel<T>(s) -	{ -	} +	template<typename T> ModelPartForEnum<T>::ModelPartForEnum(T * s) : ModelPartModel<T>(s) { }  	template<typename T> -	const Metadata & ModelPartForEnum<T>::GetMetadata() const +	const Metadata & +	ModelPartForEnum<T>::GetMetadata() const  	{  		return metadata;  	}  	template<int Side, typename Ex, typename ExP, typename T, typename V, typename R> -	inline const auto & ModelPartForEnumLookup(const typename ModelPartForEnum<T>::Enumerations & enumerations, -			const V & val, R EnumPair<T>::* rv) +	inline const auto & +	ModelPartForEnumLookup( +			const typename ModelPartForEnum<T>::Enumerations & enumerations, const V & val, R EnumPair<T>::*rv)  	{  		const auto & side = enumerations.template get<Side>();  		if (auto i = side.find(val); i != side.end()) { @@ -605,23 +691,25 @@ namespace Slicer {  	}  	template<typename T> -	T ModelPartForEnum<T>::lookup(const std::string_view & val) +	T +	ModelPartForEnum<T>::lookup(const std::string_view & val)  	{ -		return ModelPartForEnumLookup<1, InvalidEnumerationSymbol, std::string, T>(enumerations, val, -				&EnumPair<T>::first); +		return ModelPartForEnumLookup<1, InvalidEnumerationSymbol, std::string, T>( +				enumerations, val, &EnumPair<T>::first);  	}  	template<typename T> -	const std::string & ModelPartForEnum<T>::lookup(T val) +	const std::string & +	ModelPartForEnum<T>::lookup(T val)  	{ -		return ModelPartForEnumLookup<0, InvalidEnumerationValue, ::Ice::Int, T>(enumerations, val, -				&EnumPair<T>::second); +		return ModelPartForEnumLookup<0, InvalidEnumerationValue, ::Ice::Int, T>( +				enumerations, val, &EnumPair<T>::second);  	}  	template<typename T> -	void ModelPartForEnum<T>::SetValue(ValueSource && s) +	void +	ModelPartForEnum<T>::SetValue(ValueSource && s)  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		std::string val;  		s.set(val); @@ -629,54 +717,53 @@ namespace Slicer {  	}  	template<typename T> -	bool ModelPartForEnum<T>::GetValue(ValueTarget && s) +	bool +	ModelPartForEnum<T>::GetValue(ValueTarget && s)  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		s.get(lookup(*this->Model));  		return true;  	}  	// ModelPartForSequence -	template<typename T> -	ModelPartForSequence<T>::ModelPartForSequence(T * s) : -		ModelPartModel<T>(s) -	{ -	} +	template<typename T> ModelPartForSequence<T>::ModelPartForSequence(T * s) : ModelPartModel<T>(s) { }  	template<typename T> -	void ModelPartForSequence<T>::OnEachChild(const ChildHandler & ch) +	void +	ModelPartForSequence<T>::OnEachChild(const ChildHandler & ch)  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model); -		for(auto & element : *this->Model) { +		for (auto & element : *this->Model) {  			ch(elementName, elementModelPart(element), NULL);  		}  	}  	template<typename T> -	ChildRef ModelPartForSequence<T>::GetAnonChildRef(const HookFilter &) +	ChildRef +	ModelPartForSequence<T>::GetAnonChildRef(const HookFilter &)  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		this->Model->push_back(typename element_type::value_type());  		return ChildRef(ModelPart::CreateFor(this->Model->back()));  	}  	template<typename T> -	const Metadata & ModelPartForSequence<T>::GetMetadata() const +	const Metadata & +	ModelPartForSequence<T>::GetMetadata() const  	{  		return metadata;  	}  	template<typename T> -	ModelPartPtr ModelPartForSequence<T>::elementModelPart(typename T::value_type & e) const +	ModelPartPtr +	ModelPartForSequence<T>::elementModelPart(typename T::value_type & e) const  	{  		return ModelPart::CreateFor(e);  	}  	template<typename T> -	ModelPartPtr ModelPartForSequence<T>::GetContainedModelPart() +	ModelPartPtr +	ModelPartForSequence<T>::GetContainedModelPart()  	{  		return ModelPart::CreateFor<typename T::value_type>();  	} @@ -684,28 +771,24 @@ namespace Slicer {  	// ModelPartForDictionaryElementInserter  	template<typename T>  	ModelPartForDictionaryElementInserter<T>::ModelPartForDictionaryElementInserter(T * d) : -		ModelPartForStruct<typename T::value_type>(&value), -		dictionary(d) +		ModelPartForStruct<typename T::value_type>(&value), dictionary(d)  	{  	}  	template<typename T> -	void ModelPartForDictionaryElementInserter<T>::Complete() +	void +	ModelPartForDictionaryElementInserter<T>::Complete()  	{  		dictionary->insert(value);  	}  	// ModelPartForDictionary -	template<typename T> -	ModelPartForDictionary<T>::ModelPartForDictionary(T * d) : -		ModelPartModel<T>(d) -	{ -	} +	template<typename T> ModelPartForDictionary<T>::ModelPartForDictionary(T * d) : ModelPartModel<T>(d) { }  	template<typename T> -	void ModelPartForDictionary<T>::OnEachChild(const ChildHandler & ch) +	void +	ModelPartForDictionary<T>::OnEachChild(const ChildHandler & ch)  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		for (auto & pair : *this->Model) {  			ch(pairName, std::make_shared<ModelPartForStruct<typename T::value_type>>(&pair), NULL); @@ -713,17 +796,17 @@ namespace Slicer {  	}  	template<typename T> -	ChildRef ModelPartForDictionary<T>::GetAnonChildRef(const HookFilter &) +	ChildRef +	ModelPartForDictionary<T>::GetAnonChildRef(const HookFilter &)  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		return ChildRef(std::make_shared<ModelPartForDictionaryElementInserter<T>>(this->Model));  	}  	template<typename T> -	ChildRef ModelPartForDictionary<T>::GetChildRef(const std::string & name, const HookFilter &, bool matchCase) +	ChildRef +	ModelPartForDictionary<T>::GetChildRef(const std::string & name, const HookFilter &, bool matchCase)  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		if (!optionalCaseEq(name, pairName, matchCase)) {  			throw IncorrectElementName(name); @@ -732,23 +815,21 @@ namespace Slicer {  	}  	template<typename T> -	const Metadata & ModelPartForDictionary<T>::GetMetadata() const +	const Metadata & +	ModelPartForDictionary<T>::GetMetadata() const  	{  		return metadata;  	}  	template<typename T> -	ModelPartPtr ModelPartForDictionary<T>::GetContainedModelPart() +	ModelPartPtr +	ModelPartForDictionary<T>::GetContainedModelPart()  	{  		return std::make_shared<ModelPartForStruct<typename T::value_type>>(nullptr);  	}  	// ModelPartForStream -	template<typename T> -	ModelPartForStream<T>::ModelPartForStream(Stream<T> * s) : -		ModelPartModel<Stream<T>>(s) -	{ -	} +	template<typename T> ModelPartForStream<T>::ModelPartForStream(Stream<T> * s) : ModelPartModel<Stream<T>>(s) { }  	template<typename T>  	ModelPartPtr @@ -761,7 +842,6 @@ namespace Slicer {  	void  	ModelPartForStream<T>::OnEachChild(const ChildHandler & ch)  	{ -		// NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors)  		BOOST_ASSERT(this->Model);  		this->Model->Produce([&ch](const T & element) {  			ch(ModelPartForSequence<std::vector<T>>::elementName, ModelPart::CreateFor(element), NULL); @@ -782,8 +862,7 @@ namespace Slicer {  	}  }  #ifdef __clang__ -#pragma clang diagnostic pop +#	pragma clang diagnostic pop  #endif  #endif - diff --git a/slicer/slicer/serializer.cpp b/slicer/slicer/serializer.cpp index ad64fd9..329ef86 100644 --- a/slicer/slicer/serializer.cpp +++ b/slicer/slicer/serializer.cpp @@ -5,4 +5,3 @@ INSTANTIATEFACTORY(Slicer::Serializer, std::ostream &);  INSTANTIATEFACTORY(Slicer::Deserializer, std::istream &);  INSTANTIATEFACTORY(Slicer::Serializer, const std::filesystem::path &);  INSTANTIATEFACTORY(Slicer::Deserializer, const std::filesystem::path &); - diff --git a/slicer/slicer/serializer.h b/slicer/slicer/serializer.h index 90acc18..75df79a 100644 --- a/slicer/slicer/serializer.h +++ b/slicer/slicer/serializer.h @@ -1,32 +1,32 @@  #ifndef SLICER_SERIALIZER_H  #define SLICER_SERIALIZER_H +#include <c++11Helpers.h> +#include <factory.h>  #include <filesystem>  #include <slicer/modelParts.h>  #include <visibility.h> -#include <factory.h> -#include <c++11Helpers.h>  namespace Slicer {  	class DLL_PUBLIC Serializer { -		public: -			Serializer() = default; -			SPECIAL_MEMBERS_DEFAULT(Serializer); +	public: +		Serializer() = default; +		SPECIAL_MEMBERS_DEFAULT(Serializer); -			virtual ~Serializer() = default; +		virtual ~Serializer() = default; -			virtual void Serialize(ModelPartForRootPtr) = 0; +		virtual void Serialize(ModelPartForRootPtr) = 0;  	};  	using SerializerPtr = std::shared_ptr<Serializer>;  	class DLL_PUBLIC Deserializer { -		public: -			Deserializer() = default; -			SPECIAL_MEMBERS_DEFAULT(Deserializer); +	public: +		Deserializer() = default; +		SPECIAL_MEMBERS_DEFAULT(Deserializer); -			virtual ~Deserializer() = default; +		virtual ~Deserializer() = default; -			virtual void Deserialize(ModelPartForRootPtr) = 0; +		virtual void Deserialize(ModelPartForRootPtr) = 0;  	};  	using DeserializerPtr = std::shared_ptr<Deserializer>; @@ -37,4 +37,3 @@ namespace Slicer {  }  #endif - diff --git a/slicer/slicer/slicer.cpp b/slicer/slicer/slicer.cpp index 512e025..af55977 100644 --- a/slicer/slicer/slicer.cpp +++ b/slicer/slicer/slicer.cpp @@ -3,23 +3,11 @@  #include <compileTimeFormatter.h>  namespace Slicer { -	Slicer::ChildRef::ChildRef() : -		mpp(), -		mdr(emptyMetadata) -	{ -	} +	Slicer::ChildRef::ChildRef() : mpp(), mdr(emptyMetadata) { } -	Slicer::ChildRef::ChildRef(ModelPartPtr m) : -		mpp(std::move(m)), -		mdr(emptyMetadata) -	{ -	} +	Slicer::ChildRef::ChildRef(ModelPartPtr m) : mpp(std::move(m)), mdr(emptyMetadata) { } -	Slicer::ChildRef::ChildRef(Slicer::ModelPartPtr mp, const Slicer::Metadata & md) : -		mpp(std::move(mp)), -		mdr(md) -	{ -	} +	Slicer::ChildRef::ChildRef(Slicer::ModelPartPtr mp, const Slicer::Metadata & md) : mpp(std::move(mp)), mdr(md) { }  	ModelPartPtr  	Slicer::ChildRef::Child() const @@ -117,4 +105,3 @@ namespace Slicer {  		InvalidStreamOperationMsg::write(s, method);  	}  } - diff --git a/slicer/slicer/slicer.h b/slicer/slicer/slicer.h index 16d5a46..dcab8b3 100644 --- a/slicer/slicer/slicer.h +++ b/slicer/slicer/slicer.h @@ -5,36 +5,35 @@  #include <slicer/serializer.h>  namespace Slicer { -	template <typename Object> +	template<typename Object>  	Object  	DeserializeAnyWith(const DeserializerPtr & deserializer)  	{ -		Object object; +		Object object {};  		deserializer->Deserialize(ModelPart::CreateRootFor<Object>(object));  		return object;  	} -	template <typename Deserializer, typename Object, typename ... SerializerParams> +	template<typename Deserializer, typename Object, typename... SerializerParams>  	Object -	DeserializeAny(SerializerParams && ... sp) +	DeserializeAny(SerializerParams &&... sp)  	{ -		return DeserializeAnyWith<Object>(std::make_shared<Deserializer>(sp ...)); +		return DeserializeAnyWith<Object>(std::make_shared<Deserializer>(sp...));  	} -	template <typename Object> +	template<typename Object>  	void  	SerializeAnyWith(const Object & object, const SerializerPtr & serializer)  	{  		serializer->Serialize(ModelPart::CreateRootFor<const Object>(object));  	} -	template <typename Serializer, typename Object, typename ... SerializerParams> +	template<typename Serializer, typename Object, typename... SerializerParams>  	void -	SerializeAny(const Object & object, SerializerParams && ... sp) +	SerializeAny(const Object & object, SerializerParams &&... sp)  	{ -		SerializeAnyWith(object, std::make_shared<Serializer>(sp ...)); +		SerializeAnyWith(object, std::make_shared<Serializer>(sp...));  	}  }  #endif - diff --git a/slicer/test/compilation.cpp b/slicer/test/compilation.cpp index 0475bbe..2ed73e4 100644 --- a/slicer/test/compilation.cpp +++ b/slicer/test/compilation.cpp @@ -1,20 +1,21 @@  #define BOOST_TEST_MODULE compilation  #include <boost/test/unit_test.hpp> -#include <types.h>  #include <locals.h>  #include <slicer/modelParts.h>  #include <slicer/modelPartsTypes.h> +#include <types.h>  // LCOV_EXCL_START  BOOST_TEST_DONT_PRINT_LOG_VALUE(std::type_info); +BOOST_TEST_DONT_PRINT_LOG_VALUE(Slicer::ModelPartType);  // LCOV_EXCL_STOP  #define TypeTest(Var, Expr, Explicit, Expected) \  	Var obj = Expr; \  	Slicer::ModelPartPtr mpp = Slicer::ModelPart::CreateFor(obj); \  	BOOST_REQUIRE_EQUAL(Slicer::Expected, mpp->GetType()); \ -	\ +\  	BOOST_TEST_CONTEXT(#Var) { \  		auto mppvalue = mpp.get(); \  		auto amppvalue = mpp.get(); \ @@ -24,18 +25,18 @@ BOOST_TEST_DONT_PRINT_LOG_VALUE(std::type_info);  		BOOST_REQUIRE_EQUAL(typeid(*mppvalue), typeid(*apmppvalue)); \  	} -#define StackTypeTest(Var, Explicit, Expected) \ -	TypeTest(Var, Var(), Explicit, Expected) +#define StackTypeTest(Var, Explicit, Expected) TypeTest(Var, Var(), Explicit, Expected) -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_class ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_class)  { -	TypeTest(TestModule::BuiltInsPtr, std::make_shared<TestModule::BuiltIns>(), ModelPartForClass, mpt_Complex); +	TypeTest(TestModule::BuiltInsPtr, std::make_shared<TestModule::BuiltIns>(), ModelPartForClass, +			ModelPartType::Complex);  	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());  } -static -void -hookHandler(std::vector<std::string> * names, const std::string & name, const Slicer::ModelPartPtr & mpp, const Slicer::HookCommon * h) +static void +hookHandler(std::vector<std::string> * names, const std::string & name, const Slicer::ModelPartPtr & mpp, +		const Slicer::HookCommon * h)  {  	names->push_back(name);  	BOOST_REQUIRE(mpp); @@ -44,107 +45,110 @@ hookHandler(std::vector<std::string> * names, const std::string & name, const Sl  	BOOST_REQUIRE_EQUAL(h->name, name);  } - -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_sequenceclasses ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_sequenceclasses)  { -	StackTypeTest(TestModule::Classes, ModelPartForSequence, mpt_Sequence); +	StackTypeTest(TestModule::Classes, ModelPartForSequence, ModelPartType::Sequence);  	auto cmpp = mpp->GetContainedModelPart();  	BOOST_REQUIRE(cmpp); -	BOOST_REQUIRE_EQUAL(Slicer::mpt_Complex, cmpp->GetType()); +	BOOST_REQUIRE_EQUAL(Slicer::ModelPartType::Complex, cmpp->GetType());  	std::vector<std::string> names; -	cmpp->OnEachChild(std::bind(&hookHandler, &names, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); +	cmpp->OnEachChild([&](auto && PH1, auto && PH2, auto && PH3) { +		hookHandler(&names, PH1, PH2, PH3); +	});  	BOOST_REQUIRE_EQUAL(2, names.size());  	BOOST_REQUIRE_EQUAL("a", names.front());  	BOOST_REQUIRE_EQUAL("b", names.back());  } -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_sequencestructs ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_sequencestructs)  { -	StackTypeTest(TestModule::Structs, ModelPartForSequence, mpt_Sequence); +	StackTypeTest(TestModule::Structs, ModelPartForSequence, ModelPartType::Sequence);  	auto cmpp = mpp->GetContainedModelPart();  	BOOST_REQUIRE(cmpp); -	BOOST_REQUIRE_EQUAL(Slicer::mpt_Complex, cmpp->GetType()); +	BOOST_REQUIRE_EQUAL(Slicer::ModelPartType::Complex, cmpp->GetType());  	std::vector<std::string> names; -	cmpp->OnEachChild(std::bind(&hookHandler, &names, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); +	cmpp->OnEachChild([&](auto && PH1, auto && PH2, auto && PH3) { +		hookHandler(&names, PH1, PH2, PH3); +	});  	BOOST_REQUIRE_EQUAL(2, names.size());  	BOOST_REQUIRE_EQUAL("a", names.front());  	BOOST_REQUIRE_EQUAL("b", names.back());  } -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_mapclasses ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_mapclasses)  { -	StackTypeTest(TestModule::ClassMap, ModelPartForDictionary, mpt_Dictionary); +	StackTypeTest(TestModule::ClassMap, ModelPartForDictionary, ModelPartType::Dictionary);  	auto cmpp = mpp->GetContainedModelPart();  	BOOST_REQUIRE(cmpp); -	BOOST_REQUIRE_EQUAL(Slicer::mpt_Complex, cmpp->GetType()); +	BOOST_REQUIRE_EQUAL(Slicer::ModelPartType::Complex, cmpp->GetType());  } -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_mapstructs ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_mapstructs)  { -	StackTypeTest(TestModule::StructMap, ModelPartForDictionary, mpt_Dictionary); +	StackTypeTest(TestModule::StructMap, ModelPartForDictionary, ModelPartType::Dictionary);  } -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_string ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_string)  { -	StackTypeTest(std::string, ModelPartForSimple, mpt_Simple); +	StackTypeTest(std::string, ModelPartForSimple, ModelPartType::Simple);  	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());  } -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_bool ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_bool)  { -	StackTypeTest(bool, ModelPartForSimple, mpt_Simple); +	StackTypeTest(bool, ModelPartForSimple, ModelPartType::Simple);  	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());  } -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_float ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_float)  { -	StackTypeTest(Ice::Float, ModelPartForSimple, mpt_Simple); +	StackTypeTest(Ice::Float, ModelPartForSimple, ModelPartType::Simple);  	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());  } -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_double ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_double)  { -	StackTypeTest(Ice::Double, ModelPartForSimple, mpt_Simple); +	StackTypeTest(Ice::Double, ModelPartForSimple, ModelPartType::Simple);  	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());  } -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_byte ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_byte)  { -	StackTypeTest(Ice::Byte, ModelPartForSimple, mpt_Simple); +	StackTypeTest(Ice::Byte, ModelPartForSimple, ModelPartType::Simple);  	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());  } -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_short ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_short)  { -	StackTypeTest(Ice::Short, ModelPartForSimple, mpt_Simple); +	StackTypeTest(Ice::Short, ModelPartForSimple, ModelPartType::Simple);  	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());  } -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_int ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_int)  { -	StackTypeTest(Ice::Int, ModelPartForSimple, mpt_Simple); +	StackTypeTest(Ice::Int, ModelPartForSimple, ModelPartType::Simple);  	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());  } -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_long ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_long)  { -	StackTypeTest(Ice::Long, ModelPartForSimple, mpt_Simple); +	StackTypeTest(Ice::Long, ModelPartForSimple, ModelPartType::Simple);  	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());  } -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_struct ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_struct)  { -	StackTypeTest(TestModule::StructType, ModelPartForStruct, mpt_Complex); +	StackTypeTest(TestModule::StructType, ModelPartForStruct, ModelPartType::Complex);  	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());  } -BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_enum ) +BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_enum)  { -	StackTypeTest(TestModule::SomeNumbers, ModelPartForEnum, mpt_Simple); +	StackTypeTest(TestModule::SomeNumbers, ModelPartForEnum, ModelPartType::Simple);  	BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());  } -BOOST_AUTO_TEST_CASE( normalClassTypeId ) +BOOST_AUTO_TEST_CASE(normalClassTypeId)  {  	TestModule::BasePtr base = std::make_shared<TestModule::Base>(1);  	BOOST_REQUIRE(base); @@ -154,7 +158,7 @@ BOOST_AUTO_TEST_CASE( normalClassTypeId )  	BOOST_REQUIRE(!baseType);  } -BOOST_AUTO_TEST_CASE( normalSubClassTypeId ) +BOOST_AUTO_TEST_CASE(normalSubClassTypeId)  {  	TestModule::BasePtr base = std::make_shared<TestModule::D1>(1, 2);  	BOOST_REQUIRE(base); @@ -165,7 +169,7 @@ BOOST_AUTO_TEST_CASE( normalSubClassTypeId )  	BOOST_REQUIRE_EQUAL(*baseType, "::TestModule::D1");  } -BOOST_AUTO_TEST_CASE( normalSubSubClassTypeId ) +BOOST_AUTO_TEST_CASE(normalSubSubClassTypeId)  {  	TestModule::BasePtr base = std::make_shared<TestModule::D3>(1, 2, 3);  	BOOST_REQUIRE(base); @@ -176,7 +180,7 @@ BOOST_AUTO_TEST_CASE( normalSubSubClassTypeId )  	BOOST_REQUIRE_EQUAL(*baseType, "::TestModule::D3");  } -BOOST_AUTO_TEST_CASE( localClassTypeId ) +BOOST_AUTO_TEST_CASE(localClassTypeId)  {  	Locals::LocalClassPtr base = std::make_shared<Locals::LocalClass>(1, "One");  	BOOST_REQUIRE(base); @@ -186,7 +190,7 @@ BOOST_AUTO_TEST_CASE( localClassTypeId )  	BOOST_REQUIRE(!baseType);  } -BOOST_AUTO_TEST_CASE( localSubClassTypeId ) +BOOST_AUTO_TEST_CASE(localSubClassTypeId)  {  	Locals::LocalClassPtr base = std::make_shared<Locals::LocalSubClass>(1, "One", 3.1);  	BOOST_REQUIRE(base); @@ -197,7 +201,7 @@ BOOST_AUTO_TEST_CASE( localSubClassTypeId )  	BOOST_REQUIRE_EQUAL(*baseType, "::Locals::LocalSubClass");  } -BOOST_AUTO_TEST_CASE( localSubSubClassTypeId ) +BOOST_AUTO_TEST_CASE(localSubSubClassTypeId)  {  	Locals::LocalClassPtr base = std::make_shared<Locals::LocalSub2Class>(1, "One", 3.1, 1);  	BOOST_REQUIRE(base); @@ -207,4 +211,3 @@ BOOST_AUTO_TEST_CASE( localSubSubClassTypeId )  	BOOST_REQUIRE(baseType);  	BOOST_REQUIRE_EQUAL(*baseType, "::Locals::LocalSub2Class");  } - diff --git a/slicer/test/conversions.cpp b/slicer/test/conversions.cpp index 9c148aa..8af0f0f 100644 --- a/slicer/test/conversions.cpp +++ b/slicer/test/conversions.cpp @@ -1,7 +1,7 @@  #include "conversions.h"  #include <boost/numeric/conversion/cast.hpp> -#define SHORT(x) boost::numeric_cast< ::Ice::Short , int64_t >(x) +#define SHORT(x) boost::numeric_cast<::Ice::Short, int64_t>(x)  namespace Slicer {  	DLL_PUBLIC @@ -16,17 +16,16 @@ namespace Slicer {  	::TestModule::DateTime  	ptimeToDateTime(const boost::posix_time::ptime & pt)  	{ -		return ::TestModule::DateTime({ -				SHORT(pt.date().year()), SHORT(pt.date().month()), SHORT(pt.date().day()), -				SHORT(pt.time_of_day().hours()), SHORT(pt.time_of_day().minutes()), SHORT(pt.time_of_day().seconds()) -			}); +		return ::TestModule::DateTime({SHORT(pt.date().year()), SHORT(pt.date().month()), SHORT(pt.date().day()), +				SHORT(pt.time_of_day().hours()), SHORT(pt.time_of_day().minutes()), SHORT(pt.time_of_day().seconds())});  	}  	DLL_PUBLIC  	std::string  	isoDateToString(const ::TestModule::IsoDate & in)  	{ -		struct tm tm {}; +		struct tm tm { +		};  		tm.tm_mday = in.day;  		tm.tm_mon = in.month - 1;  		tm.tm_year = in.year - 1900; @@ -41,27 +40,28 @@ namespace Slicer {  	::TestModule::IsoDate  	stringToIsoDate(const std::string & in)  	{ -		struct tm tm {}; +		struct tm tm { +		};  		auto end = strptime(in.c_str(), "%Y-%m-%d", &tm);  		if (!end || *end) {  			// LCOV_EXCL_START  			throw std::runtime_error("Invalid iso-date string: " + in);  			// LCOV_EXCL_STOP  		} -		return ::TestModule::IsoDate({ -				SHORT(tm.tm_year + 1900), SHORT(tm.tm_mon + 1), SHORT(tm.tm_mday)}); +		return ::TestModule::IsoDate({SHORT(tm.tm_year + 1900), SHORT(tm.tm_mon + 1), SHORT(tm.tm_mday)});  	}  	DLL_PUBLIC  	std::string  	dateTimeToString(const ::TestModule::DateTime & in)  	{ -		struct tm tm {}; +		struct tm tm { +		};  		tm.tm_sec = in.second;  		tm.tm_min = in.minute;  		tm.tm_hour = in.hour;  		tm.tm_mday = in.day; -		tm.tm_mon = in.month- 1; +		tm.tm_mon = in.month - 1;  		tm.tm_year = in.year - 1900;  		tm.tm_isdst = -1;  		mktime(&tm); @@ -75,15 +75,15 @@ namespace Slicer {  	::TestModule::DateTime  	stringToDateTime(const std::string & in)  	{ -		struct tm tm {}; +		struct tm tm { +		};  		auto end = strptime(in.c_str(), "%Y-%b-%d %H:%M:%S", &tm);  		if (!end || *end) {  			// LCOV_EXCL_START  			throw std::runtime_error("Invalid date string: " + in);  			// LCOV_EXCL_STOP  		} -		return ::TestModule::DateTime({ -				SHORT(tm.tm_year + 1900), SHORT(tm.tm_mon + 1), SHORT(tm.tm_mday), +		return ::TestModule::DateTime({SHORT(tm.tm_year + 1900), SHORT(tm.tm_mon + 1), SHORT(tm.tm_mday),  				SHORT(tm.tm_hour), SHORT(tm.tm_min), SHORT(tm.tm_sec)});  	} @@ -111,10 +111,7 @@ namespace Slicer {  namespace TestModule {  	int completions = 0; -	AbValidator::AbValidator(ClassTypePtr * m) : -		Slicer::ModelPartForClass<ClassType>(m) -	{ -	} +	AbValidator::AbValidator(ClassTypePtr * m) : Slicer::ModelPartForClass<ClassType>(m) { }  	void  	AbValidator::Complete() @@ -129,10 +126,7 @@ namespace TestModule {  		completions += 1;  	} -	MonthValidator::MonthValidator(::Ice::Short * m) : -		Slicer::ModelPartForSimple<::Ice::Short>(m) -	{ -	} +	MonthValidator::MonthValidator(::Ice::Short * m) : Slicer::ModelPartForSimple<::Ice::Short>(m) { }  	void  	MonthValidator::Complete() @@ -147,4 +141,3 @@ namespace TestModule {  		completions += 1;  	}  } - diff --git a/slicer/test/conversions.h b/slicer/test/conversions.h index bf70407..dfb18d6 100644 --- a/slicer/test/conversions.h +++ b/slicer/test/conversions.h @@ -2,41 +2,36 @@  #define SLICER_TEST_CONVERSIONS_H  #include <boost/date_time/posix_time/posix_time_types.hpp> -#include <visibility.h>  #include <slicer/modelPartsTypes.h>  #include <types.h> +#include <visibility.h>  namespace TestModule {  	DLL_PUBLIC extern int completions;  	class DLL_PUBLIC AbValidator : public Slicer::ModelPartForClass<ClassType> { -		public: -			explicit AbValidator(ClassTypePtr *); +	public: +		explicit AbValidator(ClassTypePtr *); -			void Complete() override; +		void Complete() override;  	};  	class DLL_PUBLIC MonthValidator : public Slicer::ModelPartForSimple<::Ice::Short> { -		public: -			explicit MonthValidator(::Ice::Short *); +	public: +		explicit MonthValidator(::Ice::Short *); -			void Complete() override; +		void Complete() override;  	};  }  namespace Slicer {  	DLL_PUBLIC -	::TestModule::DateTime -	stringToDateTime(const std::string & in); +	::TestModule::DateTime stringToDateTime(const std::string & in);  	DLL_PUBLIC -	std::string -	dateTimeToString(const ::TestModule::DateTime & in); +	std::string dateTimeToString(const ::TestModule::DateTime & in);  	DLL_PUBLIC -	Ice::optional<Ice::Int> -	str2int(const std::string &); +	Ice::optional<Ice::Int> str2int(const std::string &);  	DLL_PUBLIC -	std::string -	int2str(const Ice::optional<Ice::Int> &); +	std::string int2str(const Ice::optional<Ice::Int> &);  }  #endif - diff --git a/slicer/test/helpers.cpp b/slicer/test/helpers.cpp index cbc6623..808e9d0 100644 --- a/slicer/test/helpers.cpp +++ b/slicer/test/helpers.cpp @@ -1,6 +1,6 @@  #include "helpers.h" -#include <fstream>  #include <boost/test/test_tools.hpp> +#include <fstream>  void  diff(const std::filesystem::path & left, const std::filesystem::path & right) @@ -9,9 +9,12 @@ diff(const std::filesystem::path & left, const std::filesystem::path & right)  	std::ifstream fr(right.string());  	std::string l, r; -	std::copy_if(std::istreambuf_iterator<char>(fl), std::istreambuf_iterator<char>(), back_inserter(l), [](char x){ return !isspace(x); }); -	std::copy_if(std::istreambuf_iterator<char>(fr), std::istreambuf_iterator<char>(), back_inserter(r), [](char x){ return !isspace(x); }); +	std::copy_if(std::istreambuf_iterator<char>(fl), std::istreambuf_iterator<char>(), back_inserter(l), [](char x) { +		return !isspace(x); +	}); +	std::copy_if(std::istreambuf_iterator<char>(fr), std::istreambuf_iterator<char>(), back_inserter(r), [](char x) { +		return !isspace(x); +	});  	BOOST_REQUIRE_EQUAL(l, r);  } - diff --git a/slicer/test/helpers.h b/slicer/test/helpers.h index 47754a9..b5db1bf 100644 --- a/slicer/test/helpers.h +++ b/slicer/test/helpers.h @@ -1,14 +1,12 @@  #ifndef SLICER_TEST_HELPERS_H  #define SLICER_TEST_HELPERS_H +#include <filesystem>  #include <string>  #include <visibility.h> -#include <filesystem>  // These are just thin wrappers that throw exceptions  DLL_PUBLIC -void -diff(const std::filesystem::path & left, const std::filesystem::path & right); +void diff(const std::filesystem::path & left, const std::filesystem::path & right);  #endif - diff --git a/slicer/test/preprocessor.cpp b/slicer/test/preprocessor.cpp index fe789d0..454d58a 100644 --- a/slicer/test/preprocessor.cpp +++ b/slicer/test/preprocessor.cpp @@ -1,34 +1,23 @@  #define BOOST_TEST_MODULE preprocess  #include <boost/test/unit_test.hpp> -#include <tool/parser.h> -#include <common.h> +#include "helpers.h"  #include <boost/format.hpp>  #include <buffer.h> +#include <common.h>  #include <definedDirs.h> -#include "helpers.h" +#include <tool/parser.h>  using ComponentsCount = std::map<std::string, unsigned int>; -ComponentsCount COMPONENTS_IN_TEST_ICE = { -	{ "classtype.ice", 1 }, -	{ "classes.ice", 3 }, -	{ "collections.ice", 6 }, -	{ "enums.ice", 2 }, -	{ "inheritance.ice", 12 }, -	{ "interfaces.ice", 0 }, -	{ "json.ice", 2 }, -	{ "locals.ice", 7 }, -	{ "optionals.ice", 2 }, -	{ "structs.ice", 4 }, -	{ "types.ice", 3 }, -	{ "xml.ice", 5 } -}; +ComponentsCount COMPONENTS_IN_TEST_ICE = {{"classtype.ice", 1}, {"classes.ice", 3}, {"collections.ice", 6}, +		{"enums.ice", 2}, {"inheritance.ice", 12}, {"interfaces.ice", 0}, {"json.ice", 2}, {"locals.ice", 7}, +		{"optionals.ice", 2}, {"structs.ice", 4}, {"types.ice", 3}, {"xml.ice", 5}};  unsigned int  total()  {  	unsigned int t = 0; -	for(const auto & c : COMPONENTS_IN_TEST_ICE) { +	for (const auto & c : COMPONENTS_IN_TEST_ICE) {  		t += c.second;  	}  	return t; @@ -52,21 +41,21 @@ processAll(Slicer::Slicer & s)  {  	s.includes.push_back(rootDir / "included");  	s.includes.push_back(rootDir); -	for(const auto & c : COMPONENTS_IN_TEST_ICE) { +	for (const auto & c : COMPONENTS_IN_TEST_ICE) {  		BOOST_TEST_CHECKPOINT(c.first);  		process(s, c);  	}  	BOOST_REQUIRE_EQUAL(total(), s.Components());  } -BOOST_AUTO_TEST_CASE( slicer_test_counts_path ) +BOOST_AUTO_TEST_CASE(slicer_test_counts_path)  {  	Slicer::Slicer s;  	s.cppPath = "/dev/null";  	processAll(s);  } -BOOST_AUTO_TEST_CASE( slicer_test_counts_filestar ) +BOOST_AUTO_TEST_CASE(slicer_test_counts_filestar)  {  	FILE * file = fopen("/dev/null", "a");  	BOOST_REQUIRE(file); @@ -76,9 +65,8 @@ BOOST_AUTO_TEST_CASE( slicer_test_counts_filestar )  	fclose(file);  } -BOOST_AUTO_TEST_CASE( slicer_test_counts_nullfilestar ) +BOOST_AUTO_TEST_CASE(slicer_test_counts_nullfilestar)  {  	Slicer::Slicer s;  	processAll(s);  } - diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp index 0b483b0..3ab54e5 100644 --- a/slicer/test/serializers.cpp +++ b/slicer/test/serializers.cpp @@ -1,126 +1,127 @@  #define BOOST_TEST_MODULE execute_serializers  #include <boost/test/unit_test.hpp> -#include <tool/parser.h> -#include <common.h> -#include <slicer.h> -#include <modelParts.h> -#include <xml/serializer.h> -#include <libxml2/libxml/parser.h> -#include <json/serializer.h> +#include "conversions.h" +#include "helpers.h"  #include <boost/format.hpp> +#include <common.h> +#include <definedDirs.h> +#include <fstream>  #include <functional> -#include <types.h>  #include <json.h> -#include <xml.h> +#include <json/serializer.h> +#include <libxml2/libxml/parser.h>  #include <locals.h> -#include <fstream> -#include "helpers.h" -#include <definedDirs.h> -#include "conversions.h" +#include <modelParts.h> +#include <slicer.h> +#include <tool/parser.h> +#include <types.h> +#include <xml.h> +#include <xml/serializer.h>  #ifdef SLICER_MODELPARTSTYPES_IMPL_H -#error Client code should NOT need to pull in implementation header +#	error Client code should NOT need to pull in implementation header  #endif  namespace fs = std::filesystem;  // LCOV_EXCL_START -BOOST_TEST_DONT_PRINT_LOG_VALUE ( TestModule::ClassMap::iterator ) -BOOST_TEST_DONT_PRINT_LOG_VALUE ( TestModule::SomeNumbers ) +BOOST_TEST_DONT_PRINT_LOG_VALUE(TestModule::ClassMap::iterator) +BOOST_TEST_DONT_PRINT_LOG_VALUE(TestModule::SomeNumbers)  namespace std {  	template<typename T> -	ostream & operator<<(ostream & s, const Ice::optional<T> &) { +	ostream & +	operator<<(ostream & s, const Ice::optional<T> &) +	{  		return s;  	}  }  // LCOV_EXCL_STOP  class FileBased { -	public: -		template<typename T, typename DeserializerIn> -		void -		verifyByFile(const fs::path & infile, const std::function<void(const T &)> & check = nullptr) -		{ -			verifyByFile<T, DeserializerIn>(infile, infile, check); +public: +	template<typename T, typename DeserializerIn> +	void +	verifyByFile(const fs::path & infile, const std::function<void(const T &)> & check = nullptr) +	{ +		verifyByFile<T, DeserializerIn>(infile, infile, check); +	} + +	template<typename T, typename DeserializerIn> +	void +	verifyByFile(const fs::path & infile, const fs::path & expOutFile, +			const std::function<void(const T &)> & check = nullptr) +	{ +		const fs::path input = rootDir / "initial" / infile; +		const fs::path expected = rootDir / "initial" / expOutFile; +		const fs::path tmpf = binDir / "byFile"; +		fs::create_directory(tmpf); +		const fs::path output = tmpf / infile; +		const fs::path outputJson = tmpf / fs::path(infile).replace_extension("json"); +		const fs::path outputXml = tmpf / fs::path(infile).replace_extension("xml"); + +		BOOST_TEST_CHECKPOINT("Deserialize: " << input); +		T p = Slicer::DeserializeAny<DeserializerIn, T>(input); + +		if (check) { +			BOOST_TEST_CHECKPOINT("Check1: " << input); +			check(p);  		} -		template<typename T, typename DeserializerIn> -		void -		verifyByFile(const fs::path & infile, const fs::path & expOutFile, const std::function<void(const T &)> & check = nullptr) -		{ -			const fs::path input = rootDir / "initial" / infile; -			const fs::path expected = rootDir / "initial" / expOutFile; -			const fs::path tmpf = binDir / "byFile"; -			fs::create_directory(tmpf); -			const fs::path output = tmpf / infile; -			const fs::path outputJson = tmpf / fs::path(infile).replace_extension("json"); -			const fs::path outputXml = tmpf / fs::path(infile).replace_extension("xml"); - -			BOOST_TEST_CHECKPOINT("Deserialize: " << input); -			T p = Slicer::DeserializeAny<DeserializerIn, T>(input); - -			if (check) { -				BOOST_TEST_CHECKPOINT("Check1: " << input); -				check(p); -			} - -			BOOST_TEST_CHECKPOINT("Serialize " << input << " -> " << outputJson); -			Slicer::SerializeAny<Slicer::JsonFileSerializer>(p, outputJson); - -			BOOST_TEST_CHECKPOINT("Serialize " << input << " -> " << outputXml); -			Slicer::SerializeAny<Slicer::XmlFileSerializer>(p, outputXml); - -			if (check) { -				BOOST_TEST_CHECKPOINT("Check2: " << input); -				check(p); -			} - -			BOOST_TEST_CHECKPOINT("Checksum: " << input << " === " << output); -			diff(expected, output); +		BOOST_TEST_CHECKPOINT("Serialize " << input << " -> " << outputJson); +		Slicer::SerializeAny<Slicer::JsonFileSerializer>(p, outputJson); + +		BOOST_TEST_CHECKPOINT("Serialize " << input << " -> " << outputXml); +		Slicer::SerializeAny<Slicer::XmlFileSerializer>(p, outputXml); + +		if (check) { +			BOOST_TEST_CHECKPOINT("Check2: " << input); +			check(p);  		} -		template<typename T, typename Deserializer, typename Serializer, typename Internal> -		void -		verifyByHelper(const fs::path & infile, -				const std::function<Internal(const fs::path &)> & in, -				const std::function<void(const Internal &, const fs::path &)> & out, -				const std::function<void(Internal &)> & ifree, -				const std::function<void(const T &)> & check = nullptr) -		{ -			const fs::path input = rootDir / "initial" / infile; -			const fs::path tmph = binDir / "byHandler"; -			fs::create_directory(tmph); -			const fs::path output = tmph / infile; - -			BOOST_TEST_CHECKPOINT("Read: " << input); -			Internal docRead = in(input); - -			BOOST_TEST_CHECKPOINT("Deserialize: " << input); -			T p = Slicer::DeserializeAny<Deserializer, T>(docRead); -			ifree(docRead); - -			if (check) { -				BOOST_TEST_CHECKPOINT("Check1: " << input); -				check(p); -			} - -			BOOST_TEST_CHECKPOINT("Serialize: " << input); -			Internal docWrite; -			Slicer::SerializeAny<Serializer>(p, docWrite); - -			if (check) { -				BOOST_TEST_CHECKPOINT("Check2: " << input); -				check(p); -			} - -			BOOST_TEST_CHECKPOINT("Write: " << output); -			out(docWrite, output); -			ifree(docWrite); - -			BOOST_TEST_CHECKPOINT("Checksum: " << input << " === " << output); -			diff(input, output); +		BOOST_TEST_CHECKPOINT("Checksum: " << input << " === " << output); +		diff(expected, output); +	} + +	template<typename T, typename Deserializer, typename Serializer, typename Internal> +	void +	verifyByHelper(const fs::path & infile, const std::function<Internal(const fs::path &)> & in, +			const std::function<void(const Internal &, const fs::path &)> & out, +			const std::function<void(Internal &)> & ifree, const std::function<void(const T &)> & check = nullptr) +	{ +		const fs::path input = rootDir / "initial" / infile; +		const fs::path tmph = binDir / "byHandler"; +		fs::create_directory(tmph); +		const fs::path output = tmph / infile; + +		BOOST_TEST_CHECKPOINT("Read: " << input); +		Internal docRead = in(input); + +		BOOST_TEST_CHECKPOINT("Deserialize: " << input); +		T p = Slicer::DeserializeAny<Deserializer, T>(docRead); +		ifree(docRead); + +		if (check) { +			BOOST_TEST_CHECKPOINT("Check1: " << input); +			check(p);  		} + +		BOOST_TEST_CHECKPOINT("Serialize: " << input); +		Internal docWrite; +		Slicer::SerializeAny<Serializer>(p, docWrite); + +		if (check) { +			BOOST_TEST_CHECKPOINT("Check2: " << input); +			check(p); +		} + +		BOOST_TEST_CHECKPOINT("Write: " << output); +		out(docWrite, output); +		ifree(docWrite); + +		BOOST_TEST_CHECKPOINT("Checksum: " << input << " === " << output); +		diff(input, output); +	}  };  void @@ -326,7 +327,7 @@ writeXml(xmlpp::Document * const & doc, const fs::path & path)  }  void -freeXml(xmlpp::Document * & doc) +freeXml(xmlpp::Document *& doc)  {  	delete doc;  } @@ -354,192 +355,194 @@ freeJson(json::Value &)  {  } -BOOST_FIXTURE_TEST_SUITE ( byFile, FileBased ); +BOOST_FIXTURE_TEST_SUITE(byFile, FileBased); -BOOST_AUTO_TEST_CASE( builtins_xml ) +BOOST_AUTO_TEST_CASE(builtins_xml)  {  	verifyByFile<TestModule::BuiltInsPtr, Slicer::XmlFileDeserializer>("builtins.xml", checkBuiltIns_valuesCorrect);  } -BOOST_AUTO_TEST_CASE( structtype_xml ) +BOOST_AUTO_TEST_CASE(structtype_xml)  {  	verifyByFile<TestModule::StructType, Slicer::XmlFileDeserializer>("struct.xml", checkStruct);  } -BOOST_AUTO_TEST_CASE( structtype_json ) +BOOST_AUTO_TEST_CASE(structtype_json)  {  	verifyByFile<TestModule::StructType, Slicer::JsonFileDeserializer>("struct2.json", checkStruct);  } -BOOST_AUTO_TEST_CASE( simplestring_xml ) +BOOST_AUTO_TEST_CASE(simplestring_xml)  {  	verifyByFile<std::string, Slicer::XmlFileDeserializer>("string.xml", [](const auto & s) {  		BOOST_REQUIRE_EQUAL("test string", s);  	});  } -BOOST_AUTO_TEST_CASE( simpleint_xml ) +BOOST_AUTO_TEST_CASE(simpleint_xml)  {  	verifyByFile<Ice::Int, Slicer::XmlFileDeserializer>("int.xml", [](const auto & i) {  		BOOST_REQUIRE_EQUAL(27, i);  	});  } -BOOST_AUTO_TEST_CASE( simplestring_json ) +BOOST_AUTO_TEST_CASE(simplestring_json)  {  	verifyByFile<std::string, Slicer::JsonFileDeserializer>("string2.json", [](const auto & s) {  		BOOST_REQUIRE_EQUAL("test string", s);  	});  } -BOOST_AUTO_TEST_CASE( simpleint_json ) +BOOST_AUTO_TEST_CASE(simpleint_json)  {  	verifyByFile<Ice::Int, Slicer::JsonFileDeserializer>("int2.json", [](const auto & i) {  		BOOST_REQUIRE_EQUAL(27, i);  	});  } -BOOST_AUTO_TEST_CASE( complexClass_xmlattrAndText ) +BOOST_AUTO_TEST_CASE(complexClass_xmlattrAndText)  {  	verifyByFile<TestXml::EntityRef, Slicer::XmlFileDeserializer>("entityref.xml", checkEntityRef);  } -BOOST_AUTO_TEST_CASE( sequenceOfClass_xml ) +BOOST_AUTO_TEST_CASE(sequenceOfClass_xml)  {  	verifyByFile<TestModule::Classes, Slicer::XmlFileDeserializer>("seqOfClass.xml", checkSeqOfClass);  } -BOOST_AUTO_TEST_CASE( sequenceOfClass_json ) +BOOST_AUTO_TEST_CASE(sequenceOfClass_json)  {  	verifyByFile<TestModule::Classes, Slicer::JsonFileDeserializer>("seqOfClass2.json", checkSeqOfClass);  } -BOOST_AUTO_TEST_CASE( optionals_notset_xml ) +BOOST_AUTO_TEST_CASE(optionals_notset_xml)  {  	verifyByFile<TestModule::OptionalsPtr, Slicer::XmlFileDeserializer>("optionals-notset.xml", checkOptionals_notset);  } -BOOST_AUTO_TEST_CASE( optionals_areset_xml ) +BOOST_AUTO_TEST_CASE(optionals_areset_xml)  {  	verifyByFile<TestModule::OptionalsPtr, Slicer::XmlFileDeserializer>("optionals-areset.xml", checkOptionals_areset);  } -BOOST_AUTO_TEST_CASE( inherit_a_xml ) +BOOST_AUTO_TEST_CASE(inherit_a_xml)  {  	verifyByFile<TestModule::InheritanceContPtr, Slicer::XmlFileDeserializer>("inherit-a.xml");  } -BOOST_AUTO_TEST_CASE( inherit_b_xml ) +BOOST_AUTO_TEST_CASE(inherit_b_xml)  {  	verifyByFile<TestModule::InheritanceContPtr, Slicer::XmlFileDeserializer>("inherit-b.xml", checkInherits_types);  } -BOOST_AUTO_TEST_CASE( conv_datetime_xml ) +BOOST_AUTO_TEST_CASE(conv_datetime_xml)  {  	verifyByFile<TestModule::DateTimeContainerPtr, Slicer::XmlFileDeserializer>("conv-datetime.xml");  } -BOOST_AUTO_TEST_CASE( builtins2_json ) +BOOST_AUTO_TEST_CASE(builtins2_json)  {  	verifyByFile<TestModule::BuiltInsPtr, Slicer::JsonFileDeserializer>("builtins2.json", checkBuiltIns_valuesCorrect);  } -BOOST_AUTO_TEST_CASE( builtins3_json ) +BOOST_AUTO_TEST_CASE(builtins3_json)  {  	verifyByFile<TestModule::BuiltInsPtr, Slicer::JsonFileDeserializer>("builtins3.json", checkBuiltIns3_valuesCorrect);  } -BOOST_AUTO_TEST_CASE( optionals_areset2_json ) +BOOST_AUTO_TEST_CASE(optionals_areset2_json)  { -	verifyByFile<TestModule::OptionalsPtr, Slicer::JsonFileDeserializer>("optionals-areset2.json", checkOptionals_areset); +	verifyByFile<TestModule::OptionalsPtr, Slicer::JsonFileDeserializer>( +			"optionals-areset2.json", checkOptionals_areset);  } -BOOST_AUTO_TEST_CASE( inherit_c_json ) +BOOST_AUTO_TEST_CASE(inherit_c_json)  {  	verifyByFile<TestModule::InheritanceContPtr, Slicer::JsonFileDeserializer>("inherit-c.json", checkInherits_types);  } -BOOST_AUTO_TEST_CASE( inherit_d_json ) +BOOST_AUTO_TEST_CASE(inherit_d_json)  {  	verifyByFile<TestModule::InheritanceCont2Ptr, Slicer::JsonFileDeserializer>("inherit-d.json");  } -BOOST_AUTO_TEST_CASE( inherit_mapped_json ) +BOOST_AUTO_TEST_CASE(inherit_mapped_json)  {  	verifyByFile<TestModule::InheritanceContMappedPtr, Slicer::JsonFileDeserializer>("inherit-mapped.json");  } -BOOST_AUTO_TEST_CASE( xml_attribute_xml ) +BOOST_AUTO_TEST_CASE(xml_attribute_xml)  {  	verifyByFile<TestModule::ClassClassPtr, Slicer::XmlFileDeserializer>("xmlattr.xml");  } -BOOST_AUTO_TEST_CASE( xml_barecontainers_xml ) +BOOST_AUTO_TEST_CASE(xml_barecontainers_xml)  {  	verifyByFile<TestXml::BareContainers, Slicer::XmlFileDeserializer>("bare.xml", checkBare);  } -BOOST_AUTO_TEST_CASE( xml_classOfEnums_xml ) +BOOST_AUTO_TEST_CASE(xml_classOfEnums_xml)  {  	verifyByFile<TestModule::SomeEnumsPtr, Slicer::XmlFileDeserializer>("someenums.xml", checkSomeEnums);  } -BOOST_AUTO_TEST_CASE( xml_rootEnums_xml ) +BOOST_AUTO_TEST_CASE(xml_rootEnums_xml)  {  	verifyByFile<TestModule::SomeNumbers, Slicer::XmlFileDeserializer>("enum.xml", checkSomeNumbers);  } -BOOST_AUTO_TEST_CASE( xml_attributemap_xml ) +BOOST_AUTO_TEST_CASE(xml_attributemap_xml)  {  	verifyByFile<TestXml::Maps, Slicer::XmlFileDeserializer>("attributemap.xml", attributeMap);  } -BOOST_AUTO_TEST_CASE( xml_elementmap_xml ) +BOOST_AUTO_TEST_CASE(xml_elementmap_xml)  {  	verifyByFile<TestXml::Maps, Slicer::XmlFileDeserializer>("elementmap.xml", elementMap);  } -BOOST_AUTO_TEST_CASE( json_rootEnums_json ) +BOOST_AUTO_TEST_CASE(json_rootEnums_json)  {  	verifyByFile<TestModule::SomeNumbers, Slicer::JsonFileDeserializer>("enum2.json", checkSomeNumbers);  } -BOOST_AUTO_TEST_CASE( json_objectmap ) +BOOST_AUTO_TEST_CASE(json_objectmap)  {  	verifyByFile<TestJson::Properties, Slicer::JsonFileDeserializer>("objectmap.json", checkObjectMap);  } -BOOST_AUTO_TEST_CASE( json_objectmapMember ) +BOOST_AUTO_TEST_CASE(json_objectmapMember)  { -	verifyByFile<TestJson::HasProperitiesPtr, Slicer::JsonFileDeserializer>("objectmapMember.json", checkObjectMapMember); +	verifyByFile<TestJson::HasProperitiesPtr, Slicer::JsonFileDeserializer>( +			"objectmapMember.json", checkObjectMapMember);  } -BOOST_AUTO_TEST_CASE( json_localClass ) +BOOST_AUTO_TEST_CASE(json_localClass)  {  	verifyByFile<Locals::LocalClassPtr, Slicer::JsonFileDeserializer>("localClass.json");  } -BOOST_AUTO_TEST_CASE( json_localSub2Class ) +BOOST_AUTO_TEST_CASE(json_localSub2Class)  {  	verifyByFile<Locals::LocalClassPtr, Slicer::JsonFileDeserializer>("localSub2Class.json");  } -BOOST_AUTO_TEST_CASE( json_localSubClass ) +BOOST_AUTO_TEST_CASE(json_localSubClass)  {  	verifyByFile<Locals::LocalSubClassPtr, Slicer::JsonFileDeserializer>("localSub2Class.json");  } -BOOST_AUTO_TEST_CASE( json_simpleArray ) +BOOST_AUTO_TEST_CASE(json_simpleArray)  {  	verifyByFile<TestModule::SimpleSeq, Slicer::JsonFileDeserializer>("simpleArray1.json");  } -BOOST_AUTO_TEST_CASE( xml_simpleArray ) +BOOST_AUTO_TEST_CASE(xml_simpleArray)  {  	verifyByFile<TestModule::SimpleSeq, Slicer::XmlFileDeserializer>("simpleArray2.xml");  } -BOOST_AUTO_TEST_CASE( json_emptyToNull ) +BOOST_AUTO_TEST_CASE(json_emptyToNull)  {  	verifyByFile<TestModule::Optionals2Ptr, Slicer::JsonFileDeserializer>("optionals2.json", [](const auto & o) {  		BOOST_REQUIRE(o); @@ -548,7 +551,7 @@ BOOST_AUTO_TEST_CASE( json_emptyToNull )  	});  } -BOOST_AUTO_TEST_CASE( json_emptyToNull_withValue ) +BOOST_AUTO_TEST_CASE(json_emptyToNull_withValue)  {  	verifyByFile<TestModule::Optionals2Ptr, Slicer::JsonFileDeserializer>("optionals3.json", [](const auto & o) {  		BOOST_REQUIRE(o); @@ -558,16 +561,17 @@ BOOST_AUTO_TEST_CASE( json_emptyToNull_withValue )  	});  } -BOOST_AUTO_TEST_CASE( json_emptyToNull_omitted ) +BOOST_AUTO_TEST_CASE(json_emptyToNull_omitted)  { -	verifyByFile<TestModule::Optionals2Ptr, Slicer::JsonFileDeserializer>("optionals5.json", "optionals2.json", [](const auto & o) { -		BOOST_REQUIRE(o); -		BOOST_REQUIRE(!o->optConverted); -		BOOST_REQUIRE_EQUAL(o->nonOptConverted, 4); -	}); +	verifyByFile<TestModule::Optionals2Ptr, Slicer::JsonFileDeserializer>( +			"optionals5.json", "optionals2.json", [](const auto & o) { +				BOOST_REQUIRE(o); +				BOOST_REQUIRE(!o->optConverted); +				BOOST_REQUIRE_EQUAL(o->nonOptConverted, 4); +			});  } -BOOST_AUTO_TEST_CASE( json_streams ) +BOOST_AUTO_TEST_CASE(json_streams)  {  	const auto tmpf = binDir / "byStream";  	const auto inFile = rootDir / "initial" / "inherit-c.json"; @@ -583,7 +587,7 @@ BOOST_AUTO_TEST_CASE( json_streams )  	diff(inFile, outFile);  } -BOOST_AUTO_TEST_CASE( xml_streams ) +BOOST_AUTO_TEST_CASE(xml_streams)  {  	const auto tmpf = binDir / "byStream";  	const auto inFile = rootDir / "initial" / "inherit-b.xml"; @@ -599,50 +603,51 @@ BOOST_AUTO_TEST_CASE( xml_streams )  	diff(inFile, outFile);  } -BOOST_AUTO_TEST_CASE( invalid_enum ) +BOOST_AUTO_TEST_CASE(invalid_enum)  {  	auto jdeserializer = std::make_shared<Slicer::JsonFileDeserializer>(rootDir / "initial" / "invalidEnum.json"); -	BOOST_REQUIRE_THROW(Slicer::DeserializeAnyWith<TestModule::SomeNumbers>(jdeserializer), Slicer::InvalidEnumerationSymbol); +	BOOST_REQUIRE_THROW( +			Slicer::DeserializeAnyWith<TestModule::SomeNumbers>(jdeserializer), Slicer::InvalidEnumerationSymbol);  	auto xdeserializer = std::make_shared<Slicer::XmlFileDeserializer>(rootDir / "initial" / "invalidEnum.xml"); -	BOOST_REQUIRE_THROW(Slicer::DeserializeAnyWith<TestModule::SomeNumbers>(xdeserializer), Slicer::InvalidEnumerationSymbol); +	BOOST_REQUIRE_THROW( +			Slicer::DeserializeAnyWith<TestModule::SomeNumbers>(xdeserializer), Slicer::InvalidEnumerationSymbol);  }  BOOST_AUTO_TEST_SUITE_END(); +BOOST_FIXTURE_TEST_SUITE(byHandler, FileBased); -BOOST_FIXTURE_TEST_SUITE ( byHandler, FileBased ); - -BOOST_AUTO_TEST_CASE( optionals_areset2_json ) +BOOST_AUTO_TEST_CASE(optionals_areset2_json)  { -	verifyByHelper<TestModule::OptionalsPtr, Slicer::JsonValueDeserializer, Slicer::JsonValueSerializer, json::Value>("optionals-areset2.json", readJson, writeJson, freeJson, checkOptionals_areset); +	verifyByHelper<TestModule::OptionalsPtr, Slicer::JsonValueDeserializer, Slicer::JsonValueSerializer, json::Value>( +			"optionals-areset2.json", readJson, writeJson, freeJson, checkOptionals_areset);  } -BOOST_AUTO_TEST_CASE( optionals_areset_xml ) +BOOST_AUTO_TEST_CASE(optionals_areset_xml)  { -	verifyByHelper<TestModule::OptionalsPtr, Slicer::XmlDocumentDeserializer, Slicer::XmlDocumentSerializer, xmlpp::Document *>("optionals-areset.xml", readXml, writeXml, freeXml, checkOptionals_areset); +	verifyByHelper<TestModule::OptionalsPtr, Slicer::XmlDocumentDeserializer, Slicer::XmlDocumentSerializer, +			xmlpp::Document *>("optionals-areset.xml", readXml, writeXml, freeXml, checkOptionals_areset);  } -BOOST_AUTO_TEST_CASE( simple_complete_validator ) +BOOST_AUTO_TEST_CASE(simple_complete_validator)  { -	verifyByHelper<TestModule::IsoDate, Slicer::XmlDocumentDeserializer, Slicer::XmlDocumentSerializer, xmlpp::Document *>("isodate.xml", readXml, writeXml, freeXml); +	verifyByHelper<TestModule::IsoDate, Slicer::XmlDocumentDeserializer, Slicer::XmlDocumentSerializer, +			xmlpp::Document *>("isodate.xml", readXml, writeXml, freeXml);  } -BOOST_AUTO_TEST_CASE( missingConversion ) +BOOST_AUTO_TEST_CASE(missingConversion)  {  	auto in = json::parseValue(R"J({"conv": "2016-06-30 12:34:56"})J"); -	BOOST_REQUIRE_THROW(( -		Slicer::DeserializeAny<Slicer::JsonValueDeserializer, TestModule2::MissingConvPtr>(in) -	), Slicer::NoConversionFound); +	BOOST_REQUIRE_THROW((Slicer::DeserializeAny<Slicer::JsonValueDeserializer, TestModule2::MissingConvPtr>(in)), +			Slicer::NoConversionFound);  	auto obj = std::make_shared<TestModule2::MissingConv>("2016-06-30 12:34:56");  	json::Value v; -	BOOST_REQUIRE_THROW( -		Slicer::SerializeAny<Slicer::JsonValueSerializer>(obj, v), -		Slicer::NoConversionFound); +	BOOST_REQUIRE_THROW(Slicer::SerializeAny<Slicer::JsonValueSerializer>(obj, v), Slicer::NoConversionFound);  } -BOOST_AUTO_TEST_CASE( conversion ) +BOOST_AUTO_TEST_CASE(conversion)  {  	auto in = json::parseValue(R"J({"conv": "2016-06-30 12:34:56"})J");  	auto obj = Slicer::DeserializeAny<Slicer::JsonValueDeserializer, TestModule2::ConvPtr>(in); @@ -650,13 +655,12 @@ BOOST_AUTO_TEST_CASE( conversion )  	json::Value v;  	Slicer::SerializeAny<Slicer::JsonValueSerializer>(obj, v); -	BOOST_REQUIRE_EQUAL("2016-06-30 12:34:56", -			std::get<json::String>(std::get<json::Object>(v)["conv"])); +	BOOST_REQUIRE_EQUAL("2016-06-30 12:34:56", std::get<json::String>(std::get<json::Object>(v)["conv"]));  }  BOOST_AUTO_TEST_SUITE_END(); -BOOST_AUTO_TEST_CASE( customerModelPartCounters ) +BOOST_AUTO_TEST_CASE(customerModelPartCounters)  {  	BOOST_REQUIRE_EQUAL(21, TestModule::completions);  } @@ -666,7 +670,7 @@ BOOST_FIXTURE_TEST_SUITE(l, Slicer::case_less);  BOOST_AUTO_TEST_CASE(case_less_test)  {  	using namespace std::literals; -	const auto & lc { *this }; +	const auto & lc {*this};  	BOOST_CHECK(!lc(""sv, ""sv));  	BOOST_CHECK(lc("a"sv, "b"sv));  	BOOST_CHECK(lc("A"sv, "b"sv)); @@ -686,4 +690,3 @@ BOOST_AUTO_TEST_CASE(enum_lookups)  	BOOST_CHECK_EQUAL("One", Slicer::ModelPartForEnum<TestModule::SomeNumbers>::lookup(TestModule::SomeNumbers::One));  	BOOST_CHECK_EQUAL(TestModule::SomeNumbers::One, Slicer::ModelPartForEnum<TestModule::SomeNumbers>::lookup("One"));  } - diff --git a/slicer/test/streams-mp.cpp b/slicer/test/streams-mp.cpp index 119ee1f..5764248 100644 --- a/slicer/test/streams-mp.cpp +++ b/slicer/test/streams-mp.cpp @@ -1,5 +1,4 @@ -#include <slicer/modelPartsTypes.impl.h>  #include "streams.h" +#include <slicer/modelPartsTypes.impl.h>  MODELPARTFORSTREAM(TestStream); - diff --git a/slicer/test/streams.cpp b/slicer/test/streams.cpp index 3ea4933..e68de0e 100644 --- a/slicer/test/streams.cpp +++ b/slicer/test/streams.cpp @@ -1,15 +1,16 @@  #define BOOST_TEST_MODULE streams  #include <boost/test/unit_test.hpp> -#include <xml/serializer.h> -#include <json/serializer.h> -#include <slicer.h> -#include <collections.h> -#include <definedDirs.h>  #include "helpers.h"  #include "streams.h" +#include <collections.h> +#include <definedDirs.h> +#include <json/serializer.h> +#include <slicer.h> +#include <xml/serializer.h> -void TestStream::Produce(const Consumer & c) +void +TestStream::Produce(const Consumer & c)  {  	for (int x = 0; x < 10; x += 1) {  		auto str = std::to_string(x); @@ -17,9 +18,9 @@ void TestStream::Produce(const Consumer & c)  	}  } -BOOST_FIXTURE_TEST_SUITE( stream, TestStream ); +BOOST_FIXTURE_TEST_SUITE(stream, TestStream); -BOOST_AUTO_TEST_CASE( streamToXml ) +BOOST_AUTO_TEST_CASE(streamToXml)  {  	const auto outputXml = binDir / "streamOut.xml";  	Slicer::SerializeAny<Slicer::XmlFileSerializer, const TestStream>(*this, outputXml); @@ -30,7 +31,7 @@ BOOST_AUTO_TEST_CASE( streamToXml )  	BOOST_REQUIRE_EQUAL("9", seq.back());  } -BOOST_AUTO_TEST_CASE( streamToJson ) +BOOST_AUTO_TEST_CASE(streamToJson)  {  	const auto outputJson = binDir / "streamOut.json";  	Slicer::SerializeAny<Slicer::JsonFileSerializer, const TestStream>(*this, outputJson); @@ -42,4 +43,3 @@ BOOST_AUTO_TEST_CASE( streamToJson )  }  BOOST_AUTO_TEST_SUITE_END(); - diff --git a/slicer/test/streams.h b/slicer/test/streams.h index 28c0c9d..bf80ce2 100644 --- a/slicer/test/streams.h +++ b/slicer/test/streams.h @@ -4,9 +4,8 @@  #include <slicer/modelPartsTypes.h>  class TestStream : public Slicer::Stream<std::string> { -	public: -		void Produce(const Consumer & c) override; +public: +	void Produce(const Consumer & c) override;  };  #endif - diff --git a/slicer/tool/Jamfile.jam b/slicer/tool/Jamfile.jam index fe45a72..e8ef3e9 100644 --- a/slicer/tool/Jamfile.jam +++ b/slicer/tool/Jamfile.jam @@ -16,8 +16,6 @@ lib slicer-compiler :  	<implicit-dependency>../slicer//slicer  	<include>..  	<toolset>tidy:<xcheckxx>clang-analyzer-cplusplus.NewDelete -	<toolset>tidy:<xcheckxx>clang-analyzer-cplusplus.InnerPointer -	<toolset>tidy:<xcheckxx>clang-analyzer-cplusplus.NewDeleteLeaks  	: :  	<include>..  	<library>../slicer//slicer diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 294dd7a..d342c35 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -1,31 +1,34 @@  #include "parser.h" -#include <metadata.h> -#include <common.h> +#include <Slice/CPlusPlusUtil.h>  #include <Slice/Parser.h>  #include <Slice/Preprocessor.h>  #include <boost/algorithm/string/predicate.hpp>  #include <boost/algorithm/string/replace.hpp> -#include <boost/algorithm/string/trim.hpp>  #include <boost/algorithm/string/split.hpp> -#include <Slice/CPlusPlusUtil.h> +#include <boost/algorithm/string/trim.hpp> +#include <common.h>  #include <fprintbf.h> +#include <metadata.h>  #include <safeMapFind.h>  namespace fs = std::filesystem;  namespace Slicer { -	Slicer::Slicer() : -		cpp(nullptr), -		headerPrefix("slicer"), -		components(0), -		classNo(0) +	template<typename TPtr> +	bool +	ignoreType(const TPtr & t)  	{ +		return (!t || t->hasMetaData("slicer:ignore"));  	} +	Slicer::Slicer() : cpp(nullptr), headerPrefix("slicer"), components(0), classNo(0) { } +  	void  	Slicer::defineConversions(const Slice::DataMemberPtr & dm) const  	{ -		if (!cpp) { return; } +		if (!cpp) { +			return; +		}  		auto type = dm->type();  		auto c = Slice::ContainedPtr::dynamicCast(dm->container()); @@ -33,16 +36,12 @@ namespace Slicer {  		for (const auto & conversion : conversions) {  			if (!AdHoc::containerContains(conversion.Options, "nodeclare")) {  				if (!AdHoc::containerContains(conversion.Options, "nodeclareto")) { -					fprintbf(cpp, "DLL_PUBLIC %s %s(const %s &);\n", -							conversion.ExchangeType, -							conversion.ConvertToExchangeFunc, -							Slice::typeToString(type)); +					fprintbf(cpp, "DLL_PUBLIC %s %s(const %s &);\n", conversion.ExchangeType, +							conversion.ConvertToExchangeFunc, Slice::typeToString(type));  				}  				if (!AdHoc::containerContains(conversion.Options, "nodeclarefrom")) { -					fprintbf(cpp, "DLL_PUBLIC %s %s(const %s &);\n\n", -							Slice::typeToString(type), -							conversion.ConvertToModelFunc, -							conversion.ExchangeType); +					fprintbf(cpp, "DLL_PUBLIC %s %s(const %s &);\n\n", Slice::typeToString(type), +							conversion.ConvertToModelFunc, conversion.ExchangeType);  				}  			}  		} @@ -55,8 +54,7 @@ namespace Slicer {  			for (const auto & conversion : conversions) {  				fprintbf(cpp, "\tif (tryConvertFrom< %s >(vsp, Model, &%s)) {\n\t\treturn;\n\t}\n", -						conversion.ExchangeType, -						conversion.ConvertToModelFunc); +						conversion.ExchangeType, conversion.ConvertToModelFunc);  			}  			// Default conversion  			if (!dm->hasMetaData("slicer:nodefaultconversion")) { @@ -64,8 +62,7 @@ namespace Slicer {  						Slice::typeToString(type));  			}  			// Failed to convert -			fprintbf(cpp, "\tthrow NoConversionFound(\"%s\");\n", -					Slice::typeToString(type)); +			fprintbf(cpp, "\tthrow NoConversionFound(\"%s\");\n", Slice::typeToString(type));  			fprintbf(cpp, "}\n\n");  			fprintbf(cpp, "template<> DLL_PUBLIC\nbool\n"); @@ -75,18 +72,22 @@ namespace Slicer {  			fprintbf(cpp, "\tBOOST_ASSERT(Model);\n");  			for (const auto & conversion : conversions) { -				fprintbf(cpp, "\tif (auto r = tryConvertTo< %s >(vtp, Model, &%s)) {\n\t\treturn (r == tcr_Value);\n\t}\n", -						conversion.ExchangeType, -						conversion.ConvertToExchangeFunc); +				fprintbf(cpp, +						"\tif (auto r = tryConvertTo< %s >(vtp, Model, &%s); r != TryConvertResult::NoAction) {\n" +						"\t\treturn (r == TryConvertResult::Value);\n" +						"\t}\n", +						conversion.ExchangeType, conversion.ConvertToExchangeFunc);  			}  			// Default conversion  			if (!dm->hasMetaData("slicer:nodefaultconversion")) { -				fprintbf(cpp, "\tif (auto r = tryConvertTo< %s >(vtp, Model)) {\n\t\treturn (r == tcr_Value);\n\t}\n", -					Slice::typeToString(type)); +				fprintbf(cpp, +						"\tif (auto r = tryConvertTo< %s >(vtp, Model); r != TryConvertResult::NoAction) {\n" +						"\t\treturn (r == TryConvertResult::Value);\n" +						"\t}\n", +						Slice::typeToString(type));  			}  			// Failed to convert -			fprintbf(cpp, "\tthrow NoConversionFound(\"%s\");\n", -					Slice::typeToString(type)); +			fprintbf(cpp, "\tthrow NoConversionFound(\"%s\");\n", Slice::typeToString(type));  			fprintbf(cpp, "}\n\n");  		}  	} @@ -95,7 +96,9 @@ namespace Slicer {  	Slicer::visitUnitStart(const Slice::UnitPtr & u)  	{  		fs::path topLevelFile(u->topLevelFile()); -		if (!cpp) { return true; } +		if (!cpp) { +			return true; +		}  		fprintbf(cpp, "// Begin Slicer code\n\n");  		fprintbf(cpp, "#include <%s>\n\n", (headerPrefix / "modelPartsTypes.impl.h").string()); @@ -111,9 +114,11 @@ namespace Slicer {  	}  	void -	Slicer::visitUnitEnd(const Slice::UnitPtr&) +	Slicer::visitUnitEnd(const Slice::UnitPtr &)  	{ -		if (!cpp) { return; } +		if (!cpp) { +			return; +		}  		fprintbf(cpp, "}\n\n");  		fprintbf(cpp, "// End Slicer code\n\n"); @@ -122,7 +127,9 @@ namespace Slicer {  	bool  	Slicer::visitModuleStart(const Slice::ModulePtr & m)  	{ -		if (!cpp) { return true; } +		if (!cpp) { +			return true; +		}  		fprintbf(cpp, "// Begin module %s\n\n", m->name());  		for (const auto & c : m->structs()) { @@ -143,44 +150,48 @@ namespace Slicer {  	{  		if (stype->isLocal()) {  			fprintbf(cpp, "template<>\n"); -			fprintbf(cpp, "struct isLocal< %s > { static constexpr bool value = true; };\n\n", -					type); +			fprintbf(cpp, "struct isLocal< %s > { static constexpr bool value = true; };\n\n", type);  		}  		fprintbf(cpp, "template<> DLL_PUBLIC\n"); -		fprintbf(cpp, "const std::string ModelPartForRoot< %s >::rootName(\"%s\");\n\n", -				type, name); +		fprintbf(cpp, "const std::string ModelPartForRoot< %s >::rootName(\"%s\");\n\n", type, name);  		fprintbf(cpp, "template<> DLL_PUBLIC\n"); -		fprintbf(cpp, "const std::string ModelPartForRoot< Ice::optional< %s > >::rootName(\"Optional%s\");\n\n", -				type, name); +		fprintbf(cpp, "const std::string ModelPartForRoot< Ice::optional< %s > >::rootName(\"Optional%s\");\n\n", type, +				name);  	}  	void  	Slicer::externType(const Slice::TypePtr & type) const  	{ -		if (definedTypes.count(type->typeId())) return; - -		fprintbf(cpp, "extern template class %s< %s >;\n", -				getBasicModelPart(type), Slice::ClassDeclPtr::dynamicCast(type) ? type->typeId() : Slice::typeToString(type)); +		if (definedTypes.count(type->typeId())) { +			return; +		} +		fprintbf(cpp, "extern template class %s< %s >;\n", getBasicModelPart(type), +				Slice::ClassDeclPtr::dynamicCast(type) ? type->typeId() : Slice::typeToString(type));  	}  	bool  	Slicer::visitClassDefStart(const Slice::ClassDefPtr & c)  	{ -		if (c->isInterface()) { return false; } -		if (c->hasMetaData("slicer:ignore")) { return false; } +		if (c->isInterface()) { +			return false; +		} +		if (ignoreType(c)) { +			return false; +		}  		components += 1; -		if (!cpp) { return true; } +		if (!cpp) { +			return true; +		}  		auto decl = c->declaration();  		fprintbf(cpp, "// Class %s\n", c->name()); -		visitComplexDataMembers(decl, c->allDataMembers()); +		visitComplexDataMembers(decl.get(), c->allDataMembers());  		fprintbf(cpp, "template<> DLL_PUBLIC\n");  		auto typeId = metaDataValue("slicer:typeid:", c->getMetaData()); -		fprintbf(cpp, "const std::string ModelPartForClass< %s >::typeIdProperty(\"%s\");\n\n", -				decl->typeId(), +		fprintbf(cpp, "const std::string ModelPartForClass< %s >::typeIdProperty(\"%s\");\n\n", decl->typeId(),  				typeId ? *typeId : "slicer-typeid");  		auto name = metaDataValue("slicer:root:", c->getMetaData()); @@ -188,31 +199,28 @@ namespace Slicer {  		auto typeName = metaDataValue("slicer:typename:", c->getMetaData());  		fprintbf(cpp, "template<> DLL_PUBLIC\n"); -		fprintbf(cpp, "const std::string * ModelPartForClass< %s >::className = nullptr;\n", -				decl->typeId()); +		fprintbf(cpp, "const std::string * ModelPartForClass< %s >::className = nullptr;\n", decl->typeId());  		fprintbf(cpp, "template<> DLL_PUBLIC\n"); -		fprintbf(cpp, "const std::string * ModelPartForClass< %s >::typeName = nullptr;\n", -				decl->typeId()); -		fprintbf(cpp, "template<>\nvoid ModelPartForClass< %s >::initClassName() {\n\tclassName = new std::string(\"%s\");\n\t", +		fprintbf(cpp, "const std::string * ModelPartForClass< %s >::typeName = nullptr;\n", decl->typeId()); +		fprintbf(cpp, +				"template<>\nvoid ModelPartForClass< %s >::initClassName() {\n\tclassName = new " +				"std::string(\"%s\");\n\t",  				decl->typeId(), c->scoped());  		if (typeName) { -			fprintbf(cpp, "typeName = new std::string(\"%s\");", -					*typeName); +			fprintbf(cpp, "typeName = new std::string(\"%s\");", *typeName);  		}  		else {  			fprintbf(cpp, "typeName = nullptr;");  		}  		fprintbf(cpp, "\n}\n"); -		fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForComplex< %s >::metadata ", -				c->scoped()); +		fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForComplex< %s >::metadata ", c->scoped());  		copyMetadata(c->getMetaData());  		fprintbf(cpp, ";\n\n"); -		fprintbf(cpp, "// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)\n");  		if (auto cmp = metaDataValue("slicer:custommodelpart:", c->getMetaData())) { -			fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, %s< %s >, %s);\n\n", -					Slice::typeToString(decl), getBasicModelPart(decl), c->scoped(), boost::algorithm::replace_all_copy(*cmp, ".", "::")); +			fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, %s< %s >, %s);\n\n", Slice::typeToString(decl), +					getBasicModelPart(decl), c->scoped(), boost::algorithm::replace_all_copy(*cmp, ".", "::"));  		}  		else {  			fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, ModelPartForClass<%s>, ModelPartForClass<%s>);\n\n", @@ -228,20 +236,23 @@ namespace Slicer {  	bool  	Slicer::visitStructStart(const Slice::StructPtr & c)  	{ -		if (c->hasMetaData("slicer:ignore")) { return false; } +		if (ignoreType(c)) { +			return false; +		}  		components += 1; -		if (!cpp) { return true; } +		if (!cpp) { +			return true; +		}  		fprintbf(cpp, "// Struct %s\n", c->name()); -		visitComplexDataMembers(c, c->dataMembers()); +		visitComplexDataMembers(c.get(), c->dataMembers());  		auto name = metaDataValue("slicer:root:", c->getMetaData());  		defineRoot(c->scoped(), name ? *name : c->name(), c); -		fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForComplex< %s >::metadata ", -				c->scoped()); +		fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForComplex< %s >::metadata ", c->scoped());  		copyMetadata(c->getMetaData());  		fprintbf(cpp, ";\n\n"); @@ -253,20 +264,18 @@ namespace Slicer {  	void  	Slicer::visitComplexDataMembers(const Slice::ConstructedPtr & it, const Slice::DataMemberList & dataMembers) const  	{ -		if (!cpp) { return; } +		if (!cpp) { +			return; +		}  		for (const auto & dm : dataMembers) {  			externType(dm->type());  		} -		fprintbf(cpp, "using C%d = ModelPartForComplex< %s >;\n", -				components, it->scoped()); +		fprintbf(cpp, "using C%d = ModelPartForComplex< %s >;\n", components, it->scoped());  		fprintbf(cpp, "template<> DLL_PUBLIC\n"); -		fprintbf(cpp, "const C%d::Hooks ", -				components); -		fprintbf(cpp, "C%d::hooks ([](){\n", -				components); -		fprintbf(cpp, "\t\tC%d::Hooks r;\n", -				components); +		fprintbf(cpp, "const C%d::Hooks ", components); +		fprintbf(cpp, "C%d::hooks ([](){\n", components); +		fprintbf(cpp, "\t\tC%d::Hooks r;\n", components);  		for (const auto & dm : dataMembers) {  			auto c = Slice::ContainedPtr::dynamicCast(dm->container());  			auto t = Slice::TypePtr::dynamicCast(dm->container()); @@ -274,8 +283,7 @@ namespace Slicer {  				t = Slice::ClassDefPtr::dynamicCast(dm->container())->declaration();  			}  			auto name = metaDataValue("slicer:name:", dm->getMetaData()).value_or(dm->name()); -			fprintbf(cpp, "\t\tC%d::addHook<C%d::", -					components, components); +			fprintbf(cpp, "\t\tC%d::addHook<C%d::", components, components);  			auto type = dm->type();  			if (hasMetadata(dm->getMetaData())) {  				fprintbf(cpp, "HookMetadata<"); @@ -283,12 +291,9 @@ namespace Slicer {  			else {  				fprintbf(cpp, "Hook<");  			} -			fprintbf(cpp, " %s, ", -					Slice::typeToString(type, dm->optional())); +			fprintbf(cpp, " %s, ", Slice::typeToString(type, dm->optional()));  			createNewModelPartPtrFor(type, dm, getAllMetadata(dm)); -			fprintbf(cpp, " > >(r, &%s, \"%s\"", -					dm->scoped(), -					name); +			fprintbf(cpp, " > >(r, &%s, \"%s\"", dm->scoped(), name);  			if (hasMetadata(dm->getMetaData())) {  				fprintbf(cpp, ", Metadata ");  				copyMetadata(dm->getMetaData()); @@ -302,31 +307,34 @@ namespace Slicer {  	void  	Slicer::visitEnum(const Slice::EnumPtr & e)  	{ -		if (e->hasMetaData("slicer:ignore")) { return; } +		if (ignoreType(e)) { +			return; +		}  		components += 1; -		if (!cpp) { return; } +		if (!cpp) { +			return; +		}  		fprintbf(cpp, "// Enumeration %s\n", e->name()); -		fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForEnum< %s >::metadata ", -				e->scoped()); +		fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForEnum< %s >::metadata ", e->scoped());  		copyMetadata(e->getMetaData());  		fprintbf(cpp, ";\n\n"); -		fprintbf(cpp, "template<> DLL_PUBLIC\nconst ModelPartForEnum< %s >::Enumerations\nModelPartForEnum< %s >::enumerations([]() -> ModelPartForEnum< %s >::Enumerations\n", -				e->scoped(), -				e->scoped(), -				e->scoped()); -		fprintbf(cpp, "{\n\tModelPartForEnum< %s >::Enumerations e;\n", -				e->scoped()); +		fprintbf(cpp, +				"template<> DLL_PUBLIC\nconst ModelPartForEnum< %s >::Enumerations\nModelPartForEnum< %s " +				">::enumerations([]() -> ModelPartForEnum< %s >::Enumerations\n", +				e->scoped(), e->scoped(), e->scoped()); +		fprintbf(cpp, "{\n\tModelPartForEnum< %s >::Enumerations e;\n", e->scoped());  		for (const auto & ee : e->enumerators()) {  			fprintbf(cpp, "\te.insert( { %s, \"%s\" } );\n", ee->scoped(), ee->name());  		}  		fprintbf(cpp, "\treturn e;\n}());\n\n");  		auto name = metaDataValue("slicer:root:", e->getMetaData()); -		defineRoot(e->scoped(), name ? *name : e->name(), e); +		const Slice::TypePtr t = e; +		defineRoot(e->scoped(), name ? *name : e->name(), t);  		defineMODELPART(e->scoped(), e, e->getMetaData());  	} @@ -334,20 +342,28 @@ namespace Slicer {  	void  	Slicer::visitSequence(const Slice::SequencePtr & s)  	{ -		if (s->hasMetaData("slicer:ignore")) { return; } +		if (ignoreType(s)) { +			return; +		}  		components += 1; -		if (!cpp) { return; } +		if (!cpp) { +			return; +		}  		fprintbf(cpp, "// Sequence %s\n", s->name());  		externType(s->type());  		fprintbf(cpp, "template<> DLL_PUBLIC\n"); -		fprintbf(cpp, "ChildRef ModelPartForSequence< %s >::GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase)\n{\n", +		fprintbf(cpp, +				"ChildRef ModelPartForSequence< %s >::GetChildRef(const std::string & name, const HookFilter & flt, " +				"bool matchCase)\n{\n",  				s->scoped());  		auto iname = metaDataValue("slicer:item:", s->getMetaData());  		if (iname) { -			fprintbf(cpp, "\tif (!name.empty() && !optionalCaseEq(name, \"%s\", matchCase)) { throw IncorrectElementName(name); }\n", +			fprintbf(cpp, +					"\tif (!name.empty() && !optionalCaseEq(name, \"%s\", matchCase)) { throw " +					"IncorrectElementName(name); }\n",  					*iname);  		}  		else { @@ -358,15 +374,13 @@ namespace Slicer {  		fprintbf(cpp, "template<> DLL_PUBLIC\n");  		auto ename = metaDataValue("slicer:element:", s->getMetaData()); -		fprintbf(cpp, "const std::string ModelPartForSequence< %s >::elementName(\"%s\");\n\n", -				s->scoped(), +		fprintbf(cpp, "const std::string ModelPartForSequence< %s >::elementName(\"%s\");\n\n", s->scoped(),  				ename ? *ename : "element");  		auto name = metaDataValue("slicer:root:", s->getMetaData());  		defineRoot(s->scoped(), name ? *name : s->name(), s); -		fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForSequence< %s >::metadata ", -				s->scoped()); +		fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForSequence< %s >::metadata ", s->scoped());  		copyMetadata(s->getMetaData());  		fprintbf(cpp, ";\n\n"); @@ -376,40 +390,34 @@ namespace Slicer {  	void  	Slicer::visitDictionary(const Slice::DictionaryPtr & d)  	{ -		if (d->hasMetaData("slicer:ignore")) { return; } +		if (ignoreType(d)) { +			return; +		}  		components += 1; -		if (!cpp) { return; } +		if (!cpp) { +			return; +		}  		fprintbf(cpp, "// Dictionary %s\n", d->name());  		externType(d->keyType());  		externType(d->valueType());  		auto iname = metaDataValue("slicer:item:", d->getMetaData());  		fprintbf(cpp, "template<> DLL_PUBLIC\n"); -		fprintbf(cpp, "const std::string ModelPartForDictionary< %s >::pairName(\"%s\");\n\n", -				d->scoped(), +		fprintbf(cpp, "const std::string ModelPartForDictionary< %s >::pairName(\"%s\");\n\n", d->scoped(),  				iname ? *iname : "element"); -		fprintbf(cpp, "using C%d = ModelPartForComplex< %s::value_type >;\n", -				components, d->scoped()); +		fprintbf(cpp, "using C%d = ModelPartForComplex< %s::value_type >;\n", components, d->scoped());  		fprintbf(cpp, "template<> DLL_PUBLIC\n"); -		fprintbf(cpp, "const C%d::Hooks ", -				components); -		fprintbf(cpp, "C%d::hooks ([](){\n", -				components); -		fprintbf(cpp, "\t\tC%d::Hooks r;\n", -				components); +		fprintbf(cpp, "const C%d::Hooks ", components); +		fprintbf(cpp, "C%d::hooks ([](){\n", components); +		fprintbf(cpp, "\t\tC%d::Hooks r;\n", components);  		auto addHook = [&](const std::string & name, const char * element, const Slice::TypePtr & t) {  			fprintbf(cpp, "\t\t"); -			fprintbf(cpp, "C%d::addHook< C%d::Hook< const %s, ", -					components, components, -					Slice::typeToString(t)); +			fprintbf(cpp, "C%d::addHook< C%d::Hook< const %s, ", components, components, Slice::typeToString(t));  			createNewModelPartPtrFor(t); -			fprintbf(cpp, " > >(r, &%s::value_type::%s, \"%s\");\n", -					d->scoped(), -					element, -					name); +			fprintbf(cpp, " > >(r, &%s::value_type::%s, \"%s\");\n", d->scoped(), element, name);  		};  		addHook(metaDataValue("slicer:key:", d->getMetaData()).value_or("key"), "first", d->keyType());  		addHook(metaDataValue("slicer:value:", d->getMetaData()).value_or("value"), "second", d->valueType()); @@ -420,8 +428,7 @@ namespace Slicer {  		auto name = metaDataValue("slicer:root:", d->getMetaData());  		defineRoot(d->scoped(), name ? *name : d->name(), d); -		fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForDictionary< %s >::metadata ", -				d->scoped()); +		fprintbf(cpp, "template<> DLL_PUBLIC\nconst Metadata ModelPartForDictionary< %s >::metadata ", d->scoped());  		copyMetadata(d->getMetaData());  		fprintbf(cpp, ";\n\n"); @@ -442,41 +449,37 @@ namespace Slicer {  	}  	void -	Slicer::createModelPartForConverted(const Slice::TypePtr & type, const std::string & container, const Slice::DataMemberPtr & dm) const +	Slicer::createModelPartForConverted( +			const Slice::TypePtr & type, const std::string & container, const Slice::DataMemberPtr & dm) const  	{  		fprintbf(cpp, "ModelPartForConverted< ");  		if (dm->optional()) { -			fprintbf(cpp, "Ice::optional< %s >", -					Slice::typeToString(type)); +			fprintbf(cpp, "Ice::optional< %s >", Slice::typeToString(type));  		}  		else { -			fprintbf(cpp, "%s", -					Slice::typeToString(type)); +			fprintbf(cpp, "%s", Slice::typeToString(type));  		} -		fprintbf(cpp, ", %s, &%s >", -				container, -				dm->scoped()); +		fprintbf(cpp, ", %s, &%s >", container, dm->scoped());  	}  	void -	Slicer::createNewModelPartPtrFor(const Slice::TypePtr & type, const Slice::DataMemberPtr & dm, const Slice::StringList & md) const +	Slicer::createNewModelPartPtrFor( +			const Slice::TypePtr & type, const Slice::DataMemberPtr & dm, const Slice::StringList & md) const  	{  		auto conversions = getConversions(md);  		if (dm && !conversions.empty()) { -			createModelPartForConverted(type, -					boost::algorithm::trim_right_copy_if(dm->container()->thisScope(), ispunct), -					dm); +			createModelPartForConverted( +					type, boost::algorithm::trim_right_copy_if(dm->container()->thisScope(), ispunct), dm);  		}  		else if (auto cmp = metaDataValue("slicer:custommodelpart:", md)) { -			fprintbf(cpp, "%s", -				boost::algorithm::replace_all_copy(*cmp, ".", "::")); +			fprintbf(cpp, "%s", boost::algorithm::replace_all_copy(*cmp, ".", "::"));  		}  		else {  			if (dm && dm->optional()) {  				fprintbf(cpp, "ModelPartForOptional< ");  			} -			fprintbf(cpp, "%s< %s >", -					getBasicModelPart(type), Slice::ClassDeclPtr::dynamicCast(type) ? type->typeId() : Slice::typeToString(type)); +			fprintbf(cpp, "%s< %s >", getBasicModelPart(type), +					Slice::ClassDeclPtr::dynamicCast(type) ? type->typeId() : Slice::typeToString(type));  			if (dm && dm->optional()) {  				fprintbf(cpp, " > ");  			} @@ -486,24 +489,17 @@ namespace Slicer {  	std::string  	Slicer::getBasicModelPart(const Slice::TypePtr & type) const  	{ -		if (auto builtin = Slice::BuiltinPtr::dynamicCast(type)) { -			return "ModelPartForSimple"; -		} -		else if (auto complexClass = Slice::ClassDeclPtr::dynamicCast(type)) { -			return "ModelPartForClass"; -		} -		else if (auto complexStruct = Slice::StructPtr::dynamicCast(type)) { -			return "ModelPartForStruct"; -		} -		else if (auto sequence = Slice::SequencePtr::dynamicCast(type)) { -			return "ModelPartForSequence"; -		} -		else if (auto dictionary = Slice::DictionaryPtr::dynamicCast(type)) { -			return "ModelPartForDictionary"; -		} -		else if (auto enumeration = Slice::EnumPtr::dynamicCast(type)) { -			return "ModelPartForEnum"; -		} +#define CheckTypeAndReturn(Type, ModerlPartClass) \ +	if (Type::dynamicCast(type)) { \ +		return ModerlPartClass; \ +	} +		CheckTypeAndReturn(Slice::BuiltinPtr, "ModelPartForSimple"); +		CheckTypeAndReturn(Slice::ClassDeclPtr, "ModelPartForClass"); +		CheckTypeAndReturn(Slice::StructPtr, "ModelPartForStruct"); +		CheckTypeAndReturn(Slice::SequencePtr, "ModelPartForSequence"); +		CheckTypeAndReturn(Slice::DictionaryPtr, "ModelPartForDictionary"); +		CheckTypeAndReturn(Slice::EnumPtr, "ModelPartForEnum"); +#undef CheckTypeAndReturn  		throw CompilerError("Unknown basic type");  	} @@ -568,14 +564,12 @@ namespace Slicer {  	void  	Slicer::defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata)  	{ -		fprintbf(cpp, "// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)\n");  		if (auto cmp = metaDataValue("slicer:custommodelpart:", metadata)) { -			fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, %s< %s >, %s);\n\n", -					type, getBasicModelPart(stype), type, boost::algorithm::replace_all_copy(*cmp, ".", "::")); +			fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, %s< %s >, %s);\n\n", type, getBasicModelPart(stype), type, +					boost::algorithm::replace_all_copy(*cmp, ".", "::"));  		}  		else { -			fprintbf(cpp, "MODELPARTFOR(%s, %s);\n\n", -					type, getBasicModelPart(stype)); +			fprintbf(cpp, "MODELPARTFOR(%s, %s);\n\n", type, getBasicModelPart(stype));  		}  		definedTypes.insert(stype->typeId());  	} @@ -593,8 +587,7 @@ namespace Slicer {  			throw CompilerError("Both file handle and path provided.");  		}  		auto cppfile = std::unique_ptr<FILE, decltype(&fclose)>( -			cpp || cppPath.empty() ? cpp : fopen(cppPath.c_str(), "w"), -					cppPath.empty() ? fflush : fclose); +				cpp || cppPath.empty() ? cpp : fopen(cppPath.c_str(), "w"), cppPath.empty() ? fflush : fclose);  		if (!cppfile && !cppPath.empty()) {  			throw CompilerError("Failed to open output file");  		} @@ -602,7 +595,7 @@ namespace Slicer {  			cpp = cppfile.get();  			Slicer::Slicer::Args args;  			// Copy includes to args -			for(const auto & include : includes) { +			for (const auto & include : includes) {  				args.push_back("-I" + include.string());  			} @@ -646,13 +639,11 @@ namespace Slicer {  	}  	Slicer::ConversionSpec::ConversionSpec(const Slicer::Args & s) : -		ExchangeType(s[0]), -		ConvertToModelFunc(s[1]), -		ConvertToExchangeFunc(s[2]) +		ExchangeType(s[0]), ConvertToModelFunc(s[1]), ConvertToExchangeFunc(s[2])  	{  		if (s.size() >= 4) { -			boost::algorithm::split(Options, s[3], boost::algorithm::is_any_of(","), boost::algorithm::token_compress_off); +			boost::algorithm::split( +					Options, s[3], boost::algorithm::is_any_of(","), boost::algorithm::token_compress_off);  		}  	}  }; - diff --git a/slicer/tool/parser.h b/slicer/tool/parser.h index 67aa243..295705d 100644 --- a/slicer/tool/parser.h +++ b/slicer/tool/parser.h @@ -7,81 +7,75 @@  namespace Slicer {  	class DLL_PUBLIC Slicer : public Slice::ParserVisitor { +	public: +		typedef std::vector<std::string> Args; +		class ConversionSpec {  		public: -			typedef std::vector<std::string> Args; -			class ConversionSpec { -				public: -					explicit ConversionSpec(const Args &); - -					// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -					std::string ExchangeType; -					// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -					std::string ConvertToModelFunc; -					// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -					std::string ConvertToExchangeFunc; -					// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -					Args Options; -			}; -			using Conversions = std::vector<ConversionSpec>; - -			Slicer(); - -			// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -			FILE * cpp; -			// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -			std::filesystem::path slicePath; -			// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -			std::filesystem::path cppPath; -			// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -			std::filesystem::path headerPrefix; -			// NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) -			std::vector<std::filesystem::path> includes; - -			unsigned int Execute(); -			[[nodiscard]] unsigned int Components() const; +			explicit ConversionSpec(const Args &); + +			std::string ExchangeType; +			std::string ConvertToModelFunc; +			std::string ConvertToExchangeFunc; +			Args Options; +		}; +		using Conversions = std::vector<ConversionSpec>; + +		Slicer(); + +		FILE * cpp; +		std::filesystem::path slicePath; +		std::filesystem::path cppPath; +		std::filesystem::path headerPrefix; +		std::vector<std::filesystem::path> includes; + +		unsigned int Execute(); +		[[nodiscard]] unsigned int Components() const;  #pragma GCC visibility push(hidden) -			bool visitUnitStart(const Slice::UnitPtr&) override; +		bool visitUnitStart(const Slice::UnitPtr &) override; -			void visitUnitEnd(const Slice::UnitPtr&) override; +		void visitUnitEnd(const Slice::UnitPtr &) override; -			bool visitModuleStart(const Slice::ModulePtr & m) override; +		bool visitModuleStart(const Slice::ModulePtr & m) override; -			bool visitClassDefStart(const Slice::ClassDefPtr & c) override; +		bool visitClassDefStart(const Slice::ClassDefPtr & c) override; -			bool visitStructStart(const Slice::StructPtr&) override; +		bool visitStructStart(const Slice::StructPtr &) override; -			void visitEnum(const Slice::EnumPtr &) override; +		void visitEnum(const Slice::EnumPtr &) override; -			void visitSequence(const Slice::SequencePtr & s) override; +		void visitSequence(const Slice::SequencePtr & s) override; -			void visitDictionary(const Slice::DictionaryPtr & d) override; +		void visitDictionary(const Slice::DictionaryPtr & d) override; -			void visitModuleEnd(const Slice::ModulePtr & m) override; +		void visitModuleEnd(const Slice::ModulePtr & m) override; -		private: -			void createModelPartForConverted(const Slice::TypePtr & type, const std::string & container, const Slice::DataMemberPtr & dm) const; -			void createNewModelPartPtrFor(const Slice::TypePtr & type, const Slice::DataMemberPtr & dm = Slice::DataMemberPtr(), const Slice::StringList & md = Slice::StringList()) const; -			[[nodiscard]] std::string getBasicModelPart(const Slice::TypePtr & type) const; -			void defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata); +	private: +		void createModelPartForConverted( +				const Slice::TypePtr & type, const std::string & container, const Slice::DataMemberPtr & dm) const; +		void createNewModelPartPtrFor(const Slice::TypePtr & type, +				const Slice::DataMemberPtr & dm = Slice::DataMemberPtr(), +				const Slice::StringList & md = Slice::StringList()) const; +		[[nodiscard]] std::string getBasicModelPart(const Slice::TypePtr & type) const; +		void defineMODELPART( +				const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata); -			void visitComplexDataMembers(const Slice::ConstructedPtr & t, const Slice::DataMemberList &) const; +		void visitComplexDataMembers(const Slice::ConstructedPtr & t, const Slice::DataMemberList &) const; -			void defineConversions(const Slice::DataMemberPtr & dm) const; -			void defineRoot(const std::string & type, const std::string & name, const Slice::TypePtr & stype) const; -			void externType(const Slice::TypePtr &) const; +		void defineConversions(const Slice::DataMemberPtr & dm) const; +		void defineRoot(const std::string & type, const std::string & name, const Slice::TypePtr & stype) const; +		void externType(const Slice::TypePtr &) const; -			[[nodiscard]] bool hasMetadata(const std::list<std::string> & metadata) const; -			void copyMetadata(const std::list<std::string> & metadata) const; -			static Slice::StringList getAllMetadata(const Slice::DataMemberPtr & dm); -			static Conversions getConversions(const Slice::StringList & metadata); -			std::set<std::string> definedTypes; +		[[nodiscard]] bool hasMetadata(const std::list<std::string> & metadata) const; +		void copyMetadata(const std::list<std::string> & metadata) const; +		static Slice::StringList getAllMetadata(const Slice::DataMemberPtr & dm); +		static Conversions getConversions(const Slice::StringList & metadata); +		std::set<std::string> definedTypes;  #pragma GCC visibility pop -			unsigned int components; -			unsigned int classNo; +		unsigned int components; +		unsigned int classNo;  	};  }  #endif - diff --git a/slicer/tool/slicer.cpp b/slicer/tool/slicer.cpp index 49d52a6..0145d15 100644 --- a/slicer/tool/slicer.cpp +++ b/slicer/tool/slicer.cpp @@ -1,5 +1,5 @@ -#include <tool/parser.h>  #include <boost/program_options.hpp> +#include <tool/parser.h>  namespace po = boost::program_options; @@ -9,6 +9,7 @@ main(int argc, char ** argv)  	Slicer::Slicer slicer;  	po::options_description opts("Slicer options"); +	// clang-format off  	opts.add_options()  		("help,h", "Show this help message")  		("include,I", po::value(&slicer.includes), "Add include directory to search path") @@ -16,6 +17,7 @@ main(int argc, char ** argv)  		("headerPrefix", po::value(&slicer.headerPrefix)->default_value(slicer.headerPrefix), "Prefix path for Slicer C++ #includes")  		("slice,i", po::value(&slicer.slicePath), "Input ICE Slice file")  		("cpp,o", po::value(&slicer.cppPath), "Output C++ file"); +	// clang-format on  	po::positional_options_description p;  	p.add("slice", 1); @@ -35,4 +37,3 @@ main(int argc, char ** argv)  	return 0;  } - diff --git a/slicer/xml/Jamfile.jam b/slicer/xml/Jamfile.jam index c237f93..4150632 100644 --- a/slicer/xml/Jamfile.jam +++ b/slicer/xml/Jamfile.jam @@ -15,7 +15,6 @@ lib slicer-xml :  	<library>../slicer//slicer  	<implicit-dependency>../slicer//slicer  	<implicit-dependency>xmlExceptions -	<toolset>tidy:<xcheckxx>clang-analyzer-optin.cplusplus.VirtualCall  	: :  	<library>../..//libxmlpp  	<implicit-dependency>xmlExceptions diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp index f31acb0..fbda026 100644 --- a/slicer/xml/serializer.cpp +++ b/slicer/xml/serializer.cpp @@ -1,13 +1,13 @@  #include "serializer.h" -#include <xmlExceptions.h> -#include <slicer/metadata.h> -#include <libxml++/document.h> -#include <libxml++/parsers/domparser.h>  #include <boost/lexical_cast.hpp> +#include <compileTimeFormatter.h>  #include <functional> -#include <stdexcept>  #include <glibmm/ustring.h> -#include <compileTimeFormatter.h> +#include <libxml++/document.h> +#include <libxml++/parsers/domparser.h> +#include <slicer/metadata.h> +#include <stdexcept> +#include <xmlExceptions.h>  NAMEDFACTORY(".xml", Slicer::XmlFileSerializer, Slicer::FileSerializerFactory);  NAMEDFACTORY(".xml", Slicer::XmlFileDeserializer, Slicer::FileDeserializerFactory); @@ -24,169 +24,180 @@ namespace Slicer {  	const std::string md_elements = "xml:elements";  	const std::string keyName = "key";  	const std::string valueName = "value"; -	using ElementCreatorF = xmlpp::Element * (xmlpp::Element::*) (const Glib::ustring &, const Glib::ustring &); -	const auto defaultElementCreator = std::bind((ElementCreatorF)&xmlpp::Element::add_child_element, _1, _2, Glib::ustring()); +	using ElementCreatorF = xmlpp::Element * (xmlpp::Element::*)(const Glib::ustring &, const Glib::ustring &); +	const auto defaultElementCreator = [](auto && element, auto && name) { +		return element->add_child_element(name); +	};  	static const Glib::ustring TrueText("true");  	static const Glib::ustring FalseText("false");  	class XmlValueSource : public ValueSource { -		public: -			explicit XmlValueSource(Glib::ustring s) : -				value(std::move(s)) -			{ -			} +	public: +		explicit XmlValueSource(Glib::ustring s) : value(std::move(s)) { } -			void set(bool & v) const override -			{ -				if (value == TrueText) { v = true; return; } -				if (value == FalseText) { v = false; return; } -				throw BadBooleanValue(value); +		void +		set(bool & v) const override +		{ +			if (value == TrueText) { +				v = true; +				return;  			} - -			void set(Ice::Byte & v) const override -			{ -				v = boost::numeric_cast<Ice::Byte>(boost::lexical_cast<int>(value)); +			if (value == FalseText) { +				v = false; +				return;  			} +			throw BadBooleanValue(value); +		} -			void set(Ice::Short & v) const override -			{ -				v = boost::lexical_cast<Ice::Short>(value); -			} +		void +		set(Ice::Byte & v) const override +		{ +			v = boost::numeric_cast<Ice::Byte>(boost::lexical_cast<int>(value)); +		} -			void set(Ice::Int & v) const override -			{ -				v = boost::lexical_cast<Ice::Int>(value); -			} +		void +		set(Ice::Short & v) const override +		{ +			v = boost::lexical_cast<Ice::Short>(value); +		} -			void set(Ice::Long & v) const override -			{ -				v = boost::lexical_cast<Ice::Long>(value); -			} +		void +		set(Ice::Int & v) const override +		{ +			v = boost::lexical_cast<Ice::Int>(value); +		} -			void set(Ice::Float & v) const override -			{ -				v = boost::lexical_cast<Ice::Float>(value); -			} +		void +		set(Ice::Long & v) const override +		{ +			v = boost::lexical_cast<Ice::Long>(value); +		} -			void set(Ice::Double & v) const override -			{ -				v = boost::lexical_cast<Ice::Double>(value); -			} +		void +		set(Ice::Float & v) const override +		{ +			v = boost::lexical_cast<Ice::Float>(value); +		} -			void set(std::string & v) const override -			{ -				v = value.raw(); -			} +		void +		set(Ice::Double & v) const override +		{ +			v = boost::lexical_cast<Ice::Double>(value); +		} + +		void +		set(std::string & v) const override +		{ +			v = value.raw(); +		} -		private: -			const Glib::ustring value; +	private: +		const Glib::ustring value;  	};  	class XmlContentValueSource : public XmlValueSource { -		public: -			explicit XmlContentValueSource() : -				XmlValueSource(Glib::ustring()) -			{ -			} -			explicit XmlContentValueSource(const xmlpp::ContentNode * c) : -				XmlValueSource(c->get_content()) -			{ -			} +	public: +		explicit XmlContentValueSource() : XmlValueSource(Glib::ustring()) { } +		explicit XmlContentValueSource(const xmlpp::ContentNode * c) : XmlValueSource(c->get_content()) { }  	};  	class XmlAttributeValueSource : public XmlValueSource { -		public: -			explicit XmlAttributeValueSource(const xmlpp::Attribute * a) : -				XmlValueSource(a->get_value()) -			{ -			} +	public: +		explicit XmlAttributeValueSource(const xmlpp::Attribute * a) : XmlValueSource(a->get_value()) { }  	};  	class XmlValueTarget : public ValueTarget { -		public: -			explicit XmlValueTarget(std::function<void(const Glib::ustring &)> a) : -				apply(std::move(a)) -			{ -			} +	public: +		explicit XmlValueTarget(std::function<void(const Glib::ustring &)> a) : apply(std::move(a)) { } -			void get(const bool & value) const override -			{ -				if (value) { -					apply(TrueText); -				} -				else { -					apply(FalseText); -				} +		void +		get(const bool & value) const override +		{ +			if (value) { +				apply(TrueText);  			} - -			void get(const Ice::Byte & value) const override -			{ -				apply(boost::lexical_cast<Glib::ustring>((int)value)); +			else { +				apply(FalseText);  			} +		} -			void get(const Ice::Short & value) const override -			{ -				apply(boost::lexical_cast<Glib::ustring>(value)); -			} +		void +		get(const Ice::Byte & value) const override +		{ +			apply(boost::lexical_cast<Glib::ustring>((int)value)); +		} -			void get(const Ice::Int & value) const override -			{ -				apply(boost::lexical_cast<Glib::ustring>(value)); -			} +		void +		get(const Ice::Short & value) const override +		{ +			apply(boost::lexical_cast<Glib::ustring>(value)); +		} -			void get(const Ice::Long & value) const override -			{ -				apply(boost::lexical_cast<Glib::ustring>(value)); -			} +		void +		get(const Ice::Int & value) const override +		{ +			apply(boost::lexical_cast<Glib::ustring>(value)); +		} -			void get(const Ice::Float & value) const override -			{ -				apply(boost::lexical_cast<Glib::ustring>(value)); -			} +		void +		get(const Ice::Long & value) const override +		{ +			apply(boost::lexical_cast<Glib::ustring>(value)); +		} -			void get(const Ice::Double & value) const override -			{ -				apply(boost::lexical_cast<Glib::ustring>(value)); -			} +		void +		get(const Ice::Float & value) const override +		{ +			apply(boost::lexical_cast<Glib::ustring>(value)); +		} -			void get(const std::string & value) const override -			{ -				apply(value); -			} +		void +		get(const Ice::Double & value) const override +		{ +			apply(boost::lexical_cast<Glib::ustring>(value)); +		} -		private: -			const std::function<void(const Glib::ustring &)> apply; -	}; +		void +		get(const std::string & value) const override +		{ +			apply(value); +		} +	private: +		const std::function<void(const Glib::ustring &)> apply; +	};  	class XmlAttributeValueTarget : public XmlValueTarget { -		public: -			explicit XmlAttributeValueTarget(xmlpp::Element * p, const std::string & n) : -				XmlValueTarget([p, n](auto && PH1) { -					p->set_attribute(n, PH1); -				}) -			{ -			} +	public: +		explicit XmlAttributeValueTarget(xmlpp::Element * p, const std::string & n) : +			XmlValueTarget([p, n](auto && PH1) { +				p->set_attribute(n, PH1); +			}) +		{ +		}  	};  	class XmlContentValueTarget : public XmlValueTarget { -		public: -			explicit XmlContentValueTarget(xmlpp::Element * p) : -				XmlValueTarget([p](auto && PH1) { -					p->set_first_child_text(PH1); -				}) -			{ -			} +	public: +		explicit XmlContentValueTarget(xmlpp::Element * p) : +			XmlValueTarget([p](auto && PH1) { +				p->set_first_child_text(PH1); +			}) +		{ +		} -			explicit XmlContentValueTarget(const CurrentElementCreator & cec) : -				XmlValueTarget(std::bind(&xmlpp::Element::set_first_child_text, std::bind(&CurrentElementCreator::deref, &cec), _1)) -			{ -			} +		explicit XmlContentValueTarget(const CurrentElementCreator & cec) : +			XmlValueTarget([&](auto && PH1) { +				cec->set_first_child_text(PH1); +			}) +		{ +		}  	};  	void -	XmlDeserializer::DocumentTreeIterateDictAttrs(const xmlpp::Element::const_AttributeList & attrs, const ModelPartPtr & dict) +	XmlDeserializer::DocumentTreeIterateDictAttrs( +			const xmlpp::Element::const_AttributeList & attrs, const ModelPartPtr & dict)  	{  		for (const auto & attr : attrs) {  			auto emp = dict->GetAnonChild(); @@ -307,7 +318,8 @@ namespace Slicer {  	}  	void -	XmlSerializer::ModelTreeIterate(xmlpp::Element * n, const std::string & name, const ModelPartPtr & mp, const HookCommon * hp, const ElementCreator & ec) +	XmlSerializer::ModelTreeIterate(xmlpp::Element * n, const std::string & name, const ModelPartPtr & mp, +			const HookCommon * hp, const ElementCreator & ec)  	{  		if (name.empty()) {  			return; @@ -331,7 +343,9 @@ namespace Slicer {  				});  			}  			else { -				CurrentElementCreator cec([ec, n, name] { return ec(n, name); }); +				CurrentElementCreator cec([ec, n, name] { +					return ec(n, name); +				});  				ModelTreeProcessElement(cec, mp, defaultElementCreator);  			}  		} @@ -342,7 +356,7 @@ namespace Slicer {  	{  		dict->OnEachChild([element](const auto &, const auto & mp, const auto &) {  			if (mp->HasValue()) { -				mp->GetChild(keyName)->GetValue(XmlValueTarget([&mp,element](const auto & name) { +				mp->GetChild(keyName)->GetValue(XmlValueTarget([&mp, element](const auto & name) {  					mp->GetChild(valueName)->GetValue(XmlAttributeValueTarget(element, name));  				}));  			} @@ -354,8 +368,10 @@ namespace Slicer {  	{  		dict->OnEachChild([element](const auto &, const auto & mp, const auto &) {  			if (mp->HasValue()) { -				mp->GetChild(keyName)->GetValue(XmlValueTarget([&mp,element](const auto & name) { -					CurrentElementCreator cec([&element, &name]() { return element->add_child_element(name); }); +				mp->GetChild(keyName)->GetValue(XmlValueTarget([&mp, element](const auto & name) { +					CurrentElementCreator cec([&element, &name]() { +						return element->add_child_element(name); +					});  					ModelTreeProcessElement(cec, mp->GetChild(valueName), defaultElementCreator);  				}));  			} @@ -363,9 +379,10 @@ namespace Slicer {  	}  	void -	XmlSerializer::ModelTreeProcessElement(const CurrentElementCreator & cec, ModelPartPtr mp, const ElementCreator & ec) +	XmlSerializer::ModelTreeProcessElement( +			const CurrentElementCreator & cec, ModelPartPtr mp, const ElementCreator & ec)  	{ -		if (mp->GetType() == mpt_Simple) { +		if (mp->GetType() == ModelPartType::Simple) {  			mp->GetValue(XmlContentValueTarget(cec));  		}  		else if (mp->HasValue()) { @@ -388,15 +405,9 @@ namespace Slicer {  		ModelTreeProcessElement(doc->create_root_node(name), mp, defaultElementCreator);  	} -	XmlStreamSerializer::XmlStreamSerializer(std::ostream & s) : -		strm(s) -	{ -	} +	XmlStreamSerializer::XmlStreamSerializer(std::ostream & s) : strm(s) { } -	XmlStreamDeserializer::XmlStreamDeserializer(std::istream & s) : -		strm(s) -	{ -	} +	XmlStreamDeserializer::XmlStreamDeserializer(std::istream & s) : strm(s) { }  	void  	XmlStreamDeserializer::Deserialize(ModelPartForRootPtr modelRoot) @@ -417,15 +428,9 @@ namespace Slicer {  		doc.write_to_stream(strm);  	} -	XmlFileSerializer::XmlFileSerializer(std::filesystem::path p) : -		path(std::move(p)) -	{ -	} +	XmlFileSerializer::XmlFileSerializer(std::filesystem::path p) : path(std::move(p)) { } -	XmlFileDeserializer::XmlFileDeserializer(std::filesystem::path p) : -		path(std::move(p)) -	{ -	} +	XmlFileDeserializer::XmlFileDeserializer(std::filesystem::path p) : path(std::move(p)) { }  	void  	XmlFileDeserializer::Deserialize(ModelPartForRootPtr modelRoot) @@ -445,15 +450,9 @@ namespace Slicer {  		doc.write_to_file_formatted(path);  	} -	XmlDocumentSerializer::XmlDocumentSerializer(xmlpp::Document * & d) : -		doc(d) -	{ -	} +	XmlDocumentSerializer::XmlDocumentSerializer(xmlpp::Document *& d) : doc(d) { } -	XmlDocumentDeserializer::XmlDocumentDeserializer(const xmlpp::Document * d) : -		doc(d) -	{ -	} +	XmlDocumentDeserializer::XmlDocumentDeserializer(const xmlpp::Document * d) : doc(d) { }  	void  	XmlDocumentDeserializer::Deserialize(ModelPartForRootPtr modelRoot) @@ -471,9 +470,9 @@ namespace Slicer {  	}  	AdHocFormatter(BadBooleanValueMsg, "Bad boolean value [%?]"); -	void BadBooleanValue::ice_print(std::ostream & s) const +	void +	BadBooleanValue::ice_print(std::ostream & s) const  	{  		BadBooleanValueMsg::write(s, text);  	}  } - diff --git a/slicer/xml/serializer.h b/slicer/xml/serializer.h index f41e5a7..99b03dd 100644 --- a/slicer/xml/serializer.h +++ b/slicer/xml/serializer.h @@ -1,96 +1,97 @@  #ifndef SLICER_XML_H  #define SLICER_XML_H -#include <slicer/serializer.h> +#include <lazyPointer.h>  #include <libxml++/document.h>  #include <libxml++/nodes/element.h> +#include <slicer/serializer.h>  #include <visibility.h> -#include <lazyPointer.h>  namespace Slicer { -	typedef ::AdHoc::LazyPointer<xmlpp::Element, xmlpp::Element *> CurrentElementCreator; +	using CurrentElementCreator = ::AdHoc::LazyPointer<xmlpp::Element, xmlpp::Element *>;  	class DLL_PUBLIC XmlSerializer : public Serializer { -		protected: -			typedef std::function<xmlpp::Element *(xmlpp::Element *, const Glib::ustring &)> ElementCreator; -			static void ModelTreeIterate(xmlpp::Element *, const std::string &, const ModelPartPtr & mp, const HookCommon * hp, const ElementCreator &); -			static void ModelTreeIterateRoot(xmlpp::Document *, const std::string &, const ModelPartPtr & mp); - -		protected: -			static void ModelTreeProcessElement(const CurrentElementCreator &, ModelPartPtr mp, const ElementCreator &); -			static void ModelTreeIterateDictAttrs(xmlpp::Element * element, const ModelPartPtr & dict); -			static void ModelTreeIterateDictElements(xmlpp::Element * element, const ModelPartPtr & dict); +	protected: +		using ElementCreator = std::function<xmlpp::Element *(xmlpp::Element *, const Glib::ustring &)>; +		static void ModelTreeIterate(xmlpp::Element *, const std::string &, const ModelPartPtr & mp, +				const HookCommon * hp, const ElementCreator &); +		static void ModelTreeIterateRoot(xmlpp::Document *, const std::string &, const ModelPartPtr & mp); + +	protected: +		static void ModelTreeProcessElement(const CurrentElementCreator &, ModelPartPtr mp, const ElementCreator &); +		static void ModelTreeIterateDictAttrs(xmlpp::Element * element, const ModelPartPtr & dict); +		static void ModelTreeIterateDictElements(xmlpp::Element * element, const ModelPartPtr & dict);  	};  	class DLL_PUBLIC XmlStreamSerializer : public XmlSerializer { -		public: -			XmlStreamSerializer(std::ostream &); +	public: +		explicit XmlStreamSerializer(std::ostream &); -			void Serialize(ModelPartForRootPtr) override; +		void Serialize(ModelPartForRootPtr) override; -		protected: -			std::ostream & strm; +	protected: +		std::ostream & strm;  	};  	class DLL_PUBLIC XmlFileSerializer : public XmlSerializer { -		public: -			XmlFileSerializer(std::filesystem::path); +	public: +		explicit XmlFileSerializer(std::filesystem::path); -			void Serialize(ModelPartForRootPtr) override; +		void Serialize(ModelPartForRootPtr) override; -		protected: -			const std::filesystem::path path; +	protected: +		const std::filesystem::path path;  	};  	class DLL_PUBLIC XmlDocumentSerializer : public XmlSerializer { -		public: -			XmlDocumentSerializer(xmlpp::Document * &); +	public: +		explicit XmlDocumentSerializer(xmlpp::Document *&); -			void Serialize(ModelPartForRootPtr) override; +		void Serialize(ModelPartForRootPtr) override; -		protected: -			xmlpp::Document * & doc; +	protected: +		xmlpp::Document *& doc;  	};  	class DLL_PUBLIC XmlDeserializer : public Deserializer { -		protected: -			static void DocumentTreeIterate(const xmlpp::Node * node, const ModelPartPtr & mp); -			static void DocumentTreeIterateElement(const xmlpp::Element * element, ModelPartPtr mp, const ChildRef & c); -			static void DocumentTreeIterate(const xmlpp::Document * doc, const ModelPartPtr & mp); -			static void DocumentTreeIterateDictAttrs(const xmlpp::Element::const_AttributeList & attrs, const ModelPartPtr & dict); -			static void DocumentTreeIterateDictElements(const xmlpp::Element * parent, const ModelPartPtr & dict); +	protected: +		static void DocumentTreeIterate(const xmlpp::Node * node, const ModelPartPtr & mp); +		static void DocumentTreeIterateElement(const xmlpp::Element * element, ModelPartPtr mp, const ChildRef & c); +		static void DocumentTreeIterate(const xmlpp::Document * doc, const ModelPartPtr & mp); +		static void DocumentTreeIterateDictAttrs( +				const xmlpp::Element::const_AttributeList & attrs, const ModelPartPtr & dict); +		static void DocumentTreeIterateDictElements(const xmlpp::Element * parent, const ModelPartPtr & dict);  	};  	class DLL_PUBLIC XmlStreamDeserializer : public XmlDeserializer { -		public: -			XmlStreamDeserializer(std::istream &); +	public: +		explicit XmlStreamDeserializer(std::istream &); -			void Deserialize(ModelPartForRootPtr) override; +		void Deserialize(ModelPartForRootPtr) override; -		protected: -			std::istream & strm; +	protected: +		std::istream & strm;  	};  	class DLL_PUBLIC XmlFileDeserializer : public XmlDeserializer { -		public: -			XmlFileDeserializer(std::filesystem::path); +	public: +		explicit XmlFileDeserializer(std::filesystem::path); -			void Deserialize(ModelPartForRootPtr) override; +		void Deserialize(ModelPartForRootPtr) override; -		protected: -			const std::filesystem::path path; +	protected: +		const std::filesystem::path path;  	};  	class DLL_PUBLIC XmlDocumentDeserializer : public XmlDeserializer { -		public: -			XmlDocumentDeserializer(const xmlpp::Document *); +	public: +		explicit XmlDocumentDeserializer(const xmlpp::Document *); -			void Deserialize(ModelPartForRootPtr) override; +		void Deserialize(ModelPartForRootPtr) override; -		protected: -			const xmlpp::Document * doc; +	protected: +		const xmlpp::Document * doc;  	};  }  #endif - diff --git a/slicer/xml/testSpecifics.cpp b/slicer/xml/testSpecifics.cpp index d20ea09..3d05979 100644 --- a/slicer/xml/testSpecifics.cpp +++ b/slicer/xml/testSpecifics.cpp @@ -1,19 +1,19 @@  #define BOOST_TEST_MODULE xml_specifics -#include <boost/test/unit_test.hpp> -#include <slicer/slicer.h>  #include "serializer.h" +#include <boost/test/unit_test.hpp>  #include <libxml++/parsers/domparser.h> +#include <slicer/slicer.h>  #include <types.h>  #include <xmlExceptions.h> -template <typename T, typename ... P> +template<typename T, typename... P>  T -BoostThrowWrapperHelper(P && ... p) +BoostThrowWrapperHelper(P &&... p)  {  	return Slicer::DeserializeAny<Slicer::XmlDocumentDeserializer, T>(p...);  } -BOOST_AUTO_TEST_CASE( boolean_values ) +BOOST_AUTO_TEST_CASE(boolean_values)  {  	xmlpp::DomParser doc;  	doc.parse_memory("<Boolean>true</Boolean>"); @@ -28,7 +28,7 @@ BOOST_AUTO_TEST_CASE( boolean_values )  	BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<bool>(doc.get_document()), Slicer::BadBooleanValue);  } -BOOST_AUTO_TEST_CASE( int_values ) +BOOST_AUTO_TEST_CASE(int_values)  {  	xmlpp::DomParser doc;  	doc.parse_memory("<Int>13</Int>"); @@ -47,11 +47,10 @@ BOOST_AUTO_TEST_CASE( int_values )  	BOOST_REQUIRE_THROW(BoostThrowWrapperHelper<Ice::Int>(doc.get_document()), std::bad_cast);  } -BOOST_AUTO_TEST_CASE( factories ) +BOOST_AUTO_TEST_CASE(factories)  {  	BOOST_REQUIRE(Slicer::SerializerPtr(Slicer::FileSerializerFactory::createNew(".xml", "/some.xml")));  	BOOST_REQUIRE(Slicer::DeserializerPtr(Slicer::FileDeserializerFactory::createNew(".xml", "/some.xml")));  	BOOST_REQUIRE(Slicer::SerializerPtr(Slicer::StreamSerializerFactory::createNew("application/xml", std::cout)));  	BOOST_REQUIRE(Slicer::DeserializerPtr(Slicer::StreamDeserializerFactory::createNew("application/xml", std::cin)));  } -  | 
