|
libFAUDES
Sections
Index
|
cfl_cgenerator.cppGo to the documentation of this file.00001 /** @file cfl_cgenerator.cpp Classes TcGenerator, cGenerator 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(AttributeCFlags::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(AttributeCFlags::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",1); 00109 else token.InsAttributeBoolean("value",0); 00110 rTw.Write(token); 00111 } 00112 if((mDefCFlags & mObservableFlag) != (mFlags & mObservableFlag)) { 00113 token.SetEmpty("Observable"); 00114 if(Observable()) token.InsAttributeBoolean("value",1); 00115 else token.InsAttributeBoolean("value",0); 00116 rTw.Write(token); 00117 } 00118 if((mDefCFlags & mForcibleFlag) != (mFlags & mForcibleFlag)) { 00119 token.SetEmpty("Forcible"); 00120 if(Forcible()) token.InsAttributeBoolean("value",1); 00121 else token.InsAttributeBoolean("value",0); 00122 rTw.Write(token); 00123 } 00124 if((mDefCFlags & mAbstractionFlag) != (mFlags & mAbstractionFlag)) { 00125 token.SetEmpty("Abstraction"); 00126 if(Highlevel()) token.InsAttributeBoolean("value",1); 00127 else token.InsAttributeBoolean("value",0); 00128 rTw.Write(token); 00129 } 00130 } 00131 00132 //DoRead(rTr) 00133 void AttributeCFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) { 00134 (void) rLabel; (void) pContext; 00135 mFlags=mDefCFlags; 00136 Token token; 00137 rTr.Peek(token); 00138 // faudes format, flags as integer 00139 if(token.IsInteger16()) { 00140 AttributeFlags::DoRead(rTr,rLabel,pContext); 00141 return; 00142 } 00143 // faudes format, flags as option string 00144 if(token.IsOption()) { 00145 rTr.Get(token); 00146 std::string option=token.OptionValue(); 00147 if(option.find( 'C', 0) != std::string::npos) SetControllable(); 00148 if(option.find( 'c', 0) != std::string::npos) ClrControllable(); 00149 if(option.find( 'O', 0) != std::string::npos) SetObservable(); 00150 if(option.find( 'o', 0) != std::string::npos) ClrObservable(); 00151 if(option.find( 'F', 0) != std::string::npos) SetForcible(); 00152 if(option.find( 'f', 0) != std::string::npos) ClrForcible(); 00153 if(option.find( 'A', 0) != std::string::npos) SetHighlevel(); 00154 if(option.find( 'a', 0) != std::string::npos) SetLowlevel(); 00155 return; 00156 } 00157 // xml format 00158 while(true) { 00159 rTr.Peek(token); 00160 // explicit integer 00161 if(token.IsBegin()) 00162 if(token.StringValue()=="Flags") { 00163 AttributeFlags::DoRead(rTr,rLabel,pContext); 00164 continue; 00165 } 00166 // known bits 00167 if(token.IsBegin()) 00168 if(token.StringValue()=="Controllable") { 00169 rTr.ReadBegin("Controllable",token); 00170 if(token.AttributeIntegerValue("value")) SetControllable(); 00171 else ClrControllable(); 00172 rTr.ReadEnd("Controllable"); 00173 continue; 00174 } 00175 if(token.IsBegin()) 00176 if(token.StringValue()=="Observable") { 00177 rTr.ReadBegin("Observable",token); 00178 if(token.AttributeIntegerValue("value")) SetObservable(); 00179 else ClrObservable(); 00180 rTr.ReadEnd("Observable"); 00181 continue; 00182 } 00183 if(token.IsBegin()) 00184 if(token.StringValue()=="Forcible") { 00185 rTr.ReadBegin("Forcible",token); 00186 if(token.AttributeIntegerValue("value")) SetForcible(); 00187 else ClrForcible(); 00188 rTr.ReadEnd("Forcible"); 00189 continue; 00190 } 00191 if(token.IsBegin()) 00192 if(token.StringValue()=="Abstraction") { 00193 rTr.ReadBegin("Abstraction",token); 00194 if(token.AttributeIntegerValue("value")) SetHighlevel(); 00195 else SetLowlevel(); 00196 rTr.ReadEnd("Abstraction"); 00197 continue; 00198 } 00199 // stop at unknown tag 00200 break; 00201 } 00202 } 00203 00204 00205 } // end namespace |
libFAUDES 2.18b --- 2010-12-17 --- c++ source docu by doxygen 1.6.3