diff options
author | Dan Goodliffe <randomdan@akira.random.lan> | 2014-11-30 03:08:33 +0000 |
---|---|---|
committer | Dan Goodliffe <randomdan@akira.random.lan> | 2014-11-30 03:08:33 +0000 |
commit | f1347e820c8262bec27cac1e98f5eaf8e6767d5b (patch) | |
tree | 8217a8d3d969320cb68e1abd07c120bb9bca1a28 | |
parent | Add .gitignore files (diff) | |
download | slicer-f1347e820c8262bec27cac1e98f5eaf8e6767d5b.tar.bz2 slicer-f1347e820c8262bec27cac1e98f5eaf8e6767d5b.tar.xz slicer-f1347e820c8262bec27cac1e98f5eaf8e6767d5b.zip |
Support for automatically determining a model part implementationslicer-0.8.3
-rw-r--r-- | slicer/slicer/modelParts.cpp | 13 | ||||
-rw-r--r-- | slicer/slicer/modelParts.h | 26 | ||||
-rw-r--r-- | slicer/test/Jamfile.jam | 13 | ||||
-rw-r--r-- | slicer/test/compilation.cpp | 102 |
4 files changed, 154 insertions, 0 deletions
diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp index 80d90cf..480ec1d 100644 --- a/slicer/slicer/modelParts.cpp +++ b/slicer/slicer/modelParts.cpp @@ -90,5 +90,18 @@ namespace Slicer { { return emptyMetadata; } + +#define MODELPARTFOR(Type, ModelPart) \ + ModelPartPtr ModelPartFor(Type & t) { return new ModelPart< Type >(t); } \ + ModelPartPtr ModelPartFor(Type * t) { return new ModelPart< Type >(t); } + MODELPARTFOR(std::string, ModelPartForSimple); + MODELPARTFOR(bool, ModelPartForSimple); + MODELPARTFOR(Ice::Float, ModelPartForSimple); + MODELPARTFOR(Ice::Double, ModelPartForSimple); + MODELPARTFOR(Ice::Byte, ModelPartForSimple); + MODELPARTFOR(Ice::Short, ModelPartForSimple); + MODELPARTFOR(Ice::Int, ModelPartForSimple); + MODELPARTFOR(Ice::Long, ModelPartForSimple); +#undef MODELPARTFOR } diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index da118bd..bd3889b 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -546,6 +546,32 @@ namespace Slicer { static std::string pairName; static Metadata metadata; }; + + // Templates for automatically determining a model part implementation +#define templateMODELPARTFOR(Type, ModelPart) \ + template <class T> ModelPartPtr ModelPartFor(Type & t) { return new ModelPart< Type >(t); } \ + template <class T> ModelPartPtr ModelPartFor(Type * t) { return new ModelPart< Type >(t); } +#define MODELPARTFOR(Type, ModelPart) \ + ModelPartPtr ModelPartFor(Type & t); \ + ModelPartPtr ModelPartFor(Type * t); + + templateMODELPARTFOR(IceInternal::Handle<T>, ModelPartForClass); + templateMODELPARTFOR(std::vector<T>, ModelPartForSequence); + templateMODELPARTFOR(std::list<T>, ModelPartForSequence); + template <class K, class V> ModelPartPtr ModelPartFor(std::map<K, V> & t) { return new ModelPartForDictionary< std::map<K, V> >(t); } \ + template <class K, class V> ModelPartPtr ModelPartFor(std::map<K, V> * t) { return new ModelPartForDictionary< std::map<K, V> >(t); } \ + MODELPARTFOR(std::string, ModelPartForSimple); + MODELPARTFOR(bool, ModelPartForSimple); + MODELPARTFOR(Ice::Float, ModelPartForSimple); + MODELPARTFOR(Ice::Double, ModelPartForSimple); + MODELPARTFOR(Ice::Byte, ModelPartForSimple); + MODELPARTFOR(Ice::Short, ModelPartForSimple); + MODELPARTFOR(Ice::Int, ModelPartForSimple); + MODELPARTFOR(Ice::Long, ModelPartForSimple); + // Everything else is a struct? + templateMODELPARTFOR(T, ModelPartForStruct); +#undef templateMODELPARTFOR +#undef MODELPARTFOR } #endif diff --git a/slicer/test/Jamfile.jam b/slicer/test/Jamfile.jam index ffedb00..dde7362 100644 --- a/slicer/test/Jamfile.jam +++ b/slicer/test/Jamfile.jam @@ -53,6 +53,19 @@ unit-test preprocess : <library>../slicer//slicer ; +unit-test compilation : + compilation.cpp + : + <include>.. + <library>../slicer//slicer + <library>types + <dependency>preprocess + <library>slicer-test + <library>common + <include>.. + <library>../slicer//slicer + ; + unit-test serializers : serializers.cpp : diff --git a/slicer/test/compilation.cpp b/slicer/test/compilation.cpp new file mode 100644 index 0000000..d48afd0 --- /dev/null +++ b/slicer/test/compilation.cpp @@ -0,0 +1,102 @@ +#define BOOST_TEST_MODULE compilation +#include <boost/test/unit_test.hpp> + +#include <types.h> +#include <slicer/modelParts.h> + +namespace std { + ostream & operator<<(ostream & strm, const type_info & ti) + { + strm << ti.name(); + return strm; + } +} + +#define TypeTest(Var, Expr, Explicit, Expected) \ + Var obj = Expr; \ + Slicer::ModelPartPtr mpp = new Slicer::Explicit<Var>(obj); \ + BOOST_REQUIRE_EQUAL(Slicer::Expected, mpp->GetType()); \ + \ + Slicer::ModelPartPtr autoMpp = Slicer::ModelPartFor(obj); \ + BOOST_REQUIRE_EQUAL(Slicer::Expected, autoMpp->GetType()); \ + \ + Slicer::ModelPartPtr autoPtrMpp = Slicer::ModelPartFor(&obj); \ + BOOST_REQUIRE_EQUAL(Slicer::Expected, autoPtrMpp->GetType()); \ +\ + BOOST_TEST_MESSAGE(typeid(*mpp.get())); \ + BOOST_REQUIRE_EQUAL(typeid(*mpp.get()), typeid(*autoMpp.get())); \ + BOOST_REQUIRE_EQUAL(typeid(*mpp.get()), typeid(*autoPtrMpp.get())); + +#define StackTypeTest(Var, Explicit, Expected) \ + TypeTest(Var, Var(), Explicit, Expected) + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_class ) +{ + TypeTest(TestModule::BuiltInsPtr, new TestModule::BuiltIns(), ModelPartForClass, mpt_Complex); +} + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_sequenceclasses ) +{ + StackTypeTest(TestModule::Classes, ModelPartForSequence, mpt_Sequence); +} + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_sequencestructs ) +{ + StackTypeTest(TestModule::Structs, ModelPartForSequence, mpt_Sequence); +} + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_mapclasses ) +{ + StackTypeTest(TestModule::ClassMap, ModelPartForDictionary, mpt_Dictionary); +} + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_mapstructs ) +{ + StackTypeTest(TestModule::StructMap, ModelPartForDictionary, mpt_Dictionary); +} + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_string ) +{ + StackTypeTest(std::string, ModelPartForSimple, mpt_Simple); +} + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_bool ) +{ + StackTypeTest(bool, ModelPartForSimple, mpt_Simple); +} + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_float ) +{ + StackTypeTest(Ice::Float, ModelPartForSimple, mpt_Simple); +} + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_double ) +{ + StackTypeTest(Ice::Double, ModelPartForSimple, mpt_Simple); +} + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_byte ) +{ + StackTypeTest(Ice::Byte, ModelPartForSimple, mpt_Simple); +} + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_short ) +{ + StackTypeTest(Ice::Short, ModelPartForSimple, mpt_Simple); +} + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_int ) +{ + StackTypeTest(Ice::Int, ModelPartForSimple, mpt_Simple); +} + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_bi_long ) +{ + StackTypeTest(Ice::Long, ModelPartForSimple, mpt_Simple); +} + +BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_struct ) +{ + StackTypeTest(TestModule::StructType, ModelPartForStruct, mpt_Complex); +} + |