Mercurial > hg > orthanc
changeset 6634:ab12547ac3df default
added OrthancConfiguration::LookupIntegerParameter() and OrthancConfiguration::LookupUnsignedIntegerParameter()
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Fri, 20 Mar 2026 17:05:49 +0100 |
| parents | b8e78ccac532 |
| children | 2c137c796946 |
| files | OrthancServer/Sources/OrthancConfiguration.cpp OrthancServer/Sources/OrthancConfiguration.h |
| diffstat | 2 files changed, 56 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/OrthancConfiguration.cpp Fri Mar 20 09:32:16 2026 +0100 +++ b/OrthancServer/Sources/OrthancConfiguration.cpp Fri Mar 20 17:05:49 2026 +0100 @@ -504,8 +504,8 @@ } - int OrthancConfiguration::GetIntegerParameter(const std::string& parameter, - int defaultValue) const + bool OrthancConfiguration::LookupIntegerParameter(int& target, + const std::string& parameter) const { if (json_.isMember(parameter)) { @@ -516,30 +516,67 @@ } else { - return json_[parameter].asInt(); + target = json_[parameter].asInt(); + return true; } } else { + return false; + } + } + + + int OrthancConfiguration::GetIntegerParameter(const std::string& parameter, + int defaultValue) const + { + int v; + if (LookupIntegerParameter(v, parameter)) + { + return v; + } + else + { return defaultValue; } } - unsigned int OrthancConfiguration::GetUnsignedIntegerParameter( - const std::string& parameter, - unsigned int defaultValue) const + bool OrthancConfiguration::LookupUnsignedIntegerParameter(unsigned int& target, + const std::string& parameter) const { - int v = GetIntegerParameter(parameter, defaultValue); - - if (v < 0) + int v; + if (LookupIntegerParameter(v, parameter)) { - throw OrthancException(ErrorCode_ParameterOutOfRange, - "The configuration option \"" + parameter + "\" must be a positive integer"); + if (v < 0) + { + throw OrthancException(ErrorCode_ParameterOutOfRange, + "The configuration option \"" + parameter + "\" must be a positive integer"); + } + else + { + target = static_cast<unsigned int>(v); + return true; + } } else { - return static_cast<unsigned int>(v); + return false; + } + } + + + unsigned int OrthancConfiguration::GetUnsignedIntegerParameter(const std::string& parameter, + unsigned int defaultValue) const + { + unsigned int v; + if (LookupUnsignedIntegerParameter(v, parameter)) + { + return v; + } + else + { + return defaultValue; } }
--- a/OrthancServer/Sources/OrthancConfiguration.h Fri Mar 20 09:32:16 2026 +0100 +++ b/OrthancServer/Sources/OrthancConfiguration.h Fri Mar 20 17:05:49 2026 +0100 @@ -182,9 +182,15 @@ std::string GetStringParameter(const std::string& parameter, const std::string& defaultValue) const; + bool LookupIntegerParameter(int& target, + const std::string& parameter) const; + int GetIntegerParameter(const std::string& parameter, int defaultValue) const; - + + bool LookupUnsignedIntegerParameter(unsigned int& target, + const std::string& parameter) const; + unsigned int GetUnsignedIntegerParameter(const std::string& parameter, unsigned int defaultValue) const;
