Jpp  18.3.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JOscParametersInterface.hh
Go to the documentation of this file.
1 #ifndef __JOSCPROB__JOSCPARAMETERSINTERFACE__
2 #define __JOSCPROB__JOSCPARAMETERSINTERFACE__
3 
4 #include <iostream>
5 #include <iomanip>
6 #include <string>
7 
8 #include "Jeep/JComment.hh"
9 #include "Jeep/JProperties.hh"
10 
11 #include "JSystem/JStat.hh"
12 
13 #include "JIO/JSerialisable.hh"
14 
15 #include "JLang/JClonable.hh"
16 #include "JLang/JParameter.hh"
17 #include "JLang/JStringStream.hh"
19 
20 #include "JTools/JGrid.hh"
21 
23 
24 
25 /**
26  * \author bjung, mdejong
27  */
28 
29 namespace JOSCPROB {}
30 namespace JPP { using namespace JOSCPROB; }
31 
32 namespace JOSCPROB {
33 
34  using JIO::JReader;
35  using JIO::JWriter;
36  using JIO::JSerialisable;
37 
38  using JLANG::JClonable;
40 
41 
42  /**
43  * Interface class for sets of oscillation parameters.
44  */
45  template<class T = double>
47  public JClonable<JOscParametersInterface<T> >,
48  public JSerialisable
49  {
50  public:
51 
54 
56 
58 
59 
60  /**
61  * Default constructor.
62  */
64  {}
65 
66 
67  /**
68  * Virtual destructor.
69  */
71  {}
72 
73 
74  /**
75  * Get properties of this class.
76  *
77  * \param equation equation parameters
78  * \return properties of this class
79  */
81 
82 
83  /**
84  * Get properties of this class.
85  *
86  * \param equation equation parameters
87  * \return properties of this class
88  */
90 
91 
92  /**
93  * Get instance of properties of this class.
94  *
95  * \param equation equation parameters
96  * \return instance of properties of this class
97  */
99  {
100  static JProperties properties = getProperties(equation);
101 
102  return properties;
103  }
104 
105 
106  /**
107  * Get instance of properties of this class.
108  *
109  * \param equation equation parameters
110  * \return instance of properties of this class
111  */
113  {
114  static JProperties properties = getProperties(equation);
115 
116  return properties;
117  }
118 
119 
120  /**
121  * Get oscillation parameters.
122  *
123  * \return reference to oscillation parameters
124  */
126  {
127  return static_cast<JOscParametersInterface_t&>(*this);
128  }
129 
130 
131  /**
132  * Set value for a given oscillation parameter.
133  *
134  * \param name parameter name
135  * \param value parameter value
136  */
137  void set(const std::string& name,
138  argument_type value)
139  {
140  using namespace std;
141  using namespace JPP;
142 
143  JProperties& properties = this->getPropertiesInstance();
144 
145  JOscParameter_t& parameter = properties.getValue<JOscParameter_t>(name);
146 
147  parameter.setValue(value);
148  }
149 
150 
151  /**
152  * Set value for given list of oscillation parameters.
153  *
154  * \param name parameter name
155  * \param value parameter value
156  * \param args remaining pairs of parameter names and values
157  */
158  template<class ...Args>
159  void set(const std::string& name,
160  argument_type value,
161  const Args& ...args)
162  {
163  set(name, value);
164  set(args...);
165  }
166 
167 
168  /**
169  * Set oscillation parameters.
170  *
171  * \param parameters oscillation parameters
172  */
174  {
175  using namespace std;
176  using namespace JPP;
177 
178  const JProperties& properties = parameters.getPropertiesInstance();
179 
180  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
181  const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
182 
183  this->set(i->first, parameter.getValue());
184  }
185  }
186 
187 
188  /**
189  * Check validity of oscillation parameters.
190  *
191  * \return true if all oscillation parameters are valid; else false
192  */
193  bool is_valid() const
194  {
195  bool valid = true;
196 
197  const JProperties& properties = this->getPropertiesInstance();
198 
199  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend() && valid; ++i) {
200 
201  const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
202 
203  valid = parameter.is_valid();
204  }
205 
206  return valid;
207  }
208 
209 
210  /**
211  * Get equation parameters.
212  *
213  * \return equation parameters
214  */
216  {
217  static JEquationParameters equation("=", "\n\r;,", "./", "#");
218 
219  return equation;
220  }
221 
222 
223  /**
224  * Set equation parameters.
225  *
226  * \param equation equation parameters
227  */
228  static inline void setEquationParameters(const JEquationParameters& equation)
229  {
230  getEquationParameters() = equation;
231  }
232 
233 
234  /**
235  * Binary stream input of oscillation parameters.
236  *
237  * \param in input stream
238  * \return input stream
239  */
240  JReader& read(JReader& in) override
241  {
242  JProperties& properties = this->getPropertiesInstance();
243 
244  for (JProperties::iterator i = properties.begin(); i != properties.end(); ++i) {
245 
246  bool is_defined;
247  T value;
248 
249  if ((in >> is_defined >> value) && is_defined) {
250 
251  JOscParameter_t& parameter = i->second.getValue<JOscParameter_t>();
252 
253  parameter.setValue(value);
254  }
255  }
256 
257  return in;
258  }
259 
260 
261  /**
262  * Binary stream output of oscillation parameters.
263  *
264  * \param out output stream
265  * \return output stream
266  */
267  JWriter& write(JWriter& out) const override
268  {
269  const JProperties& properties = this->getPropertiesInstance();
270 
271  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
272 
273  const JOscParameter_t& parameter = i->second.getValue<const JOscParameter_t>();
274 
275  out << parameter.isDefined() << parameter.getValue();
276  }
277 
278  return out;
279  }
280 
281 
282  /**
283  * Stream input of oscillation parameters.
284  *
285  * \param in input stream
286  * \param parameters oscillation parameters
287  * \return input stream
288  */
289  friend inline std::istream& operator>>(std::istream& in, JOscParametersInterface_t& parameters)
290  {
291  using namespace std;
292  using namespace JPP;
293 
294  JStringStream is(in);
295 
296  if (getFileStatus(is.str().c_str())) {
297  is.load();
298  }
299 
300  JProperties& properties = parameters.getPropertiesInstance();
301  is >> properties;
302 
303  return in;
304  }
305 
306 
307  /**
308  * Stream output of oscillation parameters.
309  *
310  * \param out output stream
311  * \param parameters oscillation parameters
312  * \return output stream
313  */
314  friend inline std::ostream& operator<<(std::ostream& out, const JOscParametersInterface_t& parameters)
315  {
316  return out << parameters.getPropertiesInstance();
317  }
318  };
319 
320 
321  /**
322  * Get size of given oscillation parameters set.
323  *
324  * \param parameters oscillation parameters set
325  * \return size (= number of defined parameters)
326  */
327  template<class T = double>
329  {
330  size_t n = 0;
331 
332  const JProperties& properties = parameters.getPropertiesInstance();
333 
334  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
335  const JOscParameter<T>& parameter = i->second.getValue<const JOscParameter<T> >();
336 
337  n += (size_t) parameter.isDefined();
338  }
339 
340  return n;
341  }
342 
343 
344  /**
345  * Get size of given oscillation parameters grid.
346  *
347  * \param parameters oscillation parameters grid
348  * \return size (= number of defined parameters)
349  */
351  {
352  size_t n = 1;
353 
354  const JProperties& properties = parameters.getPropertiesInstance();
355 
356  for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) {
357  const JOscParameter<JGrid<double> >& parameter = i->second.getValue<const JOscParameter<JGrid<double> > >();
358 
359  if (parameter.isDefined()) {
360  n *= getSize(parameter);
361  }
362  }
363 
364  return n;
365  }
366 }
367 
368 #endif
Abstract base class for oscillation parameter.
JReader & read(JReader &in) override
Binary stream input of oscillation parameters.
JOscParametersInterface< T > JOscParametersInterface_t
Interface for binary output.
Parameter class.
Definition: JParameter.hh:34
friend std::ostream & operator<<(std::ostream &out, const JOscParametersInterface_t &parameters)
Stream output of oscillation parameters.
friend std::istream & operator>>(std::istream &in, JOscParametersInterface_t &parameters)
Stream input of oscillation parameters.
void set(const JOscParametersInterface_t &parameters)
Set oscillation parameters.
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
Utility class to parse parameter values.
Definition: JProperties.hh:497
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Simple data structure to support I/O of equations (see class JLANG::JEquation).
JProperties & getPropertiesInstance(const JEquationParameters &equation=JOscParametersInterface_t::getEquationParameters()) const
Get instance of properties of this class.
bool is_valid() const
Check validity of oscillation parameters.
void setValue(argument_type value)
Set parameter.
is
Definition: JDAQCHSM.chsm:167
size_t getSize(T(&array)[N])
Get size of c-array.
Definition: JLangToolkit.hh:32
static void setEquationParameters(const JEquationParameters &equation)
Set equation parameters.
Utility class to parse parameter values.
JParameter_t::argument_type argument_type
const bool isDefined() const
Get status of parameter.
Definition: JParameter.hh:137
void set(const std::string &name, argument_type value, const Args &...args)
Set value for given list of oscillation parameters.
Forward declaration of binary output.
const int n
Definition: JPolint.hh:786
do set_variable OUTPUT_DIRECTORY $WORKDIR T
JWriter & write(JWriter &out) const override
Binary stream output of oscillation parameters.
Template class for object cloning.
Definition: JClonable.hh:20
then awk string
JOscParameter_t::JParameter_t JParameter_t
Interface for binary input.
virtual bool is_valid() const =0
Check validity of oscillation parameter.
JClass< T >::argument_type argument_type
Definition: JParameter.hh:39
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
virtual JProperties getProperties(const JEquationParameters &equation=JOscParametersInterface_t::getEquationParameters())=0
Get properties of this class.
Simple data structure for an abstract collection of equidistant abscissa values.
Definition: JGrid.hh:38
void set(const std::string &name, argument_type value)
Set value for a given oscillation parameter.
const T & getValue() const
Get value of parameter.
Definition: JParameter.hh:81
static JEquationParameters & getEquationParameters()
Get equation parameters.
JOscParametersInterface_t & getParameters()
Get oscillation parameters.
JOscParametersInterface()
Default constructor.
JProperties & getPropertiesInstance(const JEquationParameters &equation=JOscParametersInterface_t::getEquationParameters())
Get instance of properties of this class.
Interface class for sets of oscillation parameters.
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
File status.