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