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
27namespace faudes {
28
29
30
31/***********************************************************************************
32 *
33 * implementation of AttributeFlags
34 *
35 */
36
37// faudes type
39
40// Copy my members
41void AttributeFlags::DoCopy(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// Copy my members (dont bother about moving)
50 DoCopy(rSrcAttr);
51}
52
53// Test my members for equality
54bool AttributeFlags::DoEqual(const AttributeFlags& rOther) const {
55 return ( mFlags==rOther.mFlags );
56}
57
58//DoWrite(rTw)
59// Note: you should write attributes in a section, so that
60// the AttributeVoid read method can detect and skip them.
61// Here, we make an execption of the rule ...
62void AttributeFlags::DoWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
63 (void) rLabel; (void) pContext;
65 FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
66 Token token;
67 token.SetInteger16(mFlags);
68 rTw << token;
69 }
70}
71
72
73//DoXWrite(rTw)
74void AttributeFlags::DoXWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
75 (void) rLabel; (void) pContext;
77 FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
78 Token token;
79 token.SetEmpty("Flags");
80 token.InsAttributeInteger16("value",mFlags);
81 rTw << token;
82 }
83}
84
85
86//DoRead(rTr)
87void AttributeFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
88 (void) rLabel; (void) pContext;
89 FD_DC("AttributeFlag(" << this << ")::DoRead(tr)");
90 Token token;
91 rTr.Peek(token);
92 // faudes format
93 if(token.IsInteger16()) {
94 rTr.Get(token);
95 mFlags=token.IntegerValue();
96 return;
97 }
98 // XML format
99 if(token.IsBegin())
100 if(token.StringValue()=="Flags") {
101 rTr.ReadBegin("Flags",token);
102 mFlags=token.AttributeIntegerValue("value");
103 rTr.ReadEnd("Flags");
104 return;
105 }
106 // default
108}
109
110/***********************************************************************************
111 *
112 * implementation of AttributeCFlags
113 *
114 */
115
116
117// faudes type std
119
120// Copy my members
121void AttributeCFlags::DoCopy(const AttributeCFlags& rSrcAttr) {
122 // call base
123 AttributeFlags::DoCopy(rSrcAttr);
124}
125
126// Copy my members (dont bother about moving)
128 DoCopy(rSrcAttr);
129}
130
131// Test my members
132bool AttributeCFlags::DoEqual(const AttributeCFlags& rOther) const {
133 // call base
134 if(!AttributeFlags::DoEqual(rOther)) return false;
135 // no additional members
136 return true;
137}
138
139//Write(rTw)
140// Note: you should write attributes in a section, so that
141// the AttributeVoid read method can detect and skip them.
142// Here, we make an execption of the rule ...
143void AttributeCFlags::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
144 (void) rLabel; (void) pContext;
145 if(IsDefault()) return;
146 FD_DC("AttributeCFlags(" << this << ")::DoWrite(tr)");
147 Token token;
148 // if no other flags used, write option string
149 if( (mFlags & ~mAllCFlags) == 0 ) {
150 std::string option;
152 if(Controllable()) option = option+"C";
153 else option = option+"c";
154 }
156 if(Observable()) option = option+"O";
157 else option = option+"o";
158 }
160 if(Forcible()) option = option+"F";
161 else option = option+"f";
162 }
164 if(Highlevel()) option = option+"A";
165 else option = option+"a";
166 }
167 if(option!="") {
168 token.SetOption(option);
169 rTw << token;
170 }
171 }
172 // if other flags used, write hex
173 else {
174 token.SetInteger16(mFlags);
175 rTw << token;
176 }
177}
178
179//XWrite(rTw)
180void AttributeCFlags::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
181 (void) rLabel; (void) pContext;
182 if(IsDefault()) return;
183 FD_DC("AttributeCFlags(" << this << ")::DoXWrite(tw)");
184 Token token;
185 // if further flags are used, let base class write with base 16
186 if( (mFlags & ~mAllCFlags) != 0 ) {
187 AttributeFlags::DoXWrite(rTw,rLabel,pContext);
188 }
189 // write friendly tags anyway
190 std::string option;
192 token.SetEmpty("Controllable");
193 if(!Controllable()) token.InsAttributeBoolean("value",0);
194 rTw.Write(token);
195 }
197 token.SetEmpty("Observable");
198 if(!Observable()) token.InsAttributeBoolean("value",0);
199 rTw.Write(token);
200 }
202 token.SetEmpty("Forcible");
203 if(!Forcible()) token.InsAttributeBoolean("value",0);
204 rTw.Write(token);
205 }
207 token.SetEmpty("HighLevel");
208 if(!Highlevel()) token.SetEmpty("LowLevel");
209 rTw.Write(token);
210 }
211}
212
213//DoRead(rTr)
214void AttributeCFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
215 (void) rLabel; (void) pContext;
217 Token token;
218 rTr.Peek(token);
219 // faudes format, flags as integer
220 if(token.IsInteger16()) {
221 AttributeFlags::DoRead(rTr,rLabel,pContext);
222 return;
223 }
224 // faudes format, flags as option string
225 if(token.IsOption()) {
226 rTr.Get(token);
227 std::string option=token.OptionValue();
228 if(option.find( 'C', 0) != std::string::npos) SetControllable();
229 if(option.find( 'c', 0) != std::string::npos) ClrControllable();
230 if(option.find( 'O', 0) != std::string::npos) SetObservable();
231 if(option.find( 'o', 0) != std::string::npos) ClrObservable();
232 if(option.find( 'F', 0) != std::string::npos) SetForcible();
233 if(option.find( 'f', 0) != std::string::npos) ClrForcible();
234 if(option.find( 'A', 0) != std::string::npos) SetHighlevel();
235 if(option.find( 'a', 0) != std::string::npos) SetLowlevel();
236 return;
237 }
238 // xml format
239 while(true) {
240 rTr.Peek(token);
241 // explicit integer
242 if(token.IsBegin("Flags")) {
243 AttributeFlags::DoRead(rTr,rLabel,pContext);
244 continue;
245 }
246 // known bits
247 if(token.IsBegin("Controllable")) {
248 rTr.ReadBegin("Controllable",token);
250 if(token.ExistsAttributeInteger("value"))
251 if(token.AttributeIntegerValue("value")==false)
253 rTr.ReadEnd("Controllable");
254 continue;
255 }
256 if(token.IsBegin("Observable")) {
257 rTr.ReadBegin("Observable",token);
259 if(token.ExistsAttributeInteger("value"))
260 if(token.AttributeIntegerValue("value")==false)
262 rTr.ReadEnd("Observable");
263 continue;
264 }
265 if(token.IsBegin("Forcible")) {
266 rTr.ReadBegin("Forcible",token);
267 SetForcible();
268 if(token.ExistsAttributeInteger("value"))
269 if(token.AttributeIntegerValue("value")==false)
270 ClrForcible();
271 rTr.ReadEnd("Forcible");
272 continue;
273 }
274 if(token.IsBegin("HighLevel")) {
275 rTr.ReadBegin("HighLevel",token);
276 SetHighlevel();
277 if(token.ExistsAttributeInteger("value"))
278 if(token.AttributeIntegerValue("value")==false)
279 SetLowlevel();
280 continue;
281 }
282 if(token.IsBegin("LowLevel")) {
283 rTr.ReadBegin("LowLevel",token);
284 SetLowlevel();
285 if(token.ExistsAttributeInteger("value"))
286 if(token.AttributeIntegerValue("value")==false)
287 SetHighlevel();
288 continue;
289 }
290 // stop at unknown tag
291 break;
292 }
293}
294
295
296} // namespace
#define FD_DC(message)
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
Definition cfl_types.h:1017
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
void DoCopy(const AttributeCFlags &rSrcAttr)
bool Controllable(void) const
static const fType mAbstractionFlag
static const fType mForcibleFlag
void DoMove(AttributeCFlags &rSrcAttr)
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
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 DoMove(AttributeFlags &rSrcAttr)
void DoCopy(const AttributeFlags &rSrcAttr)
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
void SetInteger16(const Int number)
const std::string & StringValue(void) const
Int AttributeIntegerValue(const std::string &name)
Int IntegerValue(void) const
void InsAttributeBoolean(const std::string &name, Int value)
void SetOption(const std::string &rName)
bool IsBegin(void) const
void SetEmpty(const std::string &rName)
const std::string & OptionValue(void) const
bool ExistsAttributeInteger(const std::string &name)
bool IsOption(void) const
void InsAttributeInteger16(const std::string &name, Int value)
AttrType AttributeVoid

libFAUDES 2.34e --- 2026.03.16 --- c++ api documentaion by doxygen