Mercurial > hg > orthanc
diff OrthancFramework/Sources/DicomFormat/DicomValue.cpp @ 5044:6fed78e13233
Refactored DicomMap to handle sequences when needed
author | Alain Mazy <am@osimis.io> |
---|---|
date | Tue, 28 Jun 2022 17:45:09 +0200 |
parents | 43e613a7756b |
children | 0ea402b4d901 |
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomFormat/DicomValue.cpp Mon Jun 27 15:22:19 2022 +0200 +++ b/OrthancFramework/Sources/DicomFormat/DicomValue.cpp Tue Jun 28 17:45:09 2022 +0200 @@ -40,7 +40,8 @@ DicomValue::DicomValue(const DicomValue& other) : type_(other.type_), - content_(other.content_) + content_(other.content_), + sequenceJson_(other.sequenceJson_) { } @@ -61,10 +62,15 @@ content_.assign(data, size); } + DicomValue::DicomValue(const Json::Value& value) : + type_(Type_SequenceAsJson), + sequenceJson_(value) + { + } const std::string& DicomValue::GetContent() const { - if (type_ == Type_Null) + if (type_ == Type_Null || type_ == Type_SequenceAsJson) { throw OrthancException(ErrorCode_BadParameterType); } @@ -74,6 +80,19 @@ } } + const Json::Value& DicomValue::GetSequenceContent() const + { + if (type_ != Type_SequenceAsJson) + { + throw OrthancException(ErrorCode_BadParameterType); + } + else + { + return sequenceJson_; + } + } + + bool DicomValue::IsNull() const { return type_ == Type_Null; @@ -84,6 +103,15 @@ return type_ == Type_Binary; } + bool DicomValue::IsString() const + { + return type_ == Type_String; + } + + bool DicomValue::IsSequence() const + { + return type_ == Type_SequenceAsJson; + } DicomValue* DicomValue::Clone() const { @@ -107,8 +135,7 @@ bool DicomValue::ParseInteger32(int32_t& result) const { - if (IsBinary() || - IsNull()) + if (!IsString()) { return false; } @@ -120,8 +147,7 @@ bool DicomValue::ParseInteger64(int64_t& result) const { - if (IsBinary() || - IsNull()) + if (!IsString()) { return false; } @@ -133,8 +159,7 @@ bool DicomValue::ParseUnsignedInteger32(uint32_t& result) const { - if (IsBinary() || - IsNull()) + if (!IsString()) { return false; } @@ -146,8 +171,7 @@ bool DicomValue::ParseUnsignedInteger64(uint64_t& result) const { - if (IsBinary() || - IsNull()) + if (!IsString()) { return false; } @@ -159,8 +183,7 @@ bool DicomValue::ParseFloat(float& result) const { - if (IsBinary() || - IsNull()) + if (!IsString()) { return false; } @@ -172,8 +195,7 @@ bool DicomValue::ParseDouble(double& result) const { - if (IsBinary() || - IsNull()) + if (!IsString()) { return false; } @@ -185,8 +207,7 @@ bool DicomValue::ParseFirstFloat(float& result) const { - if (IsBinary() || - IsNull()) + if (!IsString()) { return false; } @@ -200,8 +221,7 @@ { uint64_t value; - if (IsBinary() || - IsNull()) + if (!IsString()) { return false; } @@ -223,6 +243,10 @@ { return false; } + else if (IsSequence()) + { + return false; + } else if (IsBinary() && !allowBinary) { return false; @@ -263,6 +287,11 @@ break; } + case Type_SequenceAsJson: + { + throw OrthancException(ErrorCode_NotImplemented); + } + default: throw OrthancException(ErrorCode_InternalError); } @@ -289,6 +318,10 @@ const std::string base64 =SerializationToolbox::ReadString(source, KEY_CONTENT); Toolbox::DecodeBase64(content_, base64); } + else if (type == "Sequence") + { + throw OrthancException(ErrorCode_NotImplemented); + } else { throw OrthancException(ErrorCode_BadFileFormat);