Jpp  15.0.0-rc.2
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  * Parameter class.
22  *
23  * This class is a simple wrapper around the template parameter with an additional status value.\n
24  * The status value indicates whether the parameter has been defined or not.\n
25  * A parameter is defined when a value has been assigned or correctly read.\n
26  * Note that the comparison between parameter objects is based on the philosophy "undefined = any value".\n
27  * Hence, if any of the two parameter values is undefined, they are considered equal.\n
28  * The comparison between a parameter object with a template value is based
29  * on the internal value of the parameter object via implicit type conversion,
30  * regardless of its state.
31  */
32  template<class T>
33  class JParameter :
34  JComparable< JParameter<T> >
35  {
36  public:
37 
39 
40  /**
41  * Default constructor.
42  */
44  __value(),
45  is_defined(false)
46  {}
47 
48 
49  /**
50  * Constructor.
51  *
52  * \param value value
53  */
54  explicit JParameter(argument_type value) :
55  __value(value),
56  is_defined(true)
57  {}
58 
59 
60  /**
61  * Assignment operator.
62  *
63  * \param value value
64  * \return this parameter
65  */
67  {
68  setValue(value);
69 
70  return *this;
71  }
72 
73 
74  /**
75  * Get value of parameter.
76  *
77  * \return value
78  */
79  const T& getValue() const
80  {
81  return __value;
82  }
83 
84 
85  /**
86  * Get value of parameter.
87  *
88  * \return value
89  */
90  T& getValue()
91  {
92  return __value;
93  }
94 
95 
96  /**
97  * Set value.
98  *
99  * \param value value
100  */
102  {
103  __value = value;
104  is_defined = true;
105  }
106 
107 
108  /**
109  * Type conversion operator.
110  *
111  * \return value
112  */
113  operator const T&() const
114  {
115  return getValue();
116  }
117 
118 
119  /**
120  * Type conversion operator.
121  *
122  * \return value
123  */
124  operator T&()
125  {
126  return getValue();
127  }
128 
129 
130  /**
131  * Get status of parameter.
132  *
133  * \return true if value has been defined (by read or assignment); else false
134  */
135  const bool isDefined() const
136  {
137  return is_defined;
138  }
139 
140 
141  /**
142  * Less than method.
143  *
144  * This method evaluates to true if both parameter values are defined and
145  * this value is less than the value of the given parameter object.
146  *
147  * \param parameter parameter
148  * \return true if both defined and first value less than second value; else false
149  */
150  inline bool less(const JParameter& parameter) const
151  {
152  return this->isDefined() && parameter.isDefined() && this->getValue() < parameter.getValue();
153  }
154 
155 
156  /**
157  * Stream input.
158  *
159  * \param in input stream
160  * \param parameter parameter
161  * \return input stream
162  */
163  friend inline std::istream& operator>>(std::istream& in, JParameter<T>& parameter)
164  {
165  in >> parameter.__value;
166 
167  parameter.is_defined = (bool) in;
168 
169  return in;
170  }
171 
172 
173  /**
174  * Stream output.
175  *
176  * \param out output stream
177  * \param parameter parameter
178  * \return output stream
179  */
180  friend inline std::ostream& operator<<(std::ostream& out, const JParameter<T>& parameter)
181  {
182  return out << parameter.__value;
183  }
184 
185 
186  protected:
189  };
190 }
191 
192 #endif
JParameter()
Default constructor.
Definition: JParameter.hh:43
Parameter class.
Definition: JParameter.hh:33
friend std::istream & operator>>(std::istream &in, JParameter< T > &parameter)
Stream input.
Definition: JParameter.hh:163
T & getValue()
Get value of parameter.
Definition: JParameter.hh:90
const bool isDefined() const
Get status of parameter.
Definition: JParameter.hh:135
JParameter(argument_type value)
Constructor.
Definition: JParameter.hh:54
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
void setValue(argument_type value)
Set value.
Definition: JParameter.hh:101
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:38
JParameter< T > & operator=(argument_type value)
Assignment operator.
Definition: JParameter.hh:66
const T & getValue() const
Get value of parameter.
Definition: JParameter.hh:79
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 source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
bool less(const JParameter &parameter) const
Less than method.
Definition: JParameter.hh:150