CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
api.cc
Go to the documentation of this file.
1 #include "ccasm/api.hh"
2 #include <wordexp.h>
3 //#include "boost/iostreams/stream.hpp"
4 //#include "boost/iostreams/device/null.hpp"
5 #include "casm/casm_io/Log.hh"
6 #include "casm/clex/PrimClex.hh"
7 #include "casm/external/boost.hh"
9 
10 using namespace CASM;
11 
12 extern "C" {
13 
15  return reinterpret_cast<costream *>(&default_log());
16  }
17 
19  return reinterpret_cast<costream *>(&default_err_log());
20  }
21 
22 
24  return reinterpret_cast<costream *>(&null_log());
25  }
26 
27 
29  return reinterpret_cast<costream *>(new OStringStreamLog());
30  }
31 
33  delete reinterpret_cast<OStringStreamLog *>(ptr);
34  }
35 
36  unsigned long casm_ostringstream_size(costream *ptr) {
37  typedef std::char_traits<char>::pos_type pos_type;
38  return reinterpret_cast<OStringStreamLog *>(ptr)->ss().tellp() + pos_type(1);
39  }
40 
41  char *casm_ostringstream_strcpy(costream *ptr, char *c_str) {
42  auto str = reinterpret_cast<OStringStreamLog *>(ptr)->ss().str();
43  std::strcpy(c_str, str.c_str());
44  return c_str;
45  }
46 
48  return nullptr;
49  }
50 
52  Log &_log(*reinterpret_cast<Log *>(log));
53  Log &_debug_log(*reinterpret_cast<Log *>(debug_log));
54  Log &_err_log(*reinterpret_cast<Log *>(err_log));
55  PrimClex *ptr = new PrimClex(fs::path(path), Logging(_log, _debug_log, _err_log));
56  return reinterpret_cast<cPrimClex *>(ptr);
57  }
58 
60  delete reinterpret_cast<PrimClex *>(ptr);
61  }
62 
64  bool read_settings,
65  bool read_composition,
66  bool read_chem_ref,
67  bool read_configs,
68  bool clear_clex) {
69  PrimClex *_primclex = reinterpret_cast<PrimClex *>(ptr);
70  _primclex->refresh(read_settings, read_composition, read_chem_ref, read_configs, clear_clex);
71  }
72 
73  void casm_command_list(costream *ostringstream_log) {
74  // print to log the recognized casm commands as a JSON array
75  Log &_log(*reinterpret_cast<OStringStreamLog *>(ostringstream_log));
76  std::vector<std::string> command_list;
77  for(const auto &val : command_map()) {
78  command_list.push_back(val.first);
79  }
80  jsonParser json;
81  json = command_list;
82  _log << json;
83  }
84 
85  int casm_capi(char *args, cPrimClex *primclex, char *root, costream *log, costream *debug_log, costream *err_log) {
86  PrimClex *_primclex = reinterpret_cast<PrimClex *>(primclex);
87  Log &_log(*reinterpret_cast<Log *>(log));
88  //Log &_debug_log(*reinterpret_cast<Log *>(debug_log));
89  Log &_err_log(*reinterpret_cast<Log *>(err_log));
90 
91  std::string s("casm ");
92  s += std::string(args);
93 
94  fs::path _root(root);
95 
96  CommandArgs command_args(s, _primclex, _root, _log, _err_log);
97  if(command_args.parse_result) {
98  return command_args.parse_result;
99  }
100 
101  return casm_api(command_args);
102  }
103 
104 }
Data structure holding basic CASM command info.
struct costream costream
For std::ostream*.
Definition: api.hh:12
void casm_primclex_refresh(cPrimClex *ptr, bool read_settings, bool read_composition, bool read_chem_ref, bool read_configs, bool clear_clex)
Definition: api.cc:63
costream * casm_ostringstream_new()
Definition: api.cc:28
costream * casm_nullstream()
Definition: api.cc:23
PrimClex * primclex
Definition: settings.cc:101
void refresh(bool read_settings=false, bool read_composition=false, bool read_chem_ref=false, bool read_configs=false, bool clear_clex=false)
Reload PrimClex data from settings.
Definition: PrimClex.cc:90
Main CASM namespace.
Definition: complete.cpp:8
Log & log
Definition: settings.cc:105
Log & null_log()
Definition: Log.hh:211
void casm_command_list(costream *ostringstream_log)
Definition: api.cc:73
CommandMap & command_map()
Return static CommandMap containing all CASM API commands.
costream * casm_STDERR()
Definition: api.cc:18
struct cPrimClex cPrimClex
For CASM::PrimClex*.
Definition: api.hh:9
void casm_ostringstream_delete(costream *ptr)
Definition: api.cc:32
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
char * casm_ostringstream_strcpy(costream *ptr, char *c_str)
Definition: api.cc:41
costream * casm_STDOUT()
Definition: api.cc:14
unsigned long casm_ostringstream_size(costream *ptr)
Definition: api.cc:36
Log & default_log()
Definition: Log.hh:201
cPrimClex * casm_primclex_new(char *path, costream *log, costream *debug_log, costream *err_log)
Definition: api.cc:51
cPrimClex * casm_primclex_null()
Definition: api.cc:47
void casm_primclex_delete(cPrimClex *ptr)
Definition: api.cc:59
Log & err_log
Definition: settings.cc:106
Log & default_err_log()
Definition: Log.hh:206
Definition: Log.hh:9
int parse_result
stores error codes when attempting to parse std::string _args -> argc, argv
int casm_capi(char *args, cPrimClex *primclex, char *root, costream *log, costream *debug_log, costream *err_log)
Definition: api.cc:85
int casm_api(const CommandArgs &args)
Executes CASM commands specified by args.