libFAUDES
Sections
Index
|
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 // check for invalid flags 00055 if((mFlags & ~mAllAttributeIosEvent) == 0) { 00056 std::string option; 00057 // check flags 00058 switch (mFlags){ 00059 case 0x10: 00060 option = "I"; 00061 break; 00062 case 0x20: 00063 option = "O"; 00064 break; 00065 default: 00066 option = "IO"; 00067 break; 00068 } 00069 if(option!="") rTw.WriteOption(option); 00070 } 00071 // if other flags are set write hex-value of whole flag configuration 00072 else { 00073 token.SetInteger16(mFlags); 00074 rTw << token; 00075 } 00076 } 00077 00078 00079 00080 //DoRead(rTw,rLabel,pContext); 00081 void AttributeIosEvent::DoRead(TokenReader& rTr, 00082 const std::string& rLabel, 00083 const Type* pContext) 00084 { 00085 (void) rLabel; 00086 (void) pContext; 00087 // initialize with default value 00088 mFlags = mDefAttributeIosEvent; 00089 Token token; 00090 rTr.Peek(token); 00091 // if token indicates a non-valid flag 00092 // set mFlags to 0x12ff 00093 if(token.Type()==Token::Integer16) { 00094 rTr.Get(token); 00095 mFlags=token.IntegerValue(); 00096 return; 00097 } 00098 // if token indicates a valid option 00099 // determine its type and set flags 00100 if(token.IsOption()) { 00101 rTr.Get(token); 00102 std::string option=token.OptionValue(); 00103 if(option.find( 'I',0 ) != std::string::npos) 00104 SetInput(); 00105 if(option.find( 'O',0 ) != std::string::npos) 00106 SetOutput(); 00107 return; 00108 } 00109 } 00110 00111 00112 /* 00113 ********************************************************************************* 00114 ********************************************************************************* 00115 ********************************************************************************* 00116 00117 Implementation: state attributes 00118 00119 ********************************************************************************* 00120 ********************************************************************************* 00121 ********************************************************************************* 00122 */ 00123 00124 00125 00126 // faudes type std 00127 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeIosState,AttributeFlags) 00128 00129 //DoAssign( rSrcAttr ) 00130 void AttributeIosState::DoAssign(const AttributeIosState& rSrcAttr) { 00131 // call base (incl virtual clear) 00132 AttributeFlags::DoAssign(rSrcAttr); 00133 } 00134 00135 00136 //ToString() 00137 std::string AttributeIosState::ToString(void) const { 00138 return ToStringInteger16(mFlags); 00139 } 00140 00141 00142 //DoWrite(rTw,rLabel,pContext); 00143 void AttributeIosState::DoWrite(TokenWriter& rTw, 00144 const std::string& rLabel, 00145 const Type* pContext) const 00146 { 00147 (void) rLabel; 00148 (void) pContext; 00149 // dont wrtite default value 00150 if(IsDefault()) return; 00151 FD_DC("AttributeIosState(" << this << ")::DoWrite(tr)"); 00152 Token token; 00153 // check if only my flags are set 00154 if( (mFlags & ~mAllIosFlags) == 0 ) { 00155 std::string option=""; 00156 if(Input()) option = "I"; 00157 if(Output()) option = "O"; 00158 if(Error()) option = "E"; 00159 token.SetOption(option); 00160 } 00161 // if other flags are used, write hex 00162 else 00163 token.SetInteger16(mFlags); 00164 // do write 00165 rTw << token; 00166 } 00167 00168 00169 //DoRead(rTw,rLabel,pContext); 00170 void AttributeIosState::DoRead(TokenReader& rTr, 00171 const std::string& rLabel, 00172 const Type* pContext) 00173 { 00174 (void) rLabel; 00175 (void) pContext; 00176 // initialize with default value 00177 mFlags=mDefIosFlags; 00178 // inspect token 00179 Token token; 00180 rTr.Peek(token); 00181 // case a: its an hex number 00182 if(token.Type()==Token::Integer16) { 00183 rTr.Get(token); 00184 mFlags=token.IntegerValue(); 00185 return; 00186 } 00187 // case b: its an option string 00188 if(token.IsOption()) { 00189 rTr.Get(token); 00190 std::string option=token.OptionValue(); 00191 if(option.find( "I", 0) != std::string::npos) SetInput(); 00192 if(option.find( "O", 0) != std::string::npos) SetOutput(); 00193 if(option.find( "E", 0) != std::string::npos) SetError(); 00194 return; 00195 } 00196 } 00197 00198 }//end namespace faudes |
libFAUDES 2.20d --- 2011.04.26 --- c++ source docu by doxygen