Interval.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef Interval_CLASS
00028 #define Interval_CLASS
00029
00030 #include <stdint.h>
00031 #include <vector>
00032 #include <iostream>
00033 #include <string>
00034 using namespace std;
00035
00036 #ifndef WITHOUT_ACS
00037 #include <asdmIDLTypesC.h>
00038 using asdmIDLTypes::IDLInterval;
00039 #endif
00040
00041 #include <StringTokenizer.h>
00042 #include <NumberFormatException.h>
00043 using asdm::StringTokenizer;
00044 using asdm::NumberFormatException;
00045
00046 #include <EndianStream.h>
00047 using asdm::EndianOSStream;
00048 using asdm::EndianIStream;
00049
00050 namespace asdm {
00051
00052 class Interval;
00053 Interval operator * ( int64_t , const Interval & );
00054 ostream & operator << ( ostream &, const Interval & );
00055 istream & operator >> ( istream &, Interval&);
00056
00064 class Interval {
00065 friend Interval operator * ( int64_t , const Interval & );
00066 friend ostream & operator << ( ostream &, const Interval & );
00067 friend istream & operator >> ( istream &, Interval&);
00068
00069 public:
00070 static int64_t fromString(const string&);
00071 static string toString(int64_t);
00072 static Interval getInterval(StringTokenizer &t) throw(NumberFormatException);
00073
00074 Interval();
00075 Interval(const Interval &);
00076 Interval(const string &s);
00077 #ifndef WITHOUT_ACS
00078 Interval(const IDLInterval &);
00079 #endif
00080 Interval(int64_t value);
00081 virtual ~Interval();
00082
00083 Interval& operator = (const Interval&);
00084 Interval& operator = (const int64_t);
00085
00086 Interval& operator += (const Interval&);
00087 Interval& operator -= (const Interval&);
00088 Interval& operator *= (const int64_t);
00089 Interval& operator /= (const int64_t);
00090
00091 Interval operator + (const Interval&) const;
00092 Interval operator - (const Interval&) const;
00093 Interval operator * (const int64_t) const;
00094 Interval operator / (const int64_t) const;
00095
00096 bool operator < (const Interval&) const;
00097 bool operator > (const Interval&) const;
00098 bool operator <= (const Interval&) const;
00099 bool operator >= (const Interval&) const;
00100 bool operator == (const Interval&) const;
00101 bool equals(const Interval&) const;
00102 bool operator != (const Interval&) const;
00103
00104 bool isZero() const;
00105
00106 Interval operator - () const;
00107 Interval operator + () const;
00108
00109 string toString() const;
00110 string toStringI() const;
00111
00117 void toBin(EndianOSStream& eoss) ;
00118
00124 static void toBin(vector<Interval> interval, EndianOSStream& eoss) ;
00125
00131 static void toBin(vector<vector<Interval> > interval, EndianOSStream& eoss) ;
00132
00139 static Interval fromBin(EndianIStream& eis);
00140
00147 static vector<Interval> from1DBin(EndianIStream& eis);
00148
00155 static vector<vector<Interval> >from2DBin(EndianIStream& eis);
00156
00157 operator string () const;
00158 int64_t get() const;
00159 #ifndef WITHOUT_ACS
00160 IDLInterval toIDLInterval() const;
00161 #endif
00162 static string unit();
00163
00164 private:
00165 int64_t value;
00166
00167 };
00168
00169
00170 inline Interval::Interval() : value(0L) {
00171 }
00172
00173 inline Interval::Interval(const Interval &t) : value(t.value) {
00174 }
00175
00176 #ifndef WITHOUT_ACS
00177 inline Interval::Interval(const IDLInterval &l) : value(l.value) {
00178 }
00179 #endif
00180
00181 inline Interval::Interval(const string &s) : value(fromString(s)) {
00182 }
00183
00184 inline Interval::Interval(int64_t v) : value(v) {
00185 }
00186
00187
00188 inline Interval::~Interval() { }
00189
00190
00191 inline Interval& Interval::operator = ( const Interval &t ) {
00192 value = t.value;
00193 return *this;
00194 }
00195
00196
00197 inline Interval& Interval::operator = ( const int64_t v ) {
00198 value = v;
00199 return *this;
00200 }
00201
00202
00203 inline Interval& Interval::operator += ( const Interval& t) {
00204 value += t.value;
00205 return *this;
00206 }
00207
00208 inline Interval& Interval::operator -= ( const Interval& t) {
00209 value -= t.value;
00210 return *this;
00211 }
00212
00213 inline Interval& Interval::operator *= ( const int64_t n) {
00214 value *= n;
00215 return *this;
00216 }
00217
00218 inline Interval& Interval::operator /= ( const int64_t n) {
00219 value /= n;
00220 return *this;
00221 }
00222
00223
00224 inline Interval Interval::operator + ( const Interval &t2 ) const {
00225 Interval tmp;
00226 tmp.value = value + t2.value;
00227 return tmp;
00228 }
00229
00230 inline Interval Interval::operator - ( const Interval &t2 ) const {
00231 Interval tmp;
00232 tmp.value = value - t2.value;
00233 return tmp;
00234 }
00235 inline Interval Interval::operator * ( const int64_t n) const {
00236 Interval tmp;
00237 tmp.value = value * n;
00238 return tmp;
00239 }
00240
00241 inline Interval Interval::operator / ( const int64_t n) const {
00242 Interval tmp;
00243 tmp.value = value / n;
00244 return tmp;
00245 }
00246
00247
00248 inline bool Interval::operator < (const Interval& x) const {
00249 return (value < x.value);
00250 }
00251
00252 inline bool Interval::operator > (const Interval& x) const {
00253 return (value > x.value);
00254 }
00255
00256 inline bool Interval::operator <= (const Interval& x) const {
00257 return (value <= x.value);
00258 }
00259
00260 inline bool Interval::operator >= (const Interval& x) const {
00261 return (value >= x.value);
00262 }
00263
00264 inline bool Interval::operator == (const Interval& x) const {
00265 return (value == x.value);
00266 }
00267 inline bool Interval::equals(const Interval& x) const {
00268 return (value == x.value);
00269 }
00270
00271 inline bool Interval::operator != (const Interval& x) const {
00272 return (value != x.value);
00273 }
00274
00275
00276 inline Interval Interval::operator - () const {
00277 Interval tmp;
00278 tmp.value = -value;
00279 return tmp;
00280 }
00281
00282 inline Interval Interval::operator + () const {
00283 Interval tmp;
00284 tmp.value = value;
00285 return tmp;
00286 }
00287
00288
00289 inline Interval::operator string () const {
00290 return toString();
00291 }
00292
00293 inline string Interval::toString() const {
00294 return toString(value);
00295 }
00296
00297 inline string Interval::toStringI() const {
00298 return toString(value);
00299 }
00300
00301 inline int64_t Interval::get() const {
00302 return value;
00303 }
00304
00305 #ifndef WITHOUT_ACS
00306 inline IDLInterval Interval::toIDLInterval() const {
00307 IDLInterval tmp;
00308 tmp.value = value;
00309 return tmp;
00310 }
00311 #endif
00312
00313
00314
00315 inline Interval operator * ( int64_t n, const Interval &x) {
00316 Interval tmp;
00317 tmp.value = x.value * n;
00318 return tmp;
00319 }
00320
00321 inline ostream & operator << ( ostream &o, const Interval &x ) {
00322 o << x.value;
00323 return o;
00324 }
00325
00326 inline istream & operator >> ( istream &i, Interval &x ) {
00327 i >> x.value;
00328 return i;
00329 }
00330
00331 inline string Interval::unit() {
00332 return string ("nanosec");
00333 }
00334
00335 }
00336
00337 #endif