libpnicore
config_option.hpp
1 //
2 // (c) Copyright 2012 DESY, Eugen Wintersberger <eugen.wintersberger@desy.de>
3 //
4 // This file is part of libpnicore.
5 //
6 // libpnicore is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // libpnicore is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with libpnicore. If not, see <http://www.gnu.org/licenses/>.
18 //
19 // ============================================================================
20 //
21 // Created on: Dec 27, 2012
22 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
23 //
24 
25 #pragma once
26 
27 #include "../types.hpp"
28 
29 
30 namespace pni{
31 namespace core{
32 
46  template<typename T>
48  {
49  private:
51  string _long_name;
52 
54  string _short_name;
55 
57  string _description;
58 
61 
63  const T *_ext_reference;
64 
67 
68  public:
69  //------------------------------------------------------------------
71  config_option();
72 
73  //------------------------------------------------------------------
82  config_option(const string &lname,const string &sname,
83  const string &description,T *exref=nullptr);
84 
85  //-----------------------------------------------------------------
95  config_option(const string &lname,const string &sname,
96  const string &description,T default_value,
97  T *exref=nullptr);
98 
99  //-----------------------------------------------------------------
101  virtual ~config_option() {}
102 
103  //-----------------------------------------------------------------
105  string long_name() const { return _long_name; }
106 
107  //-----------------------------------------------------------------
109  string short_name() const { return _short_name; }
110 
111  //-----------------------------------------------------------------
113  string description() const { return _description; }
114 
115  //-----------------------------------------------------------------
117  T default_value() const { return _default_value; }
118 
119  //-----------------------------------------------------------------
121  const T *external_reference() const { return _ext_reference; }
122 
123  //-----------------------------------------------------------------
125  bool has_default() const { return _has_default; }
126 
127  };
128 
129  //--------------------------------------------------------------------------
130  template<typename T> config_option<T>::config_option():
131  _long_name(),
132  _short_name(),
133  _description(),
134  _default_value(),
135  _ext_reference(nullptr),
136  _has_default(false)
137  {}
138 
139  //--------------------------------------------------------------------------
140  template<typename T>
141  config_option<T>::config_option(const string &lname,const string &sname,
142  const string &description,T *exref):
143  _long_name(lname),
144  _short_name(sname),
145  _description(description),
146  _default_value(),
147  _ext_reference(exref),
148  _has_default(false)
149  {}
150 
151  //--------------------------------------------------------------------------
152  template<typename T>
153  config_option<T>::config_option(const string &lname,const string &sname,
154  const string &description,T default_value,
155  T *exref):
156  _long_name(lname),
157  _short_name(sname),
158  _description(description),
159  _default_value(default_value),
160  _ext_reference(exref),
161  _has_default(true)
162  {}
163 
164 //end of namespace
165 }
166 }
string _long_name
long name of the option
Definition: config_option.hpp:51
class describing a program option
Definition: config_option.hpp:47
const T * _ext_reference
external reference
Definition: config_option.hpp:63
string _short_name
short name of the option
Definition: config_option.hpp:54
string long_name() const
get long name
Definition: config_option.hpp:105
bool has_default() const
check if option has a default value
Definition: config_option.hpp:125
Definition: add_op.hpp:29
string short_name() const
get short name
Definition: config_option.hpp:109
config_option()
default constructor
Definition: config_option.hpp:130
T _default_value
default value
Definition: config_option.hpp:60
const T * external_reference() const
get external refernce
Definition: config_option.hpp:121
string _description
description (help text)
Definition: config_option.hpp:57
bool _has_default
determin if option has default value
Definition: config_option.hpp:66
virtual ~config_option()
destructor
Definition: config_option.hpp:101
T default_value() const
get default value
Definition: config_option.hpp:117
string description() const
get description
Definition: config_option.hpp:113