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  /** Constructor */
53  Integer(void);
54 
55  /**
56  * Constructor provided with initial value.
57  *
58  * @param val
59  * Initial value.
60  */
61  Integer(Int val);
62 
63  /** Destructor */
64  ~Integer(void){}
65 
66  /**
67  * Construct on heap.
68  * Create new Integer instance and return pointer.
69  *
70  * @return
71  * Pointer to Integer instance.
72  *
73  */
74  virtual Integer* New(void) const;
75 
76  /**
77  * Construct copy on heap.
78  * Create new Integer instance and return pointer.
79  *
80  * @return
81  * Pointer to Integer instance.
82  *
83  */
84  virtual Integer* Copy(void) const;
85 
86  /**
87  * Cast the other object to Integer.
88  * Returns NULL if the cast is not possible.
89  *
90  * @param pOther
91  * Pointer to object to cast.
92  * @return
93  * Pointer to Integer instance, or NULL
94  *
95  */
96  virtual const Integer* Cast(const Type* pOther) const;
97 
98  /**
99  * Set value.
100  *
101  * @param val
102  * Value to be set.
103  */
104  void CValue(Int val);
105 
106  /**
107  * Get value.
108  *
109  * @return
110  * Value of object. (Int)
111  */
112  Int CValue(void) const;
113 
114  /**
115  * Get reference.
116  *
117  * @return
118  * Reference to c value.
119  */
120  Int* CReference(void);
121 
122  /**
123  * Sum operator.
124  */
125  Integer& operator+ (const Int& clint){
126  CValue(mCInteger + clint);
127  return *this;
128  }
129 
130  /**
131  * Sum operator.
132  */
133  Integer& operator+ (const Integer& coint){
134  CValue(mCInteger + coint.CValue());
135  return *this;
136  }
137 
138  /**
139  * Assignment operator.
140  */
141  Integer& operator= (const Int& clint){
142  CValue(clint);
143  return *this;
144  }
145 
146  /**
147  * Assignment operator.
148  */
149  Integer& operator= (const Integer& coint){
150  CValue(coint.CValue());
151  return *this;
152  }
153 
154  /**
155  * Assignment/Sum operator
156  */
157  Integer& operator+= (const Int& clint){
158  Int litmp = CValue();
159  CValue(litmp + clint);
160  return *this;
161  }
162 
163  /**
164  * Assignment/Sum operator
165  */
166  Integer& operator+= (const Integer& coint){
167  Int litmp = CValue() + coint.CValue();
168  CValue(litmp);
169  return *this;
170  }
171 
172  /**
173  * Conversion to C++ type
174  */
175  operator Int() const { return CValue();};
176 
177 
178  /**
179  * Reimplementation of faudes::Type::DoWrite()
180  * Write data to Tokenwriter.
181  *
182  * @param rTw
183  * Reference to TokenWriter.
184  * @param rLabel
185  * Label of section to write.
186  * @param pContext
187  * Context information
188  *
189  * @exception Exception
190  * - IO Error (id 2)
191  */
192  void DoWrite(TokenWriter& rTw, const std::string& rLabel = "", const Type* pContext=0) const;
193 
194  /**
195  * Read data from TokenReader.
196  *
197  * @param rTr
198  * Reference to TokenReader.
199  * @param rLabel
200  * Section to read.
201  * @param pContext
202  * Context information
203  *
204  * @exception Exception
205  * - Token mismatch
206  * - IO Error
207  */
208  void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
209 
210  protected:
211 
212  /** Variable to store current value. */
214 
215 }; // Integer
216 
217 // convenience typedef
219 
220 // Sum of two integers, uniform rti api
221 extern FAUDES_API long int IntegerSum(const Integer& arg1, const Integer& arg2);
222 
223 // Sum of multiple integers, uniform rti api
224 extern FAUDES_API long int IntegerSum(const IntegerVector& intvect);
225 
226 /*
227 ********************************************************************
228 ********************************************************************
229 ********************************************************************
230 
231 Elementary type, representing a string value.
232 
233 ********************************************************************
234 ********************************************************************
235 ********************************************************************
236 */
237 
238 /** Elementary type */
239 class FAUDES_API String : public Type{
240 
241  public:
242  /** Constructor */
243  String(void);
244 
245  /**
246  * Constructor provided with initial value.
247  *
248  * @param val
249  * Initial value.
250  */
251  String(std::string val);
252 
253  /** Destructor */
254  ~String(void){}
255 
256  /**
257  * Construct on heap.
258  * Create new String instance and return pointer.
259  *
260  * NOTE:
261  * Calling function takes control.
262  *
263  * @return
264  * Pointer to String instance.
265  */
266  virtual String* New(void) const;
267 
268  /**
269  * Construct copy on heap.
270  * Create new String instance and return pointer.
271  *
272  * @return
273  * Pointer to Integer instance.
274  *
275  */
276  virtual String* Copy(void) const;
277 
278  /**
279  * Cast the other object to String.
280  * Returns NULL if the cast is not possible.
281  *
282  * @param pOther
283  * Pointer to object to cast.
284  * @return
285  * Pointer to String instance, or NULL
286  *
287  */
288  virtual const String* Cast(const Type* pOther) const;
289 
290  /**
291  * Set value.
292  *
293  * @param val
294  * Value to be set. (std::string)
295  */
296  void CValue(std::string val);
297 
298  /**
299  * Get value
300  *
301  * @return
302  * Value of object. (std::string)
303  */
304  std::string CValue(void) const;
305 
306  /**
307  * Get reference.
308  *
309  * @return
310  * Reference to c value.
311  */
312  std::string* CReference(void);
313 
314  /**
315  * Assignment operator.
316  */
317  String& operator= (const String& costr){
318  CValue(costr.CValue());
319  return(*this);
320  }
321 
322  /*
323  * Assignment operator, std::string source
324  */
325  String& operator= (const std::string& cstr){
326  CValue(cstr);
327  return(*this);
328  }
329 
330  /**
331  * Conversion to std::string
332  */
333  operator std::string() const { return CValue();};
334 
335 
336  /**
337  * Write data to Tokenwriter.
338  *
339  * @param rTw
340  * Reference to TokenWriter.
341  * @param rLabel
342  * Label of section to write.
343  * @param pContext
344  * Write context to provide contextual information (ignored)
345  *
346  * @exception Exception
347  * - IO Error
348  */
349  void DoWrite(TokenWriter& rTw, const std::string& rLabel = "", const Type* pContext=0) const;
350 
351 
352  /**
353  * Read data from TokenReader.
354  *
355  * @param rTr
356  * Reference to TokenReader.
357  * @param rLabel
358  * Section to read.
359  * @param pContext
360  * Read context to provide contextual information (ignored)
361  *
362  * @exception Exception
363  * - Token mismatch
364  * - IO Error
365  */
366  void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
367 
368  protected:
369  /** Variable to store current value. */
370  std::string mCString;
371 
372 }; // String
373 
374 
375 
376 
377 /*
378 ********************************************************************
379 ********************************************************************
380 ********************************************************************
381 
382 Elementary type, representing a boolean value.
383 
384 ********************************************************************
385 ********************************************************************
386 ********************************************************************
387 */
388 
389 /** Elementary type */
390 class FAUDES_API Boolean : public Type{
391 
392  public:
393  /** Constructor */
394  Boolean(void);
395 
396  /**
397  * Constructor provided with initial value.
398  *
399  * @param val
400  * Initial value. (bool)
401  */
402  Boolean(bool val);
403 
404  /** Destructor */
405  ~Boolean(void){}
406 
407  /**
408  * Construct on heap.
409  * Create new Boolean instance and return pointer.
410  *
411  * NOTE:
412  * Calling function takes control.
413  *
414  * @return
415  * Pointer to Boolean instance.
416  */
417  virtual Boolean* New(void) const;
418 
419  /**
420  * Construct copy on heap.
421  * Create new Boolean instance and return pointer.
422  *
423  * @return
424  * Pointer to Boolean instance.
425  *
426  */
427  virtual Boolean* Copy(void) const;
428 
429  /**
430  * Cast the other object to Boolean.
431  * Returns NULL if the cast is not possible.
432  *
433  * @param pOther
434  * Pointer to object to cast.
435  * @return
436  * Pointer to Boolean instance, or NULL
437  *
438  */
439  virtual const Boolean* Cast(const Type* pOther) const;
440 
441  /**
442  * Set value.
443  *
444  * @param val
445  * Value to be set.
446  */
447  void CValue(bool val);
448 
449  /**
450  * Get value.
451  *
452  * @return
453  * Value of object. (bool)
454  */
455  bool CValue(void) const;
456 
457  /**
458  * Get reference.
459  *
460  * @return
461  * Reference to c value.
462  */
463  bool* CReference(void);
464 
465  /**
466  * Assignment operator.
467  */
468  Boolean& operator= (const bool& bbool){
469  CValue(bbool);
470  return(*this);
471  }
472 
473  /**
474  * Assignment operator.
475  */
476  Boolean& operator= (const Boolean& cobool){
477  CValue(cobool.CValue());
478  return(*this);
479  }
480 
481 
482  /**
483  * Conversion to C++ type bool
484  */
485  operator bool() const { return CValue();};
486 
487  /**
488  * Write data to Tokenwriter.
489  *
490  * NOTE:
491  * 0 = false
492  * 1 = true
493  *
494  * @param rTw
495  * Reference to TokenWriter.
496  * @param rLabel
497  * Label of section to write.
498  * @param pContext
499  * Write context to provide contextual information (ignored)
500  *
501  * @exception Exception
502  * - IO Error
503  */
504  void DoWrite(TokenWriter& rTw, const std::string& rLabel = "", const Type* pContext=0) const;
505 
506  /**
507  * Read data from TokenReader.
508  *
509  * NOTE:
510  * 0 = false
511  * 1 = true
512  *
513  * @param rTr
514  * Reference to TokenReader.
515  * @param rLabel
516  * Section to read.
517  * @param pContext
518  * Read context to provide contextual information (ignored)
519  *
520  * @exception Exception
521  * - Token mismatch
522  * - IO Error
523  */
524  void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
525 
526  protected:
527 
528  /** Variable to store current value. */
529  bool mCBool;
530 
531 }; // Boolean
532 
533 
534 
535 } // namespace
536 
537 #endif
Class TBaseVector.
Runtime interface, operations on faudes types.
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:81
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.32b --- 2024.03.01 --- c++ api documentaion by doxygen