Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
after_opts.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file basic/options/after_opts.cc
11 /// @brief Option lookup functions emulating Rosetta++ equivalents for transitional use
12 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com) (port to basic::options)
13 /// @author Original author(s) unknown
14 
15 
16 // Unit headers
18 #include <ObjexxFCL/format.hh> // for SS
19 #include <basic/options/keys/OptionKeys.hh> // for OptionKey, KeyType
20 #include <basic/options/option.hh> // for OptionCollection, Real...
21 #include <iostream> // for operator<<, basic_ostream
22 #include <string> // for char_traits, allocator
23 #include <utility/exit.hh> // for utility_exit
24 #include <utility/keys/AutoKey.hh> // for operator<, operator==
25 #include <utility/keys/KeyLookup.hh> // for key
26 #include <utility/options/IntegerOption.hh> // for IntegerOption
27 #include <utility/options/Option.hh> // for Option
28 #include <utility/options/RealOption.hh> // for RealOption
29 #include <utility/options/ScalarOption_T_.hh> // for ScalarOption_T_, Scala...
30 #include <utility/options/StringOption.hh> // for StringOption
31 #include <utility/options/VectorOption_T_.hh> // for VectorOption_T_
32 
34 
35 
36 namespace basic {
37 namespace options {
38 
39 
40 /// @brief Get key for an option name
41 OptionKey const &
42 key( std::string const & str )
43 {
44  return OptionKeys::key( OptionCollection::find_key_cl( str, std::string(), true ) );
45 }
46 
47 
48 bool
49 truefalseoption( std::string const & str )
50 {
51  return truefalseoption( key( str ) );
52 }
53 
54 
55 bool
57 {
58  if ( option[ key ].user() ) {
59  std::cout << "[T/F OPT]New TRUE value for [-" << key.id() << ']' << std::endl;
60  return true;
61  } else {
62  std::cout << "[T/F OPT]Default FALSE value for [-" << key.id() << ']' << std::endl;
63  return false;
64  }
65 }
66 
67 
68 double
70  std::string const & str
71 )
72 {
73  if ( ! truefalseoption( str ) ) {
74  std::cerr << "realafteroption: missing a required argument: " << str << std::endl;
75  utility_exit();
76  }
77  double val;
78  realafteroption( str, 100, val );
79  return val;
80 }
81 
82 
83 double
85  std::string const & str,
86  double const opt_default
87 )
88 {
89  double value;
90  realafteroption( key( str ), opt_default, value );
91  return value;
92 }
93 
94 
95 void
97  std::string const & str,
98  double const opt_default,
99  double & rnum
100 )
101 {
102  realafteroption( key( str ), opt_default, rnum );
103 }
104 
105 
106 void
108  OptionKey const & key,
109  double const opt_default,
110  double & rnum
111 )
112 {
113  using namespace ObjexxFCL::format;
114  if ( option[ key ].user() ) {
115  rnum = option.option< RealOption >( key );
116  std::cout << "[REAL OPT]New value for [-" << key.id() << "] " << SS( rnum ) << std::endl;
117  } else {
118  rnum = opt_default;
119  std::cout << "[REAL OPT]Default value for [-" << key.id() << "] " << SS( rnum ) << std::endl;
120  }
121 }
122 
123 
124 void
126  std::string const & str,
127  double const default1,
128  double & rnum1,
129  double const default2,
130  double & rnum2
131 )
132 {
133  real2afteroption( key( str ), default1, rnum1, default2, rnum2 );
134 }
135 
136 
137 void
139  OptionKey const & key,
140  double const default1,
141  double & rnum1,
142  double const default2,
143  double & rnum2
144 )
145 {
146  using namespace ObjexxFCL::format;
147  if ( option[ key ].user() ) {
148  RealVectorOption const & opt( option.option< RealVectorOption >( key ) );
149  if ( opt.size() < 2 ) {
150  std::cerr << "real2afteroption: option specified with < 2 values: -" << key.id() << std::endl;
151  utility_exit();
152  }
153  rnum1 = opt[ 1 ];
154  rnum2 = opt[ 2 ];
155  std::cout << "[REAL OPT]New values for [-" << key.id() << "] " << SS( rnum1 ) << SS( rnum2 ) << std::endl;
156  } else {
157  rnum1 = default1;
158  rnum2 = default2;
159  std::cout << "[REAL OPT]Default value for [-" << key.id() << "] " << SS( rnum1 ) << SS( rnum2 ) << std::endl;
160  }
161 }
162 
163 
164 void
166  std::string const & str,
167  double const default1,
168  double & rnum1,
169  double const default2,
170  double & rnum2,
171  double const default3,
172  double & rnum3
173 )
174 {
175  real3afteroption( key( str ), default1, rnum1, default2, rnum2, default3, rnum3 );
176 }
177 
178 
179 void
181  OptionKey const & key,
182  double const default1,
183  double & rnum1,
184  double const default2,
185  double & rnum2,
186  double const default3,
187  double & rnum3
188 )
189 {
190  using namespace ObjexxFCL::format;
191  if ( option[ key ].user() ) {
192  RealVectorOption const & opt( option.option< RealVectorOption >( key ) );
193  if ( opt.size() < 3 ) {
194  std::cerr << "real3afteroption: option specified with < 3 values: -" << key.id() << std::endl;
195  utility_exit();
196  }
197  rnum1 = opt[ 1 ];
198  rnum2 = opt[ 2 ];
199  rnum3 = opt[ 3 ];
200  std::cout << "[REAL OPT]New values for [-" << key.id() << "] " << SS( rnum1 ) << SS( rnum2 ) << SS( rnum3 ) << std::endl;
201  } else {
202  rnum1 = default1;
203  rnum2 = default2;
204  rnum3 = default3;
205  std::cout << "[REAL OPT]Default value for [-" << key.id() << "] " << SS( rnum1 ) << SS( rnum2 ) << SS( rnum3 ) << std::endl;
206  }
207 }
208 
209 
210 int
212  std::string const & str
213 )
214 {
215  if ( !truefalseoption( str ) ) {
216  std::cout << "intafteroption: missing required arg: " << str << std::endl;
217  utility_exit();
218  }
219  int val;
220  intafteroption( key( str ), 100, val );
221  return val;
222 }
223 
224 
225 int
227  std::string const & str,
228  int const opt_default
229 )
230 {
231  int val;
232  intafteroption( key( str ), opt_default, val );
233  return val;
234 }
235 
236 
237 void
239  std::string const & str,
240  int const opt_default,
241  int & inum
242 )
243 {
244  intafteroption( key( str ), opt_default, inum );
245 }
246 
247 
248 void
250  OptionKey const & key,
251  int const opt_default,
252  int & inum
253 )
254 {
255  using namespace ObjexxFCL::format;
256  if ( option[ key ].user() ) {
257  inum = option.option< IntegerOption >( key );
258  std::cout << "[INT OPT]New value for [-" << key.id() << "] " << SS( inum ) << std::endl;
259  } else {
260  inum = opt_default;
261  std::cout << "[INT OPT]Default value for [-" << key.id() << "] " << SS( inum ) << std::endl;
262  }
263 }
264 
265 
266 void
268  std::string const & str,
269  int const opt_default,
270  int & inum
271 )
272 {
273  optional_positive_intafteroption( key( str ), opt_default, inum );
274 }
275 
276 
277 void
279  OptionKey const & key,
280  int const opt_default,
281  int & inum
282 )
283 {
284  using namespace ObjexxFCL::format;
285  if ( option[ key ].user() ) {
286  IntegerVectorOption const & opt( option.option< IntegerVectorOption >( key ) );
287  if ( opt.size() >= 1 ) {
288  inum = opt[ 1 ];
289  std::cout << "[INT OPT]New value for [-" << key.id() << "] " << SS( inum ) << std::endl;
290  } else {
291  inum = opt_default;
292  std::cout << "[INT OPT]Default value for [-" << key.id() << "] " << SS( inum ) << std::endl;
293  }
294  } else {
295  inum = opt_default;
296  std::cout << "[INT OPT]Default value for [-" << key.id() << "] " << SS( inum ) << std::endl;
297  }
298 }
299 
300 
301 void
303  std::string const & str,
304  int const opt_default,
305  int & inum,
306  int const opt_default2,
307  int & inum2
308 )
309 {
310  int2afteroption( key( str ), opt_default, inum, opt_default2, inum2 );
311 }
312 
313 
314 void
316  OptionKey const & key,
317  int const opt_default,
318  int & inum,
319  int const opt_default2,
320  int & inum2
321 )
322 {
323  using namespace ObjexxFCL::format;
324  if ( option[ key ].user() ) {
325  IntegerVectorOption const & opt( option.option< IntegerVectorOption >( key ) );
326  if ( opt.size() < 2 ) {
327  std::cerr << "int2afteroption: option specified with < 2 values: -" << key.id() << std::endl;
328  utility_exit();
329  }
330  inum = opt[ 1 ];
331  inum2 = opt[ 2 ];
332  std::cout << "[INT OPT]New values for [-" << key.id() << "] " << SS( inum ) << SS( inum2 ) << std::endl;
333  } else {
334  inum = opt_default;
335  inum2 = opt_default2;
336  std::cout << "[INT OPT]Default values for [-" << key.id() << "] " << SS( inum ) << SS( inum2 ) << std::endl;
337  }
338 }
339 
340 
341 // require presence of the option
342 
343 std::string
345  std::string const & str
346 )
347 {
348  if ( ! truefalseoption( str ) ) {
349  std::cout << "STOP:: stringafteroption: missing a required argument: " << str << std::endl;
350  utility_exit();
351  }
352  std::string val;
353  stringafteroption( key( str ), "dummy", val );
354  return val;
355 }
356 
357 
358 std::string
360  std::string const & str,
361  std::string const & opt_default
362 )
363 {
364  std::string val;
365  stringafteroption( key( str ), opt_default, val );
366  return val;
367 }
368 
369 
370 void
372  std::string const & str,
373  std::string const & opt_default,
374  std::string & cval
375 )
376 {
377  stringafteroption( key( str ), opt_default, cval );
378 }
379 
380 
381 void
383  OptionKey const & key,
384  std::string const & opt_default,
385  std::string & cval
386 )
387 {
388  if ( option[ key ].user() ) {
389  cval = option.option< StringOption >( key );
390  std::cout << "[STR OPT]New value for [-" << key.id() << "] " << cval << '.' << std::endl;
391  } else {
392  cval = opt_default;
393  std::cout << "[STR OPT]Default value for [-" << key.id() << "] " << cval << '.' << std::endl;
394  }
395 }
396 
397 
398 void
400  std::string const & str,
401  char const opt_default,
402  char & cval
403 )
404 {
405  stringafteroption( key( str ), opt_default, cval );
406 }
407 
408 
409 void
411  OptionKey const & key,
412  char const opt_default,
413  char & cval
414 )
415 {
416  if ( option[ key ].user() ) {
417  StringOption const & opt( option.option< StringOption >( key ) );
418  cval = ( opt().length() > 0 ? opt()[ 0 ] : ' ' );
419  std::cout << "[STR OPT]New value for [-" << key.id() << "] " << cval << '.' << std::endl;
420  } else {
421  cval = opt_default;
422  std::cout << "[STR OPT]Default value for [-" << key.id() << "] " << cval << '.' << std::endl;
423  }
424 }
425 
426 
427 } // namespace options
428 } // namespace basic
ocstream cerr(std::cerr)
Wrapper around std::cerr.
Definition: ocstream.hh:290
Program real option class.
Program integer vector option class.
std::string stringafteroption(std::string const &str)
Definition: after_opts.cc:344
std::string SS(bool const &t)
Single-Spaced Format: bool Specialization.
Definition: format.cc:92
BooleanOptionKey const user("options:user")
Definition: OptionKeys.hh:40
Program string option class.
Program vector-valued option abstract base class.
Abstract automatic hidden index key for options.
Definition: OptionKey.hh:35
Program scalar-valued option abstract base class.
Key lookup map and collection and functors.
utility::options::OptionKey OptionKey
Definition: after_opts.hh:35
Program option interface class.
OptionKey const & key(std::string const &str)
Get key for an option name.
Definition: after_opts.cc:42
member1 value
Definition: Tag.cc:296
static std::string find_key_cl(std::string const &key_string, std::string const &cid, bool const top)
Find a user-specified option key in a command line context.
void real3afteroption(std::string const &str, double const default1, double &rnum1, double const default2, double &rnum2, double const default3, double &rnum3)
Definition: after_opts.cc:165
Program exit functions and macros.
basic::options::OptionKeys collection
#define utility_exit()
Macro function wrappers for utility::exit.
Definition: exit.hh:41
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
BooleanOption const & option(BooleanOptionKey const &key) const
Option by BooleanOptionKey.
utility::options::OptionCollection option
OptionCollection global.
Definition: option.cc:45
Program real option class.
Definition: RealOption.hh:40
Program string option class.
Definition: StringOption.hh:35
Option lookup functions emulating Rosetta++ equivalents for transitional use.
Program real vector option class.
int intafteroption(std::string const &str)
Definition: after_opts.cc:211
void optional_positive_intafteroption(std::string const &str, int const opt_default, int &inum)
Definition: after_opts.cc:267
Program integer option class.
double realafteroption(std::string const &str)
Definition: after_opts.cc:69
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
bool truefalseoption(std::string const &str)
Definition: after_opts.cc:49
Program integer option class.
Program options global and initialization function.
void real2afteroption(std::string const &str, double const default1, double &rnum1, double const default2, double &rnum2)
Definition: after_opts.cc:125
Automatic hidden index key abstract base class.
void int2afteroption(std::string const &str, int const opt_default, int &inum, int const opt_default2, int &inum2)
Definition: after_opts.cc:302
std::string const & id() const
ID.
Definition: AutoKey.hh:227
Size size() const
Size (number of values)