tp_timeconstraint.cppGo to the documentation of this file.00001 /* tp_timecontraint.cpp -- model of timeconstraints in timed automata */ 00002 00003 00004 /* Timeplugin for FAU Discrete Event Systems Library (libfaudes) 00005 00006 Copyright (C) 2006 B Schlein 00007 Copyright (C) 2007 Thomas Moor 00008 Exclusive copyright is granted to Klaus Schmidt 00009 00010 */ 00011 00012 00013 00014 #include "tp_timeconstraint.h" 00015 00016 namespace faudes { 00017 00018 00019 /******************************************************************** 00020 00021 Implementation of ClockSet 00022 00023 ********************************************************************/ 00024 00025 00026 // std faudes type (cannot do New() with macro) 00027 FAUDES_TYPE_IMPLEMENTATION_COPY(Void,ClockSet,NameSet) 00028 FAUDES_TYPE_IMPLEMENTATION_CAST(Void,ClockSet,NameSet) 00029 FAUDES_TYPE_IMPLEMENTATION_ASSIGN(Void,ClockSet,NameSet) 00030 FAUDES_TYPE_IMPLEMENTATION_EQUAL(Void,ClockSet,NameSet) 00031 00032 // ClockSet::msClockSymbolTable (static) 00033 SymbolTable ClockSet::msSymbolTable; 00034 00035 // ClockSet(void); 00036 ClockSet::ClockSet(void) : NameSet() { 00037 // overwrite default static symboltable 00038 mpSymbolTable= &msSymbolTable; 00039 NameSet::Name("Clocks"); 00040 FD_DC("ClockSet("<<this<<")::ClockSet() with csymtab "<< SymbolTablep()); 00041 } 00042 00043 // ClockSet(clockset) 00044 ClockSet::ClockSet(const ClockSet& rOtherSet) : NameSet(rOtherSet) { 00045 FD_DC("ClockSet(" << this << ")::ClockSet(rOtherSet " << &rOtherSet << ")"); 00046 } 00047 00048 // ClockSet(file); 00049 ClockSet::ClockSet(const std::string& rFilename, const std::string& rLabel) : NameSet() { 00050 // overwrite default static symboltable 00051 mpSymbolTable= &msSymbolTable; NameSet::Name("Clocks"); 00052 // read file 00053 NameSet::Read(rFilename,rLabel); 00054 } 00055 00056 // Clockset::New() 00057 ClockSet* ClockSet::New(void) const { 00058 ClockSet* res = new ClockSet(); 00059 res->mpSymbolTable=mpSymbolTable; 00060 return res; 00061 } 00062 00063 // DoAssign() 00064 void ClockSet::DoAssign(const ClockSet& rSourceSet) { 00065 // call base 00066 NameSet::DoAssign(rSourceSet); 00067 } 00068 00069 // DoEqual() 00070 bool ClockSet::DoEqual(const ClockSet& rOtherSet) const { 00071 // call base 00072 return NameSet::DoEqual(rOtherSet); 00073 } 00074 00075 // ClockSet::StaticSymbolTablep 00076 SymbolTable* ClockSet::StaticSymbolTablep(void) { 00077 return &msSymbolTable; 00078 } 00079 00080 00081 00082 00083 00084 /******************************************************************** 00085 00086 Implementation of ElemConstraint 00087 00088 ********************************************************************/ 00089 00090 00091 // helper (conversion from operatorname to string 00092 std::string ElemConstraint::OperatorName(Operator op){ 00093 switch(op){ 00094 case LessThan: return "LT"; 00095 case GreaterThan: return "GT"; 00096 case LessEqual: return "LE"; 00097 case GreaterEqual: return "GE"; 00098 } 00099 return "Inalid"; 00100 } 00101 00102 00103 // Constructor 00104 ElemConstraint::ElemConstraint(void) { 00105 Set(0,LessThan,0); 00106 } 00107 00108 // Constructor 00109 ElemConstraint::ElemConstraint( 00110 Idx clockindex, Operator op, const tpTime::Type timeconst) { 00111 Set(clockindex,op,timeconst); 00112 } 00113 00114 00115 // Set(clockindex, op, timeconst) 00116 void ElemConstraint::Set(Idx clockindex, Operator op, const tpTime::Type timeconst) { 00117 mClockIndex = clockindex; 00118 mCompOperator = op; 00119 mTimeConstant = timeconst; 00120 } 00121 00122 // Clock(clockindex) 00123 Idx ElemConstraint::Clock(Idx clockindex) { 00124 mClockIndex=clockindex; 00125 return mClockIndex; 00126 } 00127 00128 // Clock() 00129 Idx ElemConstraint::Clock(void) const { 00130 return mClockIndex; 00131 } 00132 00133 // CompOperator(newOp) 00134 void ElemConstraint::CompOperator(Operator newOp) { 00135 mCompOperator = newOp; 00136 } 00137 00138 00139 // CompOperator() 00140 ElemConstraint::Operator ElemConstraint::CompOperator(void) const { 00141 return mCompOperator; 00142 } 00143 00144 00145 // TimeConstant(newTimeConst) 00146 void ElemConstraint::TimeConstant (tpTime::Type newTimeConst) { 00147 mTimeConstant = newTimeConst; 00148 } 00149 00150 // TimeConstant() 00151 tpTime::Type ElemConstraint::TimeConstant(void) const { 00152 return mTimeConstant; 00153 } 00154 00155 // Str() const 00156 std::string ElemConstraint::Str(void) const { 00157 std::stringstream resstream; 00158 resstream << "(" << mClockIndex << " " 00159 << OperatorName(mCompOperator) << " " << mTimeConstant << ")"; 00160 std::string result = resstream.str(); 00161 return result; 00162 } 00163 00164 // operator== 00165 bool ElemConstraint::operator== (const ElemConstraint & otherClockConstraint) const { 00166 return ( mClockIndex == otherClockConstraint.mClockIndex 00167 && mCompOperator == otherClockConstraint.mCompOperator 00168 && mTimeConstant == otherClockConstraint.mTimeConstant ); 00169 } 00170 00171 // operator!= 00172 bool ElemConstraint::operator!= (const ElemConstraint & otherClockConstraint) const { 00173 return !(operator==(otherClockConstraint)); 00174 } 00175 00176 // operator < 00177 bool ElemConstraint::operator < (const ElemConstraint& otherElemConstraint) const { 00178 if (mClockIndex < otherElemConstraint.mClockIndex) return true; 00179 if (mClockIndex > otherElemConstraint.mClockIndex) return false; 00180 if (mCompOperator < otherElemConstraint.mCompOperator) return true; 00181 if (mCompOperator > otherElemConstraint.mCompOperator) return false; 00182 if (mTimeConstant < otherElemConstraint.mTimeConstant) return true; 00183 return false; 00184 } 00185 00186 00187 /******************************************************************** 00188 00189 Implementation of TimeConstraint 00190 00191 ********************************************************************/ 00192 00193 00194 00195 // empty constructor 00196 TimeConstraint::TimeConstraint(void) { 00197 FD_DC("TimeConstraint(" << this << ")::TimeConstraint()"); 00198 mpClockSymbolTable=ClockSet::StaticSymbolTablep(); 00199 mName="TimeConstraint"; 00200 } 00201 00202 // read file constructor 00203 TimeConstraint::TimeConstraint(const std::string& rFilename, const std::string& rLabel) { 00204 FD_DC("TimeConstraint(" << this << ")::TimeConstraint(" << rFilename << ")"); 00205 mpClockSymbolTable=ClockSet::StaticSymbolTablep(); 00206 Read(rFilename, rLabel); 00207 } 00208 00209 // constructor 00210 TimeConstraint::TimeConstraint(const TimeConstraint& rOtherTimeConstraint) { 00211 FD_DC("TimeConstraint(" << this << ")::TimeConstraint(other)"); 00212 mName=rOtherTimeConstraint.mName; 00213 mpClockSymbolTable= rOtherTimeConstraint.mpClockSymbolTable; 00214 mClockConstraints = rOtherTimeConstraint.ClockConstraints(); 00215 } 00216 00217 00218 // Destructor 00219 TimeConstraint::~TimeConstraint(void) { 00220 } 00221 00222 // ClockSymbolTablep() 00223 SymbolTable* TimeConstraint::ClockSymbolTablep(void) const { 00224 return mpClockSymbolTable; 00225 } 00226 00227 // ClockSymbolTablep(pSymTab) 00228 void TimeConstraint::ClockSymbolTablep(SymbolTable* pSymTab) { 00229 if(mClockConstraints.empty()) { 00230 mpClockSymbolTable=pSymTab; 00231 } else { 00232 // TODO: implement reindex 00233 FD_ERR("TimeConstraint::SymboltTable(pSymTab): " 00234 << "set SymbolTable not implemented!!"); 00235 abort(); 00236 } 00237 } 00238 00239 // Empty() 00240 bool TimeConstraint::Empty(void) const { 00241 return mClockConstraints.empty(); 00242 } 00243 00244 // Size of set of ElemConstraints 00245 Idx TimeConstraint::Size(void) const { 00246 return (Idx)mClockConstraints.size(); 00247 } 00248 00249 // InsClock() 00250 Idx TimeConstraint::InsClock(const std::string& rClockName) const { 00251 return mpClockSymbolTable->InsEntry(rClockName); 00252 } 00253 00254 // ClockName(clockindex) 00255 std::string TimeConstraint::ClockName(Idx clockindex) const { 00256 return mpClockSymbolTable->Symbol(clockindex); 00257 } 00258 00259 // ClockIndex(clockname) 00260 Idx TimeConstraint::ClockIndex(const std::string& rClockName) const { 00261 return mpClockSymbolTable->Index(rClockName); 00262 } 00263 00264 00265 // EStr(ElemConstraint) const 00266 std::string TimeConstraint::EStr(const ElemConstraint& rElemConstraint) const { 00267 std::stringstream resstream; 00268 resstream << "(" << ClockName(rElemConstraint.Clock()) << "[" << rElemConstraint.Clock() 00269 << "] " << ElemConstraint::OperatorName(rElemConstraint.CompOperator()) << " " 00270 << rElemConstraint.TimeConstant() << ")"; 00271 std::string result = resstream.str(); 00272 return result; 00273 } 00274 00275 // Insert(rNewConstr) 00276 TimeConstraint::Iterator TimeConstraint::Insert(const ElemConstraint& rNewConstr) { 00277 FD_DC("TimeConstraint(" << this << ")::Insert(" << rNewConstr.Str() << ")"); 00278 if(rNewConstr.Clock()<=0 || ClockName(rNewConstr.Clock())=="") { 00279 std::stringstream errstr; 00280 errstr << "Invalid ElemConstraint: \"" << rNewConstr.Str(); 00281 throw Exception("TimeConstraint::Insert", errstr.str(), 55); 00282 } 00283 return mClockConstraints.insert(rNewConstr).first; 00284 } 00285 00286 // Insert(clock, op, timeconst) 00287 TimeConstraint::Iterator TimeConstraint::Insert(Idx clockindex, Operator op, const tpTime::Type timeconst) { 00288 FD_DC("TimeConstraint(" << this << ")::Insert(" 00289 << clockindex << " " << ElemConstraint::OperatorName(op) << " " << timeconst << ")"); 00290 ElemConstraint newconstr(clockindex,op,timeconst); 00291 return Insert(newconstr); 00292 } 00293 00294 00295 // Insert(clock, op, timeconst) 00296 TimeConstraint::Iterator TimeConstraint::Insert( 00297 const std::string clockname, 00298 Operator op, 00299 const tpTime::Type timeconst) 00300 { 00301 FD_DC("TimeConstraint(" << this << ")::Insert(\"" 00302 << clockname << "\" " << ElemConstraint::OperatorName(op) << " " << timeconst << ")"); 00303 Idx clockindex = InsClock(clockname); 00304 return Insert(clockindex,op,timeconst); 00305 } 00306 00307 // Insert(rNewConstraints) 00308 void TimeConstraint::Insert(const std::list<ElemConstraint>& rNewConstraints) { 00309 FD_DC("TimeConstraint(" << this << ")::Insert(const std::list<ElemConstraint>&)"); 00310 // HELPERS 00311 std::list<ElemConstraint>::const_iterator it; 00312 // ALGORITHM 00313 for(it = rNewConstraints.begin(); it != rNewConstraints.end(); it++) 00314 Insert(*it); 00315 } 00316 00317 00318 // Insert(rOtherTimeConstraint) 00319 void TimeConstraint::Insert(const TimeConstraint& rOtherTimeConstraint) { 00320 FD_DC("TimeConstraint(" << this << ")::Insert(" << rOtherTimeConstraint.ToString() << ")"); 00321 // HELPERS 00322 Iterator it; 00323 // ALGORITHM 00324 if(mpClockSymbolTable != rOtherTimeConstraint.mpClockSymbolTable) { 00325 FD_ERR("TimeConstraint::Insert " 00326 << "SymbolTable mismatch aka not implemented!!"); 00327 abort(); 00328 } 00329 for(it = rOtherTimeConstraint.Begin(); it != rOtherTimeConstraint.End(); it++) { 00330 Insert(*it); 00331 } 00332 } 00333 00334 // ClockConstraints() 00335 std::set<ElemConstraint> TimeConstraint::ClockConstraints(void) const { 00336 return mClockConstraints; 00337 } 00338 00339 00340 // EraseByClock(clock) 00341 bool TimeConstraint::EraseByClock(Idx clock) { 00342 FD_DC("TimeConstraint(" << this << ")::EraseByClock(" << clock << ") const"); 00343 // HELPERS 00344 iterator lit,uit; 00345 00346 // ALGORITHM 00347 lit= mClockConstraints.lower_bound(ElemConstraint(clock,ElemConstraint::GreaterEqual,0)); 00348 uit= mClockConstraints.lower_bound(ElemConstraint(clock+1,ElemConstraint::GreaterEqual,0)); 00349 00350 if(lit==mClockConstraints.end()) 00351 return false; 00352 00353 mClockConstraints.erase(lit,uit); 00354 return true; 00355 } 00356 00357 00358 // Erase(it) 00359 TimeConstraint::Iterator TimeConstraint::Erase(Iterator it) { 00360 FD_DC("TimeConstraint(" << this << ")::Erase(" << it->Str() << ") const"); 00361 if(it==End()) return it; 00362 iterator del= it; //cit 00363 it++; 00364 mClockConstraints.erase(del); 00365 return it; 00366 } 00367 00368 00369 // Erase(rElemConstr) 00370 bool TimeConstraint::Erase(const ElemConstraint& rElemConstr) { 00371 FD_DC("TimeConstraint(" << this << ")::Erase(" << rElemConstr.Str() << ") const"); 00372 // HELPERS 00373 iterator it; 00374 // ALGORITHM 00375 it = mClockConstraints.find(rElemConstr); 00376 if(it == End()) return false; 00377 mClockConstraints.erase(it); 00378 return true; 00379 } 00380 00381 // Erase(clock, op, timeconst) 00382 bool TimeConstraint::Erase(Idx clockindex, Operator op, const tpTime::Type timeconst) { 00383 FD_DC("TimeConstraint(" << this << ")::Erase(" 00384 << clockindex << " " << ElemConstraint::OperatorName(op) << " " << timeconst << ")"); 00385 ElemConstraint newconstr(clockindex,op,timeconst); 00386 return Erase(newconstr); 00387 } 00388 00389 00390 // Erase(clock, op, timeconst) 00391 bool TimeConstraint::Erase(const std::string& clockname, Operator op, const tpTime::Type timeconst) 00392 { 00393 FD_DC("TimeConstraint(" << this << ")::Erase(\"" 00394 << clockname << "\" " << ElemConstraint::OperatorName(op) << " " << timeconst << ")"); 00395 Idx clockindex = ClockIndex(clockname); 00396 return Erase(clockindex,op,timeconst); 00397 } 00398 00399 // Exists(rElemConstr) 00400 bool TimeConstraint::Exists(const ElemConstraint& rElemConstr) const { 00401 FD_DC("TimeConstraint(" << this << ")::ExistsElConstr(" << rElemConstr.Str() << ") const"); 00402 // HELPERS 00403 Iterator it; 00404 // ALGORITHM 00405 it = mClockConstraints.find(rElemConstr); 00406 return (it != End()) ; 00407 } 00408 00409 00410 // Deletes all ElemConstraints 00411 void TimeConstraint::Clear(void) { 00412 FD_DC("TimeConstraint(" << this << ")::Clear() const"); 00413 mClockConstraints.clear(); 00414 } 00415 00416 00417 00418 // Iterator Begin() const 00419 TimeConstraint::Iterator TimeConstraint::Begin(void) const { 00420 return mClockConstraints.begin(); 00421 } 00422 00423 00424 // iterator End() const 00425 TimeConstraint::Iterator TimeConstraint::End(void) const { 00426 return mClockConstraints.end(); 00427 } 00428 00429 // reverse iterator RBegin() 00430 TimeConstraint::RIterator TimeConstraint::RBegin(void) const { 00431 return mClockConstraints.rbegin(); 00432 } 00433 00434 // reverse iterator REnd() const 00435 TimeConstraint::RIterator TimeConstraint::REnd(void) const { 00436 return mClockConstraints.rend(); 00437 } 00438 00439 // iterator Begin(clock) const 00440 TimeConstraint::Iterator TimeConstraint::Begin(Idx clock) const { 00441 return mClockConstraints.lower_bound(ElemConstraint(clock,ElemConstraint::GreaterEqual,0)); 00442 } 00443 00444 // iterator End(clock) const 00445 TimeConstraint::Iterator TimeConstraint::End(Idx clock) const { 00446 return mClockConstraints.lower_bound(ElemConstraint(clock+1,ElemConstraint::GreaterEqual,0)); 00447 } 00448 00449 // returns ClockSet filled with clocks used by ElemConstraints 00450 ClockSet TimeConstraint::ActiveClocks(void) const { 00451 FD_DC("TimeConstraint(" << this << ")::ActiveClocks() const"); 00452 //Helpers 00453 ClockSet result; 00454 result.SymbolTablep(mpClockSymbolTable); 00455 Iterator it; 00456 // Algorithm 00457 for(it = Begin(); it != End(); it++) 00458 result.Insert(it->Clock()); 00459 return result; 00460 } 00461 00462 // valid timeinterval for given clock 00463 TimeInterval TimeConstraint::Interval(const std::string& clockname) const{ 00464 Idx clockindex = ClockIndex(clockname); 00465 return Interval(clockindex); 00466 } 00467 00468 // valid timeinterval for given clock 00469 TimeInterval TimeConstraint::Interval(Idx clockindex) const{ 00470 FD_DC("TimeConstraint(" << this << ")::Interval(" << clockindex <<") const"); 00471 TimeInterval res; 00472 TimeInterval tint; 00473 Iterator it; 00474 for(it = Begin(clockindex); it != End(clockindex); it++) { 00475 FD_DC("TimeConstraint(" << this << ")::Interval: elemconstraint: " << it->Str()); 00476 tint.SetFull(); 00477 if(it->CompOperator() == ElemConstraint::LessThan) { 00478 tint.UB(it->TimeConstant()); 00479 tint.UBincl(false); 00480 } 00481 if(it->CompOperator() == ElemConstraint::LessEqual) { 00482 tint.UB(it->TimeConstant()); 00483 tint.UBincl(true); 00484 } 00485 if(it->CompOperator() == ElemConstraint::GreaterThan) { 00486 tint.LB(it->TimeConstant()); 00487 tint.LBincl(false); 00488 } 00489 if(it->CompOperator() == ElemConstraint::GreaterEqual) { 00490 tint.LB(it->TimeConstant()); 00491 tint.LBincl(true); 00492 } 00493 FD_DC("TimeConstraint(" << this << ")::Interval: interval: " << tint.Str()); 00494 res.Intersect(tint); 00495 } 00496 return res; 00497 } 00498 00499 00500 // set valid timeinterval for given clock 00501 void TimeConstraint::Interval(const std::string& clockname, const TimeInterval& rInterval) { 00502 Idx clockindex = InsClock(clockname); 00503 Interval(clockindex,rInterval); 00504 } 00505 00506 // set valid timeinterval for given clock 00507 void TimeConstraint::Interval(Idx clockindex, const TimeInterval& rInterval) { 00508 FD_DC("TimeConstraint(" << this << ")::Interval(" << clockindex <<", " << rInterval.Str() << ") "); 00509 EraseByClock(clockindex); 00510 if(rInterval.LBinf()==false) { 00511 ElemConstraint newconstraint; 00512 newconstraint.Clock(clockindex); 00513 if(rInterval.LBincl()) 00514 newconstraint.CompOperator(ElemConstraint::GreaterEqual); 00515 else 00516 newconstraint.CompOperator(ElemConstraint::GreaterThan); 00517 newconstraint.TimeConstant(rInterval.LB()); 00518 Insert(newconstraint); 00519 } 00520 if(rInterval.UBinf()==false) { 00521 ElemConstraint newconstraint; 00522 newconstraint.Clock(clockindex); 00523 if(rInterval.UBincl()) 00524 newconstraint.CompOperator(ElemConstraint::LessEqual); 00525 else 00526 newconstraint.CompOperator(ElemConstraint::LessThan); 00527 newconstraint.TimeConstant(rInterval.UB()); 00528 Insert(newconstraint); 00529 } 00530 } 00531 00532 00533 // Minimize() 00534 void TimeConstraint::Minimize(void) { 00535 ClockSet aclocks=ActiveClocks(); 00536 ClockSet::Iterator cit; 00537 for(cit=aclocks.Begin(); cit != aclocks.End(); cit++) { 00538 TimeInterval tint=Interval(*cit); 00539 Interval(*cit, tint); 00540 } 00541 } 00542 00543 // operator== 00544 bool TimeConstraint::operator== (const TimeConstraint & rOther) const { 00545 ClockSet aclocks=ActiveClocks(); 00546 aclocks.InsertSet(rOther.ActiveClocks()); 00547 ClockSet::Iterator cit; 00548 for(cit=aclocks.Begin(); cit != aclocks.End(); cit++) { 00549 TimeInterval tint=Interval(*cit); 00550 if(rOther.Interval(*cit)!=tint) return false; 00551 } 00552 return true; 00553 } 00554 00555 // operator!= 00556 bool TimeConstraint::operator!= (const TimeConstraint & rOther) const { 00557 return !(operator==(rOther)); 00558 } 00559 00560 00561 // Write() 00562 void TimeConstraint::Write(void) const { 00563 TokenWriter tw(TokenWriter::Stdout); 00564 Write(tw); 00565 } 00566 00567 // Write(rFilename, rLabel, openmode) 00568 void TimeConstraint::Write(const std::string& rFilename, const std::string& rLabel, 00569 std::ios::openmode openmode) const { 00570 try { 00571 TokenWriter tw(rFilename, openmode); 00572 Write(tw, rLabel); 00573 } 00574 catch (std::ios::failure&) { 00575 std::stringstream errstr; 00576 errstr << "Exception opening/writing file \"" << rFilename << "\""; 00577 throw Exception("TimeConstraint::Write", errstr.str(), 2); 00578 } 00579 } 00580 00581 // Write(tw) 00582 void TimeConstraint::Write(TokenWriter& tw) const { 00583 Write(tw, Name()); 00584 } 00585 00586 00587 // Write(tw, rLabel) 00588 void TimeConstraint::Write(TokenWriter& tw, const std::string& rLabel) const { 00589 Token token; 00590 Iterator it; 00591 int oldcolumns = tw.Columns(); 00592 tw.Columns(3); 00593 tw.WriteBegin(rLabel); 00594 for (it = Begin(); it != End(); ++it) { 00595 // 1. clock 00596 if(ClockName(it->Clock()) != "") { 00597 token.SetString(ClockName(it->Clock())); 00598 tw << token; 00599 } else { 00600 token.SetInteger(it->Clock()); 00601 tw << token; 00602 } 00603 // 2. operator 00604 token.SetString(ElemConstraint::OperatorName(it->CompOperator())); 00605 tw << token; 00606 // 3. timeconst 00607 token.SetFloat((Float) it->TimeConstant()); 00608 tw << token; 00609 } 00610 tw.WriteEnd(rLabel); 00611 tw.Columns(oldcolumns); 00612 } 00613 00614 00615 // ToString() 00616 std::string TimeConstraint::ToString(void) const { 00617 TokenWriter tw(TokenWriter::String); 00618 Write(tw); 00619 return tw.Str(); 00620 } 00621 00622 00623 // DWrite() 00624 void TimeConstraint::DWrite(void) const { 00625 TokenWriter tw(TokenWriter::Stdout); 00626 DWrite(tw); 00627 } 00628 00629 // DWrite(tw) 00630 void TimeConstraint::DWrite(TokenWriter& tw) const { 00631 Token token; 00632 Iterator it; 00633 tw.WriteBegin(Name()); 00634 for (it = Begin(); it != End(); ++it) { 00635 tw << EStr(*it); 00636 } 00637 tw.WriteEnd(Name()); 00638 } 00639 00640 // Read(rFilename, rLabel) 00641 void TimeConstraint::Read(const std::string& rFilename, const std::string& rLabel) { 00642 TokenReader tr(rFilename); 00643 Read(tr,rLabel); 00644 } 00645 00646 // Read(rTr, rLabel) 00647 void TimeConstraint::Read(TokenReader& rTr, const std::string& rLabel) { 00648 Clear(); 00649 Name(rLabel); 00650 rTr.ReadBegin(rLabel); 00651 00652 std::string clockname; 00653 tpTime::Type timeconst; 00654 ElemConstraint::Operator compop; 00655 Token token; 00656 while(rTr.Peek(token)) { 00657 // 0. check for end 00658 if (token.Type() == Token::End) { 00659 break; 00660 } 00661 // 1. read clock 00662 rTr >> token; 00663 if (token.Type() != Token::String) { 00664 std::stringstream errstr; 00665 errstr << "Invalid clock" << rTr.FileLine(); 00666 throw Exception("TimeConstraint::Read", errstr.str(), 56); 00667 } 00668 clockname=token.StringValue(); 00669 // 2. read operator 00670 rTr >> token; 00671 if (token.Type() != Token::String) { 00672 std::stringstream errstr; 00673 errstr << "Invalid operator" << rTr.FileLine(); 00674 throw Exception("TimeConstraint::Read", errstr.str(), 56); 00675 } 00676 if(token.StringValue() == "LE") { 00677 compop = ElemConstraint::LessEqual; 00678 } else if(token.StringValue() == "GE") { 00679 compop = ElemConstraint::GreaterEqual; 00680 } else if(token.StringValue() == "LT") { 00681 compop = ElemConstraint::LessThan; 00682 } else if(token.StringValue() == "GT") { 00683 compop = ElemConstraint::GreaterThan; 00684 } else { 00685 std::stringstream errstr; 00686 errstr << "Invalid operator value " << rTr.FileLine(); 00687 throw Exception("TimedTransSet::ReadTimeConstraint", errstr.str(), 56); 00688 } 00689 // 3. read timeconst 00690 rTr >> token; 00691 if (!token.IsFloat()) { 00692 std::stringstream errstr; 00693 errstr << "Invalid timeconstant" << rTr.FileLine(); 00694 throw Exception("TimeConstraint::Read", errstr.str(), 56); 00695 } 00696 timeconst=(tpTime::Type) token.FloatValue(); 00697 // 4. set constraint 00698 Insert(clockname,compop,timeconst); 00699 } // while not end 00700 rTr.ReadEnd(rLabel); 00701 } 00702 00703 00704 // End Implementation of TimeConstraint 00705 00706 00707 00708 } // namespace faudes libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |