casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Interval.h
Go to the documentation of this file.
1 /*
2  * ALMA - Atacama Large Millimeter Array
3  * (c) European Southern Observatory, 2002
4  * (c) Associated Universities Inc., 2002
5  * Copyright by ESO (in the framework of the ALMA collaboration),
6  * Copyright by AUI (in the framework of the ALMA collaboration),
7  * All rights reserved.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY, without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22  * MA 02111-1307 USA
23  *
24  * File Interval.h
25  */
26 
27 #ifndef Interval_CLASS
28 #define Interval_CLASS
29 
30 #include <stdint.h>
31 #include <vector>
32 #include <iostream>
33 #include <string>
34 
35 #ifndef WITHOUT_ACS
36 #include <asdmIDLTypesC.h>
37 #endif
38 
41 
42 #include <alma/ASDM/EndianStream.h>
43 
44 namespace asdm {
45 
46  class Interval;
47  Interval operator * ( int64_t , const Interval & );
48  std::ostream & operator << ( std::ostream &, const Interval & );
49  std::istream & operator >> ( std::istream &, Interval&);
50 
58  class Interval {
59  friend Interval operator * ( int64_t , const Interval & );
60  friend std::ostream & operator << ( std::ostream &, const Interval & );
61  friend std::istream & operator >> ( std::istream &, Interval&);
62 
63  public:
64  static int64_t fromString(const std::string&);
65  static std::string toString(int64_t);
67 
68  Interval(); // default constructor
69  Interval(const Interval &); // X const X& constructor
70  Interval(const std::string &s);
71 #ifndef WITHOUT_ACS
72  Interval(const asdmIDLTypes::IDLInterval &);
73 #endif
74  Interval(int64_t value);
75  virtual ~Interval(); // destructor
76 
77  Interval& operator = (const Interval&); // assignment operator
78  Interval& operator = (const int64_t); // assignment operator
79 
80  Interval& operator += (const Interval&); // assignment with arithmetic
81  Interval& operator -= (const Interval&); // operators
82  Interval& operator *= (const int64_t);
83  Interval& operator /= (const int64_t);
84 
85  Interval operator + (const Interval&) const; // arithmetic operators
86  Interval operator - (const Interval&) const;
87  Interval operator * (const int64_t) const;
88  Interval operator / (const int64_t) const;
89 
90  bool operator < (const Interval&) const; // comparison operators
91  bool operator > (const Interval&) const;
92  bool operator <= (const Interval&) const;
93  bool operator >= (const Interval&) const;
94  bool operator == (const Interval&) const;
95  bool equals(const Interval&) const;
96  bool operator != (const Interval&) const;
97 
98  bool isZero() const;
99 
100  Interval operator - () const; // unary minus
101  Interval operator + () const; // unary plus
102 
103  std::string toString() const;
104  std::string toStringI() const;
105 
111  void toBin(EndianOSStream& eoss) ;
112 
118  static void toBin(std::vector<Interval> interval, EndianOSStream& eoss) ;
119 
125  static void toBin(std::vector<std::vector<Interval> > interval, EndianOSStream& eoss) ;
126 
133  static Interval fromBin(EndianIStream& eis);
134 
141  static std::vector<Interval> from1DBin(EndianIStream& eis);
142 
149  static std::vector<std::vector<Interval> >from2DBin(EndianIStream& eis);
150 
151  operator std::string () const;
152  int64_t get() const;
153 #ifndef WITHOUT_ACS
154  asdmIDLTypes::IDLInterval toIDLInterval() const;
155 #endif
156  static std::string unit();
157 
158  private:
159  int64_t value;
160 
161  };
162 
163  // Interval constructors
164  inline Interval::Interval() : value(0L) {
165  }
166 
167  inline Interval::Interval(const Interval &t) : value(t.value) {
168  }
169 
170 #ifndef WITHOUT_ACS
171  inline Interval::Interval(const asdmIDLTypes::IDLInterval &l) : value(l.value) {
172  }
173 #endif
174 
175  inline Interval::Interval(const std::string &s) : value(fromString(s)) {
176  }
177 
178  inline Interval::Interval(int64_t v) : value(v) {
179  }
180 
181  // Interval destructor
182  inline Interval::~Interval() { }
183 
184  // assignment operator
186  value = t.value;
187  return *this;
188  }
189 
190  // assignment operator
191  inline Interval& Interval::operator = ( const int64_t v ) {
192  value = v;
193  return *this;
194  }
195 
196  // assignment with arithmetic operators
198  value += t.value;
199  return *this;
200  }
201 
203  value -= t.value;
204  return *this;
205  }
206 
207  inline Interval& Interval::operator *= ( const int64_t n) {
208  value *= n;
209  return *this;
210  }
211 
212  inline Interval& Interval::operator /= ( const int64_t n) {
213  value /= n;
214  return *this;
215  }
216 
217  // arithmetic functions
218  inline Interval Interval::operator + ( const Interval &t2 ) const {
219  Interval tmp;
220  tmp.value = value + t2.value;
221  return tmp;
222  }
223 
224  inline Interval Interval::operator - ( const Interval &t2 ) const {
225  Interval tmp;
226  tmp.value = value - t2.value;
227  return tmp;
228  }
229  inline Interval Interval::operator * ( const int64_t n) const {
230  Interval tmp;
231  tmp.value = value * n;
232  return tmp;
233  }
234 
235  inline Interval Interval::operator / ( const int64_t n) const {
236  Interval tmp;
237  tmp.value = value / n;
238  return tmp;
239  }
240 
241  // comparison operators
242  inline bool Interval::operator < (const Interval& x) const {
243  return (value < x.value);
244  }
245 
246  inline bool Interval::operator > (const Interval& x) const {
247  return (value > x.value);
248  }
249 
250  inline bool Interval::operator <= (const Interval& x) const {
251  return (value <= x.value);
252  }
253 
254  inline bool Interval::operator >= (const Interval& x) const {
255  return (value >= x.value);
256  }
257 
258  inline bool Interval::operator == (const Interval& x) const {
259  return (value == x.value);
260  }
261  inline bool Interval::equals(const Interval& x) const {
262  return (value == x.value);
263  }
264 
265  inline bool Interval::operator != (const Interval& x) const {
266  return (value != x.value);
267  }
268 
269  // unary - and + operators
271  Interval tmp;
272  tmp.value = -value;
273  return tmp;
274  }
275 
277  Interval tmp;
278  tmp.value = value;
279  return tmp;
280  }
281 
282  // Conversion functions
283  inline Interval::operator std::string () const {
284  return toString();
285  }
286 
287  inline std::string Interval::toString() const {
288  return toString(value);
289  }
290 
291  inline std::string Interval::toStringI() const {
292  return toString(value);
293  }
294 
295  inline int64_t Interval::get() const {
296  return value;
297  }
298 
299 #ifndef WITHOUT_ACS
300  inline asdmIDLTypes::IDLInterval Interval::toIDLInterval() const {
301  asdmIDLTypes::IDLInterval tmp;
302  tmp.value = value;
303  return tmp;
304  }
305 #endif
306 
307  // Friend functions
308 
309  inline Interval operator * ( int64_t n, const Interval &x) {
310  Interval tmp;
311  tmp.value = x.value * n;
312  return tmp;
313  }
314 
315  inline std::ostream & operator << ( std::ostream &o, const Interval &x ) {
316  o << x.value;
317  return o;
318  }
319 
320  inline std::istream & operator >> ( std::istream &i, Interval &x ) {
321  i >> x.value;
322  return i;
323  }
324 
325  inline std::string Interval::unit() {
326  return std::string ("nanosec");
327  }
328 
329 } // End namespace asdm
330 
331 #endif /* Interval_CLASS */
bool operator>(const Interval &) const
Definition: Interval.h:246
Interval & operator/=(const int64_t)
Definition: Interval.h:212
Interval & operator+=(const Interval &)
assignment with arithmetic operators
Definition: Interval.h:197
The Interval class implements an interval of time in units of nanoseconds.
Definition: Interval.h:58
friend Interval operator*(int64_t, const Interval &)
Friend functions.
friend std::ostream & operator<<(std::ostream &, const Interval &)
int64_t value
Definition: Interval.h:159
bool operator==(const Interval &) const
Definition: Interval.h:258
friend std::istream & operator>>(std::istream &, Interval &)
Interval & operator=(const Interval &)
assignment operator
Definition: Interval.h:185
static Interval fromBin(EndianIStream &eis)
Read the binary representation of an Interval from an EndianIStream and use the read value to set an ...
std::istream & operator>>(std::istream &, EntityId &)
Definition: EntityId.h:164
virtual ~Interval()
Interval destructor.
Definition: Interval.h:182
The StringTokenizer class is a translation into C++ of the Java class of the same name in Java&#39;s util...
void toBin(EndianOSStream &eoss)
Write the binary representation of this into an EndianOSStream.
The NumberFormatException class represents an exception when an error occurs in converting a numeric ...
Length operator*(double, const Length &)
Friend functions.
Definition: Length.h:432
Interval & operator*=(const int64_t)
Definition: Interval.h:207
bool equals(const Interval &) const
Definition: Interval.h:261
static std::string unit()
Definition: Interval.h:325
static std::vector< std::vector< Interval > > from2DBin(EndianIStream &eis)
Read the binary representation of a vector of vector of Interval from a EndianIStream and use the rea...
asdmIDLTypes::IDLInterval toIDLInterval() const
Definition: Interval.h:300
int64_t get() const
Definition: Interval.h:295
std::string toString() const
Definition: Interval.h:287
std::ostream & operator<<(std::ostream &, const EntityId &)
Friend functions.
Definition: EntityId.h:159
casacore::String toString(VisibilityProcessor::ProcessingType p)
Interval operator/(const int64_t) const
Definition: Interval.h:235
Interval operator-() const
unary - and + operators
Definition: Interval.h:270
static std::vector< Interval > from1DBin(EndianIStream &eis)
Read the binary representation of a vector of Interval from a EndianIStream and use the read value to...
static int64_t fromString(const std::string &)
Interval()
Interval constructors.
Definition: Interval.h:164
bool isZero() const
std::string toStringI() const
Definition: Interval.h:291
bool operator!=(const Interval &) const
Definition: Interval.h:265
bool operator<=(const Interval &) const
Definition: Interval.h:250
Interval operator+() const
Definition: Interval.h:276
bool operator>=(const Interval &) const
Definition: Interval.h:254
bool operator<(const Interval &) const
comparison operators
Definition: Interval.h:242
static Interval getInterval(StringTokenizer &t)
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
Interval & operator-=(const Interval &)
Definition: Interval.h:202