21 #include "Constraint.h"
22 #include "json/json.h"
24 #include "../Drivers/DriverException.h"
25 #include "../Validator/ObjectRequirement.h"
26 #include "../Validator/ArrayRequirement.h"
28 #include "COPSSImage.h"
33 Constraint* Constraint::BuildConstraint(
const Json::Value &json,
34 boost::mpi::communicator& comm)
36 return BuildConstraint(json, comm,
"#/Constraints");
39 Constraint* Constraint::BuildConstraint(
const Json::Value &json,
40 boost::mpi::communicator& comm,
41 const std::string& path)
55 std::string type = json.get(
"type",
"none").asString();
59 reader.parse(JsonSchema::COPSSConstraint, schema);
60 validator.
Parse(schema, path);
67 auto* c =
new COPSS(comm, 1);
71 else if(type ==
"COPSSImage")
73 reader.parse(JsonSchema::COPSSImageConstraint, schema);
74 validator.
Parse(schema, path);
81 double einner = json.get(
"einner",1).asDouble();
83 int ion_type_start = json.get(
"ion_type_start",1).asInt();
85 std::vector<double> atomTypeRadius;
86 for(
auto& atomType : json[
"atom type radius"])
87 atomTypeRadius.push_back(atomType.asDouble());
89 auto* c =
new COPSSImage(comm, 1, einner, ion_type_start, atomTypeRadius);
96 throw BuildException({path +
": Unknown constraint type specified."+type+
" is not a valid type!"});
102 void Constraint::BuildConstraint(
const Json::Value &json,
104 boost::mpi::communicator& comm,
105 const std::string &path)
111 reader.parse(JsonSchema::constraints, schema);
112 validator.
Parse(schema, path);
123 clist.push_back(
BuildConstraint(m, comm, path +
"/" + std::to_string(i)));
bool HasErrors()
Check if errors have occured.
static void BuildConstraint(const Json::Value &json, ConstraintList &clist, boost::mpi::communicator &comm, const std::string &path)
Build constraint.
Wrapper class for COPSS simulations.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value to generate Requirement(s).
Exception to be thrown when building the Driver fails.
std::vector< std::string > GetErrors()
Get list of error messages.
Requirements on an object.
std::vector< Constraint * > ConstraintList
List of Constraints.
virtual void Validate(const Value &json, const std::string &path) override
Validate json value.
virtual void Parse(Value json, const std::string &path) override
Parse JSON value and fill array.
Interface for Constraint implementations.
virtual void Validate(const Value &json, const std::string &path) override
Validate JSON value.