ios_attributes.cpp
Go to the documentation of this file.
1 /** @file ios_attributes.cpp I/O-system attributes */
2 
3 /*
4  Standart IO Systems Plug-In for FAU Discrete Event Systems
5  Library (libfaudes)
6 
7  Copyright (C) 2010, Thomas Wittmann, Thomas Moor
8 
9 */
10 
11 
12 #include "ios_attributes.h"
13 #include <cfl_types.h>
14 
15 namespace faudes {
16 
17 
18 /*
19 *********************************************************************************
20 *********************************************************************************
21 *********************************************************************************
22 
23 Implementation: event attributes
24 
25 *********************************************************************************
26 *********************************************************************************
27 *********************************************************************************
28 */
29 
30 
31 // faudes type std
32 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeIosEvent,AttributeFlags)
33 
34 
35 // Assign my members
36 void AttributeIosEvent::DoAssign(const AttributeIosEvent& rSrcAttr) {
37  // call base (incl virtual clear)
38  AttributeFlags::DoAssign(rSrcAttr);
39 }
40 
41 
42 //DoWrite(rTw,rLabel,pContext);
44  const std::string& rLabel,
45  const Type* pContext) const
46 {
47  (void) rLabel;
48  (void) pContext;
49  // dont write default values
50  if(IsDefault()) return;
51  // debug output
52  FD_DC("AttributeIosEvent(" << this << ")::DoWrite(tr)");
53  Token token;
54  // if further flags are used, let base class write with base 16
55  if( (mFlags & ~mAllIosFlags) != 0 ) {
56  AttributeFlags::DoWrite(rTw,rLabel,pContext);
57  return;
58  }
59  // write my flags symbolically
60  std::string option;
61  switch (mFlags){
62  case 0x10:
63  option = "I";
64  break;
65  case 0x20:
66  option = "O";
67  break;
68  default:
69  option = "IO";
70  break;
71  }
72  rTw.WriteOption(option);
73 }
74 
75 
76 //XWrite(rTw)
77 void AttributeIosEvent::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
78  (void) rLabel; (void) pContext;
79  if(IsDefault()) return;
80  FD_DC("AttributeIosEvent(" << this << ")::DoXWrite(tw)");
81  Token token;
82  // if further flags are used, let base cxlass write with base 16
83  if( (mFlags & ~mAllIosFlags) != 0 ) {
84  AttributeFlags::DoXWrite(rTw,rLabel,pContext);
85  }
86  // write friendly tags anyway
87  if((mDefIosFlags & mInputFlag) != (mFlags & mInputFlag)) {
88  token.SetEmpty("Input");
89  if(!Input()) token.InsAttributeBoolean("value",0);
90  rTw.Write(token);
91  }
93  token.SetEmpty("Output");
94  if(!Output()) token.InsAttributeBoolean("value",0);
95  rTw.Write(token);
96  }
97 }
98 
99 
100 
101 
102 //DoRead(rTw,rLabel,pContext);
104  TokenReader& rTr,
105  const std::string& rLabel,
106  const Type* pContext)
107 {
108  (void) rLabel;
109  (void) pContext;
110  // initialize with default value
111  mFlags = mDefIosFlags;
112  Token token;
113  rTr.Peek(token);
114  // faudes format, flags as integer
115  if(token.IsInteger16()) {
116  AttributeFlags::DoRead(rTr,rLabel,pContext);
117  return;
118  }
119  // faudes format, flags as option string
120  if(token.IsOption()) {
121  rTr.Get(token);
122  std::string option=token.OptionValue();
123  if(option.find( 'I', 0) != std::string::npos) SetInput();
124  if(option.find( 'i', 0) != std::string::npos) ClrInput();
125  if(option.find( 'O', 0) != std::string::npos) SetOutput();
126  if(option.find( 'o', 0) != std::string::npos) ClrOutput();
127  return;
128  }
129  // xml format
130  while(true) {
131  rTr.Peek(token);
132  // explicit integer
133  if(token.IsBegin("Flags")) {
134  AttributeFlags::DoRead(rTr,rLabel,pContext);
135  continue;
136  }
137  // known bits
138  if(token.IsBegin("Input")) {
139  rTr.ReadBegin("Input",token);
140  SetInput();
141  if(token.ExistsAttributeInteger("value"))
142  if(token.AttributeIntegerValue("value")==false)
143  ClrInput();
144  rTr.ReadEnd("Input");
145  continue;
146  }
147  if(token.IsBegin("Output")) {
148  rTr.ReadBegin("Output",token);
149  SetOutput();
150  if(token.ExistsAttributeInteger("value"))
151  if(token.AttributeIntegerValue("value")==false)
152  ClrOutput();
153  rTr.ReadEnd("Output");
154  continue;
155  }
156  // stop at unknown tag
157  break;
158  }
159 }
160 
161 
162 /*
163 *********************************************************************************
164 *********************************************************************************
165 *********************************************************************************
166 
167 Implementation: state attributes
168 
169 *********************************************************************************
170 *********************************************************************************
171 *********************************************************************************
172 */
173 
174 
175 
176 // faudes type std
178 
179 //DoAssign( rSrcAttr )
180 void AttributeIosState::DoAssign(const AttributeIosState& rSrcAttr) {
181  // call base (incl virtual clear)
182  AttributeFlags::DoAssign(rSrcAttr);
183 }
184 
185 
186 //ToString()
187 std::string AttributeIosState::ToString(void) const {
188  return ToStringInteger16(mFlags);
189 }
190 
191 
192 //DoWrite(rTw,rLabel,pContext);
194  const std::string& rLabel,
195  const Type* pContext) const
196 {
197  (void) rLabel;
198  (void) pContext;
199  // dont wrtite default value
200  if(IsDefault()) return;
201  FD_DC("AttributeIosState(" << this << ")::DoWrite(tr)");
202  // if further flags are used, let base class write with base 16
203  if( (mFlags & ~mAllIosFlags) != 0 ) {
204  AttributeFlags::DoWrite(rTw,rLabel,pContext);
205  return;
206  }
207  // write my flags symbolically
208  std::string option;
209  if(Input()) option+="I";
210  if(Output()) option+="O";
211  if(Error()) option+="E";
212  if(option!="")
213  rTw.WriteOption(option);
214 }
215 
216 
217 //XWrite(rTw)
218 void AttributeIosState::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
219  (void) rLabel; (void) pContext;
220  if(IsDefault()) return;
221  FD_DC("AttributeIosState(" << this << ")::DoXWrite(tw)");
222  Token token;
223  // if further flags are used, let base class write with base 16
224  if( (mFlags & ~mAllIosFlags) != 0 ) {
225  AttributeFlags::DoXWrite(rTw,rLabel,pContext);
226  }
227  // write friendly tags anyway
228  if((mDefIosFlags & mInputFlag) != (mFlags & mInputFlag)) {
229  token.SetEmpty("Input");
230  if(!Input()) token.InsAttributeBoolean("value",0);
231  rTw.Write(token);
232  }
233  if((mDefIosFlags & mOutputFlag) != (mFlags & mOutputFlag)) {
234  token.SetEmpty("Output");
235  if(!Output()) token.InsAttributeBoolean("value",0);
236  rTw.Write(token);
237  }
238  if((mDefIosFlags & mErrorFlag) != (mFlags & mErrorFlag)) {
239  token.SetEmpty("Error");
240  if(!Error()) token.InsAttributeBoolean("value",0);
241  rTw.Write(token);
242  }
243 }
244 
245 
246 
247 //DoRead(rTw,rLabel,pContext);
249  TokenReader& rTr,
250  const std::string& rLabel,
251  const Type* pContext)
252 {
253  (void) rLabel;
254  (void) pContext;
255  // initialize with default value
256  mFlags = mDefIosFlags;
257  Token token;
258  rTr.Peek(token);
259  // faudes format, flags as integer
260  if(token.IsInteger16()) {
261  AttributeFlags::DoRead(rTr,rLabel,pContext);
262  return;
263  }
264  // faudes format, flags as option string
265  if(token.IsOption()) {
266  rTr.Get(token);
267  std::string option=token.OptionValue();
268  if(option.find( 'I', 0) != std::string::npos) SetInput();
269  if(option.find( 'i', 0) != std::string::npos) ClrInput();
270  if(option.find( 'O', 0) != std::string::npos) SetOutput();
271  if(option.find( 'o', 0) != std::string::npos) ClrOutput();
272  if(option.find( 'E', 0) != std::string::npos) SetError();
273  if(option.find( 'e', 0) != std::string::npos) ClrError();
274  return;
275  }
276  // xml format
277  while(true) {
278  rTr.Peek(token);
279  // explicit integer
280  if(token.IsBegin("Flags")) {
281  AttributeFlags::DoRead(rTr,rLabel,pContext);
282  continue;
283  }
284  // known bits
285  if(token.IsBegin("Input")) {
286  rTr.ReadBegin("Input",token);
287  SetInput();
288  if(token.ExistsAttributeInteger("value"))
289  if(token.AttributeIntegerValue("value")==false)
290  ClrInput();
291  rTr.ReadEnd("Input");
292  continue;
293  }
294  if(token.IsBegin("Output")) {
295  rTr.ReadBegin("Output",token);
296  SetOutput();
297  if(token.ExistsAttributeInteger("value"))
298  if(token.AttributeIntegerValue("value")==false)
299  ClrOutput();
300  rTr.ReadEnd("Output");
301  continue;
302  }
303  if(token.IsBegin("Error")) {
304  rTr.ReadBegin("Error",token);
305  SetError();
306  if(token.ExistsAttributeInteger("value"))
307  if(token.AttributeIntegerValue("value")==false)
308  ClrError();
309  rTr.ReadEnd("Error");
310  continue;
311  }
312  // stop at unknown tag
313  break;
314  }
315 }
316 
317 
318 
319 }//end namespace faudes
#define FD_DC(message)
Debug: optional report on container operations.
Runtime interface, faudes types.
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
Definition: cfl_types.h:946
Boolean flags Attribute.
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write to TokenWriter, see Type for public wrappers.
void DoAssign(const AttributeFlags &rSrcAttr)
Assignment method.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write to TokenWriter, see Type for public wrappers.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads attribute from TokenReader, see Type for public wrappers.
fType mFlags
Flags (public access for convenience)
Attributes for events in DES with in- and outputs.
void ClrInput(void)
Clear input flag.
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes attribute to TokenWriter, see AttributeVoid for public wrappers.
static const fType mInputFlag
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads attribute from TokenReader, see AttributeVoid for public wrappers.
static const fType mDefIosFlags
bool IsDefault(void) const
Check an event's io-properties for default value.
void ClrOutput(void)
Clear output flag.
static const fType mOutputFlag
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes attribute to TokenWriter, see AttributeVoid for public wrappers.
static const fType mAllIosFlags
bool Output(void) const
Test output flag.
void SetOutput(void)
Set output flag.
void SetInput(void)
Set input flag.
bool Input(void) const
Test input flag.
Attributes for states in DESs with in- and outputs.
void ClrInput(void)
Clear input flag.
static const fType mDefIosFlags
static const fType mErrorFlag
void SetOutput(void)
Set output flag.
void SetError(void)
Set error flag.
bool IsDefault(void) const
Check a state's io-properties for default value.
bool Input(void) const
Test input flag.
bool Output(void) const
Test output flag.
bool Error(void) const
Check error flag.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads attribute from TokenReader, see AttributeVoid for public wrappers.
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes attribute to TokenWriter, see AttributeVoid for public wrappers.
void SetInput(void)
Set input flag.
static const fType mOutputFlag
static const fType mInputFlag
static const fType mAllIosFlags
virtual std::string ToString(void) const
Write attribute to string.
void ClrOutput(void)
Clear output flag.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes attribute to TokenWriter, see AttributeVoid for public wrappers.
void ClrError(void)
Clear error flag.
A TokenReader reads sequential tokens from a file or string.
void ReadEnd(const std::string &rLabel)
Close the current section by matching the previous ReadBegin().
void ReadBegin(const std::string &rLabel)
Open a section by specified label.
bool Get(Token &token)
Get next token.
bool Peek(Token &token)
Peek next token.
A TokenWriter writes sequential tokens to a file, a string or stdout.
void Write(Token &rToken)
Write next token.
void WriteOption(const std::string &rOpt)
Write option (may not contain any "+")
Tokens model atomic data for stream IO.
Definition: cfl_token.h:53
bool IsInteger16(void) const
Test token Type.
Definition: cfl_token.cpp:223
Int AttributeIntegerValue(const std::string &name)
Access attribute value.
Definition: cfl_token.cpp:396
void InsAttributeBoolean(const std::string &name, Int value)
Insert named attribute with boolean value.
Definition: cfl_token.cpp:336
bool IsBegin(void) const
Test token Type.
Definition: cfl_token.cpp:258
void SetEmpty(const std::string &rName)
Initialize as empty-tag token.
Definition: cfl_token.cpp:105
const std::string & OptionValue(void) const
Get option value of a name token.
Definition: cfl_token.cpp:183
bool ExistsAttributeInteger(const std::string &name)
Test attibute existence.
Definition: cfl_token.cpp:365
bool IsOption(void) const
Test token Type.
Definition: cfl_token.cpp:238
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
I/O-system attributes.
libFAUDES resides within the namespace faudes.
std::string ToStringInteger16(Int number)
integer to string base 16
Definition: cfl_helper.cpp:54

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen