# HG changeset patch # User Sebastien Jodogne # Date 1774022991 -3600 # Node ID d0a3f15d2793f5b8bf5d851258085927ae30232e # Parent db756d9176cc3d8b735f6ed4fe1cb43ba9c5d6a7# Parent ab12547ac3df0610226430c3c2fd3ea8260cc192 integration mainline->machine-spirits diff -r db756d9176cc -r d0a3f15d2793 OrthancServer/Sources/OrthancConfiguration.cpp --- a/OrthancServer/Sources/OrthancConfiguration.cpp Fri Mar 20 16:19:01 2026 +0100 +++ b/OrthancServer/Sources/OrthancConfiguration.cpp Fri Mar 20 17:09:51 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(v); + return true; + } } else { - return static_cast(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; } } diff -r db756d9176cc -r d0a3f15d2793 OrthancServer/Sources/OrthancConfiguration.h --- a/OrthancServer/Sources/OrthancConfiguration.h Fri Mar 20 16:19:01 2026 +0100 +++ b/OrthancServer/Sources/OrthancConfiguration.h Fri Mar 20 17:09:51 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;