diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-07-16 13:01:07 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-07-16 13:01:07 +0100 |
commit | 7286ca071504c4e3ddf1303c9606af6a0db2ff5e (patch) | |
tree | af45df2b56838748b2542c360f1cc6dad51b8442 | |
parent | Fix LCOV exclusion section terminator (diff) | |
download | slicer-7286ca071504c4e3ddf1303c9606af6a0db2ff5e.tar.bz2 slicer-7286ca071504c4e3ddf1303c9606af6a0db2ff5e.tar.xz slicer-7286ca071504c4e3ddf1303c9606af6a0db2ff5e.zip |
Switch ModelPartModel's internal model reference to pointer (breaking change for anything that extends a ModelPart)
-rw-r--r-- | slicer/slicer/modelParts.h | 5 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.h | 24 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.impl.h | 82 | ||||
-rw-r--r-- | slicer/test/conversions.cpp | 10 | ||||
-rw-r--r-- | slicer/test/conversions.h | 4 | ||||
-rw-r--r-- | slicer/tool/parser.cpp | 12 |
6 files changed, 70 insertions, 67 deletions
diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 8fce1e3..26df8e3 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -179,8 +179,9 @@ namespace Slicer { template<typename T> class DLL_PUBLIC ModelPartModel { protected: - ModelPartModel(T & m) : Model(m) { } - T & Model; + ModelPartModel() : Model(nullptr) { } + ModelPartModel(T * m) : Model(m) { } + T * Model; }; class DLL_PUBLIC ModelPartForRootBase : public ModelPart { diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index cbd953e..9c8f49e 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -12,7 +12,7 @@ namespace Slicer { template<typename T> class DLL_PUBLIC ModelPartForRoot : public ModelPartForRootBase { public: - ModelPartForRoot(T & o); + ModelPartForRoot(T * o); const std::string & GetRootName() const override; virtual bool HasValue() const override; @@ -40,7 +40,7 @@ namespace Slicer { public: typedef T element_type; - ModelPartForSimple(T & h); + ModelPartForSimple(T * h); virtual void SetValue(ValueSourcePtr s) override; virtual void GetValue(ValueTargetPtr s) override; @@ -61,7 +61,7 @@ namespace Slicer { public: typedef T element_type; - ModelPartForConverted(T & h); + ModelPartForConverted(T * h); virtual void SetValue(ValueSourcePtr s) override; virtual void GetValue(ValueTargetPtr s) override; @@ -86,7 +86,7 @@ namespace Slicer { template<typename T> class DLL_PUBLIC ModelPartForOptional : public ModelPartForOptionalBase, protected ModelPartModel<IceUtil::Optional<typename T::element_type> > { public: - ModelPartForOptional(IceUtil::Optional< typename T::element_type > & h); + ModelPartForOptional(IceUtil::Optional< typename T::element_type > * h); virtual void Create() override; virtual void GetValue(ValueTargetPtr s) override; virtual ModelPartType GetType() const override; @@ -130,7 +130,7 @@ namespace Slicer { ModelPartPtr Get(T * t) const override { - return t ? new MP(const_cast<typename std::remove_const<MT>::type &>(t->*member)) : NULL; + return t ? new MP(const_cast<typename std::remove_const<MT>::type *>(&(t->*member))) : NULL; } private: @@ -172,7 +172,7 @@ namespace Slicer { public: typedef IceInternal::Handle<T> element_type; - ModelPartForClass(element_type & h); + ModelPartForClass(element_type * h); virtual void Create() override; @@ -202,7 +202,7 @@ namespace Slicer { public: typedef T element_type; - ModelPartForStruct(T & o); + ModelPartForStruct(T * o); T * GetModel() override; @@ -225,7 +225,7 @@ namespace Slicer { typedef T element_type; typedef boost::bimap<T, std::string> Enumerations; - ModelPartForEnum(T & s); + ModelPartForEnum(T * s); virtual const Metadata & GetMetadata() const override; @@ -251,7 +251,7 @@ namespace Slicer { public: typedef T element_type; - ModelPartForSequence(T & s); + ModelPartForSequence(T * s); virtual void OnEachChild(const ChildHandler & ch) override; @@ -271,14 +271,14 @@ namespace Slicer { template<typename T> class DLL_PUBLIC ModelPartForDictionaryElementInserter : public ModelPartForStruct<typename T::value_type> { public: - ModelPartForDictionaryElementInserter(T & d); + ModelPartForDictionaryElementInserter(T * d); virtual void Complete() override; typename T::value_type value; private: - T & dictionary; + T * dictionary; }; class DLL_PUBLIC ModelPartForDictionaryBase : public ModelPart { @@ -293,7 +293,7 @@ namespace Slicer { public: typedef T element_type; - ModelPartForDictionary(T & d); + ModelPartForDictionary(T * d); virtual void OnEachChild(const ChildHandler & ch) override; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 08c14b2..6811de3 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -12,10 +12,10 @@ template class BaseModelPart; \ template class ModelPartForRoot<Type>; \ template class ModelPartForRoot< IceUtil::Optional<Type> >; \ - template<> ModelPartPtr ModelPart::CreateFor(Type & s) { return new ModelPartType(s); } \ - template<> ModelPartPtr ModelPart::CreateFor(IceUtil::Optional<Type> & s) { return new ModelPartForOptional<ModelPartType>(s); } \ - template<> ModelPartForRootPtr ModelPart::CreateRootFor(Type & s) { return new ModelPartForRoot<Type>(s); } \ - template<> ModelPartForRootPtr ModelPart::CreateRootFor(IceUtil::Optional<Type> & s) { return new ModelPartForRoot<IceUtil::Optional<Type> >(s); } \ + template<> ModelPartPtr ModelPart::CreateFor(Type & s) { return new ModelPartType(&s); } \ + template<> ModelPartPtr ModelPart::CreateFor(IceUtil::Optional<Type> & s) { return new ModelPartForOptional<ModelPartType>(&s); } \ + template<> ModelPartForRootPtr ModelPart::CreateRootFor(Type & s) { return new ModelPartForRoot<Type>(&s); } \ + template<> ModelPartForRootPtr ModelPart::CreateRootFor(IceUtil::Optional<Type> & s) { return new ModelPartForRoot<IceUtil::Optional<Type> >(&s); } \ #define MODELPARTFOR(Type, ModelPartType) \ CUSTOMMODELPARTFOR(Type, ModelPartType<Type>, ModelPartType<Type>) @@ -23,9 +23,9 @@ 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) { } @@ -132,7 +132,7 @@ namespace Slicer { // ModelPartForSimple template<typename T> - ModelPartForSimple<T>::ModelPartForSimple(T & h) : + ModelPartForSimple<T>::ModelPartForSimple(T * h) : ModelPartModel<T>(h) { } @@ -140,44 +140,44 @@ namespace Slicer { template<typename T> void ModelPartForSimple<T>::SetValue(ValueSourcePtr s) { - s->set(this->Model); + s->set(*this->Model); } template<typename T> void ModelPartForSimple<T>::GetValue(ValueTargetPtr s) { - s->get(this->Model); + s->get(*this->Model); } // ModelPartForConverted template<typename T, typename MT, typename M, MT M::* MV> - ModelPartForConverted<T, MT, M, MV>::ModelPartForConverted(T & h) : + ModelPartForConverted<T, MT, M, MV>::ModelPartForConverted(T * h) : ModelPartModel<T>(h) { } // ModelPartForOptional template<typename T> - ModelPartForOptional<T>::ModelPartForOptional(IceUtil::Optional< typename T::element_type > & h) : + ModelPartForOptional<T>::ModelPartForOptional(IceUtil::Optional< typename T::element_type > * h) : ModelPartModel<IceUtil::Optional< typename T::element_type> >(h) { - if (this->Model) { - modelPart = new T(*this->Model); + if (*this->Model) { + modelPart = new T(&**this->Model); } } template<typename T> bool ModelPartForOptional<T>::hasModel() const { - return this->Model; + return *this->Model; } template<typename T> void ModelPartForOptional<T>::Create() { - if (!this->Model) { - this->Model = typename T::element_type(); - modelPart = new T(*this->Model); + if (!*this->Model) { + *this->Model = typename T::element_type(); + modelPart = new T(&**this->Model); modelPart->Create(); } } @@ -185,9 +185,9 @@ namespace Slicer { template<typename T> void ModelPartForOptional<T>::GetValue(ValueTargetPtr s) { - if (!this->Model) { - this->Model = typename T::element_type(); - modelPart = new T(*this->Model); + if (!*this->Model) { + *this->Model = typename T::element_type(); + modelPart = new T(&**this->Model); } modelPart->GetValue(s); } @@ -237,7 +237,7 @@ namespace Slicer { // ModelPartForClass template<typename T> - ModelPartForClass<T>::ModelPartForClass(element_type & h) : + ModelPartForClass<T>::ModelPartForClass(element_type * h) : ModelPartModel<element_type>(h) { } @@ -245,25 +245,25 @@ namespace Slicer { template<typename T> void ModelPartForClass<T>::Create() { - this->Model = new T(); + *this->Model = new T(); } template<typename T> T * ModelPartForClass<T>::GetModel() { - return this->Model.get(); + return this->Model->get(); } template<typename T> ModelPartPtr ModelPartForClass<T>::GetSubclassModelPart(const std::string & name) { - return ModelPartForComplexBase::getSubclassModelPart(name, &this->Model); + return ModelPartForComplexBase::getSubclassModelPart(name, this->Model); } template<typename T> bool ModelPartForClass<T>::HasValue() const { - return this->Model; + return *this->Model; } template<typename T> @@ -275,7 +275,7 @@ namespace Slicer { template<typename T> ModelPartPtr ModelPartForClass<T>::CreateModelPart(void * p) { - return new ModelPartForClass<T>(*static_cast<element_type *>(p)); + return new ModelPartForClass<T>(static_cast<element_type *>(p)); } template<typename T> @@ -303,12 +303,12 @@ namespace Slicer { TypeId ModelPartForClass<T>::GetTypeId() const { - return ModelPartForComplexBase::GetTypeId(this->Model->ice_id(), *className); + return ModelPartForComplexBase::GetTypeId((*this->Model)->ice_id(), *className); } // ModelPartForStruct template<typename T> - ModelPartForStruct<T>::ModelPartForStruct(T & o) : + ModelPartForStruct<T>::ModelPartForStruct(T * o) : ModelPartModel<T>(o) { } @@ -316,7 +316,7 @@ namespace Slicer { template<typename T> T * ModelPartForStruct<T>::GetModel() { - return &this->Model; + return this->Model; } template<typename T> @@ -327,7 +327,7 @@ namespace Slicer { // ModelPartForEnum template<typename T> - ModelPartForEnum<T>::ModelPartForEnum(T & s) : + ModelPartForEnum<T>::ModelPartForEnum(T * s) : ModelPartModel<T>(s) { } @@ -340,7 +340,7 @@ namespace Slicer { // ModelPartForSequence template<typename T> - ModelPartForSequence<T>::ModelPartForSequence(T & s) : + ModelPartForSequence<T>::ModelPartForSequence(T * s) : ModelPartModel<T>(s) { } @@ -348,7 +348,7 @@ namespace Slicer { template<typename T> void ModelPartForSequence<T>::OnEachChild(const ChildHandler & ch) { - for(auto & element : this->Model) { + for(auto & element : *this->Model) { ch(elementName, elementModelPart(element), NULL); } } @@ -356,8 +356,8 @@ namespace Slicer { template<typename T> ChildRefPtr ModelPartForSequence<T>::GetAnonChildRef(const HookFilter &) { - this->Model.push_back(typename element_type::value_type()); - return new ImplicitChildRef(ModelPart::CreateFor(this->Model.back())); + this->Model->push_back(typename element_type::value_type()); + return new ImplicitChildRef(ModelPart::CreateFor(this->Model->back())); } template<typename T> @@ -388,8 +388,8 @@ namespace Slicer { // ModelPartForDictionaryElementInserter template<typename T> - ModelPartForDictionaryElementInserter<T>::ModelPartForDictionaryElementInserter(T & d) : - ModelPartForStruct<typename T::value_type>(value), + ModelPartForDictionaryElementInserter<T>::ModelPartForDictionaryElementInserter(T * d) : + ModelPartForStruct<typename T::value_type>(&value), dictionary(d) { } @@ -397,12 +397,12 @@ namespace Slicer { template<typename T> void ModelPartForDictionaryElementInserter<T>::Complete() { - dictionary.insert(value); + dictionary->insert(value); } // ModelPartForDictionary template<typename T> - ModelPartForDictionary<T>::ModelPartForDictionary(T & d) : + ModelPartForDictionary<T>::ModelPartForDictionary(T * d) : ModelPartModel<T>(d) { } @@ -410,8 +410,8 @@ namespace Slicer { template<typename T> void ModelPartForDictionary<T>::OnEachChild(const ChildHandler & ch) { - for (auto & pair : this->Model) { - ch(pairName, new ModelPartForStruct<typename T::value_type>(pair), NULL); + for (auto & pair : *this->Model) { + ch(pairName, new ModelPartForStruct<typename T::value_type>(&pair), NULL); } } diff --git a/slicer/test/conversions.cpp b/slicer/test/conversions.cpp index 63de1de..3df53b3 100644 --- a/slicer/test/conversions.cpp +++ b/slicer/test/conversions.cpp @@ -108,7 +108,7 @@ namespace Slicer { namespace TestModule { int completions = 0; - AbValidator::AbValidator(ClassTypePtr & m) : + AbValidator::AbValidator(ClassTypePtr * m) : Slicer::ModelPartForClass<ClassType>(m) { } @@ -116,7 +116,8 @@ namespace TestModule { void AbValidator::Complete() { - if (this->Model->a == 0 || this->Model->b == 0) { + const auto & M = *this->Model; + if (M->a == 0 || M->b == 0) { // LCOV_EXCL_START throw std::runtime_error("Mock error"); // LCOV_EXCL_STOP @@ -125,7 +126,7 @@ namespace TestModule { completions += 1; } - MonthValidator::MonthValidator(::Ice::Short & m) : + MonthValidator::MonthValidator(::Ice::Short * m) : Slicer::ModelPartForSimple<::Ice::Short>(m) { } @@ -133,7 +134,8 @@ namespace TestModule { void MonthValidator::Complete() { - if (this->Model < 1 || this->Model > 12) { + const auto & M = *this->Model; + if (M < 1 || M > 12) { // LCOV_EXCL_START throw std::runtime_error("This date smells fishy."); // LCOV_EXCL_STOP diff --git a/slicer/test/conversions.h b/slicer/test/conversions.h index 62a9c4b..76dcd97 100644 --- a/slicer/test/conversions.h +++ b/slicer/test/conversions.h @@ -11,14 +11,14 @@ namespace TestModule { class DLL_PUBLIC AbValidator : public Slicer::ModelPartForClass<ClassType> { public: - AbValidator(ClassTypePtr &); + AbValidator(ClassTypePtr *); void Complete() override; }; class DLL_PUBLIC MonthValidator : public Slicer::ModelPartForSimple<::Ice::Short> { public: - MonthValidator(::Ice::Short &); + MonthValidator(::Ice::Short *); void Complete() override; }; diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 5302044..43feace 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -60,7 +60,7 @@ namespace Slicer { fprintbf(cpp, "\t\t%s tmp;\n", conversion.ExchangeType); fprintbf(cpp, "\t\tvspt->set(tmp);\n"); - fprintbf(cpp, "\t\tModel = %s(tmp);\n", + fprintbf(cpp, "\t\t*Model = %s(tmp);\n", conversion.ConvertToModelFunc); fprintbf(cpp, "\t\treturn;\n"); fprintbf(cpp, "\t}\n"); @@ -69,7 +69,7 @@ namespace Slicer { if (!dm->hasMetaData("slicer:nodefaultconversion")) { fprintbf(cpp, "\tif (auto vspt = dynamic_cast<TValueSource< %s > *>(vsp.get())) {\n", Slice::typeToString(type)); - fprintbf(cpp, "\t\tvspt->set(Model);\n"); + fprintbf(cpp, "\t\tvspt->set(*Model);\n"); fprintbf(cpp, "\t\treturn;\n"); fprintbf(cpp, "\t}\n"); } @@ -85,7 +85,7 @@ namespace Slicer { for (const auto & conversion : conversions) { fprintbf(cpp, "\tif (auto vtpt = dynamic_cast<TValueTarget< %s > *>(vtp.get())) {\n", conversion.ExchangeType); - fprintbf(cpp, "\t\tvtpt->get(%s(Model));\n", + fprintbf(cpp, "\t\tvtpt->get(%s(*Model));\n", conversion.ConvertToExchangeFunc); fprintbf(cpp, "\t\treturn;\n"); fprintbf(cpp, "\t}\n"); @@ -94,7 +94,7 @@ namespace Slicer { if (!dm->hasMetaData("slicer:nodefaultconversion")) { fprintbf(cpp, "\tif (auto vtpt = dynamic_cast<TValueTarget< %s > *>(vtp.get())) {\n", Slice::typeToString(type)); - fprintbf(cpp, "\t\tvtpt->get(Model);\n"); + fprintbf(cpp, "\t\tvtpt->get(*Model);\n"); fprintbf(cpp, "\t\treturn;\n"); fprintbf(cpp, "\t}\n"); } @@ -330,11 +330,11 @@ namespace Slicer { fprintbf(cpp, "template<> DLL_PUBLIC\nvoid ModelPartForEnum< %s >::SetValue(ValueSourcePtr s) {\n\ std::string val;\n\ s->set(val);\n\ - this->Model = lookup(val);\n\ + *this->Model = lookup(val);\n\ }\n\n", e->scoped()); fprintbf(cpp, "template<> DLL_PUBLIC\nvoid ModelPartForEnum< %s >::GetValue(ValueTargetPtr s) {\n\ - s->get(lookup(this->Model));\n\ + s->get(lookup(*this->Model));\n\ }\n\n", e->scoped()); |