SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
IntegerRequirement.h
1 
26 #pragma once
27 
28 #include "Requirement.h"
29 
30 namespace Json
31 {
33 
39  {
40  private:
41  std::string path_;
43  int min_;
44  int max_;
45  bool multSet_;
46  bool minSet_;
47  bool maxSet_;
48  bool exclMin_;
49  bool exclMax_;
50 
51  public:
54  path_(), multipleOf_(0), min_(0), max_(0), multSet_(false),
55  minSet_(false), maxSet_(false), exclMin_(false), exclMax_(false)
56  {}
57 
59  virtual void Reset() override
60  {
61  multipleOf_ = 0;
62  minSet_ = maxSet_ = false;
63  exclMin_ = exclMax_ = false;
64  min_ = max_ = 0;
65  multSet_ = false;
66  ClearErrors();
67  ClearNotices();
68  }
69 
71 
75  virtual void Parse(Value json, const std::string& path) override
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  }
108 
110 
118  virtual void Validate(const Value& json, const std::string& path) override
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  }
145  };
146 }
Requirements on Integer values.
bool exclMin_
If True lower bound is exclusive.
bool maxSet_
If True upper bound is an active requirement.
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.
bool exclMax_
If True upper bound is exclusive.
virtual void Reset() override
Reset requirement.
int min_
Lower bound for range requirement.
bool multSet_
If True multiple of is a requirement.
bool minSet_
If True lower bound is an active requirement.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to set up Requirement.
int max_
Upper bound for range requirement.
std::string path_
Path for JSON path specification.
int multipleOf_
Multiple of requirement.
Requirements on input files.
Definition: Requirement.h:40
virtual void ClearNotices()
Clear list of notice messages.
Definition: Requirement.h:110
virtual void ClearErrors()
Clear list of error messages.
Definition: Requirement.h:95
void PushError(const std::string &error)
Add error to list of error messages.
Definition: Requirement.h:53