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

Requirements on Integer values. More...

#include <IntegerRequirement.h>

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

Public Member Functions

 IntegerRequirement ()
 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_
 Path for JSON path specification.
 
int multipleOf_
 Multiple of requirement.
 
int min_
 Lower bound for range requirement.
 
int max_
 Upper bound for range requirement.
 
bool multSet_
 If True multiple of is a requirement.
 
bool minSet_
 If True lower bound is an active requirement.
 
bool maxSet_
 If True upper bound is an active requirement.
 
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 Integer values.

This class implements several types of integer requirements.

Definition at line 38 of file IntegerRequirement.h.

Member Function Documentation

virtual void Json::IntegerRequirement::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 75 of file IntegerRequirement.h.

References Reset().

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

Here is the call graph for this function:

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

Validate JSON value.

Parameters
jsonJSON value to be validated.
pathPath for JSON path specification.

Validates that the given JSON value is of type Integer and meets the requirements generated by IntegerRequirement::Parse(). If the requirements are not met, an error is generated.

Implements Json::Requirement.

Definition at line 118 of file IntegerRequirement.h.

References max_, min_, and Json::Requirement::PushError().

119  {
120  if(!json.isInt())
121  {
122  PushError(path + ": Must be of type \"integer\".");
123  return;
124  }
125 
126  if(multSet_ && (json.asInt() % multipleOf_ != 0))
127  PushError(path + ": Value must be a multiple of " + std::to_string(multipleOf_));
128 
129  if(minSet_)
130  {
131  if(exclMin_ && json.asInt() <= min_)
132  PushError(path + ": Value must be greater than " + std::to_string(min_));
133  else if(json.asInt() < min_)
134  PushError(path + ": Value cannot be less than " + std::to_string(min_));
135  }
136 
137  if(maxSet_)
138  {
139  if(exclMax_ && json.asInt() >= max_)
140  PushError(path + ": Value must be less than " + std::to_string(max_));
141  else if(json.asInt() > max_)
142  PushError(path + ": Value cannot be greater than " + std::to_string(max_));
143  }
144  }
bool maxSet_
If True upper bound is an active requirement.
bool exclMax_
If True upper bound is exclusive.
bool multSet_
If True multiple of is a requirement.
void PushError(const std::string &error)
Add error to list of error messages.
Definition: Requirement.h:53
bool minSet_
If True lower bound is an active requirement.
int max_
Upper bound for range requirement.
int multipleOf_
Multiple of requirement.
bool exclMin_
If True lower bound is exclusive.
int min_
Lower bound for range requirement.

Here is the call graph for this function:


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