tp_timeinterval.h

Go to the documentation of this file.
00001 
00004 /* 
00005    Timeplugin for FAU Discrete Event Systems Library (libfaudes)
00006 
00007    Copyright (C) 2007  Ruediger Berndt
00008    Copyright (C) 2007  Thomas Moor
00009    Exclusive copyright is granted to Klaus Schmidt
00010 
00011 */
00012 
00013 #ifndef FAUDES_TP_TIMEINTERVAL_H
00014 #define FAUDES_TP_TIMEINTERVAL_H
00015 
00016 #include "agenerator.h"
00017 #include <cstdlib>
00018 #include <cstring>
00019 #include <cfloat>
00020 #include <climits>
00021 #include <iostream>
00022 
00023 
00024 namespace faudes {
00025 
00035 class tpTime {
00036  public:
00038    typedef long int Type;
00040    const static Type Max=INT_MAX;
00042    const static Type Min=INT_MIN+1;
00044    const static Type UnDef=INT_MIN;
00046    const static Type Step=1;
00048    std::string static Str(Type time) { 
00049      if(time == UnDef) return "undef"; 
00050      if(time < Min) return "err"; 
00051      if(time == Min) return "-inf"; 
00052      if(time > Max) return "err"; 
00053      if(time == Max) return "inf"; 
00054      return ToStringInteger(time); 
00055    };
00056 };
00057 
00058 /*
00059 Alternative time representation: cosmetic float
00060 class tpTime {
00061  public:
00062    typedef double Type;
00063    const static Type Max=FLT_MAX;
00064    const static Type Min=FLT_MIN*0.5;
00065    const static Type UnDef=FLT_MIN;
00066    const static Type Step=0.0001;
00067 };
00068 */
00069 
00070 
00071 
00080  class TimeInterval {
00081   
00082  public:
00083     
00087    TimeInterval(void) {SetFull();};
00088 
00092    ~TimeInterval(void) {};
00093 
00102    void LB(tpTime::Type time) {
00103      if(time <= tpTime::Min) time=tpTime::Min;
00104      if(time >= tpTime::Max) time=tpTime::Max;
00105      mstLB=time;
00106      if(mstLB==tpTime::Min)  mbLBincl=false; 
00107    }
00108 
00109 
00118    void UB(tpTime::Type time) {
00119      if(time <= tpTime::Min) time=tpTime::Min;
00120      if(time >= tpTime::Max) time=tpTime::Max;
00121      mstUB=time;
00122      if(mstUB==tpTime::Max)  mbUBincl=false;                                  
00123    }
00124 
00125 
00132    void UBincl(bool incl) {
00133      mbUBincl=incl;
00134      if(mstUB>=tpTime::Max) mbUBincl=false;
00135    }
00136 
00137 
00144    void LBincl(bool incl) {
00145      mbLBincl=incl;
00146      if(mstLB<=tpTime::Min) mbLBincl=false;
00147    }
00148 
00149 
00153    void setUBinf(void) {
00154      mstUB=tpTime::Max; mbUBincl=false; }
00155 
00159    void setLBinf(void) {
00160      mstLB=tpTime::Min; mbLBincl=false; }
00161 
00167    tpTime::Type UB(void) const {return mstUB;}
00168 
00174    tpTime::Type LB(void) const {return mstLB;}
00175 
00181    bool LBincl(void) const {return mbLBincl;}
00182 
00188    bool UBincl(void) const {return mbUBincl;}
00189 
00195    bool LBinf(void) const {return mstLB == tpTime::Min; }
00196 
00202    bool UBinf(void) const {return mstUB == tpTime::Max;}
00203 
00204 
00211    void Canonical(void);
00212 
00216    void SetFull(void) {
00217      mstUB=tpTime::Max; mstLB=tpTime::Min; mbUBincl=false; mbLBincl=false; };
00218 
00222    void SetEmpty(void) {
00223      mstUB=-1; mstLB=1; mbUBincl=false; mbLBincl=false; };
00224 
00228    void SetPositive(void) {
00229      mstUB=tpTime::Max; mstLB=0; mbUBincl=false; mbLBincl=true; };
00230 
00231 
00235    void SetNegative(void) {
00236      mstLB=tpTime::Min; mstUB=0; mbUBincl=false; mbLBincl=true; };
00237 
00244    bool Full(void) const { return (mstUB==tpTime::Max) && (mstLB==tpTime::Min) ;};
00245       
00252    bool Empty(void) const;
00253       
00260    bool IncludesPositive(void) const {  
00261       return ( (mstLB<0) || ((mstLB ==0) && mbLBincl) ) && (mstUB==tpTime::Max);};
00262 
00269    bool IncludesNegative(void) const {  
00270       return ( (mstUB>0) || ((mstUB ==0) && mbUBincl) ) && (mstLB==tpTime::Min);};
00271 
00277    bool In(tpTime::Type time) const;
00278 
00279 
00290    bool operator == (const TimeInterval& rOtherInterval) const {
00291      if(mstUB!=rOtherInterval.mstUB) return false;
00292      if(mstLB!=rOtherInterval.mstLB) return false;
00293      if(mbUBincl!=rOtherInterval.mbUBincl) return false;
00294      if(mbLBincl!=rOtherInterval.mbLBincl) return false;
00295      return true;
00296    }
00297 
00308    bool operator != (const TimeInterval& rOtherInterval) const {
00309      return ! (*this == rOtherInterval) ;
00310    }
00311 
00318    void PositiveLeftShift(tpTime::Type time);
00319 
00326    void Intersect(const TimeInterval& rOtherInterval);
00327       
00338    static TimeInterval Intersect(const TimeInterval& rInterval1, const TimeInterval& rInterval2);
00339       
00340 
00349    void Merge(const TimeInterval& rOtherInterval);
00350 
00362    static TimeInterval Merge(const TimeInterval& rInterval1, const TimeInterval& rInterval2);
00363             
00369    std::string Str(void) const;
00370       
00371     
00372  private:
00373 
00375    tpTime::Type mstUB;
00376 
00378    tpTime::Type mstLB;
00379 
00381    bool mbUBincl;
00382 
00384    bool mbLBincl;
00385 
00386 };
00387 
00388 
00389 } // end namespace faudes
00390 
00391 
00392 #endif

Generated on Mon Nov 10 08:13:15 2008 for libFAUDES 2.11v by  doxygen 1.4.4