PotentialType const* parse_potential_description(std::string const& str) { name_parameters_pair p; try { p = parse_parameter_string(str); } catch (ParseError& e) { std::cerr << e.what() << std::endl; throw InvalidPotentialType(str); } std::string const& name = p.first; std::vector<double> const& params = p.second; // Simply delegate to the individual constructors based on name // Unfortunately we cannot use switch-case here, since we are dealing with // strings if (name == "zero") return new ZeroPotential(params); if (name == "harmonic") return new HarmonicPotential(params); if (name == "prettyhardsquare") return new PrettyHardSquare(params); if (name == "softpentagon") return new SoftPentagon(params); if (name == "henonheiles" or name == "henon") return new HenonHeiles(params); if (name == "gaussian" or name == "gaussianblob") return new Gaussian(params); else throw UnknownPotentialType(str); return NULL; }
Constraint const* parse_constraint_description(std::string const& str) { // Parse with the generic parse_parameter_string function and extract the // name and parameters. name_parameters_pair p; try { p = parse_parameter_string(str); } catch (ParseError& e) { std::cerr << e.what() << std::endl; throw UnknownConstraintType(str); } return parse_constraint_description(p); }