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

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