Jpp  17.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  * Default constructor.
43  */
45  __value(),
46  is_defined(false)
47  {}
48 
49 
50  /**
51  * Constructor.
52  *
53  * \param value value
54  */
55  explicit JParameter(const argument_type& value) :
56  __value(value),
57  is_defined(true)
58  {}
59 
60 
61  /**
62  * Assignment operator.
63  *
64  * \param value value
65  * \return this parameter
66  */
68  {
69  setValue(value);
70 
71  return *this;
72  }
73 
74 
75  /**
76  * Get value of parameter.
77  *
78  * \return value
79  */
80  const T& getValue() const
81  {
82  return __value;
83  }
84 
85 
86  /**
87  * Get value of parameter.
88  *
89  * \return value
90  */
91  T& getValue()
92  {
93  return __value;
94  }
95 
96 
97  /**
98  * Set value.
99  *
100  * \param value value
101  */
102  void setValue(const argument_type& value)
103  {
104  __value = value;
105  is_defined = true;
106  }
107 
108 
109  /**
110  * Type conversion operator.
111  *
112  * \return value
113  */
114  operator const T&() const
115  {
116  return getValue();
117  }
118 
119 
120  /**
121  * Type conversion operator.
122  *
123  * \return value
124  */
125  operator T&()
126  {
127  return getValue();
128  }
129 
130 
131  /**
132  * Get status of parameter.
133  *
134  * \return true if value has been defined (by read or assignment); else false
135  */
136  const bool isDefined() const
137  {
138  return is_defined;
139  }
140 
141 
142  /**
143  * Less than method.
144  *
145  * This method evaluates to true if both parameter values are defined and
146  * this value is less than the value of the given parameter object.
147  *
148  * \param parameter parameter
149  * \return true if both defined and first value less than second value; else false
150  */
151  inline bool less(const JParameter<T>& parameter) const
152  {
153  return this->isDefined() && parameter.isDefined() && this->getValue() < parameter.getValue();
154  }
155 
156 
157  /**
158  * Stream input.
159  *
160  * \param in input stream
161  * \param parameter parameter
162  * \return input stream
163  */
164  friend inline std::istream& operator>>(std::istream& in, JParameter<T>& parameter)
165  {
166  in >> parameter.__value;
167 
168  parameter.is_defined = (bool) in;
169 
170  return in;
171  }
172 
173 
174  /**
175  * Stream output.
176  *
177  * \param out output stream
178  * \param parameter parameter
179  * \return output stream
180  */
181  friend inline std::ostream& operator<<(std::ostream& out, const JParameter<T>& parameter)
182  {
183  if (parameter.is_defined) {
184  out << parameter.__value;
185  }
186 
187  return out;
188  }
189 
190 
191  protected:
194  };
195 }
196 
197 #endif
JParameter()
Default constructor.
Definition: JParameter.hh:44
JParameter(const argument_type &value)
Constructor.
Definition: JParameter.hh:55
Parameter class.
Definition: JParameter.hh:34
friend std::istream & operator>>(std::istream &in, JParameter< T > &parameter)
Stream input.
Definition: JParameter.hh:164
T & getValue()
Get value of parameter.
Definition: JParameter.hh:91
const bool isDefined() const
Get status of parameter.
Definition: JParameter.hh:136
bool less(const JParameter< T > &parameter) const
Less than method.
Definition: JParameter.hh:151
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
do set_variable OUTPUT_DIRECTORY $WORKDIR T
void setValue(const argument_type &value)
Set value.
Definition: JParameter.hh:102
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
JParameter< T > & operator=(const argument_type &value)
Assignment operator.
Definition: JParameter.hh:67
const T & getValue() const
Get value of parameter.
Definition: JParameter.hh:80
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:46