Jpp  18.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JLimit.hh
Go to the documentation of this file.
1 #ifndef __JSUPPORT__JLIMIT__
2 #define __JSUPPORT__JLIMIT__
3 
4 #include <limits>
5 #include <string>
6 #include <istream>
7 #include <ostream>
8 #include <sstream>
9 
10 #include "JROOT/JCounter.hh"
11 
12 #include "JTools/JRange.hh"
13 #include "JLang/JComparable.hh"
14 
15 
16 /**
17  * \file
18  * Auxiliaries for defining the range of iterations of objects.
19  * \author mdejong
20  */
21 namespace JSUPPORT {}
22 namespace JPP { using namespace JSUPPORT; }
23 
24 namespace JSUPPORT {
25 
26  using JTOOLS::JRange;
27  using JLANG::JComparable;
28  using JROOT::counter_type;
29 
30 
31  /**
32  * Auxiliary class for defining the range of iterations of objects.
33  *
34  * Possible input syntax:
35  * <pre>
36  * <begin of iteration>:<number of iterations>
37  * <number of iterations>
38  * </pre>
39  * where the iteration starts at 0.
40  */
41  struct JLimit :
42  public JRange<counter_type>,
43  public JComparable<JLimit>,
44  public JComparable<JLimit, counter_type>
45  {
46 
48 
49 
50  /**
51  * Default constructor.
52  */
53  JLimit() :
55  {}
56 
57 
58  /**
59  * Constructor.
60  *
61  * \param counter number of entries
62  */
63  JLimit(const counter_type counter) :
64  JRange<counter_type>(JLimit::min(), counter)
65  {}
66 
67 
68  /**
69  * Constructor.
70  *
71  * \param lower lower limit
72  * \param upper upper limit
73  */
74  JLimit(const counter_type lower, const counter_type upper) :
75  JRange<counter_type>(lower, upper)
76  {}
77 
78 
79  /**
80  * Get limit.
81  *
82  * \return this limit
83  */
84  const JLimit& getLimit() const
85  {
86  return static_cast<const JLimit&>(*this);
87  }
88 
89 
90  /**
91  * Get limit.
92  *
93  * \return this limit
94  */
96  {
97  return static_cast<JLimit&>(*this);
98  }
99 
100 
101  /**
102  * Set limit.
103  *
104  * \param limit limit
105  */
106  void setLimit(const JLimit& limit)
107  {
108  static_cast<JLimit&>(*this) = limit;
109  }
110 
111 
112  /**
113  * Get minimum counter value.
114  *
115  * \return value
116  */
117  static counter_type min()
118  {
119  return 0;
120  }
121 
122 
123  /**
124  * Get maximum counter value.
125  *
126  * \return value
127  */
128  static counter_type max()
129  {
130  return std::numeric_limits<counter_type>::max();
131  }
132 
133 
134  /**
135  * Compare limit.
136  *
137  * \param limit limit
138  * \return true if this upper limit is less then given upper limit; else false
139  */
140  bool less(const JLimit& limit) const
141  {
142  return getUpperLimit() < limit.getUpperLimit();
143  }
144 
145 
146  /**
147  * Compare counter.
148  *
149  * \param counter counter
150  * \return true if this upper limit is less than counter; else false
151  */
152  bool less(const counter_type counter) const
153  {
154  return getUpperLimit() < counter;
155  }
156 
157 
158  /**
159  * Compare counter.
160  *
161  * \param counter counter
162  * \return true if this upper limit is more than counter; else false
163  */
164  bool more(const counter_type counter) const
165  {
166  return getUpperLimit() > counter;
167  }
168 
169 
170  /**
171  * Read limit from input.
172  *
173  * Note that input <tt>n</tt> will set the begin and end of the iteration to <tt>0</tt> and <tt>n</tt>, respectively;
174  * and input <tt>i:n</tt> will set the begin and end of the iteration to <tt>i</tt> and <tt>i+n</tt>, respectively.
175  *
176  * \param in input stream
177  * \param limit limit
178  * \return input stream
179  */
180  friend inline std::istream& operator>>(std::istream& in, JLimit& limit)
181  {
182  using namespace std;
183 
184  limit.setLowerLimit(JLimit::min());
185  limit.setUpperLimit(JLimit::max());
186 
187  string buffer;
188 
189  if (in >> buffer) {
190 
191  string::size_type pos = buffer.find(SEPARATOR);
192 
193  if (pos != string::npos) {
194 
195  buffer[pos] = ' ';
196 
197  istringstream is(buffer);
198 
199  if (is >> static_cast<range_type&>(limit)) {
200  limit.setUpperLimit(limit.getLowerLimit() + limit.getUpperLimit());
201  }
202 
203  } else {
204 
205  counter_type value;
206 
207  istringstream is(buffer);
208 
209  is >> value;
210 
211  limit.setUpperLimit(value);
212  }
213  }
214 
215  return in;
216  }
217 
218 
219  static const char SEPARATOR = ':'; //!< separator between values
220  };
221 
222 
223  /**
224  * Type definition of limit.
225  */
226  typedef JLimit JLimit_t;
227 }
228 
229 #endif
bool less(const JLimit &limit) const
Compare limit.
Definition: JLimit.hh:140
JRange< counter_type > range_type
Definition: JLimit.hh:47
T getLowerLimit() const
Get lower limit.
Definition: JRange.hh:202
Type definition for counter for ROOT TTree and auxiliary methods.
JLimit(const counter_type lower, const counter_type upper)
Constructor.
Definition: JLimit.hh:74
static counter_type max()
Get maximum counter value.
Definition: JLimit.hh:128
Long64_t counter_type
Type definition for counter.
is
Definition: JDAQCHSM.chsm:167
void setUpperLimit(argument_type y)
Set upper limit.
Definition: JRange.hh:235
bool more(const counter_type counter) const
Compare counter.
Definition: JLimit.hh:164
JLimit JLimit_t
Type definition of limit.
Definition: JLimit.hh:226
JLimit()
Default constructor.
Definition: JLimit.hh:53
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
T getUpperLimit() const
Get upper limit.
Definition: JRange.hh:213
static const char SEPARATOR
separator between values
Definition: JLimit.hh:219
friend std::istream & operator>>(std::istream &in, JLimit &limit)
Read limit from input.
Definition: JLimit.hh:180
Template definition of auxiliary base class for comparison of data structures.
Definition: JComparable.hh:24
Range of values.
Definition: JRange.hh:38
bool less(const counter_type counter) const
Compare counter.
Definition: JLimit.hh:152
Auxiliary class to define a range between two values.
JLimit(const counter_type counter)
Constructor.
Definition: JLimit.hh:63
static counter_type min()
Get minimum counter value.
Definition: JLimit.hh:117
const JLimit & getLimit() const
Get limit.
Definition: JLimit.hh:84
void setLimit(const JLimit &limit)
Set limit.
Definition: JLimit.hh:106
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
JLimit & getLimit()
Get limit.
Definition: JLimit.hh:95
void setLowerLimit(argument_type x)
Set lower limit.
Definition: JRange.hh:224