ios_attributes.cppGo to the documentation of this file.00001 /** @file ios_attributes.cpp I/O-system attributes */ 00002 00003 /* 00004 Standart IO Systems Plug-In for FAU Discrete Event Systems 00005 Library (libfaudes) 00006 00007 Copyright (C) 2010, Thomas Wittmann, Thomas Moor 00008 00009 */ 00010 00011 00012 #include "ios_attributes.h" 00013 #include <cfl_types.h> 00014 00015 namespace faudes { 00016 00017 00018 /* 00019 ********************************************************************************* 00020 ********************************************************************************* 00021 ********************************************************************************* 00022 00023 Implementation: event attributes 00024 00025 ********************************************************************************* 00026 ********************************************************************************* 00027 ********************************************************************************* 00028 */ 00029 00030 00031 // faudes type std 00032 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeIosEvent,AttributeFlags) 00033 00034 00035 // Assign my members 00036 void AttributeIosEvent::DoAssign(const AttributeIosEvent& rSrcAttr) { 00037 // call base (incl virtual clear) 00038 AttributeFlags::DoAssign(rSrcAttr); 00039 } 00040 00041 00042 //DoWrite(rTw,rLabel,pContext); 00043 void AttributeIosEvent::DoWrite(TokenWriter& rTw, 00044 const std::string& rLabel, 00045 const Type* pContext) const 00046 { 00047 (void) rLabel; 00048 (void) pContext; 00049 // dont write default values 00050 if(IsDefault()) return; 00051 // debug output 00052 FD_DC("AttributeIosEvent(" << this << ")::DoWrite(tr)"); 00053 Token token; 00054 // if further flags are used, let base class write with base 16 00055 if( (mFlags & ~mAllIosFlags) != 0 ) { 00056 AttributeFlags::DoWrite(rTw,rLabel,pContext); 00057 return; 00058 } 00059 // write my flags symbolically 00060 std::string option; 00061 switch (mFlags){ 00062 case 0x10: 00063 option = "I"; 00064 break; 00065 case 0x20: 00066 option = "O"; 00067 break; 00068 default: 00069 option = "IO"; 00070 break; 00071 } 00072 rTw.WriteOption(option); 00073 } 00074 00075 00076 //XWrite(rTw) 00077 void AttributeIosEvent::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00078 (void) rLabel; (void) pContext; 00079 if(IsDefault()) return; 00080 FD_DC("AttributeIosEvent(" << this << ")::DoXWrite(tw)"); 00081 Token token; 00082 // if further flags are used, let base cxlass write with base 16 00083 if( (mFlags & ~mAllIosFlags) != 0 ) { 00084 AttributeFlags::DoXWrite(rTw,rLabel,pContext); 00085 } 00086 // write friendly tags anyway 00087 if((mDefIosFlags & mInputFlag) != (mFlags & mInputFlag)) { 00088 token.SetEmpty("Input"); 00089 if(!Input()) token.InsAttributeBoolean("value",0); 00090 rTw.Write(token); 00091 } 00092 if((mDefIosFlags & mOutputFlag) != (mFlags & mOutputFlag)) { 00093 token.SetEmpty("Output"); 00094 if(!Output()) token.InsAttributeBoolean("value",0); 00095 rTw.Write(token); 00096 } 00097 } 00098 00099 00100 00101 00102 //DoRead(rTw,rLabel,pContext); 00103 void AttributeIosEvent::DoRead( 00104 TokenReader& rTr, 00105 const std::string& rLabel, 00106 const Type* pContext) 00107 { 00108 (void) rLabel; 00109 (void) pContext; 00110 // initialize with default value 00111 mFlags = mDefIosFlags; 00112 Token token; 00113 rTr.Peek(token); 00114 // faudes format, flags as integer 00115 if(token.IsInteger16()) { 00116 AttributeFlags::DoRead(rTr,rLabel,pContext); 00117 return; 00118 } 00119 // faudes format, flags as option string 00120 if(token.IsOption()) { 00121 rTr.Get(token); 00122 std::string option=token.OptionValue(); 00123 if(option.find( 'I', 0) != std::string::npos) SetInput(); 00124 if(option.find( 'i', 0) != std::string::npos) ClrInput(); 00125 if(option.find( 'O', 0) != std::string::npos) SetOutput(); 00126 if(option.find( 'o', 0) != std::string::npos) ClrOutput(); 00127 return; 00128 } 00129 // xml format 00130 while(true) { 00131 rTr.Peek(token); 00132 // explicit integer 00133 if(token.IsBegin("Flags")) { 00134 AttributeFlags::DoRead(rTr,rLabel,pContext); 00135 continue; 00136 } 00137 // known bits 00138 if(token.IsBegin("Input")) { 00139 rTr.ReadBegin("Input",token); 00140 SetInput(); 00141 if(token.ExistsAttributeInteger("value")) 00142 if(token.AttributeIntegerValue("value")==false) 00143 ClrInput(); 00144 rTr.ReadEnd("Input"); 00145 continue; 00146 } 00147 if(token.IsBegin("Output")) { 00148 rTr.ReadBegin("Output",token); 00149 SetOutput(); 00150 if(token.ExistsAttributeInteger("value")) 00151 if(token.AttributeIntegerValue("value")==false) 00152 ClrOutput(); 00153 rTr.ReadEnd("Output"); 00154 continue; 00155 } 00156 // stop at unknown tag 00157 break; 00158 } 00159 } 00160 00161 00162 /* 00163 ********************************************************************************* 00164 ********************************************************************************* 00165 ********************************************************************************* 00166 00167 Implementation: state attributes 00168 00169 ********************************************************************************* 00170 ********************************************************************************* 00171 ********************************************************************************* 00172 */ 00173 00174 00175 00176 // faudes type std 00177 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeIosState,AttributeFlags) 00178 00179 //DoAssign( rSrcAttr ) 00180 void AttributeIosState::DoAssign(const AttributeIosState& rSrcAttr) { 00181 // call base (incl virtual clear) 00182 AttributeFlags::DoAssign(rSrcAttr); 00183 } 00184 00185 00186 //ToString() 00187 std::string AttributeIosState::ToString(void) const { 00188 return ToStringInteger16(mFlags); 00189 } 00190 00191 00192 //DoWrite(rTw,rLabel,pContext); 00193 void AttributeIosState::DoWrite(TokenWriter& rTw, 00194 const std::string& rLabel, 00195 const Type* pContext) const 00196 { 00197 (void) rLabel; 00198 (void) pContext; 00199 // dont wrtite default value 00200 if(IsDefault()) return; 00201 FD_DC("AttributeIosState(" << this << ")::DoWrite(tr)"); 00202 // if further flags are used, let base class write with base 16 00203 if( (mFlags & ~mAllIosFlags) != 0 ) { 00204 AttributeFlags::DoWrite(rTw,rLabel,pContext); 00205 return; 00206 } 00207 // write my flags symbolically 00208 std::string option; 00209 if(Input()) option+="I"; 00210 if(Output()) option+="O"; 00211 if(Error()) option+="E"; 00212 if(option!="") 00213 rTw.WriteOption(option); 00214 } 00215 00216 00217 //XWrite(rTw) 00218 void AttributeIosState::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00219 (void) rLabel; (void) pContext; 00220 if(IsDefault()) return; 00221 FD_DC("AttributeIosState(" << this << ")::DoXWrite(tw)"); 00222 Token token; 00223 // if further flags are used, let base class write with base 16 00224 if( (mFlags & ~mAllIosFlags) != 0 ) { 00225 AttributeFlags::DoXWrite(rTw,rLabel,pContext); 00226 } 00227 // write friendly tags anyway 00228 if((mDefIosFlags & mInputFlag) != (mFlags & mInputFlag)) { 00229 token.SetEmpty("Input"); 00230 if(!Input()) token.InsAttributeBoolean("value",0); 00231 rTw.Write(token); 00232 } 00233 if((mDefIosFlags & mOutputFlag) != (mFlags & mOutputFlag)) { 00234 token.SetEmpty("Output"); 00235 if(!Output()) token.InsAttributeBoolean("value",0); 00236 rTw.Write(token); 00237 } 00238 if((mDefIosFlags & mErrorFlag) != (mFlags & mErrorFlag)) { 00239 token.SetEmpty("Error"); 00240 if(!Error()) token.InsAttributeBoolean("value",0); 00241 rTw.Write(token); 00242 } 00243 } 00244 00245 00246 00247 //DoRead(rTw,rLabel,pContext); 00248 void AttributeIosState::DoRead( 00249 TokenReader& rTr, 00250 const std::string& rLabel, 00251 const Type* pContext) 00252 { 00253 (void) rLabel; 00254 (void) pContext; 00255 // initialize with default value 00256 mFlags = mDefIosFlags; 00257 Token token; 00258 rTr.Peek(token); 00259 // faudes format, flags as integer 00260 if(token.IsInteger16()) { 00261 AttributeFlags::DoRead(rTr,rLabel,pContext); 00262 return; 00263 } 00264 // faudes format, flags as option string 00265 if(token.IsOption()) { 00266 rTr.Get(token); 00267 std::string option=token.OptionValue(); 00268 if(option.find( 'I', 0) != std::string::npos) SetInput(); 00269 if(option.find( 'i', 0) != std::string::npos) ClrInput(); 00270 if(option.find( 'O', 0) != std::string::npos) SetOutput(); 00271 if(option.find( 'o', 0) != std::string::npos) ClrOutput(); 00272 if(option.find( 'E', 0) != std::string::npos) SetError(); 00273 if(option.find( 'e', 0) != std::string::npos) ClrError(); 00274 return; 00275 } 00276 // xml format 00277 while(true) { 00278 rTr.Peek(token); 00279 // explicit integer 00280 if(token.IsBegin("Flags")) { 00281 AttributeFlags::DoRead(rTr,rLabel,pContext); 00282 continue; 00283 } 00284 // known bits 00285 if(token.IsBegin("Input")) { 00286 rTr.ReadBegin("Input",token); 00287 SetInput(); 00288 if(token.ExistsAttributeInteger("value")) 00289 if(token.AttributeIntegerValue("value")==false) 00290 ClrInput(); 00291 rTr.ReadEnd("Input"); 00292 continue; 00293 } 00294 if(token.IsBegin("Output")) { 00295 rTr.ReadBegin("Output",token); 00296 SetOutput(); 00297 if(token.ExistsAttributeInteger("value")) 00298 if(token.AttributeIntegerValue("value")==false) 00299 ClrOutput(); 00300 rTr.ReadEnd("Output"); 00301 continue; 00302 } 00303 if(token.IsBegin("Error")) { 00304 rTr.ReadBegin("Error",token); 00305 SetError(); 00306 if(token.ExistsAttributeInteger("value")) 00307 if(token.AttributeIntegerValue("value")==false) 00308 ClrError(); 00309 rTr.ReadEnd("Error"); 00310 continue; 00311 } 00312 // stop at unknown tag 00313 break; 00314 } 00315 } 00316 00317 00318 00319 }//end namespace faudes libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |