libFAUDES
Sections
Index
|
cfl_cgenerator.cppGo 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 token.SetOption(option); 00086 } 00087 // if other flags used, write hex 00088 else { 00089 token.SetInteger16(mFlags); 00090 } 00091 rTw << token; 00092 } 00093 00094 //XWrite(rTw) 00095 void AttributeCFlags::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00096 (void) rLabel; (void) pContext; 00097 if(IsDefault()) return; 00098 FD_DC("AttributeCFlags(" << this << ")::DoXWrite(tw)"); 00099 Token token; 00100 // if further flags are used, let base cxlass write with base 16 00101 if( (mFlags & ~mAllCFlags) != 0 ) { 00102 AttributeFlags::DoXWrite(rTw,rLabel,pContext); 00103 } 00104 // write friendly tags anyway 00105 std::string option; 00106 if((mDefCFlags & mControllableFlag) != (mFlags & mControllableFlag)) { 00107 token.SetEmpty("Controllable"); 00108 if(!Controllable()) token.InsAttributeBoolean("value",0); 00109 rTw.Write(token); 00110 } 00111 if((mDefCFlags & mObservableFlag) != (mFlags & mObservableFlag)) { 00112 token.SetEmpty("Observable"); 00113 if(!Observable()) token.InsAttributeBoolean("value",0); 00114 rTw.Write(token); 00115 } 00116 if((mDefCFlags & mForcibleFlag) != (mFlags & mForcibleFlag)) { 00117 token.SetEmpty("Forcible"); 00118 if(!Forcible()) token.InsAttributeBoolean("value",0); 00119 rTw.Write(token); 00120 } 00121 if((mDefCFlags & mAbstractionFlag) != (mFlags & mAbstractionFlag)) { 00122 token.SetEmpty("HighLevel"); 00123 if(!Highlevel()) token.SetEmpty("LowLevel"); 00124 rTw.Write(token); 00125 } 00126 } 00127 00128 //DoRead(rTr) 00129 void AttributeCFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) { 00130 (void) rLabel; (void) pContext; 00131 mFlags=mDefCFlags; 00132 Token token; 00133 rTr.Peek(token); 00134 // faudes format, flags as integer 00135 if(token.IsInteger16()) { 00136 AttributeFlags::DoRead(rTr,rLabel,pContext); 00137 return; 00138 } 00139 // faudes format, flags as option string 00140 if(token.IsOption()) { 00141 rTr.Get(token); 00142 std::string option=token.OptionValue(); 00143 if(option.find( 'C', 0) != std::string::npos) SetControllable(); 00144 if(option.find( 'c', 0) != std::string::npos) ClrControllable(); 00145 if(option.find( 'O', 0) != std::string::npos) SetObservable(); 00146 if(option.find( 'o', 0) != std::string::npos) ClrObservable(); 00147 if(option.find( 'F', 0) != std::string::npos) SetForcible(); 00148 if(option.find( 'f', 0) != std::string::npos) ClrForcible(); 00149 if(option.find( 'A', 0) != std::string::npos) SetHighlevel(); 00150 if(option.find( 'a', 0) != std::string::npos) SetLowlevel(); 00151 return; 00152 } 00153 // xml format 00154 while(true) { 00155 rTr.Peek(token); 00156 // explicit integer 00157 if(token.IsBegin("Flags")) { 00158 AttributeFlags::DoRead(rTr,rLabel,pContext); 00159 continue; 00160 } 00161 // known bits 00162 if(token.IsBegin("Controllable")) { 00163 rTr.ReadBegin("Controllable",token); 00164 SetControllable(); 00165 if(token.ExistsAttributeInteger("value")) 00166 if(token.AttributeIntegerValue("value")==false) 00167 ClrControllable(); 00168 rTr.ReadEnd("Controllable"); 00169 continue; 00170 } 00171 if(token.IsBegin("Observable")) { 00172 rTr.ReadBegin("Observable",token); 00173 SetObservable(); 00174 if(token.ExistsAttributeInteger("value")) 00175 if(token.AttributeIntegerValue("value")==false) 00176 ClrObservable(); 00177 rTr.ReadEnd("Observable"); 00178 continue; 00179 } 00180 if(token.IsBegin("Forcible")) { 00181 rTr.ReadBegin("Forcible",token); 00182 SetForcible(); 00183 if(token.ExistsAttributeInteger("value")) 00184 if(token.AttributeIntegerValue("value")==false) 00185 ClrForcible(); 00186 rTr.ReadEnd("Forcible"); 00187 continue; 00188 } 00189 if(token.IsBegin("HighLevel")) { 00190 rTr.ReadBegin("HighLevel",token); 00191 SetHighlevel(); 00192 if(token.ExistsAttributeInteger("value")) 00193 if(token.AttributeIntegerValue("value")==false) 00194 SetLowlevel(); 00195 continue; 00196 } 00197 if(token.IsBegin("LowLevel")) { 00198 rTr.ReadBegin("LowLevel",token); 00199 SetLowlevel(); 00200 if(token.ExistsAttributeInteger("value")) 00201 if(token.AttributeIntegerValue("value")==false) 00202 SetHighlevel(); 00203 continue; 00204 } 00205 // stop at unknown tag 00206 break; 00207 } 00208 } 00209 00210 00211 } // end namespace |
libFAUDES 2.20s --- 2011.10.12 --- c++ source docu by doxygen