CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
casm_functions.hh
Go to the documentation of this file.
1 #ifndef CASM_FUNCTIONS_HH
2 #define CASM_FUNCTIONS_HH
3 
4 #include <wordexp.h>
6 #include "casm/casm_io/Log.hh"
7 
29 // Command line input is not valid
30 #define ERR_INVALID_ARG 1
31 
32 // Misc. or Unknown error
33 #define ERR_UNKNOWN 2
34 
35 // No CASM project can be found in expected location
36 #define ERR_NO_PROJ 3
37 
38 // An expected input file is invalid
39 #define ERR_INVALID_INPUT_FILE 4
40 
41 // An expected input file can not be found
42 #define ERR_MISSING_INPUT_FILE 5
43 
44 // A file might be overwritten
45 #define ERR_EXISTING_FILE 6
46 
47 // Requested command can not be performed because some dependency needs to be
48 // done first (i.e. no basis set, so can't use clexulator)
49 #define ERR_MISSING_DEPENDS 7
50 
51 // Unknown attempting to overwrite another CASM project
52 #define ERR_OTHER_PROJ 8
53 
56 namespace CASM {
58 
59  class PrimClex;
60 
69  struct CommandArgs : public Logging {
71 
73  CommandArgs(int _argc,
74  char *_argv[],
75  PrimClex *_primclex,
76  fs::path _root,
77  const Logging &logging);
78 
80  CommandArgs(int _argc,
81  char *_argv[],
82  PrimClex *_primclex = nullptr,
83  fs::path _root = fs::path(),
84  Log &_log = default_log(),
85  Log &_err_log = default_err_log()) :
86  CommandArgs(_argc, _argv, _primclex, _root, Logging(_log, _log, _err_log)) {}
87 
88 
90  CommandArgs(std::string _args,
91  PrimClex *_primclex,
92  fs::path _root,
93  const Logging &logging);
94 
96  CommandArgs(std::string _args,
97  PrimClex *_primclex = nullptr,
98  fs::path _root = fs::path(),
99  Log &_log = default_log(),
100  Log &_err_log = default_err_log()) :
101  CommandArgs(_args, _primclex, _root, Logging(_log, _log, _err_log)) {}
102 
103  CommandArgs(const CommandArgs &other) = delete;
104  CommandArgs(CommandArgs &&other) = delete;
105  CommandArgs &operator=(const CommandArgs &) = delete;
106  CommandArgs &operator=(CommandArgs &&) = delete;
107 
109  ~CommandArgs();
110 
111  int argc;
112  char **argv;
117 
120 
121  bool is_help;
122  bool write_log;
123  std::string command;
124 
125  private:
126 
127  void _init();
128 
130  bool m_free_p;
131  wordexp_t m_p;
132 
133  };
134 
135  typedef std::function<int (const CommandArgs &)> Command;
136  typedef std::map<std::string, Command> CommandMap;
137 
139  CommandMap &command_map();
140 
142  int casm_api(const CommandArgs &args);
143 
144  // /// \brief Executes casm_api in specified working directory
145  // int casm_api(const CommandArgs &args, fs::path working_dir);
146 
147 
148 
151  PrimClex &make_primclex_if_not(const CommandArgs &args, std::unique_ptr<PrimClex> &uniq_primclex);
152 
155  PrimClex &make_primclex_if_not(const CommandArgs &args, std::unique_ptr<PrimClex> &uniq_primclex, Log &status_log);
156 
158  std::ostream &make_ostream_if(
159  bool output,
160  std::ostream &sout,
161  std::unique_ptr<std::ostream> &fout,
162  fs::path out_path,
163  bool gzip);
164 
165 
166  int help_command(const CommandArgs &args);
167 
168  int bset_command(const CommandArgs &args);
169 
170  int composition_command(const CommandArgs &args);
171 
172  int enum_command(const CommandArgs &args);
173 
174  int files_command(const CommandArgs &args);
175 
176  int format_command(const CommandArgs &args);
177 
178  int import_command(const CommandArgs &args);
179 
180  int init_command(const CommandArgs &args);
181 
182  int monte_command(const CommandArgs &args);
183 
184  int perturb_command(const CommandArgs &args);
185 
186  int query_command(const CommandArgs &args);
187 
188  int ref_command(const CommandArgs &args);
189 
190  int rm_command(const CommandArgs &args);
191 
192  int run_command(const CommandArgs &args);
193 
194  int select_command(const CommandArgs &args);
195 
196  int settings_command(const CommandArgs &args);
197 
198  int status_command(const CommandArgs &args);
199 
200  int super_command(const CommandArgs &args);
201 
202  int sym_command(const CommandArgs &args);
203 
204  int update_command(const CommandArgs &args);
205 
206  int version_command(const CommandArgs &args);
207 
208  int view_command(const CommandArgs &args);
209 
211 }
212 
213 #endif
Data structure holding basic CASM command info.
int update_command(const CommandArgs &args)
Definition: update.cc:62
int enum_command(const CommandArgs &args)
Definition: enum.cc:51
int rm_command(const CommandArgs &args)
Definition: rm.cc:44
int select_command(const CommandArgs &args)
Definition: select.cc:168
int files_command(const CommandArgs &args)
Definition: files.cc:47
int view_command(const CommandArgs &args)
Definition: view.cc:26
CommandArgs & operator=(const CommandArgs &)=delete
~CommandArgs()
CommandArgs destructor.
Main CASM namespace.
Definition: complete.cpp:8
int init_command(const CommandArgs &args)
Definition: init.cc:28
bool m_free_p
Used when parsing std::string args -> argc, argv.
int super_command(const CommandArgs &args)
Definition: super.cc:103
int query_command(const CommandArgs &args)
Definition: query.cc:81
CommandMap & command_map()
Return static CommandMap containing all CASM API commands.
int import_command(const CommandArgs &args)
Definition: import.cc:95
Logging(Log &log=default_log(), Log &debug_log=default_log(), Log &err_log=default_err_log())
Definition: Log.hh:250
int status_command(const CommandArgs &args)
Definition: status.cc:389
int run_command(const CommandArgs &args)
Definition: run.cc:35
int bset_command(const CommandArgs &args)
Definition: bset.cc:36
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:52
int monte_command(const CommandArgs &args)
Definition: monte.cc:106
int ref_command(const CommandArgs &args)
Definition: ref.cc:161
CommandArgs(int _argc, char *_argv[], PrimClex *_primclex, fs::path _root, const Logging &logging)
CommandArgs constructor.
std::map< std::string, Command > CommandMap
std::ostream & make_ostream_if(bool output, std::ostream &sout, std::unique_ptr< std::ostream > &fout, fs::path out_path, bool gzip)
Return a reference to proper std::ostream.
int perturb_command(const CommandArgs &args)
Definition: perturb.cc:35
int help_command(const CommandArgs &args)
Print CASM help info to args.log.
PrimClex & make_primclex_if_not(const CommandArgs &args, std::unique_ptr< PrimClex > &uniq_primclex)
If !_primclex, construct new PrimClex stored in uniq_primclex, then return reference to existing or c...
Log & default_log()
Definition: Log.hh:201
int sym_command(const CommandArgs &args)
Definition: sym.cc:32
std::function< int(const CommandArgs &)> Command
int version_command(const CommandArgs &args)
int format_command(const CommandArgs &args)
Definition: format.cc:44
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
CommandArgs(std::string _args, PrimClex *_primclex=nullptr, fs::path _root=fs::path(), Log &_log=default_log(), Log &_err_log=default_err_log())
CommandArgs constructor.
int settings_command(const CommandArgs &args)
Definition: settings.cc:257
CommandArgs(int _argc, char *_argv[], PrimClex *_primclex=nullptr, fs::path _root=fs::path(), Log &_log=default_log(), Log &_err_log=default_err_log())
CommandArgs constructor.
int casm_api(const CommandArgs &args)
Executes CASM commands specified by args.
int composition_command(const CommandArgs &args)
Definition: composition.cc:69