cfl_attributes.cpp
Go to the documentation of this file.
1 /** @file cfl_attributes.cpp Classes AttributeVoid and AttributeFlags */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5  Copyright (C) 2006 Bernd Opitz
6  Copyright (C) 2024 Thomas Moor
7  Exclusive copyright is granted to Klaus Schmidt
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 
24 #include "cfl_attributes.h"
25 
26 
27 namespace faudes {
28 
29 
30 
31 /***********************************************************************************
32  *
33  * implementation of AttributeFlags
34  *
35  */
36 
37 // faudes type
38 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeFlags,AttributeVoid)
39 
40 // Assign my members
41 void AttributeFlags::DoAssign(const AttributeFlags& rSrcAttr) {
42  // call virtual clear: TODO: dont clear in virtual function
43  Clear();
44  // assign my members
45  mFlags=rSrcAttr.mFlags;
46 }
47 
48 // Test my members for equality
49 bool AttributeFlags::DoEqual(const AttributeFlags& rOther) const {
50  return ( mFlags==rOther.mFlags );
51 }
52 
53 //DoWrite(rTw)
54 // Note: you should write attributes in a section, so that
55 // the AttributeVoid read method can detect and skip them.
56 // Here, we make an execption of the rule ...
57 void AttributeFlags::DoWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
58  (void) rLabel; (void) pContext;
60  FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
61  Token token;
62  token.SetInteger16(mFlags);
63  rTw << token;
64  }
65 }
66 
67 
68 //DoXWrite(rTw)
69 void AttributeFlags::DoXWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
70  (void) rLabel; (void) pContext;
72  FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
73  Token token;
74  token.SetEmpty("Flags");
75  token.InsAttributeInteger16("value",mFlags);
76  rTw << token;
77  }
78 }
79 
80 
81 //DoRead(rTr)
82 void AttributeFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
83  (void) rLabel; (void) pContext;
84  FD_DC("AttributeFlag(" << this << ")::DoRead(tr)");
85  Token token;
86  rTr.Peek(token);
87  // faudes format
88  if(token.IsInteger16()) {
89  rTr.Get(token);
90  mFlags=token.IntegerValue();
91  return;
92  }
93  // XML format
94  if(token.IsBegin())
95  if(token.StringValue()=="Flags") {
96  rTr.ReadBegin("Flags",token);
97  mFlags=token.AttributeIntegerValue("value");
98  rTr.ReadEnd("Flags");
99  return;
100  }
101  // default
103 }
104 
105 /***********************************************************************************
106  *
107  * implementation of AttributeCFlags
108  *
109  */
110 
111 
112 // faudes type std
114 
115 // Assign my members
116 void AttributeCFlags::DoAssign(const AttributeCFlags& rSrcAttr) {
117  // call base
118  AttributeFlags::DoAssign(rSrcAttr);
119 }
120 
121 // Test my members
122 bool AttributeCFlags::DoEqual(const AttributeCFlags& rOther) const {
123  // call base
124  if(!AttributeFlags::DoEqual(rOther)) return false;
125  // no additional members
126  return true;
127 }
128 
129 //Write(rTw)
130 // Note: you should write attributes in a section, so that
131 // the AttributeVoid read method can detect and skip them.
132 // Here, we make an execption of the rule ...
133 void AttributeCFlags::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
134  (void) rLabel; (void) pContext;
135  if(IsDefault()) return;
136  FD_DC("AttributeCFlags(" << this << ")::DoWrite(tr)");
137  Token token;
138  // if no other flags used, write option string
139  if( (mFlags & ~mAllCFlags) == 0 ) {
140  std::string option;
142  if(Controllable()) option = option+"C";
143  else option = option+"c";
144  }
146  if(Observable()) option = option+"O";
147  else option = option+"o";
148  }
150  if(Forcible()) option = option+"F";
151  else option = option+"f";
152  }
154  if(Highlevel()) option = option+"A";
155  else option = option+"a";
156  }
157  if(option!="") {
158  token.SetOption(option);
159  rTw << token;
160  }
161  }
162  // if other flags used, write hex
163  else {
164  token.SetInteger16(mFlags);
165  rTw << token;
166  }
167 }
168 
169 //XWrite(rTw)
170 void AttributeCFlags::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
171  (void) rLabel; (void) pContext;
172  if(IsDefault()) return;
173  FD_DC("AttributeCFlags(" << this << ")::DoXWrite(tw)");
174  Token token;
175  // if further flags are used, let base class write with base 16
176  if( (mFlags & ~mAllCFlags) != 0 ) {
177  AttributeFlags::DoXWrite(rTw,rLabel,pContext);
178  }
179  // write friendly tags anyway
180  std::string option;
182  token.SetEmpty("Controllable");
183  if(!Controllable()) token.InsAttributeBoolean("value",0);
184  rTw.Write(token);
185  }
187  token.SetEmpty("Observable");
188  if(!Observable()) token.InsAttributeBoolean("value",0);
189  rTw.Write(token);
190  }
192  token.SetEmpty("Forcible");
193  if(!Forcible()) token.InsAttributeBoolean("value",0);
194  rTw.Write(token);
195  }
197  token.SetEmpty("HighLevel");
198  if(!Highlevel()) token.SetEmpty("LowLevel");
199  rTw.Write(token);
200  }
201 }
202 
203 //DoRead(rTr)
204 void AttributeCFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
205  (void) rLabel; (void) pContext;
207  Token token;
208  rTr.Peek(token);
209  // faudes format, flags as integer
210  if(token.IsInteger16()) {
211  AttributeFlags::DoRead(rTr,rLabel,pContext);
212  return;
213  }
214  // faudes format, flags as option string
215  if(token.IsOption()) {
216  rTr.Get(token);
217  std::string option=token.OptionValue();
218  if(option.find( 'C', 0) != std::string::npos) SetControllable();
219  if(option.find( 'c', 0) != std::string::npos) ClrControllable();
220  if(option.find( 'O', 0) != std::string::npos) SetObservable();
221  if(option.find( 'o', 0) != std::string::npos) ClrObservable();
222  if(option.find( 'F', 0) != std::string::npos) SetForcible();
223  if(option.find( 'f', 0) != std::string::npos) ClrForcible();
224  if(option.find( 'A', 0) != std::string::npos) SetHighlevel();
225  if(option.find( 'a', 0) != std::string::npos) SetLowlevel();
226  return;
227  }
228  // xml format
229  while(true) {
230  rTr.Peek(token);
231  // explicit integer
232  if(token.IsBegin("Flags")) {
233  AttributeFlags::DoRead(rTr,rLabel,pContext);
234  continue;
235  }
236  // known bits
237  if(token.IsBegin("Controllable")) {
238  rTr.ReadBegin("Controllable",token);
239  SetControllable();
240  if(token.ExistsAttributeInteger("value"))
241  if(token.AttributeIntegerValue("value")==false)
242  ClrControllable();
243  rTr.ReadEnd("Controllable");
244  continue;
245  }
246  if(token.IsBegin("Observable")) {
247  rTr.ReadBegin("Observable",token);
248  SetObservable();
249  if(token.ExistsAttributeInteger("value"))
250  if(token.AttributeIntegerValue("value")==false)
251  ClrObservable();
252  rTr.ReadEnd("Observable");
253  continue;
254  }
255  if(token.IsBegin("Forcible")) {
256  rTr.ReadBegin("Forcible",token);
257  SetForcible();
258  if(token.ExistsAttributeInteger("value"))
259  if(token.AttributeIntegerValue("value")==false)
260  ClrForcible();
261  rTr.ReadEnd("Forcible");
262  continue;
263  }
264  if(token.IsBegin("HighLevel")) {
265  rTr.ReadBegin("HighLevel",token);
266  SetHighlevel();
267  if(token.ExistsAttributeInteger("value"))
268  if(token.AttributeIntegerValue("value")==false)
269  SetLowlevel();
270  continue;
271  }
272  if(token.IsBegin("LowLevel")) {
273  rTr.ReadBegin("LowLevel",token);
274  SetLowlevel();
275  if(token.ExistsAttributeInteger("value"))
276  if(token.AttributeIntegerValue("value")==false)
277  SetHighlevel();
278  continue;
279  }
280  // stop at unknown tag
281  break;
282  }
283 }
284 
285 
286 } // namespace
#define FD_DC(message)
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
Definition: cfl_types.h:959
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
static const fType mAllCFlags
bool Forcible(void) const
static const fType mDefCFlags
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
bool DoEqual(const AttributeCFlags &rOther) const
bool Controllable(void) const
static const fType mAbstractionFlag
static const fType mForcibleFlag
static const fType mObservableFlag
bool Highlevel(void) const
static const fType mControllableFlag
virtual bool IsDefault(void) const
bool Observable(void) const
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
bool DoEqual(const AttributeFlags &rOther) const
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
static const fType mDefFlags
void DoAssign(const AttributeFlags &rSrcAttr)
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
virtual bool IsDefault(void) const
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
void ReadEnd(const std::string &rLabel)
void ReadBegin(const std::string &rLabel)
bool Get(Token &token)
bool Peek(Token &token)
void Write(Token &rToken)
bool IsInteger16(void) const
Definition: cfl_token.cpp:224
void SetInteger16(const Int number)
Definition: cfl_token.cpp:129
const std::string & StringValue(void) const
Definition: cfl_token.cpp:178
Int AttributeIntegerValue(const std::string &name)
Definition: cfl_token.cpp:397
Int IntegerValue(void) const
Definition: cfl_token.cpp:167
void InsAttributeBoolean(const std::string &name, Int value)
Definition: cfl_token.cpp:337
void SetOption(const std::string &rName)
Definition: cfl_token.cpp:113
bool IsBegin(void) const
Definition: cfl_token.cpp:259
void SetEmpty(const std::string &rName)
Definition: cfl_token.cpp:106
const std::string & OptionValue(void) const
Definition: cfl_token.cpp:184
bool ExistsAttributeInteger(const std::string &name)
Definition: cfl_token.cpp:366
bool IsOption(void) const
Definition: cfl_token.cpp:239
void InsAttributeInteger16(const std::string &name, Int value)
Definition: cfl_token.cpp:328
AttrType AttributeVoid

libFAUDES 2.33h --- 2025.06.18 --- c++ api documentaion by doxygen