SSAGES  0.8.3
Software Suite for Advanced General Ensemble Simulations
DependencyRequirement.h
1 
26 #pragma once
27 
28 #include "Requirement.h"
29 
30 namespace Json
31 {
33 
37  {
38  private:
40  std::map<std::string, std::vector<std::string>> deps_;
41 
42  public:
44  DependencyRequirement() : deps_() {}
45 
47 
50  virtual void Reset() override
51  {
52  deps_.clear();
53  ClearErrors();
54  ClearNotices();
55  }
56 
58 
61  virtual void Parse(Value json, const std::string&) override
62  {
63  Reset();
64 
65  auto names = json.getMemberNames();
66  int i = 0;
67  for(auto& value : json)
68  {
69  if(value.isArray())
70  {
71  deps_[names[i]] = {};
72  for(auto& dep : value)
73  {
74  deps_[names[i]].push_back(dep.asString());
75  }
76  }
77  ++i;
78  }
79  }
80 
82 
86  virtual void Validate(const Value& json, const std::string& path) override
87  {
88  if(!json.isObject())
89  {
90  PushError(path + ": Dependency specified for non-object");
91  return;
92  }
93 
94  for(auto& dep : deps_)
95  {
96  auto& name = dep.first;
97  if(json.isMember(name))
98  for(const auto& val : dep.second)
99  if(!json.isMember(val))
100  PushError(path + ": \"" + name + "\" depends on \"" + val + "\"");
101  }
102  }
103 
106  };
107 }
void PushError(const std::string &error)
Add error to list of error messages.
Definition: Requirement.h:53
virtual void Reset() override
Reset Requirement.
Requires dependencies to be met.
virtual void Validate(const Value &json, const std::string &path) override
Validate that Requirement is met.
virtual void ClearErrors()
Clear list of error messages.
Definition: Requirement.h:95
virtual void Parse(Value json, const std::string &) override
Parse JSON input value.
std::map< std::string, std::vector< std::string > > deps_
Set of dependencies.
virtual void ClearNotices()
Clear list of notice messages.
Definition: Requirement.h:110
Requirements on input files.
Definition: Requirement.h:39