Jpp  18.4.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JOscParameter.hh
Go to the documentation of this file.
1 #ifndef __JOSCPROB__JOSCPARAMETER__
2 #define __JOSCPROB__JOSCPARAMETER__
3 
4 #include "JLang/JException.hh"
5 #include "JLang/JParameter.hh"
6 
7 #include "JTools/JGrid.hh"
8 
9 
10 /**
11  * \author bjung, mdejong
12  */
13 
14 namespace JOSCPROB {}
15 namespace JPP { using namespace JOSCPROB; }
16 
17 namespace JOSCPROB {
18 
19  using JLANG::JParameter;
20 
21  using JTOOLS::JGrid;
22 
23 
24  /**
25  * Abstract base class for oscillation parameter.
26  */
27  template<class T = double>
28  struct JOscParameter :
29  public JParameter<T>
30  {
32 
34 
35 
36  /**
37  * Default constructor.
38  */
40  JParameter_t()
41  {}
42 
43 
44  /**
45  * Constructor.
46  *
47  * \param value oscillation parameter value
48  */
49  explicit JOscParameter(argument_type value) :
50  JParameter_t(value)
51  {}
52 
53 
54  /**
55  * Assignment operator.
56  *
57  * \param value oscillation parameter value
58  * \return oscillation parameter
59  */
61  {
62  setValue(value);
63 
64  return *this;
65  }
66 
67 
68  /**
69  * Set parameter.
70  *
71  * \param value oscillation parameter value
72  */
73  void setValue(argument_type value)
74  {
75  using namespace JPP;
76 
78 
79  if (!this->is_valid()) {
80  THROW(JValueOutOfRange, "JOscParameter<T>::setValue(): Given oscillation parameter is invalid " << value);
81  }
82  }
83 
84 
85  /**
86  * Check validity of oscillation parameter.
87  *
88  * \return true if valid; else false
89  */
90  virtual bool is_valid() const = 0;
91 
92 
93  /**
94  * Stream input.
95  *
96  * \param in input stream
97  * \param parameter oscillation parameter
98  * \return input stream
99  */
100  friend inline std::istream& operator>>(std::istream& in, JOscParameter<T>& parameter)
101  {
102  using namespace JPP;
103 
104  in >> static_cast<JParameter_t&>(parameter);
105 
106  if (!parameter.is_valid()) {
107  THROW(JValueOutOfRange, "JOscParameter<T>::operator>>(): Given oscillation parameter is invalid " << parameter);
108  }
109 
110  return in;
111  }
112 
113 
114  /**
115  * Stream output.
116  *
117  * \param out output stream
118  * \param parameter oscillation parameter
119  * \return output stream
120  */
121  friend inline std::ostream& operator<<(std::ostream& out, const JOscParameter<T>& parameter)
122  {
123  return out << static_cast<const JParameter_t&>(parameter);
124  }
125  };
126 
127 
128  /**
129  * Get size of given oscillation parameter grid.
130  *
131  * \param grid oscillation parameteter grid
132  * \return size of oscillation parameter
133  */
134  inline size_t getSize(const JOscParameter<JGrid<double> >& grid)
135  {
136  return (grid.isDefined() ? grid.getValue().getSize() : 0);
137  }
138 }
139 
140 #endif
Abstract base class for oscillation parameter.
Exceptions.
Parameter class.
Definition: JParameter.hh:34
JOscParameter()
Default constructor.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
friend std::istream & operator>>(std::istream &in, JOscParameter< T > &parameter)
Stream input.
void setValue(argument_type value)
Set parameter.
size_t getSize(T(&array)[N])
Get size of c-array.
Definition: JLangToolkit.hh:32
JParameter_t::argument_type argument_type
JParameter< T > JParameter_t
void setValue(argument_type value)
Set value.
Definition: JParameter.hh:103
JOscParameter< T > & operator=(argument_type value)
Assignment operator.
virtual bool is_valid() const =0
Check validity of oscillation parameter.
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
Simple data structure for an abstract collection of equidistant abscissa values.
Definition: JGrid.hh:38
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:178
JOscParameter(argument_type value)
Constructor.