CASM  1.1.0
A Clusters Approach to Statistical Mechanics
CompositionAxes_json_io.cc
Go to the documentation of this file.
2 
6 
7 namespace CASM {
8 
9 void from_json(CompositionAxes &composition_axes, const jsonParser &json) {
10  composition_axes = CompositionAxes();
11 
12  json.get_if(composition_axes.all_axes, "possible_axes");
13 
14  json.get_if(composition_axes.enumerated, "enumerated");
15 
16  // Backward compatibility
17  std::map<std::string, CompositionConverter> custom;
18  json.get_if(custom, "custom_axes");
19  composition_axes.all_axes.insert(custom.begin(), custom.end());
20 
21  if (json.contains("standard_axes")) {
22  std::map<std::string, CompositionConverter> standard;
23  from_json(standard, json["standard_axes"]);
24  for (auto const &el : standard) {
25  composition_axes.enumerated.insert(el.first);
26  }
27  standard.insert(standard.begin(), standard.end());
28  }
29 
30  std::string key;
31  json.get_if(key, "current_axes");
32  if (!key.empty()) {
33  composition_axes.select(key);
34  }
35 }
36 
38 jsonParser &to_json(CompositionAxes const &composition_axes, jsonParser &json) {
39  json = jsonParser::object();
40 
41  if (composition_axes.has_current_axes()) {
42  json["current_axes"] = composition_axes.curr_key;
43  }
44 
45  json["possible_axes"] = composition_axes.all_axes;
46 
47  if (composition_axes.enumerated.size()) {
48  json["enumerated"] = composition_axes.enumerated;
49  }
50 
51  return json;
52 }
53 
54 } // namespace CASM
static jsonParser object()
Returns an empty json object.
Definition: jsonParser.hh:395
bool contains(const std::string &name) const
Return true if JSON object contains 'name'.
Definition: jsonParser.cc:601
bool get_if(T &t, const std::string &key, Args &&... args) const
Definition: jsonParser.hh:740
Main CASM namespace.
Definition: APICommand.hh:8
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
void from_json(ClexDescription &desc, const jsonParser &json)
bool has_current_axes() const
True if curr_key is set.
std::set< std::string > enumerated
void select(std::string key)
Set this->curr using key.
std::map< std::string, CompositionConverter > all_axes