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 
35 /**
36  * Minimal Attribute. Attributes are used as template parameters for
37  * faudes containers and generators and facilitate the modelling of customized
38  * properties of events, states and transitions. The AttributeVoid class defines
39  * the minimal interface of faudes attributes and therefore is the designated
40  * base class for all attribute implementations. The AttributeVoid class does
41  * not define any actual properties. See AttributeFlags for a non-trivial example.
42  *
43  * To derive a class from AttributeVoid you should reimplement the virtual
44  * interface
45  * - virtual methody DoRead and DoWrite for token io (as in faudes::Type)
46  * - virtual methods for DoAssign() (as in faudes::Type)
47  * - the factory method New() (use provided macro from faudes::Type)
48  * - the rti typecast method Cast() (use provided macro from faudes::Type)
49  * - user level Assign() method (use provided macro from faudes::Type)
50  */
51 
52 class FAUDES_API AttributeVoid : public Type {
53 
55 
56 public:
57 
58  using Type::operator=;
59  using Type::operator==;
60  using Type::operator!=;
61 
62  /** Constructor */
63  AttributeVoid(void);
64 
65  /** Copy Constructor */
66  AttributeVoid(const AttributeVoid& rSrcAttr);
67 
68  /** Destructor */
69  virtual ~AttributeVoid(void);
70 
71  /**
72  * Test for default value.
73  */
74  virtual bool IsDefault(void) const {return true;};
75 
76  /**
77  * Set to default value.
78  * Derived classes must reimplement this function for Clear to operate properly.
79  */
80  virtual void SetDefault(void) {};
81 
82  /**
83  * Synonym for SetDefault to match std interface
84  */
85  virtual void Clear(void) { SetDefault(); };
86 
87  /**
88  * Skip attribute tokens.
89  *
90  * Helper method to be called after all sttribute derived classes had their
91  * chance to read their data. It skips all tokens and sections until it reaches a
92  * String or decimal Integer.
93  *
94  * @param rTr
95  * TokenReader to read from
96  * @exception Exception
97  * - IO error (id 1)
98  */
99  static void Skip(TokenReader& rTr);
100 
101 protected:
102 
103  /**
104  * Assign attribute members.
105  * Since AttributeVoid has no members, this method does nothing.
106  * Derived classes are meant to reimplement DoAssign by first calling
107  * their base and then assigning additional member variables.
108  *
109  * @param rSrcAttr
110  * Source to assign from
111  */
112  void DoAssign(const AttributeVoid& rSrcAttr) { (void) rSrcAttr; };
113 
114  /**
115  * Test equality of configuration data.
116  * Derived attributes should reimplement this class to compare
117  * configuration data. The base AttributeVoid returns true as a default.
118  * @param rOther
119  * Other object to compare with.
120  * @return
121  * True on match.
122  */
123  bool DoEqual(const AttributeVoid& rOther) const { (void) rOther; return true; }
124 
125  /**
126  * Actual read method to read attribute from tokenreader.
127  *
128  * For derived attributue classes, this method must either read all tokens that
129  * belong to the respective attribute, or none. It may throw exceptions on token
130  * mismatch within the relevant attribute, but it may not throw exceptions when
131  * it encounters tokens that possibly belong to another attribute. The latter are
132  * to be skipped by the provided Skip method. See Type::Read
133  * for public wrappers.
134  *
135  * @param rTr
136  * TokenReader to read from
137  * @param rLabel
138  * Section to read
139  * @param pContext
140  * Read context to provide contextual information
141  *
142  * @exception Exception
143  * - IO error (id 1)
144  */
145  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
146 
147  /**
148  * Actual write method to write the attribute to a TokenWriter.
149  *
150  * Reimplement this method for derived attribute classes to define the token io
151  * format. See Type::Write for public wrappers.
152  *
153  * @param rTw
154  * Reference to TokenWriter
155  * @param rLabel
156  * Label of section to write
157  * @param pContext
158  * Write context to provide contextual information
159  *
160  * @exception Exception
161  * - IO errors (id 2)
162  */
163  virtual void DoDWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
164 
165  /**
166  * Actual write method to write the attribute to a TokenWriter.
167  *
168  * Reimplement this method for derived attribute classes to define the token io
169  * format. See Type::Write for public wrappers.
170  *
171  * @param rTw
172  * Reference to TokenWriter
173  * @param rLabel
174  * Label of section to write
175  * @param pContext
176  * Write context to provide contextual information
177  *
178  * @exception Exception
179  * - IO errors (id 2)
180  */
181  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
182 
183 
184 
185 }; // class AttributeVoid
186 
187 
188 /** Convenience typdef flag data */
189 typedef unsigned long int fType;
190 
191 /**
192  * Boolean flags Attribute. This attribute class uses a flag word to represent
193  * boolean values. The current implementation uses a long int type and hence handles
194  * up to 32 flags. Each flag is accessed by the according bit mask.
195  *
196  * The current version
197  * of libFAUDES uses bits 0,1,2 of event attributes for controllability properties
198  * (see AttributeCFlags) and the bits 31 and 32 of state attributes for the Qt based
199  * GUI project. Further versions may use the lower 8 bits of the event aflags and the higher 8
200  * bits of state flags. You are free to use any flags for your application, but if possible try
201  * to avoid the above mentioned. For extensive use of flags, you may also consider to
202  * define a separate attribute class, perhaps with a different fType.
203  */
204 
205 
206 
208 
210 
211 public:
212 
213  using AttributeVoid::operator=;
214  using AttributeVoid::operator==;
215  using AttributeVoid::operator!=;
216 
217  /** Default constructor */
218  AttributeFlags(void) : AttributeVoid(), mFlags(mDefFlags) {};
219 
220  /** Copy constructor */
221  AttributeFlags(const AttributeFlags& rOther) : AttributeVoid(), mFlags(rOther.mFlags) {};
222 
223  /** Destructor */
224  virtual ~AttributeFlags(void) {};
225 
226  /**
227  * Test a flag
228  */
229  bool Test(fType mask) const { return ( (mFlags & mask) != 0 ); };
230 
231  /**
232  * Test multible flags, combine by "and"
233  */
234  bool TestAll(fType mask) const { return ( (mFlags & mask) == mask ); };
235 
236  /**
237  * Test multible flags, combine by "or"
238  */
239  bool TestSome(fType mask) const { return ( (mFlags & mask) != 0 ); };
240 
241  /**
242  * Test multible flags, combine by "not or"
243  */
244  bool TestNone(fType mask) const { return ( (mFlags & mask) == 0 ); };
245 
246  /**
247  * Set multiple flags
248  */
249  void Set(fType mask) {mFlags |= mask; };
250 
251  /**
252  * Clear multiple flags
253  */
254  void Clr(fType mask) {mFlags &= ~mask; };
255 
256  /**
257  * Test for default value
258  */
259  virtual bool IsDefault(void) const {return mFlags==mDefFlags;};
260 
261  /** Flags (public access for convenience) */
263 
264  /* default flags */
265  const static fType mDefFlags=0x0;
266 
267 
268 protected:
269 
270  /**
271  * Assignment method.
272  *
273  * @param rSrcAttr
274  * Source to assign from
275  */
276  void DoAssign(const AttributeFlags& rSrcAttr);
277 
278  /**
279  * Test equality of configuration data.
280  *
281  * @param rOther
282  * Other object to compare with.
283  * @return
284  * True on match.
285  */
286  bool DoEqual(const AttributeFlags& rOther) const;
287 
288 
289  /**
290  * Reads attribute from TokenReader, see Type for public wrappers.
291  *
292  * Test whether the current token is an integer with base 16. If so, read the token to the
293  * flags value. Else, dont take any tokens. The label and context arguments are ignored.
294  *
295  * @param rTr
296  * TokenReader to read from
297  * @param rLabel
298  * Section to read
299  * @param pContext
300  * Read context to provide contextual information
301  *
302  * @exception Exception
303  * - IO error (id 1)
304  */
305  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
306 
307  /**
308  * Write to TokenWriter, see Type for public wrappers.
309  *
310  * If not the defult value, write the flag value as base 16 integer token. Else,
311  * do nothing. The label and context arguments are ignored.
312  *
313  * @param rTw
314  * Reference to TokenWriter
315  * @param rLabel
316  * Label of section to write
317  * @param pContext
318  * Write context to provide contextual information
319  *
320  * @exception Exception
321  * - IO errors (id 2)
322  */
323  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
324 
325  /**
326  * Write to TokenWriter, see Type for public wrappers.
327  *
328  * If not the defult value, write the flags in XML format.
329  * Else, do nothing. The label and context arguments are ignored.
330  *
331  * @param rTw
332  * Reference to TokenWriter
333  * @param rLabel
334  * Label of section to write
335  * @param pContext
336  * Write context to provide contextual information
337  *
338  * @exception Exception
339  * - IO errors (id 2)
340  */
341  virtual void DoXWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
342 
343 
344 
345 }; // class AttributeFlags
346 
347 
348 } // namespace faudes
349 
350 #endif
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:80
Runtime interface, registry for faudes-types and functions.
Class TokenReader.
Class TokenWriter.
Runtime interface, faudes types.
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
faudes type declaration macro
Definition: cfl_types.h:867
Boolean flags Attribute.
bool TestNone(fType mask) const
Test multible flags, combine by "not or".
bool TestAll(fType mask) const
Test multible flags, combine by "and".
virtual ~AttributeFlags(void)
Destructor.
AttributeFlags(void)
Default constructor.
virtual bool IsDefault(void) const
Test for default value.
AttributeFlags(const AttributeFlags &rOther)
Copy constructor.
bool Test(fType mask) const
Test a flag.
fType mFlags
Flags (public access for convenience)
void Clr(fType mask)
Clear multiple flags.
void Set(fType mask)
Set multiple flags.
bool TestSome(fType mask) const
Test multible flags, combine by "or".
Minimal Attribute.
virtual bool IsDefault(void) const
Test for default value.
bool DoEqual(const AttributeVoid &rOther) const
Test equality of configuration data.
void DoAssign(const AttributeVoid &rSrcAttr)
Assign attribute members.
virtual void Clear(void)
Synonym for SetDefault to match std interface.
virtual void SetDefault(void)
Set to default value.
A TokenReader reads sequential tokens from a file or string.
A TokenWriter writes sequential tokens to a file, a string or stdout.
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
libFAUDES resides within the namespace faudes.
unsigned long int fType
Convenience typdef flag data.

libFAUDES 2.32f --- 2024.12.22 --- c++ api documentaion by doxygen