cfl_attributes.h
Go to the documentation of this file.
1/** @file cfl_attributes.h Classes AttributeVoid and AttributeFlags */
2
3
4/* FAU Discrete Event Systems Library (libfaudes)
5
6Copyright (C) 2007, 2024 Thomas Moor
7Exclusive copyright is granted to Klaus Schmidt
8
9This library is free software; you can redistribute it and/or
10modify it under the terms of the GNU Lesser General Public
11License as published by the Free Software Foundation; either
12version 2.1 of the License, or (at your option) any later version.
13
14This library is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public
20License along with this library; if not, write to the Free Software
21Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23
24#ifndef FAUDES_ATTRIBUTES_H
25#define FAUDES_ATTRIBUTES_H
26
27#include "cfl_types.h"
28#include "cfl_registry.h"
29#include "cfl_tokenreader.h"
30#include "cfl_tokenwriter.h"
31
32namespace faudes {
33
34// v2.33 transitioning: select minimal attribute to be AttrType
36
37
38/** Convenience typdef flag data */
39typedef unsigned long int fType;
40
41/**
42 * Boolean flags Attribute. This attribute class uses a flag word to represent
43 * boolean values. The current implementation uses a long int type and hence handles
44 * up to 32 flags. Each flag is accessed by the according bit mask.
45 *
46 * The current version of libFAUDES uses bits 0,1,2 of event attributes for controllability
47 * properties (see AttributeCFlags) and the bits 31 and 32 of state attributes for the Qt based
48 * GUI project. Further versions may use the lower 8 bits of the event aflags and the higher 8
49 * bits of state flags. You are free to use any flags for your application, but if possible try
50 * to avoid the above mentioned. For extensive use of flags, you may also consider to
51 * define a separate attribute class, perhaps with a different fType.
52 */
53
54
56
58
59public:
60
61 /** modern compilers seem to insist in explicit using */
62 using AttributeVoid::operator=;
63 using AttributeVoid::operator==;
64 using AttributeVoid::operator!=;
65
66 /** Default constructor */
67 AttributeFlags(void) : AttributeVoid(), mFlags(mDefFlags) {};
68
69 /** Copy constructor */
70 AttributeFlags(const AttributeFlags& rOther) : AttributeVoid(), mFlags(rOther.mFlags) {};
71
72 /** Destructor */
73 virtual ~AttributeFlags(void) {};
74
75 /**
76 * Test a flag
77 */
78 bool Test(fType mask) const { return ( (mFlags & mask) != 0 ); };
79
80 /**
81 * Test multible flags, combine by "and"
82 */
83 bool TestAll(fType mask) const { return ( (mFlags & mask) == mask ); };
84
85 /**
86 * Test multible flags, combine by "or"
87 */
88 bool TestSome(fType mask) const { return ( (mFlags & mask) != 0 ); };
89
90 /**
91 * Test multible flags, combine by "not or"
92 */
93 bool TestNone(fType mask) const { return ( (mFlags & mask) == 0 ); };
94
95 /**
96 * Set multiple flags
97 */
98 void Set(fType mask) {mFlags |= mask; };
99
100 /**
101 * Clear multiple flags
102 */
103 void Clr(fType mask) {mFlags &= ~mask; };
104
105 /**
106 * Test for default value
107 */
108 virtual bool IsDefault(void) const {return mFlags==mDefFlags;};
109
110 /** Flags (public access for convenience) */
112
113 /* default flags */
114 const static fType mDefFlags=0x0;
115
116
117protected:
118
119 /**
120 * Copyment method.
121 *
122 * @param rSrcAttr
123 * Source to assign from
124 */
125 void DoCopy(const AttributeFlags& rSrcAttr);
126
127 /**
128 * Copyment method.
129 *
130 * @param rSrcAttr
131 * Source to assign from
132 */
133 void DoMove(AttributeFlags& rSrcAttr);
134
135 /**
136 * Test equality of configuration data.
137 *
138 * @param rOther
139 * Other object to compare with.
140 * @return
141 * True on match.
142 */
143 bool DoEqual(const AttributeFlags& rOther) const;
144
145
146 /**
147 * Reads attribute from TokenReader, see Type for public wrappers.
148 *
149 * Test whether the current token is an integer with base 16. If so, read the token to the
150 * flags value. Else, dont take any tokens. The label and context arguments are ignored.
151 *
152 * @param rTr
153 * TokenReader to read from
154 * @param rLabel
155 * Section to read
156 * @param pContext
157 * Read context to provide contextual information
158 *
159 * @exception Exception
160 * - IO error (id 1)
161 */
162 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
163
164 /**
165 * Write to TokenWriter, see Type for public wrappers.
166 *
167 * If not the defult value, write the flag value as base 16 integer token. Else,
168 * do nothing. The label and context arguments are ignored.
169 *
170 * @param rTw
171 * Reference to TokenWriter
172 * @param rLabel
173 * Label of section to write
174 * @param pContext
175 * Write context to provide contextual information
176 *
177 * @exception Exception
178 * - IO errors (id 2)
179 */
180 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
181
182 /**
183 * Write to TokenWriter, see Type for public wrappers.
184 *
185 * If not the defult value, write the flags in XML format.
186 * Else, do nothing. The label and context arguments are ignored.
187 *
188 * @param rTw
189 * Reference to TokenWriter
190 * @param rLabel
191 * Label of section to write
192 * @param pContext
193 * Write context to provide contextual information
194 *
195 * @exception Exception
196 * - IO errors (id 2)
197 */
198 virtual void DoXWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
199
200
201
202}; // class AttributeFlags
203
204
205/**
206 * Attribute class to model event controllability properties.
207 *
208 * This attribute is meant to be an event attribute and can distinguish between
209 * controllable, observable, forcible and abstraction events. It is based on faudes::AttributeFlags
210 * and uses the lower four bits in the flag word to store the respective boolean values.
211 * The AttributeCFlags class adds convenience functions to access these bits and a default-value
212 * that corresponds to observable and neiter controllable nor forcible.
213 *
214 * Presuming that only controllability flags are uses (different from default), the
215 * token representation is by an Option String consisting of the initials <tt>c</tt>,<tt>o</tt>,<tt>f</tt>
216 * and <tt>a</tt>, where initials are capitatised for set flags and default values
217 * are not written; eg <tt>+C+</tt>
218 * for a controllable event that is observable (default), not forcible (default) and
219 * an abstraction event (default).
220 * If other than the four controllability bits are used, std. hex format is used.
221 *
222 */
223
224
226
228
229 public:
230
231 using AttributeFlags::operator=;
232 using AttributeFlags::operator==;
233 using AttributeFlags::operator!=;
234
235 /**
236 * Default constructor
237 */
238 AttributeCFlags(void) : AttributeFlags() { mFlags=mDefCFlags; };
239
240 /** Copy constructor */
241 AttributeCFlags(const AttributeCFlags& rOther) : AttributeFlags(rOther) {};
242
243 /** Destructor */
244 virtual ~AttributeCFlags(void) {};
245
246 /**
247 * Set controllable flag
248 */
249 void SetControllable(void) { mFlags |= mControllableFlag; }
250
251 /**
252 * Clear controllable flag
253 */
254
255 void ClrControllable(void) { mFlags &= ~mControllableFlag; };
256
257 /**
258 * Query controllablility
259 */
260 bool Controllable(void) const {return ( (mFlags & mControllableFlag) != 0 ); }
261
262
263 /**
264 * Set observable flag
265 */
266 void SetObservable(void) { mFlags |= mObservableFlag; }
267
268 /**
269 * Clear observable flag
270 */
271 void ClrObservable(void) { mFlags &= ~mObservableFlag; };
272
273 /**
274 * Query observablility
275 */
276 bool Observable(void) const {return ( (mFlags & mObservableFlag) != 0 ); }
277
278
279 /**
280 * Set forcible flag
281 */
282 void SetForcible(void) { mFlags |= mForcibleFlag; }
283
284 /**
285 * Clear forcible flag
286 */
287
288 void ClrForcible(void) { mFlags &= ~mForcibleFlag; };
289
290 /**
291 * Query forcibility
292 */
293 bool Forcible(void) const {return ( (mFlags & mForcibleFlag) != 0 ); }
294
295
296 /**
297 * Set abstraction flag
298 */
299 void SetHighlevel(void) { mFlags |= mAbstractionFlag; }
300
301 /**
302 * Clear abstraction flag
303 */
304 void SetLowlevel(void) { mFlags &= ~mAbstractionFlag; };
305
306 /**
307 * Query abstaction flag
308 */
309 bool Highlevel(void) const {return ( (mFlags & mAbstractionFlag) != 0 ); }
310
311 /**
312 * Query abstaction flag
313 */
314 bool Lowlevel(void) const {return ( (mFlags & mAbstractionFlag) == 0 ); }
315
316
317 /**
318 * Test for default value
319 */
320 virtual bool IsDefault(void) const {return mFlags==mDefCFlags;};
321
322 // flag masks for the three properties
323 const static fType mControllableFlag =0x01;
324 const static fType mObservableFlag =0x02;
325 const static fType mForcibleFlag =0x04;
326 const static fType mAbstractionFlag =0x08;
327
328 private:
329 /** Overall default value */
330 const static fType mDefCFlags =0x0a;
331
332 /** All flags used by CFlags */
333 const static fType mAllCFlags =0x0f;
334
335 protected:
336
337 /**
338 * Copyment method.
339 *
340 * @param rSrcAttr
341 * Source to assign from
342 */
343 void DoCopy(const AttributeCFlags& rSrcAttr);
344
345 /**
346 * Copyment method.
347 *
348 * @param rSrcAttr
349 * Source to assign from
350 */
351 void DoMove(AttributeCFlags& rSrcAttr);
352
353 /**
354 * Test equality of configuration data.
355 *
356 * @param rOther
357 * Other attribute to compare with.
358 * @return
359 * True on match.
360 */
361 bool DoEqual(const AttributeCFlags& rOther) const;
362
363 /**
364 * Reads attribute from TokenReader, see AttributeVoid for public wrappers.
365 * Reads a single token if it can be interpreted as AttributeCFlag, that is, if
366 * it is a respective option string or hex number. Label and Context
367 * argument are ignored. No token mismatch exceptions are thrown on error.
368 *
369 * @param rTr
370 * TokenReader to read from
371 * @param rLabel
372 * Section to read
373 * @param pContext
374 * Read context to provide contextual information
375 *
376 * @exception Exception
377 * - IO error (id 1)
378 */
379 virtual void DoRead(TokenReader& rTr, const std::string& rLabel="", const Type* pContext=0);
380
381 /**
382 * Writes attribute to TokenWriter, see AttributeVoid for public wrappers.
383 * Label and Context argument are ignored.
384 *
385 * @param rTw
386 * TokenWriter to write to
387 * @param rLabel
388 * Section to write
389 * @param pContext
390 * Write context to provide contextual information
391 *
392 * @exception Exception
393 * - IO error (id 2)
394 */
395 virtual void DoWrite(TokenWriter& rTw,const std::string& rLabel="", const Type* pContext=0) const;
396
397
398 /**
399 * Writes attribute to TokenWriter (XML format), see AttributeVoid for public wrappers.
400 * Label and Context argument are ignored.
401 *
402 * @param rTw
403 * TokenWriter to write to
404 * @param rLabel
405 * Section to write
406 * @param pContext
407 * Write context to provide contextual information
408 *
409 * @exception Exception
410 * - IO error (id 2)
411 */
412 virtual void DoXWrite(TokenWriter& rTw,const std::string& rLabel="", const Type* pContext=0) const;
413
414
415
416}; // class AttributeCFlags
417
418} // namespace faudes
419
420#endif
#define FAUDES_API
Class TokenReader.
Class TokenWriter.
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition cfl_types.h:918
bool Lowlevel(void) const
bool Forcible(void) const
virtual ~AttributeCFlags(void)
bool Controllable(void) const
AttributeCFlags(const AttributeCFlags &rOther)
bool Highlevel(void) const
virtual bool IsDefault(void) const
bool Observable(void) const
bool TestNone(fType mask) const
bool TestAll(fType mask) const
virtual ~AttributeFlags(void)
virtual bool IsDefault(void) const
AttributeFlags(const AttributeFlags &rOther)
bool Test(fType mask) const
void Set(fType mask)
bool TestSome(fType mask) const
unsigned long int fType
AttrType AttributeVoid

libFAUDES 2.34d --- 2026.03.11 --- c++ api documentaion by doxygen