Mercurial > hg > orthanc
diff Core/WebServiceParameters.cpp @ 3444:6fe42a335a80
WebServiceParameters::GetBooleanUserProperty()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 24 Jun 2019 17:15:03 +0200 |
parents | 595bfee4391a |
children | 94f4a18a79cc |
line wrap: on
line diff
--- a/Core/WebServiceParameters.cpp Mon Jun 24 16:55:28 2019 +0200 +++ b/Core/WebServiceParameters.cpp Mon Jun 24 17:15:03 2019 +0200 @@ -289,13 +289,22 @@ { if (!IsReservedKey(*it)) { - if (peer[*it].type() != Json::stringValue) + switch (peer[*it].type()) { - throw OrthancException(ErrorCode_BadFileFormat); - } - else - { - userProperties_[*it] = peer[*it].asString(); + case Json::stringValue: + userProperties_[*it] = peer[*it].asString(); + break; + + case Json::booleanValue: + userProperties_[*it] = peer[*it].asBool() ? "1" : "0"; + break; + + case Json::intValue: + userProperties_[*it] = boost::lexical_cast<std::string>(peer[*it].asInt()); + break; + + default: + throw OrthancException(ErrorCode_BadFileFormat); } } } @@ -402,6 +411,33 @@ return true; } } + + + bool WebServiceParameters::GetBooleanUserProperty(const std::string& key, + bool defaultValue) const + { + Dictionary::const_iterator found = userProperties_.find(key); + + if (found == userProperties_.end()) + { + return defaultValue; + } + else if (found->second == "0" || + found->second == "false") + { + return false; + } + else if (found->second == "1" || + found->second == "true") + { + return true; + } + else + { + throw OrthancException(ErrorCode_BadFileFormat, "Bad value for a Boolean user property in the parameters " + "of a Web service: Property \"" + key + "\" equals: " + found->second); + } + } bool WebServiceParameters::IsAdvancedFormatNeeded() const