cfl_cgenerator.cpp

Go to the documentation of this file.
00001 /** @file cfl_cgenerator.cpp Classes TcGenerator, System and AttributeCFlags */
00002 
00003 
00004 /* FAU Discrete Event Systems Library (libfaudes)
00005 
00006    Copyright (C) 2006  Bernd Opitz
00007    Copyright (C) 2007  Thomas Moor
00008    Exclusive copyright is granted to Klaus Schmidt
00009 
00010    This library is free software; you can redistribute it and/or
00011    modify it under the terms of the GNU Lesser General Public
00012    License as published by the Free Software Foundation; either
00013    version 2.1 of the License, or (at your option) any later version.
00014 
00015    This library is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018    Lesser General Public License for more details.
00019 
00020    You should have received a copy of the GNU Lesser General Public
00021    License along with this library; if not, write to the Free Software
00022    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00023 
00024 
00025       
00026 #include "cfl_cgenerator.h" 
00027 
00028 
00029 namespace faudes {
00030 
00031 
00032 
00033 /***********************************************************************************
00034  *
00035  * implementation of AttributeCFlags 
00036  *
00037  */
00038 
00039 
00040 // faudes type std
00041 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeCFlags,AttributeFlags)
00042 
00043 // Assign my members
00044 void AttributeCFlags::DoAssign(const AttributeCFlags& rSrcAttr) { 
00045   // call base
00046   AttributeFlags::DoAssign(rSrcAttr);
00047 }
00048 
00049 // Test my members
00050 bool AttributeCFlags::DoEqual(const AttributeCFlags& rOther) const { 
00051   // call base
00052   if(!AttributeFlags::DoEqual(rOther)) return false;
00053   // no additional members
00054   return true;
00055 }
00056 
00057 //Write(rTw)
00058 // Note: you should write attributes in a section, so that
00059 // the AttributeVoid read method can detect and skip them.
00060 // Here, we make an execption of the rule ...
00061 void AttributeCFlags::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00062   (void) rLabel; (void) pContext;
00063   if(IsDefault()) return;
00064   FD_DC("AttributeCFlags(" << this << ")::DoWrite(tr)");
00065   Token token;
00066   // if no other flags used, write option string
00067   if( (mFlags & ~mAllCFlags) == 0 ) {
00068     std::string option;
00069     if((mDefCFlags & mControllableFlag) != (mFlags & mControllableFlag)) {
00070       if(Controllable()) option = option+"C";
00071       else option = option+"c";
00072     }
00073     if((mDefCFlags & mObservableFlag) != (mFlags & mObservableFlag)) {
00074       if(Observable()) option = option+"O";
00075       else option = option+"o";
00076     }
00077     if((mDefCFlags & mForcibleFlag) != (mFlags & mForcibleFlag)) {
00078       if(Forcible()) option = option+"F";
00079       else option = option+"f";
00080     }
00081     if((mDefCFlags & mAbstractionFlag) != (mFlags & mAbstractionFlag)) {
00082       if(Highlevel()) option = option+"A";
00083       else option = option+"a";
00084     }
00085     if(option!="") {
00086       token.SetOption(option);
00087       rTw << token;
00088     }
00089   } 
00090   // if other flags used, write hex
00091   else { 
00092     token.SetInteger16(mFlags);
00093     rTw << token;
00094   }
00095 }
00096 
00097 //XWrite(rTw)
00098 void AttributeCFlags::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00099   (void) rLabel; (void) pContext;
00100   if(IsDefault()) return;
00101   FD_DC("AttributeCFlags(" << this << ")::DoXWrite(tw)");
00102   Token token;
00103   // if further flags are used, let base class write with base 16 
00104   if( (mFlags & ~mAllCFlags) != 0 ) {
00105     AttributeFlags::DoXWrite(rTw,rLabel,pContext);
00106   }
00107   // write friendly tags anyway
00108   std::string option;
00109   if((mDefCFlags & mControllableFlag) != (mFlags & mControllableFlag)) {
00110     token.SetEmpty("Controllable");
00111     if(!Controllable()) token.InsAttributeBoolean("value",0);
00112     rTw.Write(token);
00113   }
00114   if((mDefCFlags & mObservableFlag) != (mFlags & mObservableFlag)) {
00115     token.SetEmpty("Observable");
00116     if(!Observable()) token.InsAttributeBoolean("value",0);
00117     rTw.Write(token);
00118   }
00119   if((mDefCFlags & mForcibleFlag) != (mFlags & mForcibleFlag)) {
00120     token.SetEmpty("Forcible");
00121     if(!Forcible()) token.InsAttributeBoolean("value",0);
00122     rTw.Write(token);
00123   }
00124   if((mDefCFlags & mAbstractionFlag) != (mFlags & mAbstractionFlag)) {
00125     token.SetEmpty("HighLevel");
00126     if(!Highlevel()) token.SetEmpty("LowLevel");
00127     rTw.Write(token);
00128   } 
00129 }
00130 
00131 //DoRead(rTr)
00132 void AttributeCFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00133   (void) rLabel; (void) pContext;
00134   mFlags=mDefCFlags;
00135   Token token;
00136   rTr.Peek(token);
00137   // faudes format, flags as integer
00138   if(token.IsInteger16()) { 
00139     AttributeFlags::DoRead(rTr,rLabel,pContext);
00140     return;
00141   } 
00142   // faudes format, flags as option string
00143   if(token.IsOption()) {
00144     rTr.Get(token);
00145     std::string option=token.OptionValue();
00146     if(option.find( 'C', 0) != std::string::npos) SetControllable();
00147     if(option.find( 'c', 0) != std::string::npos) ClrControllable();
00148     if(option.find( 'O', 0) != std::string::npos) SetObservable();
00149     if(option.find( 'o', 0) != std::string::npos) ClrObservable();
00150     if(option.find( 'F', 0) != std::string::npos) SetForcible();
00151     if(option.find( 'f', 0) != std::string::npos) ClrForcible();
00152     if(option.find( 'A', 0) != std::string::npos) SetHighlevel();
00153     if(option.find( 'a', 0) != std::string::npos) SetLowlevel();
00154     return;
00155   }
00156   // xml format 
00157   while(true) {
00158     rTr.Peek(token);
00159     // explicit integer
00160     if(token.IsBegin("Flags")) {
00161       AttributeFlags::DoRead(rTr,rLabel,pContext);
00162       continue;
00163     }
00164     // known bits
00165     if(token.IsBegin("Controllable")) {
00166       rTr.ReadBegin("Controllable",token);
00167       SetControllable();
00168       if(token.ExistsAttributeInteger("value"))
00169   if(token.AttributeIntegerValue("value")==false)
00170           ClrControllable();
00171       rTr.ReadEnd("Controllable");
00172       continue;
00173     }
00174     if(token.IsBegin("Observable")) {
00175       rTr.ReadBegin("Observable",token);
00176       SetObservable();
00177       if(token.ExistsAttributeInteger("value"))
00178   if(token.AttributeIntegerValue("value")==false)
00179           ClrObservable();
00180       rTr.ReadEnd("Observable");
00181       continue;
00182     }
00183     if(token.IsBegin("Forcible")) {
00184       rTr.ReadBegin("Forcible",token);
00185       SetForcible();
00186       if(token.ExistsAttributeInteger("value"))
00187   if(token.AttributeIntegerValue("value")==false)
00188           ClrForcible();
00189       rTr.ReadEnd("Forcible");
00190       continue;
00191     }
00192     if(token.IsBegin("HighLevel")) {
00193       rTr.ReadBegin("HighLevel",token);
00194       SetHighlevel();
00195       if(token.ExistsAttributeInteger("value"))
00196   if(token.AttributeIntegerValue("value")==false)
00197           SetLowlevel();
00198       continue;
00199     }
00200     if(token.IsBegin("LowLevel")) {
00201       rTr.ReadBegin("LowLevel",token);
00202       SetLowlevel();
00203       if(token.ExistsAttributeInteger("value"))
00204   if(token.AttributeIntegerValue("value")==false)
00205           SetHighlevel();
00206       continue;
00207     }
00208     // stop at unknown tag
00209     break;
00210   }
00211 }
00212 
00213 
00214 } // end namespace

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen