hio_attributes.cpp
Go to the documentation of this file.
1 /** @file hio_attributes.cpp Event and state attributes for hierarchical I/O systems */
2 
3 /* Hierarchical IO Systems Plug-In for FAU Discrete Event Systems Library (libfaudes)
4 
5  Copyright (C) 2006 Sebastian Perk
6  Copyright (C) 2006 Thomas Moor
7  Copyright (C) 2006 Klaus Schmidt
8 
9 */
10 
11 #include "hio_attributes.h"
12 
13 namespace faudes {
14 
15 
16 /***********************************************************************************
17  *
18  * implementation of HioEventFlags
19  *
20  */
21 
22 // faudes type std
23 FAUDES_TYPE_IMPLEMENTATION(Void,HioEventFlags,AttributeFlags)
24 
25 // Assign my members
26 void HioEventFlags::DoAssign(const HioEventFlags& rSrcAttr) {
27  // call base (incl virtual clear)
28  AttributeFlags::DoAssign(rSrcAttr);
29 }
30 
31 //DoWrite(rTw,rLabel,pContext);
32 void HioEventFlags::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
33 
34  (void) rLabel; (void) pContext;
35  if(IsDefault()) return;
36  FD_DC("HioEventFlags(" << this << ")::DoWrite(tr)");
37 
38  Token token;
39  if( (mFlags & ~mAllHioEventFlags) == 0 ) {
40  std::string option;
41  switch (mFlags)
42  {
43  case 4: option = "U";break; //0000 0100
44  case 8: option = "Y";break; //0000 1000
45  case 36: option = "UE";break; //0010 0100
46  case 40: option = "YE";break; //0010 1000
47  case 20: option = "UP";break; //0001 0100
48  case 24: option = "YP";break; //0001 1000
49  case 68: option = "UC";break; //0100 0100
50  case 72: option = "YC";break; //0100 1000
51  case 132: option = "UL";break; //1000 0100
52  case 136: option = "YL";break; //1000 1000
53  default: option = "??";break;
54  }
55  token.SetOption(option);
56  }
57  // if other flags used, write hex
58  else {
59  token.SetInteger16(mFlags);
60  }
61  rTw << token;
62  }
63 //}
64 
65 
66 //DoRead(rTw,rLabel,pContext);
67 void HioEventFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
68  (void) rLabel;
69  (void) pContext;
70  // initialize with dfeualt
72  Token token;
73  rTr.Peek(token);
74  // faudes format, flags as integer
75  if(token.IsInteger16()) {
76  AttributeFlags::DoRead(rTr,rLabel,pContext);
77  return;
78  }
79  // faudes format, flags as option string
80  if(token.IsOption()) {
81  rTr.Get(token);
82  std::string option=token.OptionValue();
83 
84  if(option.find( 'Y', 0) != std::string::npos) SetY();
85  if(option.find( 'U', 0) != std::string::npos) SetU();
86  if(option.find( 'P', 0) != std::string::npos){ SetP(); ClrE();}
87  if(option.find( 'E', 0) != std::string::npos){ SetE(); ClrP();}
88  if(option.find( 'C', 0) != std::string::npos){ SetC(); ClrP();}
89  if(option.find( 'L', 0) != std::string::npos){ SetL(); ClrE();}
90  return;
91  }
92  // xml format
93  while(true) {
94  rTr.Peek(token);
95  // explicit integer
96  if(token.IsBegin("Flags")) {
97  AttributeFlags::DoRead(rTr,rLabel,pContext);
98  continue;
99  }
100  // known bits
101  /*
102  xml format not yet implemented,
103  see iosystem for template
104  */
105  // stop at unknown tag
106  break;
107  }
108 }
109 
110 
111 /***********************************************************************************
112  *
113  * implementation of HioStateFlags
114  *
115  */
116 /***************************************************************************/
117 
118 // faudes type std
120 
121 // Assign my members
122 void HioStateFlags::DoAssign(const HioStateFlags& rSrcAttr) {
123  // call base (incl virtual clear)
124  AttributeFlags::DoAssign(rSrcAttr);
125 }
126 
127 //DoWrite(rTw,rLabel,pContext);
128 void HioStateFlags::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
129  (void) rLabel; (void) pContext;
130  if(IsDefault()) return;
131  FD_DC("HioStateFlags(" << this << ")::DoWrite(tr)");
132  Token token;
133  if( (mFlags & ~mAllHioStateFlags) == 0 ) {
134  std::string option;
135  if(IsErr()) option = "Err";
136  switch (mFlags&0xFF) // AllHioStateFlags but not ErrFlag
137  {
138  case 1: option = option+"QY"; break; //0000 0001
139  case 2: option = option+"QU"; break; //0000 0010
140  case 4: option = option+"QC"; break; //0000 0100
141  case 6: option = option+"QUc"; break; //0000 0110
142  case 8: option = option+"QP"; break; //0000 1000
143  case 9: option = option+"QYp"; break; //0000 1001
144  case 10: option = option+"QUp"; break; //0000 1010
145  case 16: option = option+"QE"; break; //0001 0000
146  case 17: option = option+"QYe"; break; //0001 0001
147  case 18: option = option+"QUe"; break; //0001 0010
148  case 25: option = option+"QYpYe"; break; //0001 1001
149  case 32: option = option+"QL"; break; //0010 0000
150  case 34: option = option+"QUl"; break; //0010 0010
151  case 64: option = option+"QYcUp"; break; //0100 0000
152  case 128: option = option+"QYlUe"; break; //1000 0000
153 
154  default: if( !IsErr() ) option = option+"??"; break;
155  }
156 
157  token.SetOption(option);
158  }
159  // if other flags used, write hex
160  else {
161  token.SetInteger16(mFlags);
162  }
163  rTw << token;
164  }
165 
166 //ToString()
167 std::string HioStateFlags::ToString(void) const {
168  return ToStringInteger16(mFlags);
169 }
170 
171 //DoRead(rTw,rLabel,pContext);
172 void HioStateFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
173  (void) rLabel;
174  (void) pContext;
175  // initialize with dfeualt
177  Token token;
178  rTr.Peek(token);
179  // faudes format, flags as integer
180  if(token.IsInteger16()) {
181  AttributeFlags::DoRead(rTr,rLabel,pContext);
182  return;
183  }
184  // faudes format, flags as option string
185  if(token.IsOption()) {
186  rTr.Get(token);
187  std::string option=token.OptionValue();
188 
189  if(option.find( "QY", 0) != std::string::npos){ SetQY();}
190  if(option.find( "QU", 0) != std::string::npos){ SetQU();}
191  if(option.find( "QC", 0) != std::string::npos){ SetQC();}
192  if(option.find( "QUc", 0) != std::string::npos){ SetQU(); SetQC();}
193  if(option.find( "QP", 0) != std::string::npos){ SetQP();}
194  if(option.find( "QYp", 0) != std::string::npos){ SetQY(); SetQP();}
195  if(option.find( "QUp", 0) != std::string::npos){ SetQU(); SetQP();}
196  if(option.find( "QE", 0) != std::string::npos){ SetQE();}
197  if(option.find( "QYe", 0) != std::string::npos){ SetQY(); SetQE();}
198  if(option.find( "QUe", 0) != std::string::npos){ SetQU(); SetQE();}
199  if(option.find( "QYpYe", 0) != std::string::npos){ SetQY(); SetQP(); SetQE();}
200  if(option.find( "QL", 0) != std::string::npos){ SetQL();}
201  if(option.find( "QUl", 0) != std::string::npos){ SetQU(); SetQL();}
202  if(option.find( "QYcUp", 0) != std::string::npos){ SetQYcUp();}
203  if(option.find( "QYlUe", 0) != std::string::npos){ SetQYlUe();}
204  if(option.find( "Err", 0) != std::string::npos){ SetErr();}
205  return;
206  }
207  // xml format
208  while(true) {
209  rTr.Peek(token);
210  // explicit integer
211  if(token.IsBegin("Flags")) {
212  AttributeFlags::DoRead(rTr,rLabel,pContext);
213  continue;
214  }
215  // known bits
216  /*
217  xml format not yet implemented,
218  see iosystem for template
219  */
220  // stop at unknown tag
221  break;
222  }
223 }
224 
225 
226 
227 
228 } //End namespace
#define FD_DC(message)
Debug: optional report on container operations.
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
Definition: cfl_types.h:946
Boolean flags Attribute.
void DoAssign(const AttributeFlags &rSrcAttr)
Assignment method.
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)
Event attributes for hierarchical discrete event systems with inputs and outputs.
void SetU(void)
Set U-flag.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads attribute from TokenReader, see AttributeVoid for public wrappers.
void ClrE(void)
Clear E-flag.
void SetP(void)
Set P-flag.
static const fType mAllHioEventFlags
void SetC(void)
Set C-flag.
static const fType mDefHioEventFlags
void SetE(void)
Set E-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 SetY(void)
Set Y-flag.
void SetL(void)
Set L-flag.
bool IsDefault(void) const
Test for default value (ie input and membership in neither P-,E-,C-, nor L-alphabet)
void ClrP(void)
Clear P-flag.
State attributes for hierarchical discrete event systems with inputs and outputs.
static const fType mDefHioStateFlags
void SetQU(void)
Set QU-state flag.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes attribute to TokenWriter, see AttributeVoid for public wrappers.
virtual std::string ToString(void) const
Write attribute to string.
void SetQYlUe(void)
Set QYlUe-state flag.
void SetQE(void)
Set QE-state flag.
static const fType mAllHioStateFlags
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads attribute from TokenReader, see AttributeVoid for public wrappers.
void SetQYcUp(void)
Set QYcUp-state flag.
void SetErr(void)
Set Err-state flag.
void SetQY(void)
Set QY-state flag.
void SetQL(void)
Set QL-state flag.
bool IsDefault(void) const
Test for default value.
void SetQC(void)
Set QC-state flag.
void SetQP(void)
Set QP-state flag.
bool IsErr(void) const
Query Err-state flag.
A TokenReader reads sequential tokens from a file or string.
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.
Tokens model atomic data for stream IO.
Definition: cfl_token.h:53
bool IsInteger16(void) const
Test token Type.
Definition: cfl_token.cpp:223
void SetInteger16(const Int number)
Initialize as Integer16 token.
Definition: cfl_token.cpp:128
void SetOption(const std::string &rName)
Initialize as Option token.
Definition: cfl_token.cpp:112
bool IsBegin(void) const
Test token Type.
Definition: cfl_token.cpp:258
const std::string & OptionValue(void) const
Get option value of a name token.
Definition: cfl_token.cpp:183
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
Event and state attributes for hierarchical I/O systems.
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