diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-06 23:21:58 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-06 23:21:58 +0000 |
commit | e378a97a6cf8069933bf80e4c2445030435692dd (patch) | |
tree | 9e2d5c6535166d3062e2bce6af50237c342fb2e6 | |
parent | Add missing support for optional roots in user types (diff) | |
download | slicer-e378a97a6cf8069933bf80e4c2445030435692dd.tar.bz2 slicer-e378a97a6cf8069933bf80e4c2445030435692dd.tar.xz slicer-e378a97a6cf8069933bf80e4c2445030435692dd.zip |
Improve support for optional types
-rw-r--r-- | slicer/slicer/modelParts.cpp | 6 | ||||
-rw-r--r-- | 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<std::string>::rootName = "String"; template<> DLL_PUBLIC std::string Slicer::ModelPartForRoot<bool>::rootName = "Boolean"; template<> DLL_PUBLIC std::string Slicer::ModelPartForRoot<Ice::Float>::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; |