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