SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
RequirementLoader.cpp
1 
26 #include "RequirementLoader.h"
27 #include "StringRequirement.h"
28 #include "IntegerRequirement.h"
29 #include "NumberRequirement.h"
30 #include "ObjectRequirement.h"
31 #include "ArrayRequirement.h"
32 #include "BooleanRequirement.h"
33 #include "NullRequirement.h"
34 #include "EnumRequirement.h"
35 #include "AllOfRequirement.h"
36 #include "AnyOfRequirement.h"
37 #include "OneOfRequirement.h"
38 #include "NotRequirement.h"
39 
40 namespace Json
41 {
42  std::unique_ptr<Requirement> RequirementLoader::LoadRequirement(const Value &json)
43  {
44  std::unique_ptr<Requirement> item = nullptr;
45  // Load up apitemriate requirement type.
46  if(json["type"].asString() == "string")
47  item = std::unique_ptr<Requirement>(new StringRequirement());
48  else if(json["type"].asString() == "integer")
49  item = std::unique_ptr<Requirement>(new IntegerRequirement());
50  else if(json["type"].asString() == "number")
51  item = std::unique_ptr<Requirement>(new NumberRequirement());
52  else if(json["type"].asString() == "object")
53  item = std::unique_ptr<Requirement>(new ObjectRequirement());
54  else if(json["type"].asString() == "array")
55  item = std::unique_ptr<Requirement>(new ArrayRequirement());
56  else if(json["type"].asString() == "boolean")
57  item = std::unique_ptr<Requirement>(new BooleanRequirement());
58  else if(json["type"].asString() == "null")
59  item = std::unique_ptr<Requirement>(new NullRequirement());
60  else if(json["allOf"].isArray())
61  item = std::unique_ptr<Requirement>(new AllOfRequirement());
62  else if(json["anyOf"].isArray())
63  item = std::unique_ptr<Requirement>(new AnyOfRequirement());
64  else if(json["oneOf"].isArray())
65  item = std::unique_ptr<Requirement>(new OneOfRequirement());
66  else if(json["enum"].isArray())
67  item = std::unique_ptr<Requirement>(new EnumRequirement());
68  else if(json["not"].isObject())
69  item = std::unique_ptr<Requirement>(new NotRequirement());
70  // last resort.
71  else if(json.isObject())
72  item = std::unique_ptr<Requirement>(new ObjectRequirement());
73 
74  return item;
75  }
76 
77  std::unique_ptr<Requirement> RequirementLoader::LoadExtended(const Value &json)
78  {
79  std::unique_ptr<Requirement> item = nullptr;
80  if(json.isObject() && json.isMember("allOf") && json["allOf"].isArray())
81  item = std::unique_ptr<Requirement>(new AllOfRequirement());
82  else if(json.isObject() && json.isMember("anyOf") && json["anyOf"].isArray())
83  item = std::unique_ptr<Requirement>(new AnyOfRequirement());
84  else if(json.isObject() && json.isMember("oneOf") && json["oneOf"].isArray())
85  item = std::unique_ptr<Requirement>(new OneOfRequirement());
86 
87  return item;
88  }
89 
90  std::unique_ptr<Requirement> RequirementLoader::LoadRequirement(const ValueType& type)
91  {
92  std::unique_ptr<Requirement> item = nullptr;
93 
94  switch(type)
95  {
96  case nullValue:
97  item = std::unique_ptr<Requirement>(new NullRequirement());
98  break;
99  case intValue:
100  item = std::unique_ptr<Requirement>(new IntegerRequirement());
101  break;
102  case realValue:
103  item = std::unique_ptr<Requirement>(new NumberRequirement());
104  break;
105  case stringValue:
106  item = std::unique_ptr<Requirement>(new StringRequirement());
107  break;
108  case booleanValue:
109  item = std::unique_ptr<Requirement>(new BooleanRequirement());
110  break;
111  case arrayValue:
112  item = std::unique_ptr<Requirement>(new ArrayRequirement());
113  break;
114  case objectValue:
115  item = std::unique_ptr<Requirement>(new ObjectRequirement());
116  break;
117  default:
118  item = nullptr;
119  }
120 
121  return item;
122  }
123 }
Requires that all of a list of Requirements hold.
Requires that at least one of a list of Requirements hold.
Array of Requirements.
Requires json value to be of type Bool.
Requires entry to be member of an enum.
Requirements on Integer values.
Requires a given Requirement to fail.
Requires value to be of type Null.
Requirements on a numeric value.
Requirements on an object.
Requires exactly one of a list of Requirements to hold.
std::unique_ptr< Requirement > LoadExtended(const Value &json)
Extended Requirement loader.
std::unique_ptr< Requirement > LoadRequirement(const Value &json)
Load specific requirement.
Requirements on strings.