From e378a97a6cf8069933bf80e4c2445030435692dd Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 6 Dec 2015 23:21:58 +0000 Subject: Improve support for optional types --- slicer/slicer/modelParts.cpp | 6 ++++++ slicer/slicer/modelParts.h | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp index 3c839e8..d0747e4 100644 --- a/slicer/slicer/modelParts.cpp +++ b/slicer/slicer/modelParts.cpp @@ -111,6 +111,12 @@ namespace Slicer { return ref ? ref->Child() : ModelPartPtr(NULL); } + bool + ModelPart::IsOptional() const + { + return false; + } + template<> DLL_PUBLIC std::string Slicer::ModelPartForRoot::rootName = "String"; template<> DLL_PUBLIC std::string Slicer::ModelPartForRoot::rootName = "Boolean"; template<> DLL_PUBLIC std::string Slicer::ModelPartForRoot::rootName = "Float"; diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 6903de6..863a72b 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -195,6 +195,7 @@ namespace Slicer { virtual void GetValue(ValueTargetPtr); virtual bool HasValue() const = 0; virtual const Metadata & GetMetadata() const; + virtual bool IsOptional() const; static const std::string & ToExchangeTypeName(const std::string &); static const std::string & ToModelTypeName(const std::string &); @@ -326,12 +327,15 @@ namespace Slicer { modelPart->GetValue(s); } - virtual bool HasValue() const override { return OptionalMember; } + virtual bool HasValue() const override { return OptionalMember && modelPart->HasValue(); } virtual ModelPartType GetType() const { return T::type; } + + virtual bool IsOptional() const override { return true; }; + virtual const Metadata & GetMetadata() const override { return modelPart->GetMetadata(); } private: @@ -544,13 +548,15 @@ namespace Slicer { return *ModelObject; } - virtual bool HasValue() const override { return ModelObject; } + virtual bool HasValue() const override { return ModelObject && mp->HasValue(); } virtual ModelPartType GetType() const override { return mp->GetType(); } + virtual bool IsOptional() const override { return mp->IsOptional(); } + private: T * ModelObject; bool owned; -- cgit v1.2.3