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
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 #ifndef VRS_TIMEREQUIREMENT_H
00083 #define VRS_TIMEREQUIREMENT_H
00084
00085 #include <vrs/time.h>
00086
00087 #undef min
00088 #undef max
00089
00090 namespace VRS {
00091
00093 class VRS_CORE_API TimeRequirement {
00094
00095 public:
00096 TimeRequirement(bool isInfinite = false);
00097 TimeRequirement(
00098 VRSTime natural,
00099 VRSTime shrink,
00100 VRSTime stretch,
00101 double relativeAlignment = 0.0
00102 );
00107 void mergeMax (const TimeRequirement& tr, double k);
00108 void mergeMin (const TimeRequirement& tr, double k);
00118 bool operator==(const TimeRequirement&) const;
00119
00120 void setNatural(VRSTime time);
00121 void setShrink(VRSTime time);
00122 void setStretch(VRSTime time);
00131 VRSTime getNatural() const;
00132 VRSTime getShrink() const;
00133 VRSTime getStretch() const;
00135
00136 VRSTime maximum() const;
00137 VRSTime minimum() const;
00139
00140 void setAlignment(double alignment);
00141 double getAlignment() const;
00145 void setToInfinite();
00146 void setToUndefined();
00147 void setToDefined();
00148 static const TimeRequirement infinite;
00150
00151 bool isDefined() const;
00152 bool isUndefined() const;
00153 bool isInfinite() const;
00154
00155 TimeRequirement operator+ (const TimeRequirement&) const;
00156 TimeRequirement& operator+= (const TimeRequirement&);
00157 TimeRequirement& operator* (double);
00158 TimeRequirement& operator/ (double);
00159
00160
00161 VRS_SERIALIZABLE_NO_SO_CLASS(TimeRequirement);
00162
00163 private:
00164
00165 VRSTime natural_;
00166 VRSTime shrink_;
00167 VRSTime stretch_;
00168 double align_;
00169
00170 enum { Infinite, Undefined, Defined };
00171 int state_;
00172 };
00173
00174 inline VRSTime TimeRequirement::getNatural() const {
00175 return natural_;
00176 }
00177 inline VRSTime TimeRequirement::getShrink() const {
00178 return shrink_;
00179 }
00180 inline VRSTime TimeRequirement::getStretch() const {
00181 return stretch_;
00182 }
00183
00184 inline VRSTime TimeRequirement::minimum () const {
00185 return VRSTime(std::max(natural_ - shrink_, 0.0));
00186 }
00187 inline VRSTime TimeRequirement::maximum () const {
00188 return natural_ + stretch_;
00189 }
00190
00191 inline void TimeRequirement::setNatural(VRSTime t) {
00192 natural_ = t;
00193 }
00194 inline void TimeRequirement::setShrink(VRSTime t) {
00195 shrink_ = t;
00196 }
00197 inline void TimeRequirement::setStretch(VRSTime t) {
00198 stretch_ = t;
00199 }
00200
00201 inline void TimeRequirement::setAlignment(double align) {
00202 VRS_Assertion(align>=0.0 && align<=1.0, "alignment must be in [0,1]");
00203 align_ = align;
00204 }
00205
00206 inline double TimeRequirement::getAlignment() const { return align_; }
00207
00208 inline bool TimeRequirement::isDefined() const {
00209 return state_==Defined;
00210 }
00211 inline bool TimeRequirement::isUndefined() const {
00212 return state_==Undefined;
00213 }
00214 inline bool TimeRequirement::isInfinite() const {
00215 return state_==Infinite;
00216 }
00217
00218 }
00219
00220 #endif // VRS_TIMEREQUIREMENT_H