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
13using namespace faudes;
14
15
16
17/* canonical */
19 // make left closed
20 if((!mbLBincl)&&(!LBinf())) {
22 LBincl(true);
23 }
24 // make right open
25 if(UBincl()) {
27 UBincl(false);
28 }
29}
30
31/* bool Empty const() */
32bool TimeInterval::Empty() const {
33 if(mstLB<mstUB)
34 return false;
35 if(mstLB==mstUB)
36 if((mbLBincl==true) && (mbUBincl==true))
37 return false;
38 return true;
39}
40
41/* bool In(time) */
42bool TimeInterval::In(Time::Type time) const {
43 if(time<mstLB) return false;
44 if(time> mstUB) return false;
45 if(time == mstLB) if( ! mbLBincl) return false;
46 if(time == mstUB) if(! mbUBincl) return false;
47 return true;
48}
49
50/* PositiveLeftShift */
52 if(!UBinf()) UB(mstUB-time);
53 if(!LBinf()) LB(mstLB-time);
54 if( LBinf() || mstLB <= 0){
55 LB(0);
56 mbLBincl=true;
57 }
58}
59
60/* std::string Str() const */
61std::string TimeInterval::Str(void) const {
62
63 std::string res;
64 std::stringstream resstream;
65
66 if(Empty()) {
67 resstream << "[empty]";
68 res=resstream.str();
69 return(res);
70 }
71
72 if(mbLBincl) resstream << "[";
73 else resstream << "(";
74 if(LBinf()) resstream << "-inf";
75 else resstream << mstLB;
76 resstream << ", ";
77 if(UBinf()) resstream << "inf";
78 else resstream << mstUB;
79 if(mbUBincl) resstream << "]";
80 else resstream << ")";
81 res=resstream.str();
82 return(res);
83
84}
85
86/* void Intersect(const TimeInterval& rOtherInterval) */
87void TimeInterval::Intersect(const TimeInterval& rOtherInterval) {
88
89 FD_DC("TimeInterval::Intersect(otherinterval): " << Str()<<" & " <<
90 rOtherInterval.Str() );
91
92 // other upper bound matches
93 if(UB()==rOtherInterval.UB()) {
94 if(!rOtherInterval.UBincl()) UBincl(false);
95 }
96 // other upper bound wins
97 if(UB() > rOtherInterval.UB()) {
98 UB(rOtherInterval.UB());
99 UBincl(rOtherInterval.UBincl());
100 }
101 // other lower bound matches
102 if(LB()==rOtherInterval.LB()) {
103 if(!rOtherInterval.LBincl()) LBincl(false);
104 }
105 // other lower bound wins
106 if(LB() < rOtherInterval.LB()) {
107 LB(rOtherInterval.LB());
108 LBincl(rOtherInterval.LBincl());
109 }
110
111 FD_DC("TimeInterval::Intersect( ... ), ret: " << Str());
112}
113
114
115/* TimeInterval Intersect(const TimeInterval& rInterval1, const TimeInterval& rInterval2) */
116TimeInterval TimeInterval::Intersect(const TimeInterval& rInterval1, const TimeInterval& rInterval2) {
117 FD_DC("TimeInterval::Intersect(" << rInterval1.Str()<<", " <<
118 rInterval2.Str() << ")");
119 TimeInterval res=rInterval1;
120 res.Intersect(rInterval2);
121 FD_DC("TimeInterval::Intersect( ... ), ret: " << res.Str());
122 return(res);
123}
124
125
126/* void Merge(const TimeInterval& rOtherInterval) */
127void TimeInterval::Merge(const TimeInterval& rOtherInterval) {
128 // other upper bound matches
129 if(UB()==rOtherInterval.UB()) {
130 if(rOtherInterval.UBincl()) UBincl(true);
131 }
132 // other upper bound wins
133 if(UB() < rOtherInterval.UB()) {
134 UB(rOtherInterval.UB());
135 UBincl(rOtherInterval.UBincl());
136 }
137 // other lower bound matches
138 if(LB()==rOtherInterval.LB()) {
139 if(rOtherInterval.LBincl() ) LBincl(true);
140 }
141 // other lower bound wins
142 if(LB()<rOtherInterval.LB()) {
143 LB(rOtherInterval.LB());
144 LBincl(rOtherInterval.LBincl());
145 }
146}
147
148/* TimeInterval Merge(const TimeInterval& rInterval1, const TimeInterval& rInterval2) */
149TimeInterval TimeInterval::Merge(const TimeInterval& rInterval1, const TimeInterval& rInterval2) {
150 TimeInterval res=rInterval1;
151 res.Merge(rInterval2);
152 return res;
153}
#define FD_DC(message)
void LB(Time::Type time)
void Merge(const TimeInterval &rOtherInterval)
Time::Type LB(void) const
bool LBincl(void) const
void PositiveLeftShift(Time::Type time)
Time::Type UB(void) const
bool UBinf(void) const
bool UBincl(void) const
bool In(Time::Type time) const
std::string Str(void) const
void UBincl(bool incl)
void LBincl(bool incl)
void UB(Time::Type time)
bool LBinf(void) const
bool Empty(void) const
void Intersect(const TimeInterval &rOtherInterval)
static Type Step(void)

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen