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 /**
111 * Pretty print.
112 */
113 virtual std::string Str(void) const;
114
115 /** Flags (public access for convenience) */
117
118 /* default flags */
119 const static fType mDefFlags=0x0;
120
121
122protected:
123
124 /**
125 * Copyment method.
126 *
127 * @param rSrcAttr
128 * Source to assign from
129 */
130 void DoCopy(const AttributeFlags& rSrcAttr);
131
132 /**
133 * Copyment method.
134 *
135 * @param rSrcAttr
136 * Source to assign from
137 */
138 void DoMove(AttributeFlags& rSrcAttr);
139
140 /**
141 * Test equality of configuration data.
142 *
143 * @param rOther
144 * Other object to compare with.
145 * @return
146 * True on match.
147 */
148 bool DoEqual(const AttributeFlags& rOther) const;
149
150
151 /**
152 * Reads attribute from TokenReader, see Type for public wrappers.
153 *
154 * Test whether the current token is an integer with base 16. If so, read the token to the
155 * flags value. Else, dont take any tokens. The label and context arguments are ignored.
156 *
157 * @param rTr
158 * TokenReader to read from
159 * @param rLabel
160 * Section to read
161 * @param pContext
162 * Read context to provide contextual information
163 *
164 * @exception Exception
165 * - IO error (id 1)
166 */
167 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
168
169 /**
170 * Write to TokenWriter, see Type for public wrappers.
171 *
172 * If not the defult value, write the flag value as base 16 integer token. Else,
173 * do nothing. The label and context arguments are ignored.
174 *
175 * @param rTw
176 * Reference to TokenWriter
177 * @param rLabel
178 * Label of section to write
179 * @param pContext
180 * Write context to provide contextual information
181 *
182 * @exception Exception
183 * - IO errors (id 2)
184 */
185 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
186
187 /**
188 * Write to TokenWriter, see Type for public wrappers.
189 *
190 * If not the defult value, write the flags in XML format.
191 * Else, do nothing. The label and context arguments are ignored.
192 *
193 * @param rTw
194 * Reference to TokenWriter
195 * @param rLabel
196 * Label of section to write
197 * @param pContext
198 * Write context to provide contextual information
199 *
200 * @exception Exception
201 * - IO errors (id 2)
202 */
203 virtual void DoXWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
204
205
206
207}; // class AttributeFlags
208
209
210/**
211 * Attribute class to model event controllability properties.
212 *
213 * This attribute is meant to be an event attribute and can distinguish between
214 * controllable, observable, forcible and abstraction events. It is based on faudes::AttributeFlags
215 * and uses the lower four bits in the flag word to store the respective boolean values.
216 * The AttributeCFlags class adds convenience functions to access these bits and a default-value
217 * that corresponds to observable and neiter controllable nor forcible.
218 *
219 * Presuming that only controllability flags are uses (different from default), the
220 * token representation is by an Option String consisting of the initials <tt>c</tt>,<tt>o</tt>,<tt>f</tt>
221 * and <tt>a</tt>, where initials are capitatised for set flags and default values
222 * are not written; eg <tt>+C+</tt>
223 * for a controllable event that is observable (default), not forcible (default) and
224 * an abstraction event (default).
225 * If other than the four controllability bits are used, std. hex format is used.
226 *
227 */
228
229
231
233
234 public:
235
236 using AttributeFlags::operator=;
237 using AttributeFlags::operator==;
238 using AttributeFlags::operator!=;
239
240 /**
241 * Default constructor
242 */
243 AttributeCFlags(void) : AttributeFlags() { mFlags=mDefCFlags; };
244
245 /** Copy constructor */
246 AttributeCFlags(const AttributeCFlags& rOther) : AttributeFlags(rOther) {};
247
248 /** Destructor */
249 virtual ~AttributeCFlags(void) {};
250
251 /**
252 * Set controllable flag
253 */
254 void SetControllable(void) { mFlags |= mControllableFlag; }
255
256 /**
257 * Clear controllable flag
258 */
259
260 void ClrControllable(void) { mFlags &= ~mControllableFlag; };
261
262 /**
263 * Query controllablility
264 */
265 bool Controllable(void) const {return ( (mFlags & mControllableFlag) != 0 ); }
266
267
268 /**
269 * Set observable flag
270 */
271 void SetObservable(void) { mFlags |= mObservableFlag; }
272
273 /**
274 * Clear observable flag
275 */
276 void ClrObservable(void) { mFlags &= ~mObservableFlag; };
277
278 /**
279 * Query observablility
280 */
281 bool Observable(void) const {return ( (mFlags & mObservableFlag) != 0 ); }
282
283
284 /**
285 * Set forcible flag
286 */
287 void SetForcible(void) { mFlags |= mForcibleFlag; }
288
289 /**
290 * Clear forcible flag
291 */
292
293 void ClrForcible(void) { mFlags &= ~mForcibleFlag; };
294
295 /**
296 * Query forcibility
297 */
298 bool Forcible(void) const {return ( (mFlags & mForcibleFlag) != 0 ); }
299
300
301 /**
302 * Set preemptible flag
303 */
304 void SetPreemptible(void) { mFlags |= mPreemptibleFlag; }
305
306 /**
307 * Clear preemptible flag
308 */
309 void ClrPreemptible(void) { mFlags &= ~mPreemptibleFlag; };
310
311 /**
312 * Query abstaction flag
313 */
314 bool Preemptible(void) const {return ( (mFlags & mPreemptibleFlag) != 0 ); }
315
316
317 /**
318 * Test for default value
319 */
320 virtual bool IsDefault(void) const {return mFlags==mDefCFlags;};
321
322 /**
323 * Pretty print.
324 */
325 virtual std::string Str(void) const;
326
327 // flag masks for the three properties
328 const static fType mControllableFlag =0x01;
329 const static fType mObservableFlag =0x02;
330 const static fType mForcibleFlag =0x04;
331 const static fType mPreemptibleFlag =0x08;
332
333 private:
334 /** Overall default value */
335 const static fType mDefCFlags =0x02;
336
337 /** All flags used by CFlags */
338 const static fType mAllCFlags =0x0f;
339
340 protected:
341
342 /**
343 * Copyment method.
344 *
345 * @param rSrcAttr
346 * Source to assign from
347 */
348 void DoCopy(const AttributeCFlags& rSrcAttr);
349
350 /**
351 * Copyment method.
352 *
353 * @param rSrcAttr
354 * Source to assign from
355 */
356 void DoMove(AttributeCFlags& rSrcAttr);
357
358 /**
359 * Test equality of configuration data.
360 *
361 * @param rOther
362 * Other attribute to compare with.
363 * @return
364 * True on match.
365 */
366 bool DoEqual(const AttributeCFlags& rOther) const;
367
368 /**
369 * Reads attribute from TokenReader, see AttributeVoid for public wrappers.
370 * Reads a single token if it can be interpreted as AttributeCFlag, that is, if
371 * it is a respective option string or hex number. Label and Context
372 * argument are ignored. No token mismatch exceptions are thrown on error.
373 *
374 * @param rTr
375 * TokenReader to read from
376 * @param rLabel
377 * Section to read
378 * @param pContext
379 * Read context to provide contextual information
380 *
381 * @exception Exception
382 * - IO error (id 1)
383 */
384 virtual void DoRead(TokenReader& rTr, const std::string& rLabel="", const Type* pContext=0);
385
386 /**
387 * Writes attribute to TokenWriter, see AttributeVoid for public wrappers.
388 * Label and Context argument are ignored.
389 *
390 * @param rTw
391 * TokenWriter to write to
392 * @param rLabel
393 * Section to write
394 * @param pContext
395 * Write context to provide contextual information
396 *
397 * @exception Exception
398 * - IO error (id 2)
399 */
400 virtual void DoWrite(TokenWriter& rTw,const std::string& rLabel="", const Type* pContext=0) const;
401
402
403 /**
404 * Writes attribute to TokenWriter (XML format), see AttributeVoid for public wrappers.
405 * Label and Context argument are ignored.
406 *
407 * @param rTw
408 * TokenWriter to write to
409 * @param rLabel
410 * Section to write
411 * @param pContext
412 * Write context to provide contextual information
413 *
414 * @exception Exception
415 * - IO error (id 2)
416 */
417 virtual void DoXWrite(TokenWriter& rTw,const std::string& rLabel="", const Type* pContext=0) const;
418
419
420
421}; // class AttributeCFlags
422
423} // namespace faudes
424
425#endif
#define FAUDES_API
Class TokenReader.
Class TokenWriter.
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition cfl_types.h:918
bool Preemptible(void) const
bool Forcible(void) const
virtual ~AttributeCFlags(void)
bool Controllable(void) const
AttributeCFlags(const AttributeCFlags &rOther)
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.34g --- 2026.03.30 --- c++ api documentaion by doxygen