Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Option.hh
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 utility/options/Option.hh
11 /// @brief Program option interface class
12 /// @author Stuart G. Mentzer (Stuart_Mentzer@objexx.com)
13 /// @author Modified by Sergey Lyskov (Sergey.Lyskov@jhu.edu)
14 
15 
16 #ifndef INCLUDED_utility_options_Option_hh
17 #define INCLUDED_utility_options_Option_hh
18 
19 
20 // Unit headers
22 
23 // Package headers
26 // C++ headers
27 #include <cstddef>
28 #include <string>
29 
30 
31 namespace utility {
32 namespace options {
33 
34 
35 /// @brief Program option interface class
36 class Option
37 {
38 
39 
40 protected: // Types
41 
42 
43  /// @brief Option state enumeration
44  enum State {
45  INACTIVE, // No default or user-specified value
46  DEFAULT, // Default value active
47  USER // User-specified value active
48  };
49 
50 
51 public: // Types
52 
53 
54  // STL/boost style
56  typedef std::size_t size_type;
57 
58  // Project style
59  typedef OptionKey Key;
60  typedef std::size_t Size;
61 
62 
63 protected: // Creation
64 
65 
66  /// @brief Default constructor
67  inline
68  Option() :
69  is_group_(false),
70  been_accessed_(false),
71  restricted_access_(false)
72  {}
73 
74 
75  /// @brief Copy constructor
76  inline
77  Option( Option const & option) :
78  is_group_(option.is_group_),
79  been_accessed_(false),
81  {}
82 
83 
84 public: // Creation
85 
86 
87  /// @brief Clone this
88  virtual
89  Option *
90  clone() const = 0;
91 
92 
93  /// @brief Destructor
94  inline
95  virtual
97  {}
98 
99 
100 protected: // Assignment
101 
102 
103  /// @brief Copy assignment
104  inline
105  Option &
107  {
108  if ( this != &option ) {
109  is_group_ = option.is_group_;
112  }
113  return *this;
114  }
115 
116 
117 public: // Methods
118 
119 
120  /// @brief Activate
121  virtual
122  Option &
123  activate() = 0;
124 
125 
126  /// @brief Deactivate
127  virtual
128  Option &
129  deactivate() = 0;
130 
131 
132  /// @brief Set to default value, if any
133  virtual
134  Option &
135  to_default() = 0;
136 
137 
138  /// @brief Clear
139  virtual
140  Option &
141  clear() = 0;
142 
143 
144  /// @brief Value assignment from a command line string
145  virtual
146  Option &
147  cl_value( std::string const & value_str ) = 0;
148 
149 
150  /// @brief Legal specifications check: Report and return error state
151  virtual
152  bool
153  legal_specs_report() const = 0;
154 
155 
156  /// @brief Legal value limits check: Report and return error state
157  virtual
158  bool
159  legal_limits_report() const = 0;
160 
161 
162  /// @brief Legal size limits check: Report and return error state
163  virtual
164  bool
165  legal_size_report() const = 0;
166 
167 
168  /// @brief Legal default value check: Report and return error state
169  virtual
170  bool
171  legal_default_report() const = 0;
172 
173 
174  /// @brief Legal default value check
175  virtual
176  void
177  legal_default_check() const = 0;
178 
179 
180  /// @brief Legal value check: Report and return error state
181  virtual
182  bool
183  legal_report() const = 0;
184 
185 
186  /// @brief Legal value check
187  virtual
188  void
189  legal_check() const = 0;
190 
191 
192  /// @brief Required specified option check: Report and return error state
193  virtual
194  bool
195  specified_report() const = 0;
196 
197 
198  /// @brief Required specified option check
199  virtual
200  void
201  specified_check() const = 0;
202 
203 
204 public: // Properties
205 
206  Option &
207  is_group( bool value ) {
208  is_group_ = value;
209  return *this;
210  }
211 
212  /// @brief Is this the synonymous option for an option group (e.g. -in:file:file)
213  bool
214  is_group() const { return is_group_; }
215 
216  /// @brief Key
217  virtual
218  Key const &
219  key() const = 0;
220 
221 
222  /// @brief ID
223  virtual
224  std::string const &
225  id() const = 0;
226 
227 
228  /// @brief Identifier
229  virtual
230  std::string const &
231  identifier() const = 0;
232 
233 
234  /// @brief Code
235  virtual
236  std::string const &
237  code() const = 0;
238 
239 
240  /// @brief Name
241  virtual
242  std::string const &
243  name() const = 0;
244 
245 
246  /// @brief Description
247  virtual
248  std::string const &
249  description() const = 0;
250 
251 
252  /// @brief short_Description
253  virtual
254  std::string const &
255  short_description() const = 0;
256 
257 
258  /// @brief Legal or inactive default value?
259  virtual
260  bool
261  legal_default() const = 0;
262 
263 
264  /// @brief Legal value?
265  virtual
266  bool
267  legal() const = 0;
268 
269 
270  /// @brief Has a default?
271  virtual
272  bool
273  has_default() const = 0;
274 
275 
276  /// @brief Default active?
277  virtual
278  bool
279  default_active() const = 0;
280 
281 
282  /// @brief Default inactive?
283  virtual
284  bool
285  default_inactive() const = 0;
286 
287 
288  /// @brief Active? That is, the option has some value, either the default one or specified on the command line.
289  virtual
290  bool
291  active() const = 0;
292 
293 
294  /// @brief User-specified? That is, the option value was specified on the command line.
295  /// You should probably use active() instead in almost all cases!
296  virtual
297  bool
298  user() const = 0;
299 
300 
301  /// @brief Is a string readable as this option's value type?
302  virtual
303  bool
304  is_value( std::string const & value_str ) const = 0;
305 
306 
307  /// @brief Is a string readable as this option's value type and a legal command line value?
308  virtual
309  bool
310  is_cl_value( std::string const & value_str ) const = 0;
311 
312 
313  /// @brief Can another value be added and stay within any size constraints?
314  virtual
315  bool
316  can_hold_another() const = 0;
317 
318 
319  /// @brief Default size (number of default values)
320  virtual
321  Size
322  default_size() const = 0;
323 
324 
325  /// @brief Number of default values (default size)
326  virtual
327  Size
328  n_default_value() const = 0;
329 
330 
331  /// @brief Size (number of values)
332  virtual
333  Size
334  size() const = 0;
335 
336 
337  /// @brief Number of values (size)
338  virtual
339  Size
340  n_value() const = 0;
341 
342 
343  /// @brief Option type code string representation
344  virtual
345  std::string
346  type_string() const = 0;
347 
348 
349  /// @brief Legal value string representation
350  virtual
351  std::string
352  legal_string() const = 0;
353 
354 
355  /// @brief Size constraint string representation
356  virtual
357  std::string
358  size_constraint_string() const = 0;
359 
360 
361  /// @brief Default value string representation
362  virtual
363  std::string
364  default_string() const = 0;
365 
366 
367  /// @brief Value string representation
368  virtual
369  std::string
370  value_string() const = 0;
371 
372 
373  /// @brief =Value string representation
374  virtual
375  std::string
376  equals_string() const = 0;
377 
378 
379  /// @brief Set access property to true.
380  void been_accessed() const { been_accessed_ = true; }
381  void set_accessed( bool setting ) const { been_accessed_ = setting; }
382 
383  /// @brief Return true if option value was anyhow accessed.
384  bool is_been_accessed() const { return been_accessed_; }
385 
386  /// @brief Restrict direct access to option for general use.
387  /// @details In the past, protocols were able to access the values
388  /// of options in the option system directly. However this tied
389  /// protocol behavior tightly to setting specific options on the
390  /// command line, making it difficult to use Rosetta using other
391  /// workflows. Now, options are accessed through the resource
392  /// manager, which has control over which options are passed to
393  /// which protocols.
394  ///
395  /// basic::resource_manager::ResourceManager::get_instance()->get_option(key);
396  ///
397  /// To incrementally deprectate direct usage of options, an option
398  /// is set to have restricted access in basic/options/options_rosetta.py
399  ///
400  Option &
401  restrict_access( bool setting ) {
402  restricted_access_ = setting;
403  return *this;
404  }
405 
406  void
408  bool do_check
409  ) const {
410  if ( restricted_access_ && do_check ) {
412  "Attempting to access option '" + code() + "' that has restricted access. Please use 'basic::resource_manager::ResourceManager::get_instance()->get_option( " + code() + " );' instead.");
413  }
414  }
415 
416 public: // Comparison
417 
418 
419  /// @brief Option < Option
420  /// @note Key-based ordering
421  /// @note Needed for use as option in associative containers
422  friend
423  inline
424  bool
425  operator <( Option const & a, Option const & b )
426  {
427  return ( a.key() < b.key() );
428  }
429 
430 
431 private: // Private data members
432 
433  /// @brief Is this a synonymous option for an option group (e.g. -in:file:file)
434  bool is_group_;
435 
436  /// @brief flag, will be true if application was trying to anyhow access/check option value.
437  /// Used to create option usage reports.
438  /// False by default, any access functions ie: user(), active(), value(), operator()() will set it to true.
439  mutable bool been_accessed_;
440 
441  /// @brief Is directly accessing this option deprecated in favor of
442  /// accessing it through the resource manager?
444 
445 }; // Option
446 
447 
448 // Friend function namespace declarations
449 
450 
451 /// @brief Option < Option
452 bool
453 operator <( Option const & a, Option const & b );
454 
455 
456 } // namespace options
457 } // namespace utility
458 
459 
460 #endif // INCLUDED_utility_options_Option_HH
void been_accessed() const
Set access property to true.
Definition: Option.hh:380
Option & operator=(Option const &option)
Copy assignment.
Definition: Option.hh:106
virtual bool is_value(std::string const &value_str) const =0
Is a string readable as this option's value type?
virtual Option & cl_value(std::string const &value_str)=0
Value assignment from a command line string.
virtual bool specified_report() const =0
Required specified option check: Report and return error state.
bool is_group_
Is this a synonymous option for an option group (e.g. -in:file:file)
Definition: Option.hh:434
virtual bool legal_limits_report() const =0
Legal value limits check: Report and return error state.
virtual Option * clone() const =0
Clone this.
virtual std::string const & identifier() const =0
Identifier.
virtual ~Option()
Destructor.
Definition: Option.hh:96
virtual Size size() const =0
Size (number of values)
Option & restrict_access(bool setting)
Restrict direct access to option for general use.
Definition: Option.hh:401
virtual std::string const & id() const =0
ID.
virtual bool legal_specs_report() const =0
Legal specifications check: Report and return error state.
Option & is_group(bool value)
Definition: Option.hh:207
friend bool operator<(Option const &a, Option const &b)
Option < Option.
Definition: Option.hh:425
bool been_accessed_
flag, will be true if application was trying to anyhow access/check option value. Used to create opti...
Definition: Option.hh:439
virtual bool default_active() const =0
Default active?
virtual bool active() const =0
Active? That is, the option has some value, either the default one or specified on the command line...
virtual Size default_size() const =0
Default size (number of default values)
bool operator<(Option const &a, Option const &b)
Option < Option.
Definition: Option.hh:425
std::size_t Size
Definition: Option.hh:60
virtual std::string equals_string() const =0
=Value string representation
virtual std::string size_constraint_string() const =0
Size constraint string representation.
virtual void legal_check() const =0
Legal value check.
Abstract automatic hidden index key for options.
Definition: OptionKey.hh:35
virtual Option & activate()=0
Activate.
Abstract automatic hidden index key for options.
common derived classes for thrown exceptions
virtual Option & to_default()=0
Set to default value, if any.
Option(Option const &option)
Copy constructor.
Definition: Option.hh:77
virtual std::string legal_string() const =0
Legal value string representation.
std::size_t size_type
Definition: Option.hh:56
virtual std::string const & code() const =0
Code.
Option()
Default constructor.
Definition: Option.hh:68
virtual Size n_value() const =0
Number of values (size)
State
Option state enumeration.
Definition: Option.hh:44
utility::options::Option forward declarations
member1 value
Definition: Tag.cc:296
virtual std::string type_string() const =0
Option type code string representation.
virtual bool legal() const =0
Legal value?
virtual bool user() const =0
User-specified? That is, the option value was specified on the command line. You should probably use ...
virtual bool legal_size_report() const =0
Legal size limits check: Report and return error state.
virtual bool can_hold_another() const =0
Can another value be added and stay within any size constraints?
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
virtual void legal_default_check() const =0
Legal default value check.
virtual void specified_check() const =0
Required specified option check.
virtual Key const & key() const =0
Key.
virtual bool legal_report() const =0
Legal value check: Report and return error state.
void set_accessed(bool setting) const
Definition: Option.hh:381
bool is_been_accessed() const
Return true if option value was anyhow accessed.
Definition: Option.hh:384
Program option interface class.
Definition: Option.hh:36
virtual Option & deactivate()=0
Deactivate.
virtual bool default_inactive() const =0
Default inactive?
virtual std::string const & short_description() const =0
short_Description
bool is_group() const
Is this the synonymous option for an option group (e.g. -in:file:file)
Definition: Option.hh:214
virtual bool legal_default() const =0
Legal or inactive default value?
void check_restricted_access(bool do_check) const
Definition: Option.hh:407
bool restricted_access_
Is directly accessing this option deprecated in favor of accessing it through the resource manager...
Definition: Option.hh:443
virtual std::string default_string() const =0
Default value string representation.
virtual std::string value_string() const =0
Value string representation.
virtual std::string const & name() const =0
Name.
virtual bool is_cl_value(std::string const &value_str) const =0
Is a string readable as this option's value type and a legal command line value?
virtual Size n_default_value() const =0
Number of default values (default size)
virtual bool has_default() const =0
Has a default?
virtual Option & clear()=0
Clear.
virtual std::string const & description() const =0
Description.
virtual bool legal_default_report() const =0
Legal default value check: Report and return error state.
rule< Scanner, option_closure::context_t > option
Definition: Tag.cc:378