Scarab  v1.5.3
Project 8 C++ Utility Library
configurator.hh
Go to the documentation of this file.
1 /*
2  * configurator.hh
3  *
4  * Created on: Nov 5, 2013
5  * Author: nsoblath
6  */
7 
8 #ifndef SCARAB_CONFIGURATOR_HH_
9 #define SCARAB_CONFIGURATOR_HH_
10 
11 #include "error.hh"
12 #include "param.hh"
13 
14 namespace scarab
15 {
17  {
18  public:
19  configurator( int an_argc, char** an_argv, scarab::param_node* a_default = NULL );
20  virtual ~configurator();
21 
22  const std::string& exe_name() const;
23 
25  const scarab::param_node& config() const;
26 
27  bool help_flag() const;
28  bool version_flag() const;
29 
30  template< typename XReturnType >
31  XReturnType get( const std::string& a_name ) const;
32 
33  template< typename XReturnType >
34  XReturnType get( const std::string& a_name, XReturnType a_default ) const;
35 
36  private:
37  std::string f_exe_name; // the name of the executable being used
38 
42 
44 
45  std::string f_string_buffer;
46  };
47 
48  template< typename XReturnType >
49  XReturnType configurator::get( const std::string& a_name ) const
50  {
51  f_param_buffer = const_cast< scarab::param* >( f_master_config->at( a_name ) );
52  if( f_param_buffer != NULL && f_param_buffer->is_value() )
53  {
54  return f_param_buffer->as_value().get< XReturnType >();
55  }
56  throw error() << "configurator does not have a value for <" << a_name << ">";
57  }
58 
59  template< typename XReturnType >
60  XReturnType configurator::get( const std::string& a_name, XReturnType a_default ) const
61  {
62  f_param_buffer = const_cast< scarab::param* >( f_master_config->at( a_name ) );
63  if( f_param_buffer != NULL && f_param_buffer->is_value() )
64  {
65  return f_param_buffer->as_value().get< XReturnType >();
66  }
67  return a_default;
68 
69  }
70 
71  inline bool configurator::help_flag() const
72  {
73  return f_help_flag;
74  }
75 
76  inline bool configurator::version_flag() const
77  {
78  return f_version_flag;
79  }
80 
81  inline const std::string& configurator::exe_name() const
82  {
83  return f_exe_name;
84  }
85 
87  {
88  return *f_master_config;
89  }
90 
92  {
93  return *f_master_config;
94  }
95 
96 
97 } /* namespace psyllid */
98 #endif /* PSYLLID_CONFIGURATOR_HH_ */
bool help_flag() const
Definition: configurator.hh:71
virtual bool is_value() const
Definition: param.hh:410
XValType get() const
Definition: param.hh:539
param_value & as_value()
Definition: param.hh:425
bool version_flag() const
Definition: configurator.hh:76
const std::string & exe_name() const
Definition: configurator.hh:81
scarab::param * f_param_buffer
Definition: configurator.hh:43
scarab::param_node & config()
Definition: configurator.hh:86
const param * at(const std::string &a_name) const
Definition: param.hh:1024
scarab::param_node * f_master_config
Definition: configurator.hh:39
std::string f_string_buffer
Definition: configurator.hh:45
configurator(int an_argc, char **an_argv, scarab::param_node *a_default=NULL)
Definition: configurator.cc:28
XReturnType get(const std::string &a_name) const
Definition: configurator.hh:49
std::string f_exe_name
Definition: configurator.hh:37