SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
NotRequirement.h
1 
26 #pragma once
27 
28 #include "Requirement.h"
29 #include "RequirementLoader.h"
30 
31 namespace Json
32 {
34 
37  class NotRequirement : public Requirement
38  {
39  private:
40  std::unique_ptr<Requirement> req_;
41 
42  public:
44  NotRequirement() : req_(nullptr) {}
45 
47  virtual void ClearErrors() override
48  {
49  if(req_)
50  req_->ClearErrors();
51 
53  }
54 
56  virtual void ClearNotices() override
57  {
58  if(req_ != nullptr)
59  req_->ClearNotices();
60 
62  }
63 
65  virtual void Reset() override
66  {
67  ClearErrors();
68  ClearNotices();
69 
70  req_.reset();
71  }
72 
74 
78  virtual void Parse(Value json, const std::string& path) override
79  {
80  Reset();
81  RequirementLoader loader;
82 
83  auto& head = json.isMember("not") ? json["not"] : json;
84  if((req_ = loader.LoadRequirement(head)))
85  req_->Parse(head, path);
86  }
87 
89 
97  virtual void Validate(const Value& json, const std::string& path) override
98  {
99  req_->Validate(json, path);
100  if(!req_->HasErrors())
101  PushError(path + ": Value must not validate against requirement.");
102  }
103  };
104 }
Requires a given Requirement to fail.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value and generate Requirement to be negated.
virtual void Reset() override
Reset Requirement.
NotRequirement()
Constructor.
virtual void Validate(const Value &json, const std::string &path) override
Validate that JSON value fails the given Requirement.
virtual void ClearNotices() override
Clear list of notices.
std::unique_ptr< Requirement > req_
Requirement to negate.
virtual void ClearErrors() override
Clear list of error messages.
Helper class to load Requirement.
std::unique_ptr< Requirement > LoadRequirement(const Value &json)
Load specific 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