Mercurial > hg > orthanc
diff OrthancFramework/Sources/SerializationToolbox.cpp @ 5379:b31c73bc7cb6
Toolbox : more set functions
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 31 Aug 2023 15:20:41 +0200 |
parents | f783b99e4738 |
children | 97004471a5c5 |
line wrap: on
line diff
--- a/OrthancFramework/Sources/SerializationToolbox.cpp Thu Aug 24 16:35:55 2023 +0200 +++ b/OrthancFramework/Sources/SerializationToolbox.cpp Thu Aug 31 15:20:41 2023 +0200 @@ -178,23 +178,44 @@ value[field.c_str()].type() != Json::arrayValue) { throw OrthancException(ErrorCode_BadFileFormat, - "List of strings expected in field: " + field); + "List of strings expected in field: " + field); } const Json::Value& arr = value[field.c_str()]; - target.resize(arr.size()); + try + { + ReadArrayOfStrings(target, arr); + } + catch (OrthancException& ex) + { // more detailed error + throw OrthancException(ErrorCode_BadFileFormat, + "List of strings expected in field: " + field); + } + } + - for (Json::Value::ArrayIndex i = 0; i < arr.size(); i++) + void SerializationToolbox::ReadArrayOfStrings(std::vector<std::string>& target, + const Json::Value& array) + { + if (array.type() != Json::arrayValue) { - if (arr[i].type() != Json::stringValue) + throw OrthancException(ErrorCode_BadFileFormat, + "List of strings expected"); + } + + target.resize(array.size()); + + for (Json::Value::ArrayIndex i = 0; i < array.size(); i++) + { + if (array[i].type() != Json::stringValue) { throw OrthancException(ErrorCode_BadFileFormat, - "List of strings expected in field: " + field); + "List of strings expected"); } else { - target[i] = arr[i].asString(); + target[i] = array[i].asString(); } } } @@ -230,6 +251,20 @@ } + void SerializationToolbox::ReadSetOfStrings(std::set<std::string>& target, + const Json::Value& value) + { + std::vector<std::string> tmp; + ReadArrayOfStrings(tmp, value); + + target.clear(); + for (size_t i = 0; i < tmp.size(); i++) + { + target.insert(tmp[i]); + } + } + + void SerializationToolbox::ReadSetOfTags(std::set<DicomTag>& target, const Json::Value& value, const std::string& field)