CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Complete.hh
Go to the documentation of this file.
1 #ifndef COMPLETE_HH
2 #define COMPLETE_HH
3 
4 #include <string>
5 #include <vector>
6 #include <stdexcept>
7 #include <utility>
8 #include <boost/program_options.hpp>
11 
12 namespace CASM {
13 
14  class PrimClex;
15 
16  namespace Completer {
17 
19  std::string strip_argument(const std::string &raw_input);
20 
21  //*****************************************************************************************************//
22 
33  class Suboption {
34 
35  public:
37 
39  Suboption(const std::string &init_longname, std::string init_short, ARG_TYPE init_expected_types);
40 
42  Suboption(const po::option_description &init_boost_option);
43 
45  std::string long_tag() const;
46 
48  std::string short_tag() const;
49 
51  bool matches(const std::string &test_tag) const;
52 
54  ARG_TYPE argument_type() const;
55 
56  private:
57 
59  const std::string m_long;
60 
62  const std::string m_short;
63 
65  const ARG_TYPE m_expected_arg;
66 
68  void _sanity_throw() const;
69  };
70 
71  namespace Suboption_impl {
73  std::string pull_short(const po::option_description &single_boost_option);
74 
76  std::string pull_long(const po::option_description &single_boost_option);
77  }
78 
79  //*****************************************************************************************************//
80 
81 
92  class Option {
93  typedef std::size_t size_type;
95 
96  public:
97 
99  Option(const std::string &init_tag, const po::options_description &init_premade_descs);
100 
102  std::string tag() const;
103 
105  std::vector<std::string> probe_suboptions() const;
106 
108  ARG_TYPE probe_argument_type(const std::string &suboption_tag) const;
109 
111  void push_back(const Suboption &new_suboption);
112 
114  bool matches(const std::string &test_tag) const;
115 
116  private:
117 
119  Option(const std::string &init_tag, const std::vector<Suboption> &init_allowed_subopts);
120 
122  std::string m_tag; //Make this const once the default constructors of Engine are gone?
123 
125  std::vector<Suboption> m_avail_suboptions;
126 
127  };
128 
129 
130  //*****************************************************************************************************//
131 
132 
146  class Engine {
147  typedef std::size_t size_type;
149 
150  public:
151 
153  Engine() {};
154 
156  Engine(const std::vector<Option> &init_options);
157 
159  //Engine(const std::vector<CASM::po::options_description> &init_premade_descs);
160 
162  std::vector<std::string> probe_options() const;
163 
165  std::vector<std::string> probe_suboptions(const std::string &option_tag) const;
166 
168  std::vector<std::string> probe_arguments(const std::string &option_tag, const std::string &suboption_tag) const;
169 
171  //std::vector<std::string> probe_guess(const std::string current_word) const;
172 
174  void push_back(const Option &new_option);
175 
176  private:
177 
179  std::vector<Option> m_avail_options;
180 
182  ARG_TYPE _probe_argument_type(const std::string &option_tag, const std::string &suboption_tag) const;
183 
185  //const *CASM::PrimClex m_pclex;
186 
187  };
188  }
189 }
190 
191 #endif
std::vector< std::string > probe_suboptions(const std::string &option_tag) const
For a particular option, get the available suboptions.
Definition: Complete.cc:174
std::vector< Suboption > m_avail_suboptions
List of all the available –suboptions this option has.
Definition: Complete.hh:125
ARG_TYPE probe_argument_type(const std::string &suboption_tag) const
For a particular –suboption, get what kind of arguments are expected. suboption_tag should be pre-st...
Definition: Complete.cc:134
Option(const std::string &init_tag, const po::options_description &init_premade_descs)
Construct with program options.
Definition: Complete.cc:100
bool matches(const std::string &test_tag) const
Check if the given string corresponds to the tag of *this.
Definition: Complete.cc:144
const std::string m_long
–long identifier (includes leading "--")
Definition: Complete.hh:59
std::string tag() const
Return the identifying name of *this (e.g. "super", "monte", etc)
Definition: Complete.cc:109
const std::string m_short
-s(hort) identifyer (includes leading '-')
Definition: Complete.hh:62
Main CASM namespace.
Definition: complete.cpp:8
std::string short_tag() const
Return short name as char.
Definition: Complete.cc:73
std::string strip_argument(const std::string &raw_input)
Remove "--" or "-" from beginning of string if it exists, and return as new string.
Definition: Complete.cc:12
bool matches(const std::string &test_tag) const
See if a provided string matches either the –long or -s(hort) tags. Expects leading '-' characters...
Definition: Complete.cc:77
std::size_t size_type
Definition: Complete.hh:93
void push_back(const Suboption &new_suboption)
Append a new suboption to the option.
std::string long_tag() const
Return long name in string format.
Definition: Complete.cc:69
void _sanity_throw() const
Make sure values make sense.
Definition: Complete.cc:60
std::string pull_long(const po::option_description &single_boost_option)
Get the –long tag from boost.
Definition: Complete.cc:40
ARG_TYPE argument_type() const
Return the expected types of arguments that follow *this.
Definition: Complete.cc:89
const ARG_TYPE m_expected_arg
Type of arguments expected.
Definition: Complete.hh:65
std::vector< std::string > probe_options() const
Construct by passing boost program options (eventually preferred so that it can update itself) ...
Definition: Complete.cc:159
ArgHandler::ARG_TYPE ARG_TYPE
Definition: Complete.hh:148
std::vector< std::string > probe_suboptions() const
Return what the suboptions (–long format) for *this are.
Definition: Complete.cc:118
void push_back(const Option &new_option)
Guess what should be returned based on the current word (probably not gonna make it that smart) ...
Definition: Complete.cc:263
Suboption(const std::string &init_longname, std::string init_short, ARG_TYPE init_expected_types)
Explicit construction. Be sure to include "--" and '-' in the tags.
Definition: Complete.cc:45
std::string pull_short(const po::option_description &single_boost_option)
Get the -s(hort) tag from boost, or make it "- " if it doesn't exist.
Definition: Complete.cc:29
ArgHandler::ARG_TYPE ARG_TYPE
Definition: Complete.hh:36
std::string m_tag
Name that identifies this casm option (e.g. "monte", "init", etc)
Definition: Complete.hh:122
std::vector< std::string > probe_arguments(const std::string &option_tag, const std::string &suboption_tag) const
Return the arguments that should be bash completed.
Definition: Complete.cc:191
std::vector< Option > m_avail_options
List of all the available (presumably casm) options (e.g. "monte", "init", etc)
Definition: Complete.hh:179
std::size_t size_type
Definition: Complete.hh:147
Engine()
Default constructor so you can push back your own things.
Definition: Complete.hh:153
ARG_TYPE _probe_argument_type(const std::string &option_tag, const std::string &suboption_tag) const
For a particular option with suboption, get what kind of arguments are expected.
Definition: Complete.cc:253
ArgHandler::ARG_TYPE ARG_TYPE
Definition: Complete.hh:94