Jpp  18.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JParameter.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JPARAMETER__
2 #define __JLANG__JPARAMETER__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "JLang/JClass.hh"
8 #include "JLang/JComparable.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JLANG {}
16 namespace JPP { using namespace JLANG; }
17 
18 namespace JLANG {
19 
20 
21  /**
22  * Parameter class.
23  *
24  * This class is a simple wrapper around the template parameter with an additional status value.\n
25  * The status value indicates whether the parameter has been defined or not.\n
26  * A parameter is defined when a value has been assigned or correctly read.\n
27  * Note that the comparison between parameter objects is based on the philosophy "undefined = any value".\n
28  * Hence, if any of the two parameter values is undefined, they are considered equal.\n
29  * The comparison between a parameter object with a template value is based
30  * on the internal value of the parameter object via implicit type conversion,
31  * regardless of its state.
32  */
33  template<class T>
34  class JParameter :
35  public JComparable< JParameter<T> >
36  {
37  public:
38 
40 
41 
42  /**
43  * Default constructor.
44  */
46  __value(),
47  is_defined(false)
48  {}
49 
50 
51  /**
52  * Constructor.
53  *
54  * \param value value
55  */
56  explicit JParameter(argument_type value) :
57  __value(value),
58  is_defined(true)
59  {}
60 
61 
62  /**
63  * Assignment operator.
64  *
65  * \param value value
66  * \return this parameter
67  */
69  {
70  setValue(value);
71 
72  return *this;
73  }
74 
75 
76  /**
77  * Get value of parameter.
78  *
79  * \return value
80  */
81  const T& getValue() const
82  {
83  return __value;
84  }
85 
86 
87  /**
88  * Get value of parameter.
89  *
90  * \return value
91  */
92  T& getValue()
93  {
94  return __value;
95  }
96 
97 
98  /**
99  * Set value.
100  *
101  * \param value value
102  */
104  {
105  __value = value;
106  is_defined = true;
107  }
108 
109 
110  /**
111  * Type conversion operator.
112  *
113  * \return value
114  */
115  operator const T&() const
116  {
117  return getValue();
118  }
119 
120 
121  /**
122  * Type conversion operator.
123  *
124  * \return value
125  */
126  operator T&()
127  {
128  return getValue();
129  }
130 
131 
132  /**
133  * Get status of parameter.
134  *
135  * \return true if value has been defined (by read or assignment); else false
136  */
137  const bool isDefined() const
138  {
139  return is_defined;
140  }
141 
142 
143  /**
144  * Less than method.
145  *
146  * This method evaluates to true if both parameter values are defined and
147  * this value is less than the value of the given parameter object.
148  *
149  * \param parameter parameter
150  * \return true if both defined and first value less than second value; else false
151  */
152  inline bool less(const JParameter<T>& parameter) const
153  {
154  return this->isDefined() && parameter.isDefined() && this->getValue() < parameter.getValue();
155  }
156 
157 
158  /**
159  * Stream input.
160  *
161  * \param in input stream
162  * \param parameter parameter
163  * \return input stream
164  */
165  friend inline std::istream& operator>>(std::istream& in, JParameter<T>& parameter)
166  {
167  in >> parameter.__value;
168 
169  parameter.is_defined = (bool) in;
170 
171  return in;
172  }
173 
174 
175  /**
176  * Stream output.
177  *
178  * \param out output stream
179  * \param parameter parameter
180  * \return output stream
181  */
182  friend inline std::ostream& operator<<(std::ostream& out, const JParameter<T>& parameter)
183  {
184  if (parameter.is_defined) {
185  out << parameter.__value;
186  }
187 
188  return out;
189  }
190 
191 
192  protected:
195  };
196 }
197 
198 #endif
JParameter()
Default constructor.
Definition: JParameter.hh:45
Parameter class.
Definition: JParameter.hh:34
friend std::istream & operator>>(std::istream &in, JParameter< T > &parameter)
Stream input.
Definition: JParameter.hh:165
T & getValue()
Get value of parameter.
Definition: JParameter.hh:92
const bool isDefined() const
Get status of parameter.
Definition: JParameter.hh:137
bool less(const JParameter< T > &parameter) const
Less than method.
Definition: JParameter.hh:152
JParameter(argument_type value)
Constructor.
Definition: JParameter.hh:56
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
void setValue(argument_type value)
Set value.
Definition: JParameter.hh:103
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
JClass< T >::argument_type argument_type
Definition: JParameter.hh:39
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
JParameter< T > & operator=(argument_type value)
Assignment operator.
Definition: JParameter.hh:68
const T & getValue() const
Get value of parameter.
Definition: JParameter.hh:81