SSAGES  0.9.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:
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 }
Requires that at least one of a list of Requirements hold.
RequireList reqs_
List of Requirements.
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.
virtual void Reset() override
Reset all Requirements.
virtual void ClearErrors() override
Clear list of error messages for all Requirements.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value and create list of Requirements.
AnyOfRequirement()
Constructor.
Helper class to load Requirement.
std::unique_ptr< Requirement > LoadRequirement(const Value &json)
Load specific requirement.
Requirements on input files.
Definition: Requirement.h:40
void PushNotice(const std::string &notice)
Add message to list of notices.
Definition: Requirement.h:62
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
std::vector< std::unique_ptr< Requirement > > RequireList
List of Requirements.
Definition: Requirement.h:117