diff --git a/src/common/database.cpp b/src/common/database.cpp index 33cf6920c1..24be5c5ace 100644 --- a/src/common/database.cpp +++ b/src/common/database.cpp @@ -237,6 +237,34 @@ bool YamlDatabase::asString(const YAML::Node &node, const std::string &name, std return asType(node, name, out); } +bool YamlDatabase::asUInt16Rate( const YAML::Node& node, const std::string& name, uint16& out, uint16 maximum ){ + if( this->asUInt16( node, name, out ) ){ + if( out > maximum ){ + this->invalidWarning( node[name], "Node \"%s\" with value %" PRIu16 " exceeds maximum of %" PRIu16 ".\n", name.c_str(), out, maximum ); + + return false; + }else{ + return true; + } + }else{ + return false; + } +} + +bool YamlDatabase::asUInt32Rate( const YAML::Node& node, const std::string& name, uint32& out, uint32 maximum ){ + if( this->asUInt32( node, name, out ) ){ + if( out > maximum ){ + this->invalidWarning( node[name], "Node \"%s\" with value %" PRIu32 " exceeds maximum of %" PRIu32 ".\n", name.c_str(), out, maximum ); + + return false; + }else{ + return true; + } + }else{ + return false; + } +} + void YamlDatabase::invalidWarning( const YAML::Node &node, const char* fmt, ... ){ va_list ap; diff --git a/src/common/database.hpp b/src/common/database.hpp index 76a402609d..db13f00b47 100644 --- a/src/common/database.hpp +++ b/src/common/database.hpp @@ -46,6 +46,8 @@ protected: bool asFloat(const YAML::Node &node, const std::string &name, float &out); bool asDouble(const YAML::Node &node, const std::string &name, double &out); bool asString(const YAML::Node &node, const std::string &name, std::string &out); + bool asUInt16Rate(const YAML::Node& node, const std::string& name, uint16& out, uint16 maximum=10000); + bool asUInt32Rate(const YAML::Node& node, const std::string& name, uint32& out, uint32 maximum=10000); public: YamlDatabase( const std::string type_, uint16 version_, uint16 minimumVersion_ ){