SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
Public Member Functions | Private Attributes | List of all members
Json::NumberRequirement Class Reference

Requirements on a numeric value. More...

#include <NumberRequirement.h>

Inheritance diagram for Json::NumberRequirement:
Inheritance graph
[legend]

Public Member Functions

 NumberRequirement ()
 Constructor.
 
virtual void Reset () override
 Reset Requirement.
 
virtual void Parse (Value json, const std::string &path) override
 Parse JSON value to set up Requirement. More...
 
virtual void Validate (const Value &json, const std::string &path) override
 Validate JSON value. More...
 
- Public Member Functions inherited from Json::Requirement
bool HasErrors ()
 Check if errors have occured. More...
 
std::vector< std::string > GetErrors ()
 Get list of error messages. More...
 
virtual void ClearErrors ()
 Clear list of error messages.
 
virtual bool HasNotices ()
 Check if notices have been queued. More...
 
std::vector< std::string > GetNotices ()
 Get list of notices. More...
 
virtual void ClearNotices ()
 Clear list of notice messages.
 
virtual ~Requirement ()
 Destructor.
 

Private Attributes

std::string path_
 JSON path.
 
double multipleOf_
 Base value for "multiple of" requirement.
 
double min_
 Lower bound for range requirement.
 
double max_
 Upper bound for range requirement.
 
bool multSet_
 If True, "Multiple of" requirement is active.
 
bool minSet_
 If True, Lower bound for range requirement is active.
 
bool maxSet_
 If True, Upper bound for range requirement is active.
 
bool exclMin_
 If True, lower bound is exclusive.
 
bool exclMax_
 If True, upper bound is exclusive.
 

Additional Inherited Members

- Protected Member Functions inherited from Json::Requirement
void PushError (const std::string &error)
 Add error to list of error messages. More...
 
void PushNotice (const std::string &notice)
 Add message to list of notices. More...
 

Detailed Description

Requirements on a numeric value.

The numbers are stored internally as double.

Definition at line 39 of file NumberRequirement.h.

Member Function Documentation

◆ Parse()

virtual void Json::NumberRequirement::Parse ( Value  json,
const std::string &  path 
)
inlineoverridevirtual

Parse JSON value to set up Requirement.

Parameters
jsonJSON input value.
pathPath for JSON path specification.

Implements Json::Requirement.

Definition at line 77 of file NumberRequirement.h.

78  {
79  Reset();
80 
81  path_ = path;
82  if(json.isMember("multipleOf") && json["multipleOf"].isNumeric())
83  {
84  multSet_ = true;
85  multipleOf_ = json["multipleOf"].asDouble();
86  }
87 
88  if(json.isMember("minimum") && json["minimum"].isNumeric())
89  {
90  minSet_ = true;
91  min_ = json["minimum"].asDouble();
92  }
93 
94  if(json.isMember("maximum") && json["maximum"].isNumeric())
95  {
96  maxSet_ = true;
97  max_ = json["maximum"].asDouble();
98  }
99 
100  if(json.isMember("exclusiveMinimum") && json["exclusiveMinimum"].isBool())
101  {
102  exclMin_ = json["exclusiveMinimum"].asBool();
103  }
104 
105  if(json.isMember("exclusiveMaximum") && json["exclusiveMaximum"].isBool())
106  {
107  exclMax_ = json["exclusiveMaximum"].asBool();
108  }
109  }
double max_
Upper bound for range requirement.
bool exclMax_
If True, upper bound is exclusive.
bool exclMin_
If True, lower bound is exclusive.
double min_
Lower bound for range requirement.
bool multSet_
If True, "Multiple of" requirement is active.
bool maxSet_
If True, Upper bound for range requirement is active.
bool minSet_
If True, Lower bound for range requirement is active.
double multipleOf_
Base value for "multiple of" requirement.
virtual void Reset() override
Reset Requirement.
std::string path_
JSON path.

References exclMax_, exclMin_, max_, maxSet_, min_, minSet_, multipleOf_, multSet_, path_, and Reset().

Here is the call graph for this function:

◆ Validate()

virtual void Json::NumberRequirement::Validate ( const Value &  json,
const std::string &  path 
)
inlineoverridevirtual

Validate JSON value.

Parameters
jsonJSON value to validate.
pathPath for JSON path specification.

Test that the JSON value meets the requirements set via NumberRequirement::Parse(). If the validation fails, an error is added to the list of error messages.

Implements Json::Requirement.

Definition at line 120 of file NumberRequirement.h.

121  {
122  if(!json.isNumeric())
123  {
124  PushError(path + ": Must be of type \"number\".");
125  return;
126  }
127 
128  if(multSet_ && fmod(json.asDouble(), multipleOf_) != 0)
129  PushError(path + ": Value must be a multiple of " + std::to_string(multipleOf_));
130 
131  if(minSet_)
132  {
133  if(exclMin_ && json.asDouble() <= min_)
134  PushError(path + ": Value must be greater than " + std::to_string(min_));
135  else if(json.asDouble() < min_)
136  PushError(path + ": Value cannot be less than " + std::to_string(min_));
137  }
138 
139  if(maxSet_)
140  {
141  if(exclMax_ && json.asDouble() >= max_)
142  PushError(path + ": Value must be less than " + std::to_string(max_));
143  else if(json.asDouble() > max_)
144  PushError(path + ": Value cannot be greater than " + std::to_string(max_));
145  }
146  }
void PushError(const std::string &error)
Add error to list of error messages.
Definition: Requirement.h:53

References exclMax_, exclMin_, max_, maxSet_, min_, minSet_, multipleOf_, multSet_, and Json::Requirement::PushError().

Here is the call graph for this function:

The documentation for this class was generated from the following file: