diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-07-16 13:33:34 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2017-07-16 13:33:34 +0100 |
commit | d9072626f00098e89362e7a5ae0975a68d40107d (patch) | |
tree | 2f2a86ee0e1537e20b8d33b6a2d49ec83f9cd957 | |
parent | Switch ModelPartModel's internal model reference to pointer (breaking change ... (diff) | |
download | slicer-d9072626f00098e89362e7a5ae0975a68d40107d.tar.bz2 slicer-d9072626f00098e89362e7a5ae0975a68d40107d.tar.xz slicer-d9072626f00098e89362e7a5ae0975a68d40107d.zip |
Add assertions in places where the model pointer is required to valid
-rw-r--r-- | slicer/slicer/modelPartsTypes.impl.h | 25 | ||||
-rw-r--r-- | slicer/tool/parser.cpp | 2 |
2 files changed, 23 insertions, 4 deletions
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 6811de3..0ded2a2 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -140,12 +140,14 @@ namespace Slicer { template<typename T> void ModelPartForSimple<T>::SetValue(ValueSourcePtr s) { + BOOST_ASSERT(this->Model); s->set(*this->Model); } template<typename T> void ModelPartForSimple<T>::GetValue(ValueTargetPtr s) { + BOOST_ASSERT(this->Model); s->get(*this->Model); } @@ -161,6 +163,7 @@ namespace Slicer { ModelPartForOptional<T>::ModelPartForOptional(IceUtil::Optional< typename T::element_type > * h) : ModelPartModel<IceUtil::Optional< typename T::element_type> >(h) { + BOOST_ASSERT(this->Model); if (*this->Model) { modelPart = new T(&**this->Model); } @@ -169,12 +172,14 @@ namespace Slicer { template<typename T> bool ModelPartForOptional<T>::hasModel() const { + BOOST_ASSERT(this->Model); return *this->Model; } template<typename T> void ModelPartForOptional<T>::Create() { + BOOST_ASSERT(this->Model); if (!*this->Model) { *this->Model = typename T::element_type(); modelPart = new T(&**this->Model); @@ -185,6 +190,7 @@ namespace Slicer { template<typename T> void ModelPartForOptional<T>::GetValue(ValueTargetPtr s) { + BOOST_ASSERT(this->Model); if (!*this->Model) { *this->Model = typename T::element_type(); modelPart = new T(&**this->Model); @@ -245,24 +251,28 @@ namespace Slicer { template<typename T> void ModelPartForClass<T>::Create() { + BOOST_ASSERT(this->Model); *this->Model = new T(); } template<typename T> T * ModelPartForClass<T>::GetModel() { + BOOST_ASSERT(this->Model); return this->Model->get(); } template<typename T> ModelPartPtr ModelPartForClass<T>::GetSubclassModelPart(const std::string & name) { + BOOST_ASSERT(this->Model); return ModelPartForComplexBase::getSubclassModelPart(name, this->Model); } template<typename T> bool ModelPartForClass<T>::HasValue() const { + BOOST_ASSERT(this->Model); return *this->Model; } @@ -303,6 +313,7 @@ namespace Slicer { TypeId ModelPartForClass<T>::GetTypeId() const { + BOOST_ASSERT(this->Model); return ModelPartForComplexBase::GetTypeId((*this->Model)->ice_id(), *className); } @@ -316,6 +327,7 @@ namespace Slicer { template<typename T> T * ModelPartForStruct<T>::GetModel() { + BOOST_ASSERT(this->Model); return this->Model; } @@ -347,15 +359,17 @@ namespace Slicer { template<typename T> void ModelPartForSequence<T>::OnEachChild(const ChildHandler & ch) - { - for(auto & element : *this->Model) { - ch(elementName, elementModelPart(element), NULL); - } + { + BOOST_ASSERT(this->Model); + for(auto & element : *this->Model) { + ch(elementName, elementModelPart(element), NULL); } + } template<typename T> ChildRefPtr ModelPartForSequence<T>::GetAnonChildRef(const HookFilter &) { + BOOST_ASSERT(this->Model); this->Model->push_back(typename element_type::value_type()); return new ImplicitChildRef(ModelPart::CreateFor(this->Model->back())); } @@ -410,6 +424,7 @@ namespace Slicer { template<typename T> void ModelPartForDictionary<T>::OnEachChild(const ChildHandler & ch) { + BOOST_ASSERT(this->Model); for (auto & pair : *this->Model) { ch(pairName, new ModelPartForStruct<typename T::value_type>(&pair), NULL); } @@ -418,12 +433,14 @@ namespace Slicer { template<typename T> ChildRefPtr ModelPartForDictionary<T>::GetAnonChildRef(const HookFilter &) { + BOOST_ASSERT(this->Model); return new ImplicitChildRef(new ModelPartForDictionaryElementInserter<T>(this->Model)); } template<typename T> ChildRefPtr ModelPartForDictionary<T>::GetChildRef(const std::string & name, const HookFilter &) { + BOOST_ASSERT(this->Model); if (name != pairName) { throw IncorrectElementName(name); } diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 43feace..bc8c0ef 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -53,6 +53,7 @@ namespace Slicer { fprintbf(cpp, "template<> DLL_PUBLIC\nvoid\n"); createModelPartForConverted(type, c->scoped(), dm); fprintbf(cpp, "::SetValue(ValueSourcePtr vsp)\n{\n"); + fprintbf(cpp, "\tBOOST_ASSERT(Model);\n"); for (const auto & conversion : conversions) { fprintbf(cpp, "\tif (auto vspt = dynamic_cast<TValueSource< %s > *>(vsp.get())) {\n", @@ -81,6 +82,7 @@ namespace Slicer { fprintbf(cpp, "template<> DLL_PUBLIC\nvoid\n"); createModelPartForConverted(type, c->scoped(), dm); fprintbf(cpp, "::GetValue(ValueTargetPtr vtp)\n{\n"); + fprintbf(cpp, "\tBOOST_ASSERT(Model);\n"); for (const auto & conversion : conversions) { fprintbf(cpp, "\tif (auto vtpt = dynamic_cast<TValueTarget< %s > *>(vtp.get())) {\n", |