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//DoXWrite(rTw)
73void AttributeFlags::DoXWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
74 (void) rLabel; (void) pContext;
76 FD_DC("AttributeFlags(" << this << ")::DoWrite(tr)");
77 Token token;
78 token.SetEmpty("Flags");
79 token.InsAttributeInteger16("value",mFlags);
80 rTw << token;
81 }
82}
83
84
85//DoRead(rTr)
86void AttributeFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
87 (void) rLabel; (void) pContext;
88 FD_DC("AttributeFlag(" << this << ")::DoRead(tr)");
89 Token token;
90 rTr.Peek(token);
91 // faudes format
92 if(token.IsInteger16()) {
93 rTr.Get(token);
94 mFlags=token.IntegerValue();
95 return;
96 }
97 // XML format
98 if(token.IsBegin())
99 if(token.StringValue()=="Flags") {
100 rTr.ReadBegin("Flags",token);
101 mFlags=token.AttributeIntegerValue("value");
102 rTr.ReadEnd("Flags");
103 return;
104 }
105 // default
107}
108
109// Pretty print
110std::string AttributeFlags::Str(void) const {
112}
113
114/***********************************************************************************
115 *
116 * implementation of AttributeCFlags
117 *
118 */
119
120
121// faudes type std
123
124// Copy my members
125void AttributeCFlags::DoCopy(const AttributeCFlags& rSrcAttr) {
126 // call base
127 AttributeFlags::DoCopy(rSrcAttr);
128}
129
130// Copy my members (dont bother about moving)
132 DoCopy(rSrcAttr);
133}
134
135// Test my members
136bool AttributeCFlags::DoEqual(const AttributeCFlags& rOther) const {
137 // call base
138 if(!AttributeFlags::DoEqual(rOther)) return false;
139 // no additional members
140 return true;
141}
142
143//Write(rTw)
144// Note: you should write attributes in a section, so that
145// the AttributeVoid read method can detect and skip them.
146// Here, we make an execption of the rule ...
147void AttributeCFlags::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
148 (void) rLabel; (void) pContext;
149 if(IsDefault()) return;
150 FD_DC("AttributeCFlags(" << this << ")::DoWrite(tr)");
151 Token token;
152 // if no other flags used, write option string
153 if( (mFlags & ~mAllCFlags) == 0 ) {
154 std::string option;
156 if(Controllable()) option = option+"C";
157 else option = option+"c";
158 }
160 if(Observable()) option = option+"O";
161 else option = option+"o";
162 }
164 if(Forcible()) option = option+"F";
165 else option = option+"f";
166 }
168 if(Preemptible()) option = option+"P";
169 else option = option+"p";
170 }
171 if(option!="") {
172 token.SetOption(option);
173 rTw << token;
174 }
175 }
176 // if other flags used, write hex
177 else {
178 token.SetInteger16(mFlags);
179 rTw << token;
180 }
181}
182
183//XWrite(rTw)
184void AttributeCFlags::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
185 (void) rLabel; (void) pContext;
186 if(IsDefault()) return;
187 FD_DC("AttributeCFlags(" << this << ")::DoXWrite(tw)");
188 Token token;
189 // if further flags are used, let base class write with base 16
190 if( (mFlags & ~mAllCFlags) != 0 ) {
191 AttributeFlags::DoXWrite(rTw,rLabel,pContext);
192 }
193 // write friendly tags anyway
194 std::string option;
196 token.SetEmpty("Controllable");
197 if(!Controllable()) token.InsAttributeBoolean("value",0);
198 rTw.Write(token);
199 }
201 token.SetEmpty("Observable");
202 if(!Observable()) token.InsAttributeBoolean("value",0);
203 rTw.Write(token);
204 }
206 token.SetEmpty("Forcible");
207 if(!Forcible()) token.InsAttributeBoolean("value",0);
208 rTw.Write(token);
209 }
211 token.SetEmpty("Preemptible");
212 if(!Preemptible()) token.InsAttributeBoolean("value",0);
213 rTw.Write(token);
214 }
215}
216
217//DoRead(rTr)
218void AttributeCFlags::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
219 (void) rLabel; (void) pContext;
221 Token token;
222 rTr.Peek(token);
223 // faudes format, flags as integer
224 if(token.IsInteger16()) {
225 AttributeFlags::DoRead(rTr,rLabel,pContext);
226 return;
227 }
228 // faudes format, flags as option string
229 if(token.IsOption()) {
230 rTr.Get(token);
231 std::string option=token.OptionValue();
232 if(option.find( 'C', 0) != std::string::npos) SetControllable();
233 if(option.find( 'c', 0) != std::string::npos) ClrControllable();
234 if(option.find( 'O', 0) != std::string::npos) SetObservable();
235 if(option.find( 'o', 0) != std::string::npos) ClrObservable();
236 if(option.find( 'F', 0) != std::string::npos) SetForcible();
237 if(option.find( 'f', 0) != std::string::npos) ClrForcible();
238 if(option.find( 'P', 0) != std::string::npos) SetPreemptible();
239 if(option.find( 'p', 0) != std::string::npos) ClrPreemptible();
240 return;
241 }
242 // xml format
243 while(true) {
244 rTr.Peek(token);
245 // explicit integer
246 if(token.IsBegin("Flags")) {
247 AttributeFlags::DoRead(rTr,rLabel,pContext);
248 continue;
249 }
250 // known bits
251 if(token.IsBegin("Controllable")) {
252 rTr.ReadBegin("Controllable",token);
254 if(token.ExistsAttributeInteger("value"))
255 if(token.AttributeIntegerValue("value")==false)
257 rTr.ReadEnd("Controllable");
258 continue;
259 }
260 if(token.IsBegin("Observable")) {
261 rTr.ReadBegin("Observable",token);
263 if(token.ExistsAttributeInteger("value"))
264 if(token.AttributeIntegerValue("value")==false)
266 rTr.ReadEnd("Observable");
267 continue;
268 }
269 if(token.IsBegin("Forcible")) {
270 rTr.ReadBegin("Forcible",token);
271 SetForcible();
272 if(token.ExistsAttributeInteger("value"))
273 if(token.AttributeIntegerValue("value")==false)
274 ClrForcible();
275 rTr.ReadEnd("Forcible");
276 continue;
277 }
278 if(token.IsBegin("Preemptible")) {
279 rTr.ReadBegin("Preemptible",token);
281 if(token.ExistsAttributeInteger("value"))
282 if(token.AttributeIntegerValue("value")==false)
284 rTr.ReadEnd("Preemptible");
285 continue;
286 }
287 // stop at unknown tag
288 break;
289 }
290}
291
292
293// Pretty print
294std::string AttributeCFlags::Str(void) const {
295 std::string str;
296 // do my named flags
297 if(Controllable()) str = str+"C";
298 else str = str+"c";
299 if(Observable()) str = str+"O";
300 else str = str+"o";
302 if(Forcible()) str = str+"F";
303 else str = str+"f";
304 }
306 if(Preemptible()) str = str+"P";
307 else str = str+"p";
308 }
309 // if other flags used, append hex
310 if( (mFlags & ~mAllCFlags) != 0 )
311 str=str + ToStringInteger16(mFlags);
312 return str;
313}
314
315
316
317} // namespace
#define FD_DC(message)
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
Definition cfl_types.h:1017
bool Preemptible(void) const
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
static const fType mAllCFlags
bool Forcible(void) const
virtual std::string Str(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 mForcibleFlag
void DoMove(AttributeCFlags &rSrcAttr)
static const fType mObservableFlag
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
static const fType mPreemptibleFlag
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)
virtual std::string Str(void) const
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)
std::string ToStringInteger16(Int number)
Definition cfl_utils.cpp:55
AttrType AttributeVoid

libFAUDES 2.34g --- 2026.04.09 --- c++ api documentaion by doxygen