SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
Public Member Functions | Private Attributes | List of all members
Json::OneOfRequirement Class Reference

Requires exactly one of a list of Requirements to hold. More...

#include <OneOfRequirement.h>

Inheritance diagram for Json::OneOfRequirement:
Inheritance graph
[legend]

Public Member Functions

 OneOfRequirement ()
 Constructor.
 
virtual void ClearErrors () override
 Clear list of error messages for all Requirements.
 
virtual void ClearNotices () override
 Clear list of notices for all Requirements.
 
virtual void Reset () override
 Reset requirement.
 
virtual void Parse (Value json, const std::string &path) override
 Parse JSON value to generate Requirement. More...
 
virtual void Validate (const Value &json, const std::string &path) override
 Validate that only one of the Requirements hold. More...
 
- Public Member Functions inherited from Json::Requirement
bool HasErrors ()
 Check if errors have occured. More...
 
std::vector< std::string > GetErrors ()
 Get list of error messages. More...
 
virtual bool HasNotices ()
 Check if notices have been queued. More...
 
std::vector< std::string > GetNotices ()
 Get list of notices. More...
 
virtual ~Requirement ()
 Destructor.
 

Private Attributes

RequireList reqs_
 List of Requirements.
 

Additional Inherited Members

- Protected Member Functions inherited from Json::Requirement
void PushError (const std::string &error)
 Add error to list of error messages. More...
 
void PushNotice (const std::string &notice)
 Add message to list of notices. More...
 

Detailed Description

Requires exactly one of a list of Requirements to hold.

Definition at line 37 of file OneOfRequirement.h.

Member Function Documentation

◆ Parse()

virtual void Json::OneOfRequirement::Parse ( Value  json,
const std::string &  path 
)
inlineoverridevirtual

Parse JSON value to generate Requirement.

Parameters
jsonJSON input value.
pathPath for JSON path specification.

Implements Json::Requirement.

Definition at line 77 of file OneOfRequirement.h.

78  {
79  Reset();
80  RequirementLoader loader;
81 
82  auto& head = json.isMember("oneOf") ? json["oneOf"] : json;
83 
84  for(auto& val : head)
85  if(auto req = loader.LoadRequirement(val))
86  {
87  reqs_.push_back(std::move(req));
88  reqs_.back()->Parse(val, path);
89  }
90 
91  }
virtual void Reset() override
Reset requirement.
RequireList reqs_
List of Requirements.

References Json::RequirementLoader::LoadRequirement(), reqs_, and Reset().

Here is the call graph for this function:

◆ Validate()

virtual void Json::OneOfRequirement::Validate ( const Value &  json,
const std::string &  path 
)
inlineoverridevirtual

Validate that only one of the Requirements hold.

Parameters
jsonJSON value to be validated.
pathPath for JSON path specification.

Implements Json::Requirement.

Definition at line 98 of file OneOfRequirement.h.

99  {
100  int validated = 0;
101  for(auto& r : reqs_)
102  {
103  r->Validate(json, path);
104  if(!r->HasErrors())
105  ++validated;
106  }
107 
108  if(validated > 1)
109  PushError(path + ": Input must validate against only one schema");
110  else if(validated == 0)
111  for(auto& r : reqs_)
112  {
113  if(r->HasErrors())
114  for(const auto& error : r->GetErrors())
115  PushError(error);
116 
117  if(r->HasNotices())
118  for(const auto& notice : r->GetNotices())
119  PushNotice(notice);
120  }
121  }
void PushNotice(const std::string &notice)
Add message to list of notices.
Definition: Requirement.h:62
void PushError(const std::string &error)
Add error to list of error messages.
Definition: Requirement.h:53

References Json::Requirement::PushError(), Json::Requirement::PushNotice(), and reqs_.

Here is the call graph for this function:

The documentation for this class was generated from the following file: