CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
Handlers.cc
Go to the documentation of this file.
1 #ifndef HANDLERS_CC
2 #define HANDLERS_CC
3 
7 
8 namespace CASM {
9  namespace Completer {
11 
12 
13  ARG_TYPE ArgHandler::determine_type(const po::option_description &boost_option) {
14  //This string will become something like "<path>", or "arg", or "<path> (=MASTER)"
15  std::string raw_boost_format = boost_option.format_parameter();
16  //Sometimes boost option has default arguments. We don't want to include that
17  std::string argtype_str;
18  std::string::size_type space_pos = raw_boost_format.find(' ');
19 
20  //Spaces found, probably printing default value as well. Strip it off.
21  if(space_pos != std::string::npos) {
22  argtype_str = raw_boost_format.substr(0, space_pos);
23  }
24 
25  //No spaces found, so format_parameter already returned what we wanted
26  else {
27  argtype_str = raw_boost_format;
28  }
29 
30  for(auto it = m_argument_table.begin(); it != m_argument_table.end(); ++it) {
31  if(it->first == argtype_str) {
32  return it->second;
33  }
34  }
35 
36  return ARG_TYPE::VOID;
37  }
38 
39  std::string ArgHandler::path() {
40  return m_argument_table[0].first;
41  }
42 
43  std::string ArgHandler::command() {
44  return m_argument_table[1].first;
45  }
46 
47  std::string ArgHandler::supercell() {
48  return m_argument_table[2].first;
49  }
50 
51  std::string ArgHandler::query() {
52  return m_argument_table[3].first;
53  }
54 
55  std::string ArgHandler::operation() {
56  return m_argument_table[4].first;
57  }
58 
59  std::string ArgHandler::configname() {
60  return m_argument_table[5].first;
61  }
62 
63  std::string ArgHandler::coordtype() {
64  return m_argument_table[6].first;
65  }
66 
67 
68  void ArgHandler::void_to_bash(std::vector<std::string> &arguments) {
69  return;
70  }
71 
72  void ArgHandler::path_to_bash(std::vector<std::string> &arguments) {
73  arguments.push_back("BASH_COMP_PATH");
74  return;
75  }
76 
77  void ArgHandler::command_to_bash(std::vector<std::string> &arguments) {
78  arguments.push_back("BASH_COMP_BIN");
79  return;
80  }
81 
82  void scelname_to_bash(std::vector<std::string> &arguments) {
83  return;
84  }
85 
86  void ArgHandler::query_to_bash(std::vector<std::string> &arguments) {
87  DataFormatterDictionary<Configuration> dict = make_dictionary<Configuration>();
88 
89  for(auto it = dict.begin(); it != dict.cend(); ++it) {
91  arguments.push_back(it->name());
92  }
93  }
94  return;
95  }
96 
97  void ArgHandler::operator_to_bash(std::vector<std::string> &arguments) {
98  DataFormatterDictionary<Configuration> dict = make_dictionary<Configuration>();
99 
100  for(auto it = dict.begin(); it != dict.cend(); ++it) {
102  arguments.push_back(it->name());
103  }
104  }
105  return;
106  }
107 
108 
115  const std::vector<std::pair<std::string, ARG_TYPE> > ArgHandler::m_argument_table({
116  std::make_pair("<path>", ARG_TYPE::PATH),
117  std::make_pair("<command>", ARG_TYPE::COMMAND),
118  std::make_pair("<supercell>", ARG_TYPE::SCELNAME),
119  std::make_pair("<query>", ARG_TYPE::QUERY),
120  std::make_pair("<operation>", ARG_TYPE::OPERATOR),
121  std::make_pair("<configuration>", ARG_TYPE::CONFIGNAME),
122  std::make_pair("<type>", ARG_TYPE::COORDTYPE)
123  });
124 
125 
126  //*****************************************************************************************************//
127 
128  OptionHandlerBase::OptionHandlerBase(const std::string &init_option_tag):
129  m_tag(init_option_tag),
130  m_desc(std::string("'casm ") + init_option_tag + std::string("' usage")),
131  m_gzip_flag(false) {
132  }
133 
134  OptionHandlerBase::OptionHandlerBase(const std::string &init_option_tag, const std::string &init_descriptor):
135  m_tag(init_option_tag),
136  m_desc(init_descriptor),
137  m_gzip_flag(false) {
138  }
139 
140  const std::string &OptionHandlerBase::tag() const {
141  return m_tag;
142  }
143 
145  po::variables_map &OptionHandlerBase::vm() {
146  return m_vm;
147  }
148 
150  const po::variables_map &OptionHandlerBase::vm() const {
151  return m_vm;
152  }
153 
160  const po::options_description &OptionHandlerBase::desc() {
161  if(m_desc.options().size() == 0) {
162  initialize();
163  }
164 
165  return m_desc;
166  }
167 
169  return m_selection_path;
170  }
171 
172  const std::vector<fs::path> &OptionHandlerBase::selection_paths() const {
173  return m_selection_paths;
174  }
175 
176  const std::string &OptionHandlerBase::verbosity_str() const {
177  return m_verbosity_str;
178  }
179 
181  return m_settings_path;
182  }
183 
184  std::string OptionHandlerBase::input_str() const {
185  return m_input_str;
186  }
187 
189  return m_output_path;
190  }
191 
193  return m_gzip_flag;
194  }
195 
196  const std::vector<std::string> &OptionHandlerBase::help_opt_vec() const {
197  return m_help_opt_vec;
198  }
199 
200  const std::string &OptionHandlerBase::config_str() const {
201  return m_config_str;
202  }
203 
204  const std::vector<std::string> &OptionHandlerBase::config_strs() const {
205  return m_config_strs;
206  }
207 
208  const std::string &OptionHandlerBase::supercell_str() const {
209  return m_supercell_str;
210  }
211 
212  const std::vector<std::string> &OptionHandlerBase::supercell_strs() const {
213  return m_supercell_strs;
214  }
215 
216  const std::string &OptionHandlerBase::coordtype_str() const {
217  return m_coordtype_str;
218  }
219 
221  COORD_TYPE selected_mode;
222 
223  if(m_coordtype_str[0] == 'F' || m_coordtype_str[0] == 'f') {
224  selected_mode = COORD_TYPE::FRAC;
225  }
226 
227  else if(m_coordtype_str[0] == 'C' || m_coordtype_str[0] == 'c') {
228  selected_mode = COORD_TYPE::CART;
229  }
230 
231  else {
232  selected_mode = COORD_TYPE::COORD_DEFAULT;
233  }
234 
235  return selected_mode;
236  }
237 
239  m_desc.add_options()
240  ("config,c",
241  po::value<fs::path>(&m_selection_path)->default_value(_default)->value_name(ArgHandler::path()),
242  (std::string("Only consider the selected configurations of the given selection file. "
243  "Standard selections are 'MASTER', 'CALCULATED', 'ALL', or 'NONE'. "
244  "If not specified, '") + _default.string() + std::string("' will be used.")).c_str());
245  return;
246  }
247 
249  m_desc.add_options()
250  ("configs,c",
251  po::value<std::vector<fs::path> >(&m_selection_paths)->multitoken()->default_value(std::vector<fs::path> {_default})->value_name(ArgHandler::path()),
252  (std::string("Only consider the selected configurations of the given selection file. "
253  "Standard selections are 'MASTER', 'CALCULATED', 'ALL', or 'NONE'. "
254  "If not specified, '") + _default.string() + std::string("' will be used.")).c_str());
255  return;
256  }
257 
259  m_desc.add_options()
260  ("config,c",
261  po::value<fs::path>(&m_selection_path)->value_name(ArgHandler::path()),
262  "Only consider the selected configurations of the given selection file. "
263  "Standard selections are 'MASTER', 'CALCULATED', 'ALL', or 'NONE'. ");
264  return;
265  }
266 
268  m_desc.add_options()
269  ("configs,c",
270  po::value<std::vector<fs::path> >(&m_selection_paths)->multitoken()->value_name(ArgHandler::path()),
271  "Only consider the selected configurations of the given selection files. "
272  "Standard selections are 'MASTER', 'CALCULATED', 'ALL', or 'NONE'. ");
273  return;
274  }
275 
277  m_desc.add_options()
278  ("help,h", "Print help message")
279  ("desc", "Print extended usage description");
280  return;
281  }
282 
284  m_desc.add_options()
285  ("help,h", po::value<std::vector<std::string> >(&m_help_opt_vec)->multitoken()->zero_tokens(), "Print general help. Use '--help properties' for a list of query-able properties or '--help operators' for a list of query operators");
286  return;
287  }
288 
290  //TODO: add ArgHandler for this
291  m_desc.add_options()
292  ("verbosity", po::value<std::string>(&m_verbosity_str)->default_value("standard"), "Verbosity of output. Options are 'none', 'quiet', 'standard', 'verbose', 'debug', or an integer 0-100 (0: none, 100: all).");
293  return;
294  }
295 
297  std::string help_str = "Settings input file specifying which parameters should be used. See 'casm format --" + m_tag + "'.";
298 
299  if(required) {
300  m_desc.add_options()
301  ("settings,s", po::value<fs::path>(&m_settings_path)->required()->value_name(ArgHandler::path()), help_str.c_str());
302  }
303  else {
304  m_desc.add_options()
305  ("settings,s", po::value<fs::path>(&m_settings_path)->value_name(ArgHandler::path()), help_str.c_str());
306  }
307 
308  return;
309  }
310 
312  std::string help_str = "String specifying input settings. See 'casm format --" + m_tag + "'.";
313 
314  if(required) {
315  m_desc.add_options()
316  ("input,i", po::value<std::string>(&m_input_str)->required(), help_str.c_str());
317  }
318  else {
319  m_desc.add_options()
320  ("input,i", po::value<std::string>(&m_input_str), help_str.c_str());
321  }
322 
323  return;
324  }
325 
327  m_desc.add_options()
328  ("output,o", po::value<fs::path>(&m_output_path)->value_name(ArgHandler::path()), "Name for output file. Use STDOUT to print results without extra messages.");
329  return;
330  }
331 
333  m_desc.add_options()
334  ("gzip,z", po::value(&m_gzip_flag)->zero_tokens(), "Write gzipped output file.");
335  return;
336  }
337 
339  std::string help_str;
340  help_str = "Single supercell name to use casm " + m_tag + " with, such as 'SCEL4_2_2_1_0_0_0'";
341  m_desc.add_options()
342  ("scelname", po::value<std::string>(&m_supercell_str)->value_name(ArgHandler::supercell()), help_str.c_str());
343  return;
344  }
345 
347  std::string help_str;
348  help_str = "One or more supercells to use casm " + m_tag + " with, such as 'SCEL4_2_2_1_0_0_0'";
349  m_desc.add_options()
350  ("scelnames", po::value<std::vector<std::string> >(&m_supercell_strs)->multitoken()->value_name(ArgHandler::supercell()), help_str.c_str());
351  return;
352  }
353 
355  std::string help_str;
356 
357  help_str = "Single configuration to use casm " + m_tag + " with, such as 'SCEL4_2_2_1_0_0_0/3'";
358 
359  m_desc.add_options()
360  ("configname", po::value<std::string>(&m_config_str)->value_name(ArgHandler::configname()), help_str.c_str());
361 
362  return;
363  }
364 
366  std::string help_str;
367 
368  help_str = "One or more configurations to use casm " + m_tag + " with, such as 'SCEL4_2_2_1_0_0_0/3'";
369 
370  m_desc.add_options()
371  ("confignames", po::value<std::vector<std::string> >(&m_config_strs)->multitoken()->value_name(ArgHandler::configname()), help_str.c_str());
372 
373  return;
374  }
375 
376 
378  m_desc.add_options()
379  ("coord", po::value<std::string>(&m_coordtype_str)->default_value("frac")->value_name(ArgHandler::coordtype()), "Type of coordinate system to use. Use 'frac' for fractional (default) or 'cart' for Cartesian.");
380  return;
381  }
382 
383  //*****************************************************************************************************//
384 
385  }
386 }
387 
388 #endif
COORD_TYPE coordtype_enum() const
Return the coordinate type recasted as the CASM defined enum.
Definition: Handlers.cc:220
std::string m_input_str
The settings path to go with add_input_suboption()
Definition: Handlers.hh:199
static void operator_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for OPERATOR.
Definition: Handlers.cc:97
const std::string & coordtype_str() const
Return the coordinate type in the form of a string.
Definition: Handlers.cc:216
std::vector< std::string > m_help_opt_vec
The list of strings to go with add_general_help_suboption()
Definition: Handlers.hh:177
std::string m_supercell_str
The string of the supercell name of add_scelname_suboption()
Definition: Handlers.hh:243
void add_output_suboption()
Add a –output suboption. Expects to allow "STDOUT" to print to screen.
Definition: Handlers.cc:326
std::vector< std::string > m_config_strs
The list of the supercell names of add_configname_suboption()
Definition: Handlers.hh:276
void add_verbosity_suboption()
Add a –verbosity suboption. Default "standard" of "none", "quiet", "standard", "verbose", "debug" or an int 0-100.
Definition: Handlers.cc:289
void add_scelnames_suboption()
Add a –scelnames suboption.
Definition: Handlers.cc:346
virtual void initialize()=0
Fill in the options descriptions accordingly.
ArgHandler::ARG_TYPE ARG_TYPE
Definition: Complete.cc:10
static std::string configname()
Get value_type string for configuration completion.
Definition: Handlers.cc:59
const fs::path settings_path() const
Returns the path corresponding to add_settings_suboption.
Definition: Handlers.cc:180
const std::string & config_str() const
Returns the name of the supercell for add_configname_suboption(), for when multiple=false.
Definition: Handlers.cc:200
void add_help_suboption()
Add a plain –help suboption.
Definition: Handlers.cc:276
void add_settings_suboption(bool required=true)
Add a –settings suboption. Expects a corresponding casm format to go with it.
Definition: Handlers.cc:296
void add_configname_suboption()
Add a –configname suboption.
Definition: Handlers.cc:354
std::string m_config_str
The name of a single configname to go with add_configname_suboption()
Definition: Handlers.hh:265
void add_general_help_suboption()
Add a smart –help suboption that takes "properties" or "operators".
Definition: Handlers.cc:283
void add_configlists_nodefault_suboption()
Add –configs suboption (no default)
Definition: Handlers.cc:267
void add_configlist_suboption(const fs::path &_default="MASTER")
Add –config suboption (defaults to MASTER)
Definition: Handlers.cc:238
Main CASM namespace.
Definition: complete.cpp:8
static void query_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for QUERY.
Definition: Handlers.cc:86
fs::path m_selection_path
The selection string to go with add_config_suboption.
Definition: Handlers.hh:140
const std::string & verbosity_str() const
Returns the string corresponding to add_verbosity_suboption()
Definition: Handlers.cc:176
std::string m_tag
name of the casm command
Definition: Handlers.hh:123
const fs::path & selection_path() const
Returns the string corresponding to add_config_suboption()
Definition: Handlers.cc:168
static std::string path()
Get value_type string for path completion.
Definition: Handlers.cc:39
static std::string supercell()
Get value_type string for supercell completion.
Definition: Handlers.cc:47
void add_input_suboption(bool required=true)
Add a –input suboption. Expects a corresponding casm format to go with it.
Definition: Handlers.cc:311
void add_configlists_suboption(const fs::path &_default="MASTER")
Add –configs suboption (defaults to MASTER)
Definition: Handlers.cc:248
static std::string coordtype()
Get value_type string for coordinate mode completion.
Definition: Handlers.cc:63
iterator begin()
Definition: unique_map.hh:247
static std::string operation()
Get value_type string for operation completion.
Definition: Handlers.cc:55
std::string input_str() const
Returns the path corresponding to add_input_suboption.
Definition: Handlers.cc:184
void add_configlist_nodefault_suboption()
Add –config suboption (no default)
Definition: Handlers.cc:258
const po::options_description & desc()
Get the program options, filled with the initialized values.
Definition: Handlers.cc:160
po::variables_map m_vm
Boost program options variable map.
Definition: Handlers.hh:129
static ARG_TYPE determine_type(const po::option_description &boost_option)
Translate the stored boost value_name into an ARG_TYPE for the completer engine.
Definition: Handlers.cc:13
const std::vector< std::string > & help_opt_vec() const
Returns the list of strings corresponding to add_general_help_suboption()
Definition: Handlers.cc:196
static std::string command()
Get value_type string for command completion (i.e. stuff in your $PATH)
Definition: Handlers.cc:43
fs::path m_output_path
The path that goes with add_output_suboption.
Definition: Handlers.hh:221
static std::string query()
Get value_type string for query completion.
Definition: Handlers.cc:51
OptionHandlerBase(const std::string &init_option_tag)
Define the name of the command during construction.
Definition: Handlers.cc:128
static void void_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for VOID (i.e. do nothing) ...
Definition: Handlers.cc:68
po::options_description m_desc
Boost program options. All the derived classes have them, but will fill them up themselves.
Definition: Handlers.hh:126
const std::vector< std::string > & config_strs() const
Returns the names of the supercells for add_configname_suboption(), for when multiple=false.
Definition: Handlers.cc:204
bool gzip_flag() const
Returns the value assigned for add_gzip_suboption()
Definition: Handlers.cc:192
static void path_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for PATH.
Definition: Handlers.cc:72
void add_gzip_suboption()
Add a –gzip suboption. The value will default to false unless overridden by the derived class...
Definition: Handlers.cc:332
const std::string & supercell_str() const
Returns the name of the supercell for add_scelname_suboption()
Definition: Handlers.cc:208
void add_confignames_suboption()
Add a –confignames suboption.
Definition: Handlers.cc:365
fs::path m_settings_path
The settings path to go with add_settings_suboption()
Definition: Handlers.hh:210
const std::vector< std::string > & supercell_strs() const
Returns the list of the supercells for add_scelnames_suboption()
Definition: Handlers.cc:212
Abstract base class from which all other DatumFormatter classes inherit.
void add_scelname_suboption()
Add a –scelname suboption.
Definition: Handlers.cc:338
bool m_gzip_flag
The bool that goes with add_gzip_suboption.
Definition: Handlers.hh:232
po::variables_map & vm()
Get the variables map.
Definition: Handlers.cc:145
void add_coordtype_suboption()
Add a –coord suboption to specify FRAC or CART.
Definition: Handlers.cc:377
const std::string & tag() const
The desired name for the casm option (Perhaps this should get tied with CommandArg?)
Definition: Handlers.cc:140
std::string m_verbosity_str
The verbosity string to go with add_config_suboption.
Definition: Handlers.hh:188
static void command_to_bash(std::vector< std::string > &arguments)
Fill the output strings with bash completion appropriate values for COMMAND.
Definition: Handlers.cc:77
std::string m_coordtype_str
The enum value in the form of a string for add_coordtype_suboption(). Only the first letter matters...
Definition: Handlers.hh:287
std::vector< std::string > m_supercell_strs
The list of supercell names of add_scelnames_suboption()
Definition: Handlers.hh:254
const fs::path output_path() const
Returns the path corresponding to add_output_suboption()
Definition: Handlers.cc:188
static const std::vector< std::pair< std::string, ARG_TYPE > > m_argument_table
List of pairs relating the value type name of po::option_description to its corresponding argument ty...
Definition: Handlers.hh:86
const_iterator cend() const
Definition: unique_map.hh:267
std::vector< fs::path > m_selection_paths
The selection string to go with add_config_suboption.
Definition: Handlers.hh:151
Parsing dictionary for constructing a DataFormatter object.
void scelname_to_bash(std::vector< std::string > &arguments)
Definition: Handlers.cc:82
const std::vector< fs::path > & selection_paths() const
Returns the string corresponding to add_config_suboption()
Definition: Handlers.cc:172