SSAGES  0.8.3
Software Suite for Advanced General Ensemble Simulations
AnyOfRequirement.h
1 
26 #pragma once
27 
28 #include "Requirement.h"
29 #include "RequirementLoader.h"
30 
31 namespace Json
32 {
34 
38  {
39  private:
41 
42  public:
44  AnyOfRequirement() : reqs_(0) {}
45 
47  virtual void ClearErrors() override
48  {
49  for(auto& r : reqs_)
50  r->ClearErrors();
51 
53  }
54 
56  virtual void ClearNotices() override
57  {
58  for(auto& r : reqs_)
59  r->ClearNotices();
60 
62  }
63 
65  virtual void Reset() override
66  {
67  ClearErrors();
68  ClearNotices();
69  reqs_.clear();
70  }
71 
73 
81  virtual void Parse(Value json, const std::string& path) override
82  {
83  Reset();
84  RequirementLoader loader;
85 
86  auto& head = json.isMember("anyOf") ? json["anyOf"] : json;
87 
88  for(auto& val : head)
89  if(auto req = loader.LoadRequirement(val))
90  {
91  reqs_.push_back(std::move(req));
92  reqs_.back()->Parse(val, path);
93  }
94 
95  }
96 
98 
102  virtual void Validate(const Value& json, const std::string& path) override
103  {
104  for(auto& r : reqs_)
105  {
106  r->Validate(json, path);
107  if(!r->HasErrors())
108  return;
109  }
110 
111  // Collect errors.
112  for(auto& r : reqs_)
113  {
114  if(r->HasErrors())
115  for(const auto& error : r->GetErrors())
116  PushError(error);
117 
118  if(r->HasNotices())
119  for(const auto& notice : r->GetNotices())
120  PushNotice(notice);
121  }
122  }
123  };
124 }
virtual void Reset() override
Reset all Requirements.
RequireList reqs_
List of Requirements.
virtual void ClearErrors() override
Clear list of error messages for all Requirements.
AnyOfRequirement()
Constructor.
void PushError(const std::string &error)
Add error to list of error messages.
Definition: Requirement.h:53
Requires that at least one of a list of Requirements hold.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value and create list of Requirements.
virtual void ClearErrors()
Clear list of error messages.
Definition: Requirement.h:95
std::unique_ptr< Requirement > LoadRequirement(const Value &json)
Load specific requirement.
virtual void Validate(const Value &json, const std::string &path) override
Validate that at least one Requirement holds.
virtual void ClearNotices() override
Clear list of notices for all Requirements.
Helper class to load Requirement.
virtual void ClearNotices()
Clear list of notice messages.
Definition: Requirement.h:110
Requirements on input files.
Definition: Requirement.h:39
std::vector< std::unique_ptr< Requirement > > RequireList
List of Requirements.
Definition: Requirement.h:117
void PushNotice(const std::string &notice)
Add message to list of notices.
Definition: Requirement.h:62