tp_timeinterval.cppGo to the documentation of this file.00001 /* tp_timeinterval.cpp -- model of interval */ 00002 00003 /* Timeplugin for FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2007 Ruediger Berndt 00006 Copyright (C) 2007 Thomas Moor 00007 Exclusive copyright is granted to Klaus Schmidt 00008 00009 */ 00010 00011 #include "tp_timeinterval.h" 00012 00013 using namespace faudes; 00014 00015 /* canonical */ 00016 void TimeInterval::Canonical(void) { 00017 // make left closed 00018 if((!mbLBincl)&&(!LBinf())) { 00019 LB(mstLB+tpTime::Step); 00020 LBincl(true); 00021 } 00022 // make right open 00023 if(UBincl()) { 00024 UB(mstLB+tpTime::Step); 00025 UBincl(false); 00026 } 00027 } 00028 00029 /* bool Empty const() */ 00030 bool TimeInterval::Empty() const { 00031 if(mstLB<mstUB) 00032 return false; 00033 if(mstLB==mstUB) 00034 if((mbLBincl==true) && (mbUBincl==true)) 00035 return false; 00036 return true; 00037 } 00038 00039 /* bool In(time) */ 00040 bool TimeInterval::In(tpTime::Type time) const { 00041 if(time<mstLB) return false; 00042 if(time> mstUB) return false; 00043 if(time == mstLB) if( ! mbLBincl) return false; 00044 if(time == mstUB) if(! mbUBincl) return false; 00045 return true; 00046 } 00047 00048 /* PositiveLeftShift */ 00049 void TimeInterval::PositiveLeftShift(tpTime::Type time) { 00050 if(!UBinf()) UB(mstUB-time); 00051 if(!LBinf()) LB(mstLB-time); 00052 if( LBinf() || mstLB <= 0){ 00053 LB(0); 00054 mbLBincl=true; 00055 } 00056 } 00057 00058 /* std::string Str() const */ 00059 std::string TimeInterval::Str(void) const { 00060 00061 std::string res; 00062 std::stringstream resstream; 00063 00064 if(Empty()) { 00065 resstream << "[empty]"; 00066 res=resstream.str(); 00067 return(res); 00068 } 00069 00070 if(mbLBincl) resstream << "["; 00071 else resstream << "("; 00072 if(LBinf()) resstream << "-inf"; 00073 else resstream << mstLB; 00074 resstream << ", "; 00075 if(UBinf()) resstream << "inf"; 00076 else resstream << mstUB; 00077 if(mbUBincl) resstream << "]"; 00078 else resstream << ")"; 00079 res=resstream.str(); 00080 return(res); 00081 00082 } 00083 00084 /* void Intersect(const TimeInterval& rOtherInterval) */ 00085 void TimeInterval::Intersect(const TimeInterval& rOtherInterval) { 00086 00087 FD_DC("TimeInterval::Intersect(otherinterval): " << Str()<<" & " << 00088 rOtherInterval.Str() ); 00089 00090 // other upper bound matches 00091 if(UB()==rOtherInterval.UB()) { 00092 if(!rOtherInterval.UBincl()) UBincl(false); 00093 } 00094 // other upper bound wins 00095 if(UB() > rOtherInterval.UB()) { 00096 UB(rOtherInterval.UB()); 00097 UBincl(rOtherInterval.UBincl()); 00098 } 00099 // other lower bound matches 00100 if(LB()==rOtherInterval.LB()) { 00101 if(!rOtherInterval.LBincl()) LBincl(false); 00102 } 00103 // other lower bound wins 00104 if(LB() < rOtherInterval.LB()) { 00105 LB(rOtherInterval.LB()); 00106 LBincl(rOtherInterval.LBincl()); 00107 } 00108 00109 FD_DC("TimeInterval::Intersect( ... ), ret: " << Str()); 00110 } 00111 00112 00113 /* TimeInterval Intersect(const TimeInterval& rInterval1, const TimeInterval& rInterval2) */ 00114 TimeInterval TimeInterval::Intersect(const TimeInterval& rInterval1, const TimeInterval& rInterval2) { 00115 FD_DC("TimeInterval::Intersect(" << rInterval1.Str()<<", " << 00116 rInterval2.Str() << ")"); 00117 TimeInterval res=rInterval1; 00118 res.Intersect(rInterval2); 00119 FD_DC("TimeInterval::Intersect( ... ), ret: " << res.Str()); 00120 return(res); 00121 } 00122 00123 00124 /* void Merge(const TimeInterval& rOtherInterval) */ 00125 void TimeInterval::Merge(const TimeInterval& rOtherInterval) { 00126 // other upper bound matches 00127 if(UB()==rOtherInterval.UB()) { 00128 if(rOtherInterval.UBincl()) UBincl(true); 00129 } 00130 // other upper bound wins 00131 if(UB() < rOtherInterval.UB()) { 00132 UB(rOtherInterval.UB()); 00133 UBincl(rOtherInterval.UBincl()); 00134 } 00135 // other lower bound matches 00136 if(LB()==rOtherInterval.LB()) { 00137 if(rOtherInterval.LBincl() ) LBincl(true); 00138 } 00139 // other lower bound wins 00140 if(LB()<rOtherInterval.LB()) { 00141 LB(rOtherInterval.LB()); 00142 LBincl(rOtherInterval.LBincl()); 00143 } 00144 } 00145 00146 /* TimeInterval Merge(const TimeInterval& rInterval1, const TimeInterval& rInterval2) */ 00147 TimeInterval TimeInterval::Merge(const TimeInterval& rInterval1, const TimeInterval& rInterval2) { 00148 TimeInterval res=rInterval1; 00149 res.Merge(rInterval2); 00150 return(res); 00151 } libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |