CASM  1.1.0
A Clusters Approach to Statistical Mechanics
casm_functions.hh
Go to the documentation of this file.
1 #ifndef CASM_FUNCTIONS_HH
2 #define CASM_FUNCTIONS_HH
3 
4 #include <boost/filesystem/path.hpp>
5 
6 #include "casm/app/CLIParse.hh"
7 #include "casm/app/errors.hh"
11 
36 namespace CASM {
37 
38 void print_splash(std::ostream &out);
39 
40 class PrimClex;
41 class jsonParser;
42 
52 struct CommandArgs : public CLIParse {
54  CommandArgs(int _argc, char *_argv[], PrimClex *_primclex = nullptr,
55  fs::path _root = fs::path());
56 
58  CommandArgs(std::string _args, PrimClex *_primclex = nullptr,
59  fs::path _root = fs::path());
60 
61  CommandArgs(const CommandArgs &other) = delete;
62  CommandArgs(CommandArgs &&other) = delete;
63  CommandArgs &operator=(const CommandArgs &) = delete;
65 
67  ~CommandArgs();
68 
70 
71  fs::path root;
72 
73  bool is_help;
74 
75  // if LOG should be written
76  bool write_log;
77 
78  // which casm sub-command ('init', 'enum', etc.)
79  std::string command;
80 
81  private:
82  void _init();
83 };
84 
85 typedef std::function<int(const CommandArgs &)> Command;
86 typedef std::map<std::string, Command> CommandMap;
87 
90 
92 int casm_api(const CommandArgs &args);
93 
97  std::unique_ptr<PrimClex> &uniq_primclex);
98 
100 std::ostream &make_ostream_if(bool output, std::ostream &sout,
101  std::unique_ptr<std::ostream> &fout,
102  fs::path out_path, bool gzip);
103 
104 int help_command(const CommandArgs &args);
105 
106 int version_command(const CommandArgs &args);
107 
108 template <typename OptionType>
109 class InterfaceBase;
110 
113 template <typename OptionType>
116 
118 template <typename OptionType>
120  public:
122 
123  virtual ~InterfaceBase() {}
124 
125  virtual std::string help() const = 0;
126 
127  virtual std::string name() const = 0;
128 
129  virtual int run(PrimClex const &primclex,
130  jsonParser const &json_options) const = 0;
131 
132  std::unique_ptr<InterfaceBase> clone() const {
133  return std::unique_ptr<InterfaceBase>(this->_clone());
134  }
135 
136  private:
137  virtual InterfaceBase *_clone() const = 0;
138 };
139 
141 template <typename OptionType>
142 std::unique_ptr<InterfaceMap<OptionType> > make_interface_map() {
143  return notstd::make_unique<InterfaceMap<OptionType> >(
144  [](const InterfaceBase<OptionType> &e) -> std::string {
145  return e.name();
146  },
147  [](const InterfaceBase<OptionType> &e)
149  return notstd::clone(e);
150  });
151 }
152 
154 } // namespace CASM
155 
156 #endif
Base class for generic use of algorithms through the API.
virtual InterfaceBase * _clone() const =0
std::unique_ptr< InterfaceBase > clone() const
virtual std::string name() const =0
virtual int run(PrimClex const &primclex, jsonParser const &json_options) const =0
virtual std::string help() const =0
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:55
A 'cloneable_ptr' can be used in place of 'unique_ptr'.
std::map wrapper to enforce a 1-1 ValueType->KeyType relationship
Definition: unique_map.hh:124
CommandMap & command_map()
Return static CommandMap containing all CASM API commands.
int version_command(const CommandArgs &args)
int help_command(const CommandArgs &args)
Print CASM help info to log()
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.
std::map< std::string, Command > CommandMap
int casm_api(const CommandArgs &args)
Executes CASM commands specified by args.
std::unique_ptr< InterfaceMap< OptionType > > make_interface_map()
Use to construct an InterfaceMap.
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...
std::function< int(const CommandArgs &)> Command
Main CASM namespace.
Definition: APICommand.hh:8
void print_splash(std::ostream &out)
std::unique_ptr< T > clone(const T &obj)
PrimClex * primclex
Definition: settings.cc:135
Data structure holding basic CASM command info.
CommandArgs & operator=(const CommandArgs &)=delete
CommandArgs(int _argc, char *_argv[], PrimClex *_primclex=nullptr, fs::path _root=fs::path())
CommandArgs constructor.
std::string command
CommandArgs & operator=(CommandArgs &&)=delete
CommandArgs(const CommandArgs &other)=delete
CommandArgs(CommandArgs &&other)=delete
~CommandArgs()
CommandArgs destructor.