CASM  1.1.0
A Clusters Approach to Statistical Mechanics
CompositionAxes_file_io.cc
Go to the documentation of this file.
2 
7 
8 namespace CASM {
9 
11  try {
12  jsonParser json{_filename};
13  return json.get<CompositionAxes>();
14 
15  } catch (...) {
16  std::cerr << "Error reading composition axes from " << _filename
17  << std::endl;
18  throw;
19  }
20 }
21 
23 void write_composition_axes(fs::path _filename,
24  CompositionAxes const& composition_axes) {
25  SafeOfstream outfile;
26  outfile.open(_filename);
27  jsonParser json;
28  to_json(composition_axes, json);
29  json.print(outfile.ofstream());
30  outfile.close();
31 }
32 
33 } // namespace CASM
Write to a temporary file to ensure a good write, then rename.
Definition: SafeOfstream.hh:31
void close()
Closes stream, and if not a failed write, removes "file" and renames "file.tmp" to "file".
Definition: SafeOfstream.hh:84
void open(fs::path name, std::string tmp_ext="tmp")
Opens "file.tmp" for writing, with intended final target "file".
Definition: SafeOfstream.hh:65
fs::ofstream & ofstream()
Access underlying stream.
Definition: SafeOfstream.hh:80
void print(std::ostream &stream, unsigned int indent=2, unsigned int prec=12) const
Print json to stream.
Definition: jsonParser.cc:188
T get(Args &&... args) const
Get data from json, using one of several alternatives.
Definition: jsonParser.hh:716
Main CASM namespace.
Definition: APICommand.hh:8
jsonParser & to_json(const ClexDescription &desc, jsonParser &json)
void write_composition_axes(fs::path _filename, CompositionAxes const &composition_axes)
Write CompositionAxes to file.
CompositionAxes read_composition_axes(fs::path _filename)