CASM  1.1.0
A Clusters Approach to Statistical Mechanics
APICommand.hh
Go to the documentation of this file.
1 #ifndef CASM_APICommand
2 #define CASM_APICommand
3 
4 #include <boost/program_options.hpp>
5 
7 
8 namespace CASM {
9 
10 class PrimClex;
11 
19  public:
20  APICommandBase(const CommandArgs &_args);
21 
22  virtual ~APICommandBase() {}
23 
24  const CommandArgs &args() const;
25 
26  fs::path root() const;
27 
28  bool in_project() const;
29 
30  PrimClex &primclex() const;
31 
32  virtual int vm_count_check() const = 0;
33 
34  virtual int help() const = 0;
35 
36  virtual int desc() const = 0;
37 
38  virtual int run() const = 0;
39 
40  private:
43  mutable std::unique_ptr<PrimClex> m_primclex;
44 };
45 
49 template <typename _OptionType>
50 class APICommand : public APICommandBase {
51  public:
52  typedef _OptionType OptionType;
53 
54  APICommand(const CommandArgs &_args, OptionType &_opt)
55  : APICommandBase(_args), m_opt(_opt) {}
56 
57  int count(std::string s) const { return opt().vm().count(s); }
58 
59  const po::variables_map &vm() const { return opt().vm(); }
60 
61  const OptionType &opt() const { return m_opt; }
62 
63  private:
65 };
66 
68 template <typename CommandType>
69 std::unique_ptr<CommandType> make_api_command(
70  CommandArgs const &args, typename CommandType::OptionType &opt);
71 
73 template <typename CommandType>
74 std::unique_ptr<CommandType> make_api_command(
75  std::string cli_str, PrimClex &primclex,
76  typename CommandType::OptionType &opt);
77 
79 template <typename CommandType>
80 int run_api_command(const CommandArgs &args);
81 
82 } // namespace CASM
83 
84 #endif
std::set< std::string > & s
virtual int desc() const =0
const CommandArgs & args() const
Definition: APICommand.cc:11
virtual int help() const =0
const CommandArgs & m_args
Definition: APICommand.hh:41
virtual int run() const =0
std::unique_ptr< PrimClex > m_primclex
Definition: APICommand.hh:43
PrimClex & primclex() const
Definition: APICommand.cc:17
virtual int vm_count_check() const =0
bool in_project() const
Definition: APICommand.cc:15
virtual ~APICommandBase()
Definition: APICommand.hh:22
APICommandBase(const CommandArgs &_args)
Definition: APICommand.cc:8
fs::path root() const
Definition: APICommand.cc:13
OptionType & m_opt
Definition: APICommand.hh:64
_OptionType OptionType
Definition: APICommand.hh:52
const OptionType & opt() const
Definition: APICommand.hh:61
const po::variables_map & vm() const
Definition: APICommand.hh:59
int count(std::string s) const
Definition: APICommand.hh:57
APICommand(const CommandArgs &_args, OptionType &_opt)
Definition: APICommand.hh:54
PrimClex is the top-level data structure for a CASM project.
Definition: PrimClex.hh:55
Main CASM namespace.
Definition: APICommand.hh:8
std::unique_ptr< CommandType > make_api_command(CommandArgs const &args, typename CommandType::OptionType &opt)
Parse command line options and make API command. Throws for parsing errors.
int run_api_command(const CommandArgs &args)
Standardizes how 'casm X' api commands are executed and implemented.
PrimClex * primclex
Definition: settings.cc:135
Data structure holding basic CASM command info.