Skip to content
Permalink
Browse files

Added unsigned rate support for yaml (#4442)

Added core functions to supported reading unsigned rates.
By default rates are values between 0 and 10000, if no other maximum is defined.
  • Loading branch information...
Lemongrass3110 committed Nov 4, 2019
1 parent f10fdf5 commit 159ce4e3cd833b34677692a0212eb8d907abaa69
Showing with 30 additions and 0 deletions.
  1. +28 −0 src/common/database.cpp
  2. +2 −0 src/common/database.hpp
@@ -237,6 +237,34 @@ bool YamlDatabase::asString(const YAML::Node &node, const std::string &name, std
return asType<std::string>(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;

@@ -46,6 +46,8 @@ class YamlDatabase{
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_ ){

0 comments on commit 159ce4e

Please sign in to comment.
You can’t perform that action at this time.