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