diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-08-16 23:02:14 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-08-16 23:02:51 +0100 |
commit | 5dec62e8a79979af3adbc30b496202aebc0ac992 (patch) | |
tree | 5f4d35e0ce6115014b2b70fb8d0b039b9eb6e2fb | |
parent | Assert behaviour of ModelPartForClass::GetTypeId with a non-local class (diff) | |
download | slicer-5dec62e8a79979af3adbc30b496202aebc0ac992.tar.bz2 slicer-5dec62e8a79979af3adbc30b496202aebc0ac992.tar.xz slicer-5dec62e8a79979af3adbc30b496202aebc0ac992.zip |
Initial support for operating on local (classes)
-rw-r--r-- | slicer/slicer/modelPartsTypes.cpp | 6 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.h | 6 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.impl.h | 16 | ||||
-rw-r--r-- | slicer/test/compilation.cpp | 33 | ||||
-rw-r--r-- | slicer/test/locals.ice | 10 | ||||
-rw-r--r-- | slicer/test/preprocessor.cpp | 1 |
6 files changed, 71 insertions, 1 deletions
diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp index c1661de..7d6edaf 100644 --- a/slicer/slicer/modelPartsTypes.cpp +++ b/slicer/slicer/modelPartsTypes.cpp @@ -116,6 +116,12 @@ namespace Slicer { return (id == className) ? TypeId() : ModelPart::ToExchangeTypeName(id); } + std::string ModelPartForComplexBase::demangle(const char * mangled) + { + auto buf = std::unique_ptr<char, decltype(free)*>(abi::__cxa_demangle(mangled, NULL, NULL, NULL), std::free); + return "::" + std::string(buf.get()); + } + void ModelPartForOptionalBase::OnEachChild(const ChildHandler & ch) { if (this->hasModel()) { diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index 69c29b3..904a88a 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -2,6 +2,7 @@ #define SLICER_MODELPARTSTYPES_H #include "modelParts.h" +#include <Ice/ObjectF.h> namespace Slicer { template<typename T> @@ -116,6 +117,7 @@ namespace Slicer { 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); }; template<typename T> @@ -182,6 +184,10 @@ namespace Slicer { virtual bool HasValue() const override; virtual 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; virtual IceUtil::Optional<std::string> GetTypeIdProperty() const override; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 3f701c2..1567b63 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -411,7 +411,21 @@ namespace Slicer { ModelPartForClass<T>::GetTypeId() const { BOOST_ASSERT(this->Model); - return ModelPartForComplexBase::GetTypeId((*this->Model)->ice_id(), *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 + { + 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 + { + return ModelPartForComplexBase::demangle(typeid(*this->Model->get()).name()); } // ModelPartForStruct diff --git a/slicer/test/compilation.cpp b/slicer/test/compilation.cpp index 0ba6b11..3a0f54e 100644 --- a/slicer/test/compilation.cpp +++ b/slicer/test/compilation.cpp @@ -2,6 +2,7 @@ #include <boost/test/unit_test.hpp> #include <types.h> +#include <locals.h> #include <slicer/modelParts.h> #include <slicer/modelPartsTypes.h> @@ -172,3 +173,35 @@ BOOST_AUTO_TEST_CASE( normalSubSubClassTypeId ) BOOST_REQUIRE_EQUAL(*baseType, "::TestModule::D3"); } +BOOST_AUTO_TEST_CASE( localClassTypeId ) +{ + Locals::LocalClassPtr base = new Locals::LocalClass(1, "One"); + BOOST_REQUIRE(base); + auto a = Slicer::ModelPart::CreateFor(base); + BOOST_REQUIRE(a); + auto baseType = a->GetTypeId(); + BOOST_REQUIRE(!baseType); +} + +BOOST_AUTO_TEST_CASE( localSubClassTypeId ) +{ + Locals::LocalClassPtr base = new Locals::LocalSubClass(1, "One", 3.1); + BOOST_REQUIRE(base); + auto a = Slicer::ModelPart::CreateFor(base); + BOOST_REQUIRE(a); + auto baseType = a->GetTypeId(); + BOOST_REQUIRE(baseType); + BOOST_REQUIRE_EQUAL(*baseType, "::Locals::LocalSubClass"); +} + +BOOST_AUTO_TEST_CASE( localSubSubClassTypeId ) +{ + Locals::LocalClassPtr base = new Locals::LocalSub2Class(1, "One", 3.1, 1); + BOOST_REQUIRE(base); + auto a = Slicer::ModelPart::CreateFor(base); + BOOST_REQUIRE(a); + auto baseType = a->GetTypeId(); + BOOST_REQUIRE(baseType); + BOOST_REQUIRE_EQUAL(*baseType, "::Locals::LocalSub2Class"); +} + diff --git a/slicer/test/locals.ice b/slicer/test/locals.ice index eb914dd..1fbe43a 100644 --- a/slicer/test/locals.ice +++ b/slicer/test/locals.ice @@ -10,6 +10,16 @@ module Locals { local enum E { a, b }; + local class LocalClass { + int a; + string b; + }; + local class LocalSubClass extends LocalClass { + double c; + }; + local class LocalSub2Class extends LocalSubClass { + int d; + }; }; #endif diff --git a/slicer/test/preprocessor.cpp b/slicer/test/preprocessor.cpp index b37b18b..869c2a0 100644 --- a/slicer/test/preprocessor.cpp +++ b/slicer/test/preprocessor.cpp @@ -19,6 +19,7 @@ ComponentsCount COMPONENTS_IN_TEST_ICE = { { "inheritance.ice", 12 }, { "interfaces.ice", 0 }, { "json.ice", 2 }, + { "locals.ice", 7 }, { "optionals.ice", 1 }, { "structs.ice", 4 }, { "types.ice", 3 }, |