13 namespace CubicLibrary {
18 std::map<std::string, CubicsValues> fluid_map;
19 std::map<std::string, std::string> aliases_map;
21 std::map<std::string, std::string> JSONstring_map;
33 for (rapidjson::Value::ValueIterator itr = listing.Begin(); itr != listing.End(); ++itr) {
42 if (itr->HasMember(
"rhomolarc") && (*itr)[
"rhomolarc"].IsNumber()) {
45 if (itr->HasMember(
"alpha") && (*itr)[
"alpha"].IsObject()) {
46 rapidjson::Value& alpha = (*itr)[
"alpha"];
52 if (itr->HasMember(
"alpha0") && (*itr)[
"alpha0"].IsArray()) {
55 std::pair<std::map<std::string, CubicsValues>::iterator,
bool> ret;
56 ret = fluid_map.insert(std::pair<std::string, CubicsValues>(
upper(val.
name), val));
59 fluid_map.erase(ret.first);
60 ret = fluid_map.insert(std::pair<std::string, CubicsValues>(
upper(val.
name), val));
62 std::cout <<
"added the cubic fluid: " + val.
name << std::endl;
64 assert(ret.second ==
true);
67 for (std::vector<std::string>::const_iterator it = val.
aliases.begin(); it != val.
aliases.end(); ++it) {
68 if (aliases_map.find(*it) == aliases_map.end()) {
70 aliases_map.insert(std::pair<std::string, std::string>(*it,
upper(val.
name)));
76 std::pair<std::map<std::string, std::string>::iterator,
bool> addJson;
80 JSONstring_map.erase(addJson.first);
83 std::cout <<
"added the cubic fluid: " + val.
name << std::endl;
85 assert(addJson.second ==
true);
94 std::string uppercase_identifier =
upper(key);
96 std::map<std::string, std::string>::iterator it = JSONstring_map.find(uppercase_identifier);
98 if (it == JSONstring_map.end()) {
99 std::map<std::string, std::string>::iterator italias = aliases_map.find(uppercase_identifier);
100 if (italias != aliases_map.end()) {
102 it = JSONstring_map.find(italias->second);
104 throw ValueError(
format(
"Fluid identifier [%s] was not found in CubicsLibrary", uppercase_identifier.c_str()));
108 rapidjson::Document doc;
110 rapidjson::Document doc2;
112 doc2.PushBack(doc, doc.GetAllocator());
117 std::string uppercase_identifier =
upper(identifier);
119 std::map<std::string, CubicsValues>::iterator it = fluid_map.find(uppercase_identifier);
121 if (it != fluid_map.end()) {
124 std::map<std::string, std::string>::iterator italias = aliases_map.find(uppercase_identifier);
125 if (italias != aliases_map.end()) {
127 return fluid_map.find(italias->second)->second;
129 throw ValueError(
format(
"Fluid identifier [%s] was not found in CubicsLibrary", uppercase_identifier.c_str()));
134 std::vector<std::string> out;
135 for (std::map<std::string, CubicsValues>::const_iterator it = fluid_map.begin(); it != fluid_map.end(); ++it) {
136 out.push_back(it->first);
141 static CubicsLibraryClass library;
149 rapidjson::Document dd;
151 dd.Parse<0>(JSON.c_str());
152 if (dd.HasParseError()) {
153 throw ValueError(
"Cubics JSON is not valid JSON");
157 }
catch (std::exception& e) {
158 throw ValueError(
format(
"Unable to load cubics library with error: %s", errstr.c_str()));
162 throw ValueError(
format(
"Unable to validate cubics library against schema with error: %s", errstr.c_str()));
170 return library.
get(identifier);