tp_timeinterval.cpp
Go to the documentation of this file.
1 /* tp_timeinterval.cpp -- model of interval */
2 
3 /* Timeplugin for FAU Discrete Event Systems Library (libfaudes)
4 
5  Copyright (C) 2007 Ruediger Berndt
6  Copyright (C) 2007 Thomas Moor
7  Exclusive copyright is granted to Klaus Schmidt
8 
9 */
10 
11 #include "tp_timeinterval.h"
12 
13 using namespace faudes;
14 
15 /* canonical */
17  // make left closed
18  if((!mbLBincl)&&(!LBinf())) {
20  LBincl(true);
21  }
22  // make right open
23  if(UBincl()) {
25  UBincl(false);
26  }
27 }
28 
29 /* bool Empty const() */
30 bool TimeInterval::Empty() const {
31  if(mstLB<mstUB)
32  return false;
33  if(mstLB==mstUB)
34  if((mbLBincl==true) && (mbUBincl==true))
35  return false;
36  return true;
37 }
38 
39 /* bool In(time) */
40 bool TimeInterval::In(tpTime::Type time) const {
41  if(time<mstLB) return false;
42  if(time> mstUB) return false;
43  if(time == mstLB) if( ! mbLBincl) return false;
44  if(time == mstUB) if(! mbUBincl) return false;
45  return true;
46 }
47 
48 /* PositiveLeftShift */
50  if(!UBinf()) UB(mstUB-time);
51  if(!LBinf()) LB(mstLB-time);
52  if( LBinf() || mstLB <= 0){
53  LB(0);
54  mbLBincl=true;
55  }
56 }
57 
58 /* std::string Str() const */
59 std::string TimeInterval::Str(void) const {
60 
61  std::string res;
62  std::stringstream resstream;
63 
64  if(Empty()) {
65  resstream << "[empty]";
66  res=resstream.str();
67  return(res);
68  }
69 
70  if(mbLBincl) resstream << "[";
71  else resstream << "(";
72  if(LBinf()) resstream << "-inf";
73  else resstream << mstLB;
74  resstream << ", ";
75  if(UBinf()) resstream << "inf";
76  else resstream << mstUB;
77  if(mbUBincl) resstream << "]";
78  else resstream << ")";
79  res=resstream.str();
80  return(res);
81 
82 }
83 
84 /* void Intersect(const TimeInterval& rOtherInterval) */
85 void TimeInterval::Intersect(const TimeInterval& rOtherInterval) {
86 
87  FD_DC("TimeInterval::Intersect(otherinterval): " << Str()<<" & " <<
88  rOtherInterval.Str() );
89 
90  // other upper bound matches
91  if(UB()==rOtherInterval.UB()) {
92  if(!rOtherInterval.UBincl()) UBincl(false);
93  }
94  // other upper bound wins
95  if(UB() > rOtherInterval.UB()) {
96  UB(rOtherInterval.UB());
97  UBincl(rOtherInterval.UBincl());
98  }
99  // other lower bound matches
100  if(LB()==rOtherInterval.LB()) {
101  if(!rOtherInterval.LBincl()) LBincl(false);
102  }
103  // other lower bound wins
104  if(LB() < rOtherInterval.LB()) {
105  LB(rOtherInterval.LB());
106  LBincl(rOtherInterval.LBincl());
107  }
108 
109  FD_DC("TimeInterval::Intersect( ... ), ret: " << Str());
110 }
111 
112 
113 /* TimeInterval Intersect(const TimeInterval& rInterval1, const TimeInterval& rInterval2) */
114 TimeInterval TimeInterval::Intersect(const TimeInterval& rInterval1, const TimeInterval& rInterval2) {
115  FD_DC("TimeInterval::Intersect(" << rInterval1.Str()<<", " <<
116  rInterval2.Str() << ")");
117  TimeInterval res=rInterval1;
118  res.Intersect(rInterval2);
119  FD_DC("TimeInterval::Intersect( ... ), ret: " << res.Str());
120  return(res);
121 }
122 
123 
124 /* void Merge(const TimeInterval& rOtherInterval) */
125 void TimeInterval::Merge(const TimeInterval& rOtherInterval) {
126  // other upper bound matches
127  if(UB()==rOtherInterval.UB()) {
128  if(rOtherInterval.UBincl()) UBincl(true);
129  }
130  // other upper bound wins
131  if(UB() < rOtherInterval.UB()) {
132  UB(rOtherInterval.UB());
133  UBincl(rOtherInterval.UBincl());
134  }
135  // other lower bound matches
136  if(LB()==rOtherInterval.LB()) {
137  if(rOtherInterval.LBincl() ) LBincl(true);
138  }
139  // other lower bound wins
140  if(LB()<rOtherInterval.LB()) {
141  LB(rOtherInterval.LB());
142  LBincl(rOtherInterval.LBincl());
143  }
144 }
145 
146 /* TimeInterval Merge(const TimeInterval& rInterval1, const TimeInterval& rInterval2) */
147 TimeInterval TimeInterval::Merge(const TimeInterval& rInterval1, const TimeInterval& rInterval2) {
148  TimeInterval res=rInterval1;
149  res.Merge(rInterval2);
150  return(res);
151 }

libFAUDES 2.24g --- 2014.09.15 --- c++ api documentaion by doxygen