cfl_elementary.h
Go to the documentation of this file.
1 /** @file cfl_elementary.h Runtime interface, elementary types */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5 Copyright (C) 2009 Ruediger Berndt
6 Copyright (C) 2010 Thomas Moor
7 
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12 
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
21 
22 
23 #ifndef FAUDES_ELEMENTARY_H
24 #define FAUDES_ELEMENTARY_H
25 
26 #include "cfl_types.h"
27 #include "cfl_functions.h"
28 #include "cfl_basevector.h"
29 
30 
31 
32 namespace faudes {
33 
34 
35 
36 /*
37 ********************************************************************
38 ********************************************************************
39 ********************************************************************
40 
41 Elementary type, representing an integer value.
42 
43 ********************************************************************
44 ********************************************************************
45 ********************************************************************
46 */
47 
48 /** Elementary type */
49 class FAUDES_API Integer : public Type {
50 
51  public:
52 
53  using Type::operator=;
54 
55  /** Constructor */
56  Integer(void);
57 
58  /**
59  * Constructor provided with initial value.
60  *
61  * @param val
62  * Initial value.
63  */
64  Integer(Int val);
65 
66  /** Destructor */
67  ~Integer(void){}
68 
69  /**
70  * Construct on heap.
71  * Create new Integer instance and return pointer.
72  *
73  * @return
74  * Pointer to Integer instance.
75  *
76  */
77  virtual Integer* New(void) const;
78 
79  /**
80  * Construct copy on heap.
81  * Create new Integer instance and return pointer.
82  *
83  * @return
84  * Pointer to Integer instance.
85  *
86  */
87  virtual Integer* Copy(void) const;
88 
89  /**
90  * Cast the other object to Integer.
91  * Returns NULL if the cast is not possible.
92  *
93  * @param pOther
94  * Pointer to object to cast.
95  * @return
96  * Pointer to Integer instance, or NULL
97  *
98  */
99  virtual const Integer* Cast(const Type* pOther) const;
100 
101  /**
102  * Set value.
103  *
104  * @param val
105  * Value to be set.
106  */
107  void CValue(Int val);
108 
109  /**
110  * Get value.
111  *
112  * @return
113  * Value of object. (Int)
114  */
115  Int CValue(void) const;
116 
117  /**
118  * Get reference.
119  *
120  * @return
121  * Reference to c value.
122  */
123  Int* CReference(void);
124 
125  /**
126  * Sum operator.
127  */
128  Integer& operator+ (const Int& clint){
129  CValue(mCInteger + clint);
130  return *this;
131  }
132 
133  /**
134  * Sum operator.
135  */
136  Integer& operator+ (const Integer& coint){
137  CValue(mCInteger + coint.CValue());
138  return *this;
139  }
140 
141  /**
142  * Assignment operator.
143  */
144  Integer& operator= (const Int& clint){
145  CValue(clint);
146  return *this;
147  }
148 
149  /**
150  * Assignment operator.
151  */
152  Integer& operator= (const Integer& coint){
153  CValue(coint.CValue());
154  return *this;
155  }
156 
157  /**
158  * Assignment/Sum operator
159  */
160  Integer& operator+= (const Int& clint){
161  Int litmp = CValue();
162  CValue(litmp + clint);
163  return *this;
164  }
165 
166  /**
167  * Assignment/Sum operator
168  */
169  Integer& operator+= (const Integer& coint){
170  Int litmp = CValue() + coint.CValue();
171  CValue(litmp);
172  return *this;
173  }
174 
175  /**
176  * Conversion to C++ type
177  */
178  operator Int() const { return CValue();};
179 
180 
181  /**
182  * Reimplementation of faudes::Type::DoWrite()
183  * Write data to Tokenwriter.
184  *
185  * @param rTw
186  * Reference to TokenWriter.
187  * @param rLabel
188  * Label of section to write.
189  * @param pContext
190  * Context information
191  *
192  * @exception Exception
193  * - IO Error (id 2)
194  */
195  void DoWrite(TokenWriter& rTw, const std::string& rLabel = "", const Type* pContext=0) const;
196 
197  /**
198  * Read data from TokenReader.
199  *
200  * @param rTr
201  * Reference to TokenReader.
202  * @param rLabel
203  * Section to read.
204  * @param pContext
205  * Context information
206  *
207  * @exception Exception
208  * - Token mismatch
209  * - IO Error
210  */
211  void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
212 
213  protected:
214 
215  /** Variable to store current value. */
217 
218 }; // Integer
219 
220 // convenience typedef
222 
223 // Sum of two integers, uniform rti api
224 extern FAUDES_API long int IntegerSum(const Integer& arg1, const Integer& arg2);
225 
226 // Sum of multiple integers, uniform rti api
227 extern FAUDES_API long int IntegerSum(const IntegerVector& intvect);
228 
229 /*
230 ********************************************************************
231 ********************************************************************
232 ********************************************************************
233 
234 Elementary type, representing a string value.
235 
236 ********************************************************************
237 ********************************************************************
238 ********************************************************************
239 */
240 
241 /** Elementary type */
242 class FAUDES_API String : public Type{
243 
244  public:
245 
246  using Type::operator=;
247 
248  /** Constructor */
249  String(void);
250 
251  /**
252  * Constructor provided with initial value.
253  *
254  * @param val
255  * Initial value.
256  */
257  String(std::string val);
258 
259  /** Destructor */
260  ~String(void){}
261 
262  /**
263  * Construct on heap.
264  * Create new String instance and return pointer.
265  *
266  * NOTE:
267  * Calling function takes control.
268  *
269  * @return
270  * Pointer to String instance.
271  */
272  virtual String* New(void) const;
273 
274  /**
275  * Construct copy on heap.
276  * Create new String instance and return pointer.
277  *
278  * @return
279  * Pointer to Integer instance.
280  *
281  */
282  virtual String* Copy(void) const;
283 
284  /**
285  * Cast the other object to String.
286  * Returns NULL if the cast is not possible.
287  *
288  * @param pOther
289  * Pointer to object to cast.
290  * @return
291  * Pointer to String instance, or NULL
292  *
293  */
294  virtual const String* Cast(const Type* pOther) const;
295 
296  /**
297  * Set value.
298  *
299  * @param val
300  * Value to be set. (std::string)
301  */
302  void CValue(std::string val);
303 
304  /**
305  * Get value
306  *
307  * @return
308  * Value of object. (std::string)
309  */
310  std::string CValue(void) const;
311 
312  /**
313  * Get reference.
314  *
315  * @return
316  * Reference to c value.
317  */
318  std::string* CReference(void);
319 
320  /**
321  * Assignment operator.
322  */
323  String& operator= (const String& costr){
324  CValue(costr.CValue());
325  return(*this);
326  }
327 
328  /*
329  * Assignment operator, std::string source
330  */
331  String& operator= (const std::string& cstr){
332  CValue(cstr);
333  return(*this);
334  }
335 
336  /**
337  * Conversion to std::string
338  */
339  operator std::string() const { return CValue();};
340 
341 
342  /**
343  * Write data to Tokenwriter.
344  *
345  * @param rTw
346  * Reference to TokenWriter.
347  * @param rLabel
348  * Label of section to write.
349  * @param pContext
350  * Write context to provide contextual information (ignored)
351  *
352  * @exception Exception
353  * - IO Error
354  */
355  void DoWrite(TokenWriter& rTw, const std::string& rLabel = "", const Type* pContext=0) const;
356 
357 
358  /**
359  * Read data from TokenReader.
360  *
361  * @param rTr
362  * Reference to TokenReader.
363  * @param rLabel
364  * Section to read.
365  * @param pContext
366  * Read context to provide contextual information (ignored)
367  *
368  * @exception Exception
369  * - Token mismatch
370  * - IO Error
371  */
372  void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
373 
374  protected:
375  /** Variable to store current value. */
376  std::string mCString;
377 
378 }; // String
379 
380 
381 
382 
383 /*
384 ********************************************************************
385 ********************************************************************
386 ********************************************************************
387 
388 Elementary type, representing a boolean value.
389 
390 ********************************************************************
391 ********************************************************************
392 ********************************************************************
393 */
394 
395 /** Elementary type */
396 class FAUDES_API Boolean : public Type{
397 
398  public:
399 
400  using Type::operator=;
401 
402  /** Constructor */
403  Boolean(void);
404 
405  /**
406  * Constructor provided with initial value.
407  *
408  * @param val
409  * Initial value. (bool)
410  */
411  Boolean(bool val);
412 
413  /** Destructor */
414  ~Boolean(void){}
415 
416  /**
417  * Construct on heap.
418  * Create new Boolean instance and return pointer.
419  *
420  * NOTE:
421  * Calling function takes control.
422  *
423  * @return
424  * Pointer to Boolean instance.
425  */
426  virtual Boolean* New(void) const;
427 
428  /**
429  * Construct copy on heap.
430  * Create new Boolean instance and return pointer.
431  *
432  * @return
433  * Pointer to Boolean instance.
434  *
435  */
436  virtual Boolean* Copy(void) const;
437 
438  /**
439  * Cast the other object to Boolean.
440  * Returns NULL if the cast is not possible.
441  *
442  * @param pOther
443  * Pointer to object to cast.
444  * @return
445  * Pointer to Boolean instance, or NULL
446  *
447  */
448  virtual const Boolean* Cast(const Type* pOther) const;
449 
450  /**
451  * Set value.
452  *
453  * @param val
454  * Value to be set.
455  */
456  void CValue(bool val);
457 
458  /**
459  * Get value.
460  *
461  * @return
462  * Value of object. (bool)
463  */
464  bool CValue(void) const;
465 
466  /**
467  * Get reference.
468  *
469  * @return
470  * Reference to c value.
471  */
472  bool* CReference(void);
473 
474  /**
475  * Assignment operator.
476  */
477  Boolean& operator= (const bool& bbool){
478  CValue(bbool);
479  return(*this);
480  }
481 
482  /**
483  * Assignment operator.
484  */
485  Boolean& operator= (const Boolean& cobool){
486  CValue(cobool.CValue());
487  return(*this);
488  }
489 
490 
491  /**
492  * Conversion to C++ type bool
493  */
494  operator bool() const { return CValue();};
495 
496  /**
497  * Write data to Tokenwriter.
498  *
499  * NOTE:
500  * 0 = false
501  * 1 = true
502  *
503  * @param rTw
504  * Reference to TokenWriter.
505  * @param rLabel
506  * Label of section to write.
507  * @param pContext
508  * Write context to provide contextual information (ignored)
509  *
510  * @exception Exception
511  * - IO Error
512  */
513  void DoWrite(TokenWriter& rTw, const std::string& rLabel = "", const Type* pContext=0) const;
514 
515  /**
516  * Read data from TokenReader.
517  *
518  * NOTE:
519  * 0 = false
520  * 1 = true
521  *
522  * @param rTr
523  * Reference to TokenReader.
524  * @param rLabel
525  * Section to read.
526  * @param pContext
527  * Read context to provide contextual information (ignored)
528  *
529  * @exception Exception
530  * - Token mismatch
531  * - IO Error
532  */
533  void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
534 
535  protected:
536 
537  /** Variable to store current value. */
538  bool mCBool;
539 
540 }; // Boolean
541 
542 
543 
544 } // namespace
545 
546 #endif
Class TBaseVector.
Runtime interface, operations on faudes types.
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:80
Runtime interface, faudes types.
Elementary type.
void CValue(bool val)
Set value.
bool mCBool
Variable to store current value.
~Boolean(void)
Destructor.
Elementary type.
Int mCInteger
Variable to store current value.
void CValue(Int val)
Set value.
~Integer(void)
Destructor.
Elementary type.
std::string mCString
Variable to store current value.
void CValue(std::string val)
Set value.
~String(void)
Destructor.
Vector template.
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.
long int IntegerSum(const Integer &arg1, const Integer &arg2)
TBaseVector< Integer > IntegerVector
long int Int
Type definition for integer type (let target system decide, minimum 32bit)

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