cfl_types.h
Go to the documentation of this file.
1 /** @file cfl_types.h Runtime interface, faudes types */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5 Copyright (C) 2009 Ruediger Berndt
6 Copyright (C) 2010, 2024 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_RTITYPES_H
24 #define FAUDES_RTITYPES_H
25 
26 #include <list>
27 #include <string>
28 #include <vector>
29 #include <map>
30 #include <utility>
31 #include <string>
32 #include <iostream>
33 #include <typeinfo>
34 #include <algorithm>
35 
36 #include "cfl_definitions.h"
37 #include "cfl_token.h"
38 #include "cfl_tokenreader.h"
39 #include "cfl_tokenwriter.h"
40 #include "cfl_exception.h"
41 
42 
43 
44 namespace faudes {
45 
46 
47 /************************************************
48  ************************************************
49  ************************************************/
50 
51 
52 /** @defgroup RunTimeInterface Run-Time Interface
53 
54 The libFAUDES run-time interface (RTI) facilitates the development
55 of applications that are transparent to libFAUDES extensions, e.g.,
56 the libFAUDES version of the Lua interpreter luafaudes and the
57 graphical user interface DESTool.
58 
59 The run-time interface provides a TypeRegistry for the application
60 to instantiate objects by specifying their type as a std::string.
61 The TypeRegistry is accompanied by the FunctionRegistry for
62 the application to execute functions by their name. Thus, a libFAUDES
63 application can query both registries and provide the
64 supported types and functions to the user.
65 The <a href="../reference/index.html">libFAUDES user-reference</a>
66 is set up by the build system to represent the contents of both
67 registries.
68 
69 The run-time interface is implemented
70 by the following components:
71 - base class faudes::Type for RTI enabled classes (faudes-types)
72 - documentation class faudes::TypeDefinition to accompany faudes-types;
73 - container class faudes::TypeRegistry to hold faudes::TypeDefintiion objects;
74 - base class faudes::Function for RTI enabled function wrappers (faudes-functions);
75 - documentation class faudes::FunctionDefinition to accompany faudes-functions;
76 - container class faudes::FunctionRegistry to hold FunctionDefintiion objects.
77 
78 @section RunTimeInterfaceSec2 Faudes-Types
79 
80 Classes that participate in the run-time interface are referred to
81 as faudes-types, instances are so called faudes-objects. Any faudes-type must
82 be derived from the base class faudes::Type. A faudes-type inherits
83 the convenience interface for token IO from Type, and, most relevent for the run-time
84 interface, the factory function New(): each faudes-types must reimplement New()
85 to allocate a new object of their respective type on heap. For a fully functional
86 faudes-type, also an appropriate assignment operator and a copy constructor
87 are required.
88 
89 
90 @section RunTimeInterfaceSec3 Faudes-Type Definitions
91 
92 A faudes-type is accompanied by an instance of faudes::TypeDefinition. It holds
93 a name (std::string) to identify the faudes-type,
94 documentation (short text and html reference),
95 and one faudes-object of the respective faudes-type.
96 The latter is referred to as the prototype object and its New() method is used to construct
97 new faudes-objects of the respective faudes-type. Thus, given a TypeDefinition,
98 one can instantiate a corresponding faudes-object. To setup a
99 TypeDefinition, you are meant to provide the faudes-type name, the protototype
100 and a file from which to read the documentation.
101 
102 
103 @section RunTimeInterfaceSec4 Faudes-Functions and Faudes-Function Definitions
104 
105 Functions that participate in the run-time interface are organized similar
106 to faudes-types. There is a base class faudes::Function from which to derive
107 particular faudes-functions. The base class provides an interface to set
108 function parameter values and to actually execute the function on the parameters.
109 To derive a class from Function, you must reimplement the methods New(), DoTypeCheck(),
110 and DoExecute(). The DoTypeCheck method is supposed to use a dynamic cast
111 to initialize typed references to the function parameters. The DoExecute method
112 then executes the function, typically by invoking a function via its
113 C++ API. Each Function class is accompanied by a faudes::FunctionDefinition instance
114 which holds a prototype, basic documentation and a list of valid signatures. Each signature
115 represents a valid parameter type configurations in terms of faudes-types.
116 
117 @section RunTimeInterfaceSec5 Type- and Function-Registry
118 
119 The faudes::TypeRegistry and the faudes::FunctionRegistry are containers for TypeDefinition
120 and FunctionDefinition instances, respectively. Applications access the registries via
121 faudes-type names and faudes-function names, see e.g. the global functions NewObject() and
122 NewFunction(). There is also in interface to iterate through the regsitries and
123 to test for the existence of an entry. However, while both registries inherit the std token-io
124 interface, neither registry can be fully configured by reading from file. This is because
125 each entry requires not only data (documentation, signature, etc) but also a prototype
126 instance. The std C++ run-time type information (RTTI) does not provide a mechanism
127 to instantiate an object of a class that is specified at runtime. Thus, each protototype
128 must be defined at compiletime. The global function LoadRegistry() is automatically
129 set-up by the build system to gather all relevant prototypes, insert them in the
130 registries and to subsequently read further documentation from a configuration
131 file.
132 
133 @section RunTimeInterfaceSec6 RTI and the Build System
134 
135 At stage <tt>make configure</tt>, the build system sets up the function LoadRegistry()
136 by
137 - setting the macro FAUDES_PLUGINS_RTILOAD to a list of function calls in order to invoke
138  one load function per plugin;
139 - running the tool <tt>rti2code</tt> to generate c code to register faudes-types and-functions
140  found in the configuration file ("libfaudes.rti").
141 
142 Code generation should work for all types and functions with documentation entry "CType()" specified.
143 Since there is only one CType() entry, all signatures of a function must be implemented by a single
144 c-function. The generated code is placed at "./include/rtiautoload.*". The build system also provides
145 support to merge the configuration "libfaudes.rti" file from various sources, incl. plugins.
146 
147 To have your C++ class participate in the libFAUDES run-time interface:
148 
149 -# derive your class from faudes::Type;
150 -# make sure your class has a public default constructor and a public copy constructor;
151 -# use the provided macros to reimplement the virtual functions New(), Copy(), Cast(),
152  Assign(), Equal(), and the acording operators =, == and !=;
153 -# reimplement the virtual functions DoAssign(), DoEqual(), DoRead(), DoWrite() and Clear();
154 -# optionally, reimplement the alternative output formats DoDWrite(), DoSWrite(), DoXWrite()
155 -# provide an .rti file for the formal TypeDefinition;
156 -# supplement your .rti file by an HTML formated documentation text;
157 
158 You will need to inspect and edit the main Makefile or your plugin's Makefile
159 to advertise your additional sources. A <tt>make configure</tt> will then
160 assemble all the bits and pieces.
161 
162 To have your C++ function participate in the libFAUDES run-time interface:
163 
164 -# make sure all your parameters are faudes-types (exceptions being
165  the elementary types bool, string and integer, which are converted automatically);
166 -# provide an .rti file for the formal FunctionDefinition, advertise this file;
167  either in the main Makefile or in the Makefile of your plugin;
168 -# supplement yout .rti file by an html formated documentation text;
169 
170 
171 */
172 
173 // forward
174 class TypeDefinition;
175 
176 /**
177  * Base class of all libFAUDES objects that participate in
178  * the run-time interface. Eg, generator, alphabet, attributes etc.
179  * The class is designed to impose as little overhead as possible, and
180  * hence, does not hold any data. It does, however, provide a
181  * uniform interface for assignment, factory functions, and token IO.
182  *
183  * We think of a faudes-typed object to be configured by defining
184  * data and, in due course, manipulated via its public interface
185  * by faudes-functions. Any faudes-type must provide a Clear() method that
186  * resets the object configuration to a unique default value.
187  * It is the configuration data that can be read from and written to token
188  * streams, and it is the configuration data that is used for assigments.
189  * Any additional data a faudes-typed object may host, is ignored by the
190  * interface inherited from the the base faudes::Type. Examples for such
191  * additional data is the unique id of a Generator, and the deferred copy
192  * pointers in faudes sets derived from faudes::TBaseSet.
193  *
194  * The faudes::Type assignment semantics are not meant to create exact copies
195  * of a given source object. Thogether with the uniquely defined default value,
196  * we can have assignments by both up- and downcasts. A faudes::Generator can be
197  * assigned from the derived faudes::System (a Generator with controllability
198  * attributes) by dropping the extra features. Vice versa, when a System is assigned
199  * from a plain Generator, any extra features take their respective default values.
200  * This relaxed interpretation of assignments is implemented by the method
201  * Assign(). The token format for file IO is organised in a similar fashion: any generator
202  * derivate can be configured from the token stream produced by any other generator class.
203  * In contrast, faudes-typed objects also implement an assignment operator
204  * that uses the standard C++ conventions.
205  *
206  * The following methods are used to implement the faudes::Type interface:
207  *
208  * - DoRead() to read the defining data from a token stream
209  * - DoWrite() to write the defining data to a token stream
210  * - DoXWrite() to write the defining data to a token stream in an alternative XML format
211  * - DoSWrite() and DoDWrite for alternative output formats (statistical summary and debugging)
212  *
213  * - Name() to get/set the name of an optional (and purely cosmetic) object name
214  * - Clear() to reset all configuration data,
215  * - New() to construct an object of identical type on heap (factory method),
216  * - Copy() to construct an object of identical type and configuration on heap (factory method),
217  * - Cast() to dynamically cast another object to this type (type check method)
218  * - Assign() to do an assignment from any castable Type derivate
219  * - DoAssign(), or the operator "=", to assign from an object with identical type.
220  * - Equal() to test relaxed equality with any castable Type derivate
221  * - DoEqual(), or the operators "==" and "!=", to test exact equality of configuration data
222  *
223  * In most cases, only DoRead(), DoWrite(), DoAssign(), DoEqual() and Clear() need to be implemented
224  * manualy. The other methods can be declared and implemented by macros
225  * FAUDES_TYPE_DELARATION and FAUDES_TYPE_IMPLEMENTATION, respectively. The various
226  * attribute classes illustrate their ussage; see e.g. AttributeFlags.
227  *
228  *
229  * Note on token IO: In libFAUDES 2.16e, implementation of a new file format is prepared
230  * by the virtual function interface DoXWrite(). The intention is to better support advanced
231  * XML editors, in particular for configuration files. When implementing DoXWrite() for a
232  * derived class, make sure that DoRead() will gracefully accept tokens written by both DoWrite()
233  * and DoXWrite(), as a basis for a fileformat conversion tool. Future versions of libFAUDES will drop
234  * compatibility with the old token format, except for model data (generators, alphabets).
235  *
236  * @ingroup RunTimeInterface
237  */
238 
240 
241  public:
242 
243  /** Constructor */
244  Type(void);
245 
246  /** Copy constructor */
247  Type(const Type& rType);
248 
249  /** Destructor */
250  virtual ~Type(void);
251 
252  /**
253  * Construct on heap.
254  * Technically not a constructor, this function creates an object with the
255  * same type Type. New() is defined as a virtual function and derived
256  * classes are meant to re-implement with the appropiate constructor.
257  * This can be done via the provided macros FAUDES_TYPE_DECLARATION and
258  * FAUDES_TYPE_IMPLEMENTATION.
259  * As with new, it is the callers reponsabilty to delete the object when no longer needed.
260  *
261  * @return
262  * Pointer to new Type object
263  */
264  virtual Type* New(void) const;
265 
266  /**
267  * Construct on heap.
268  * Technically not a constructor, this function creates an object with the
269  * same type Type and the same configuration. Copy() is defined as a virtual function and derived
270  * classes are meant to re-implement with the appropiate copy constructor.
271  * This can be done via the provided macros FAUDES_TYPE_DECLARATION and
272  * FAUDES_TYPE_IMPLEMENTATION.
273  * As with new, it is the callers reponsabilty to delete the object when no longer needed.
274  *
275  * @return
276  * Pointer to new Type object
277  */
278  virtual Type* Copy(void) const;
279 
280  /**
281  * Cast other object to this type.
282  * Enables the run-time interface to test whether pObject is derived
283  * from this object. This feature is used e.g. in the faudes container
284  * classes to test attributes. Derived classes must reimplement this
285  * function using the appropriate dynamic cast.
286  *
287  * Re-implementation can be done via the convenience macros
288  * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
289  *
290  * @return
291  * Typed pointer object
292  */
293  virtual const Type* Cast(const Type* pOther) const;
294 
295  /**
296  * Clear configuration data. Derived classes should re-implement this
297  * method to ensure some consistent configuration data.
298  */
299  virtual void Clear(void);
300 
301  /**
302  * Assign configuration data from other object.
303  * Derived classes should reimplement this method to first try to cast
304  * the source to the respective class. If successful, the protected
305  * function DoAssign is invoked to perform the actual assignment. If the cast fails,
306  * the Assign method of the parent class is called. Thus, faudes
307  * objects are up- and downcatsed for assignment, maintaining as much of
308  * the source data as digestable by the destination object. On the downside,
309  * there is no sensible typechecking at compile-time.
310  *
311  * Re-implementation can be done via the convenience macros
312  * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
313  *
314  * @param rSrc
315  * Source to copy from
316  * @return Reference to this object.
317  */
318  virtual Type& Assign(const Type& rSrc);
319 
320 
321  /**
322  * Assign configurationdata from other object.
323  * Derived classes should implement the operator form for the assignment
324  * for each source type which allows for a non-trivial assignment. This includes
325  * the particular case were the source and destination types match exactly. In the
326  * latter case the DoAssign method should be invoked. In contrast to
327  * the Assign function, the operator form must not be reimplemented for
328  * missmatched source types: the operator form only accepts sensible source types.
329  * This allows for compiletime typeckecking. However, the downside is that
330  * when the type is not known at compiletime, configuration is not properly
331  * assigned.
332  *
333  * Re-implementation can be done via the convenience macros
334  * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
335  *
336  * @param rSrc
337  * Source to copy from
338  * @return Reference to this object.
339  */
340  Type& operator=(const Type& rSrc);
341 
342  /**
343  * Test equality of configuration data.
344  * Derived classes should reimplement this method to return true
345  * if both actual types and configuration data match.
346  * The object name or id (if any) is not considered in the test.
347  *
348  * This method calls the virtual method DoEqual(). Re-implementation can
349  * be done via the convenience macros
350  * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
351  *
352  * @param rOther
353  * Other object to compare with.
354  * @return
355  * True on match.
356  */
357  virtual bool Equal(const Type& rOther) const;
358 
359  /**
360  * Test equality of configuration data.
361  * The operator form of the equality test is only defined for matching
362  * types, no cast will be performed. Thus, the test will be optimistic
363  * if the type is not known at compiletime.
364  * The object name or id is not considered in the test.
365  *
366  * This methoc calls the virtual method DoEqual(). Re-implementation can
367  * be done via the convenience macros
368  * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
369  *
370  * @param rOther
371  * Other object to compare with.
372  * @return
373  * True on match.
374  */
375  bool operator==(const Type& rOther) const;
376 
377 
378  /**
379  * Test equality of configuration data.
380  * See operator==(const Type&).
381  *
382  * This method calls the virtual method DoEqual(). Re-implementation can
383  * be done via the convenience macros
384  * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
385  *
386  * @param rOther
387  * Other objevt to compare with.
388  * @return
389  * True on mismatch.
390  */
391  bool operator!=(const Type& rOther) const;
392 
393 
394  /**
395  * Set the objects's name.
396  *
397  * The base class Type does not implement an object name,
398  * derivatives usually do so, except for attributes.
399  *
400  * @param rName
401  * Name
402  */
403  virtual void Name(const std::string& rName);
404 
405  /**
406  * Get objects's name.
407  *
408  * The base class Type does not implement an object name,
409  * derivatives usually do so, except for attributes.
410  * @return
411  * Name of generator
412  */
413  virtual const std::string& Name(void) const;
414 
415  /**
416  * Get objects's type name.
417  *
418  * Retrieve the faudes-type name from the type registry.
419  * This method silently returns the empty string if the type is
420  * not (yet) registered.
421  *
422  * @return
423  * Faudes-type name or empty string.
424  */
425  virtual const std::string& TypeName(void) const;
426 
427  /**
428  * Write configuration data to console.
429  * Note: this write function uses the virtual function DoWrite(), to be
430  * reimplemented by derived classes.
431  *
432  * @param pContext
433  * Write context to provide contextual information
434  *
435  */
436  void Write(const Type* pContext=0) const;
437 
438  /**
439  * Write configuration data to a file.
440  * Note: this write function uses the virtual function DoWrite(), to be
441  * reimplemented by derived classes.
442  *
443  * @param pFileName
444  * Name of file
445  * @param rLabel
446  * Label of section to write
447  * @param pContext
448  * Write context to provide contextual information
449  * @param openmode
450  * ios::openmode
451  *
452  * @exception Exception
453  * - IO errors (id 2)
454  */
455  void Write(const std::string& pFileName, const std::string& rLabel="",
456  const Type* pContext=0, std::ios::openmode openmode = std::ios::out|std::ios::trunc) const;
457 
458  /**
459  * Write configuration data to a file.
460  * Note: this write function uses the virtual function DoWrite(), to be
461  * reimplemented by derived classes.
462  *
463  * @param pFileName
464  * Name of file
465  * @param openmode
466  * ios::openmode
467  *
468  * @exception Exception
469  * - IO errors (id 2)
470  */
471  void Write(const std::string& pFileName, std::ios::openmode openmode) const;
472 
473  /**
474  * Write configuration data to TokenWriter.
475  * Note: this write function uses the virtual function DoWrite(), to be
476  * reimplemented by derived classes.
477  *
478  * @param rTw
479  * Reference to TokenWriter
480  * @param rLabel
481  * Label of section to write
482  * @param pContext
483  * Write context to provide contextual information
484  *
485  * @exception Exception
486  * - IO errors (id 2)
487  */
488  void Write(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
489 
490  /**
491  * Write configuration data to an XML file.
492  * Note: this method uses the faudes type to set a DOCTYPE markup; for derived classes
493  * which do not report their faudes type, you should reimplement this
494  * function. Actual token io is done via DoXWrite().
495  *
496  * @param pFileName
497  * Name of file
498  * @param rLabel
499  * Label of section to write
500  * @param pContext
501  * Write context to provide contextual information
502  *
503  * @exception Exception
504  * - IO errors (id 2)
505  */
506  virtual void XWrite(const std::string& pFileName, const std::string& rLabel="",
507  const Type* pContext=0) const;
508 
509  /**
510  * Write configuration data in XML format to concole
511  * Note: this write function uses the virtual function DoXWrite(), to be
512  * reimplemented by derived classes. No DOCTYPE markup will be written.
513  *
514  * @param pContext
515  * Write context to provide contextual information
516  *
517  */
518  void XWrite(const Type* pContext=0) const;
519 
520  /**
521  * Write configuration data in XML format to TokenWriter.
522  * Note: this write function uses the virtual function DoXWrite(), to be
523  * reimplemented by derived classes.
524  *
525  * @param rTw
526  * Reference to TokenWriter
527  * @param rLabel
528  * Label of section to write
529  * @param pContext
530  * Write context to provide contextual information
531  *
532  * @exception Exception
533  * - IO errors (id 2)
534  */
535  void XWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
536 
537  /**
538  * Write configuration data to a string.
539  * Note: this write function uses the virtual function DoWrite(), to be
540  * reimplemented by derived classes.
541  *
542  * @param rLabel
543  * Label of section to write
544  * @param pContext
545  * Write context to provide contextual information
546  * @return
547  * output string
548  * @exception Exception
549  * - IO errors (id 2)
550  */
551  std::string ToString(const std::string& rLabel="", const Type* pContext=0) const;
552 
553  /**
554  * Write configuration data to a formated string.
555  * In contrast to ToString, ToText does not suppress comments and
556  * End-Of-Line marks.
557  * Note: this write function uses the virtual function DoWrite(), to be
558  * reimplemented by derived classes.
559  *
560  * @param rLabel
561  * Label of section to write
562  * @param pContext
563  * Write context to provide contextual information
564  * @return
565  * output string
566  * @exception Exception
567  * - IO errors (id 2)
568  */
569  std::string ToText(const std::string& rLabel="", const Type* pContext=0) const;
570 
571  /**
572  * Write configuration data to console, debugging format.
573  * Note: this write function uses the virtual function DoDWrite(), to be
574  * reimplemented by derived classes.
575  *
576  * @param pContext
577  * Write context to provide contextual information
578  *
579  */
580  void DWrite(const Type* pContext=0) const;
581 
582  /**
583  * Write configuration data to a file, debugging format.
584  * Note: this write function uses the virtual function DoDWrite(), to be
585  * reimplemented by derived classes.
586  *
587  * @param pFileName
588  * Name of file
589  * @param rLabel
590  * Label of section to write
591  * @param pContext
592  * Write context to provide contextual information
593  * @param openmode
594  * ios::openmode
595  *
596  * @exception Exception
597  * - IO errors (id 2)
598  */
599  void DWrite(const std::string& pFileName, const std::string& rLabel="",
600  const Type* pContext=0, std::ios::openmode openmode = std::ios::out|std::ios::trunc) const;
601 
602  /**
603  * Write configuration data in debug format to TokenWriter.
604  * Note: this write function uses the virtual function DoWrite(), to be
605  * reimplemented by derived classes.
606  *
607  * @param rTw
608  * Reference to TokenWriter
609  * @param rLabel
610  * Label of section to write
611  * @param pContext
612  * Write context to provide contextual information
613  *
614  * @exception Exception
615  * - IO errors (id 2)
616  */
617  void DWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
618 
619  /**
620  * Write statistics comment to TokenWriter.
621  * Note: this write function use the virtual function DoSWrite(), to be
622  * reimplemented by derived classes.
623  *
624  * @param rTw
625  * Reference to TokenWriter
626  *
627  * @exception Exception
628  * - IO errors (id 2)
629  */
630  void SWrite(TokenWriter& rTw) const;
631 
632  /**
633  * Write statistics comment to console.
634  * Note: this write function uses the virtual function DoSWrite(), to be
635  * reimplemented by derived classes.
636  *
637  */
638  void SWrite(void) const;
639 
640  /**
641  * Write statistics to a string.
642  * Note: this write function uses the virtual function DoSWrite(), to be
643  * reimplemented by derived classes.
644  *
645  * @return
646  * output string
647  * @exception Exception
648  * - IO errors (id 2)
649  */
650  std::string ToSText(void) const;
651 
652  /**
653  * Read configuration data from file with label specified.
654  * Note: all read functions use the virtual function DoRead(), to be
655  * reimplemented for by derived classes.
656  *
657  * @param rFileName
658  * Name of file
659  * @param rLabel
660  * Section to read from
661  * @param pContext
662  * Read context to provide contextual information
663  *
664  * @exception Exception
665  * - IO errors (id 1)
666  * - token mismatch from DoRead()
667  */
668  void Read(const std::string& rFileName, const std::string& rLabel = "", const Type* pContext=0);
669 
670  /**
671  * Read configuration data from a string.
672  * Note: this read function uses the virtual function DoRead(), to be
673  * reimplemented by derived classes.
674  *
675  * @param rString
676  * String to read from
677  * @param rLabel
678  * Section to read
679  * @param pContext
680  * Read context to provide contextual information
681  * @exception Exception
682  * - IO errors (id 1)
683  * - token mismatch from DoRead()
684  */
685  void FromString(const std::string& rString, const std::string& rLabel="", const Type* pContext=0);
686 
687  /**
688  * Read configuration data from TokenReader with label sepcified.
689  * Note: all read functions use the virtual function DoRead(), to be
690  * reimplemented for by derived classes.
691  *
692  * @param rTr
693  * Reference to tokenreader
694  * @param rLabel
695  * Section to read
696  * @param pContext
697  * Read context to provide contextual information
698  *
699  * @exception Exception
700  * - IO errors (id 1)
701  * - token mismatch from DoRead()
702  */
703  void Read(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
704 
705 
706  protected:
707 
708  /**
709  * Assign configuration data from other object.
710  *
711  * Reimplement this function to copy all configuration data from
712  * another faudes object. Typically, you will first call the base class'
713  * DoAssign, which includes a Clear(). Then, you will set up any additional members.
714  *
715  * @param rSrc
716  * Source to copy from
717  */
718  void DoAssign(const Type& rSrc);
719 
720  /**
721  * Test equality of configuration data.
722  * Derived classes should reimplement this method to compare all relevant
723  * configuration, except the name.
724  *
725  * @param rOther
726  * Other object to compare with.
727  * @return
728  * True on match.
729  */
730  bool DoEqual(const Type& rOther) const;
731 
732 
733  /**
734  * Read configuration data of this object from TokenReader.
735  *
736  * Reimplement this method in derived classes to provide the std token io
737  * interface defined in the public section of Type.
738  *
739  * @param rTr
740  * TokenReader to read from
741  * @param rLabel
742  * Section to read
743  * @param pContext
744  * Read context to provide contextual information
745  *
746  * @exception Exception
747  * - IO error (id 1)
748  */
749  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
750 
751  /**
752  * Write configuration data of this object to TokenWriter.
753  *
754  * Reimplement this method in derived classes to provide the std token io
755  * interface defined in the public section of Type.
756  *
757  * @param rTw
758  * Reference to TokenWriter
759  * @param rLabel
760  * Label of section to write
761  * @param pContext
762  * Write context to provide contextual information
763  *
764  * @exception Exception
765  * - IO errors (id 2)
766  */
767  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
768 
769  /**
770  * Write configuration data of this object to TokenWriter in XML format.
771  *
772  * Reimplement this method in derived classes to provide the XML
773  * token io interface defined in the public section of Type. The default implementation
774  * invokes the std token output via
775  * DoWrite(TokenWriter&, const std::string&,const Type* )
776  *
777  * @param rTw
778  * Reference to TokenWriter
779  * @param rLabel
780  * Label of section to write
781  * @param pContext
782  * Write context to provide contextual information
783  *
784  * @exception Exception
785  * - IO errors (id 2)
786  */
787  virtual void DoXWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
788 
789  /**
790  * Write configuration data in debugging format to TokenWriter.
791  *
792  * Reimplement this method in derived classes to provide the std token io
793  * interface defined in the public section of Type.
794  *
795  * @param rTw
796  * Reference to TokenWriter
797  * @param rLabel
798  * Label of section to write
799  * @param pContext
800  * Write context to provide contextual information
801  *
802  * @exception Exception
803  * - IO errors (id 2)
804  */
805  virtual void DoDWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
806 
807  /**
808  * Write statistical data as a comment to TokenWriter.
809  *
810  * Reimplement this method in derived classes to provide the std token io
811  * interface defined in the public section of Type.
812  *
813  * @param rTw
814  * Reference to TokenWriter
815  *
816  * @exception Exception
817  * - IO errors (id 2)
818  */
819  virtual void DoSWrite(TokenWriter& rTw) const;
820 
821  /**
822  * Get objects's type definition.
823  *
824  * Returns the type definition corresponding to this object, or
825  * NULL if the object is not of a registered type.
826  *
827  * Technical note: for minimal memory requirement, the type definition
828  * is not cached but retrieved on every invokation of this method.
829  * Derived classes may reimplement this method for performance
830  * reasons. Options include a look-up cache or a static member
831  * for the actual type definition. The latter variant will make the
832  * type independant from the type registry.
833  *
834  * @return
835  * Type definition reference.
836  */
837  virtual const TypeDefinition* TypeDefinitionp(void) const;
838 
839 
840  /*
841  * Convenience function to set up std begin token
842  * for XML mode token I/O.
843  *
844  *
845  * @param rLabel
846  * User specified label
847  * @param rFallbackLabel
848  * Class defined fallback label
849  * @return
850  * Configured begin token
851  */
852  virtual Token XBeginTag(const std::string& rLabel="", const std::string& rFallbackLabel="") const;
853 
854 
855 private:
856 
857  // static string constant
858  static std::string msStringVoid;
859  static std::string msStringEmpty;
860 
861 };
862 
863 
864 /**
865 YS in 2023:
866 operators =/==/!= use virtual DoAssign/DoEqual; so the operators themself do
867 not need to be virtual
868 */
869 
870 
871 /** faudes type declaration macro */
872 #define FAUDES_TYPE_DECLARATION(ftype,ctype,cbase) \
873  public: virtual ctype* New(void) const; \
874  public: virtual ctype* Copy(void) const; \
875  public: virtual const Type* Cast(const Type* pOther) const; \
876  public: virtual ctype& Assign(const Type& rSrc); \
877  public: virtual bool Equal(const Type& rOther) const; \
878  public: ctype& operator=(const ctype& rSrc); \
879  public: bool operator==(const ctype& rOther) const; \
880  public: bool operator!=(const ctype& rOther) const;
881 
882 /** faudes type declaration macro, template version */
883 #define FAUDES_TYPE_TDECLARATION(ftype,ctype,cbase) \
884  public: virtual ctype* New(void) const; \
885  public: virtual ctype* Copy(void) const; \
886  public: virtual const Type* Cast(const Type* pOther) const; \
887  public: virtual ctype& Assign(const Type& rSrc); \
888  public: virtual bool Equal(const Type& rOther) const; \
889  public: ctype& operator=(const ctype& rSrc); \
890  public: bool operator==(const ctype& rOther) const; \
891  public: bool operator!=(const ctype& rOther) const;
892 
893 /** faudes type implementation macros */
894 #define FAUDES_TYPE_IMPLEMENTATION_NEW(ftype,ctype,cbase) \
895  ctype* ctype::New(void) const { return new ctype(); }
896 #define FAUDES_TYPE_IMPLEMENTATION_COPY(ftype,ctype,cbase) \
897  ctype* ctype::Copy(void) const { return new ctype(*this); }
898 #define FAUDES_TYPE_IMPLEMENTATION_CAST(ftype,ctype,cbase) \
899  const Type* ctype::Cast(const Type* pOther) const { \
900  return dynamic_cast< const ctype * >(pOther); }
901 #define FAUDES_TYPE_IMPLEMENTATION_ASSIGN(ftype,ctype,cbase) \
902  ctype& ctype::Assign(const Type& rSrc) { \
903  if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
904  this->Clear(); DoAssign(*csattr);} \
905  else { \
906  cbase::Assign(rSrc);}; \
907  return *this;} \
908  ctype& ctype::operator=(const ctype& rSrc) { this->Clear(); DoAssign(rSrc); return *this; }
909 #define FAUDES_TYPE_IMPLEMENTATION_EQUAL(ftype,ctype,cbase) \
910  bool ctype::Equal(const Type& rOther) const { \
911  if(&rOther==this) return true; \
912  if(typeid(rOther) != typeid(*this)) return false; \
913  const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
914  if(!csattr) return false; \
915  if(!DoEqual(*csattr)) return false; \
916  return true;} \
917  bool ctype::operator==(const ctype& rOther) const { return DoEqual(rOther); } \
918  bool ctype::operator!=(const ctype& rOther) const { return !DoEqual(rOther); }
919 
920 /** faudes type implementation macros, template version */
921 #define FAUDES_TYPE_TIMPLEMENTATION_NEW(ftype,ctype,cbase,ctemp) \
922  ctemp ctype* ctype::New(void) const { \
923  return new ctype(); }
924 #define FAUDES_TYPE_TIMPLEMENTATION_COPY(ftype,ctype,cbase,ctemp) \
925  ctemp ctype* ctype::Copy(void) const { \
926  return new ctype(*this); }
927 #define FAUDES_TYPE_TIMPLEMENTATION_CAST(ftype,ctype,cbase,ctemp) \
928  ctemp const Type* ctype::Cast(const Type* pOther) const { \
929  return dynamic_cast< const ctype * >(pOther); }
930 #define FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(ftype,ctype,cbase,ctemp) \
931  ctemp ctype& ctype::Assign(const Type& rSrc) { \
932  if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
933  this->Clear(); DoAssign(*csattr);} \
934  else { \
935  cbase::Assign(rSrc);}; \
936  return *this;} \
937  ctemp ctype& ctype::operator=(const ctype& rSrc) { this->Clear(); DoAssign(rSrc); return *this; }
938 #define FAUDES_TYPE_TIMPLEMENTATION_EQUAL(ftype,ctype,cbase,ctemp) \
939  ctemp bool ctype::Equal(const Type& rOther) const { \
940  if(&rOther==this) return true; \
941  if(typeid(rOther) != typeid(*this)) return false; \
942  const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
943  if(!csattr) return false; \
944  if(!DoEqual(*csattr)) return false; \
945  return true;} \
946  ctemp bool ctype::operator==(const ctype& rOther) const { return DoEqual(rOther); } \
947  ctemp bool ctype::operator!=(const ctype& rOther) const { return !DoEqual(rOther); }
948 
949 
950 /** faudes type implementation macros, overall */
951 #define FAUDES_TYPE_IMPLEMENTATION(ftype,ctype,cbase) \
952  ctype* ctype::New(void) const { \
953  return new ctype(); } \
954  ctype* ctype::Copy(void) const { \
955  return new ctype(*this); } \
956  const Type* ctype::Cast(const Type* pOther) const { \
957  return dynamic_cast< const ctype * >(pOther); } \
958  ctype& ctype::Assign(const Type& rSrc) { \
959  if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
960  this->Clear(); this->DoAssign(*csattr);} \
961  else { \
962  cbase::Assign(rSrc);}; \
963  return *this;} \
964  ctype& ctype::operator=(const ctype& rSrc) { this->Clear(); this->DoAssign(rSrc); return *this; } \
965  bool ctype::Equal(const Type& rOther) const { \
966  if(&rOther==this) return true; \
967  if(typeid(rOther) != typeid(*this)) return false; \
968  const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
969  if(!csattr) return false; \
970  if(!this->DoEqual(*csattr)) return false; \
971  return true;} \
972  bool ctype::operator==(const ctype& rOther) const { return this->DoEqual(rOther); } \
973  bool ctype::operator!=(const ctype& rOther) const { return !this->DoEqual(rOther); }
974 
975 
976 /** faudes type implementation macros, overall */
977 #define FAUDES_TYPE_TIMPLEMENTATION(ftype,ctype,cbase,ctemp) \
978  ctemp ctype* ctype::New(void) const { \
979  return new ctype(); } \
980  ctemp ctype* ctype::Copy(void) const { \
981  return new ctype(*this); } \
982  ctemp const Type* ctype::Cast(const Type* pOther) const { \
983  return dynamic_cast< const ctype * >(pOther); } \
984  ctemp ctype& ctype::Assign(const Type& rSrc) { \
985  if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
986  this->Clear(); this->DoAssign(*csattr);} \
987  else { \
988  cbase::Assign(rSrc);}; \
989  return *this;} \
990  ctemp ctype& ctype::operator=(const ctype& rSrc) { this->Clear(); this->DoAssign(rSrc); return *this; } \
991  ctemp bool ctype::Equal(const Type& rOther) const { \
992  if(&rOther==this) return true; \
993  if(typeid(rOther) != typeid(*this)) return false; \
994  const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
995  if(!csattr) return false; \
996  if(!this->DoEqual(*csattr)) return false; \
997  return true;} \
998  ctemp bool ctype::operator==(const ctype& rOther) const { return this->DoEqual(rOther); } \
999  ctemp bool ctype::operator!=(const ctype& rOther) const { return !this->DoEqual(rOther); }
1000 
1001 
1002 
1003 
1004 
1005 /**
1006  * Structure to hold documentation data relating to a faudes-type or -function.
1007  * This class is the common base for faudes::TypeDefinition and faudes::FunctionDefinition.
1008  * It supports token io as demonstrated by the follwoing example for a type defintion:
1009  *
1010  * @code
1011  * <TypeDefinition name="CoreFaudes::Generator" ctype="faudes::Generator">
1012  *
1013  * <Documentation ref="generators.html#plain">
1014  * The common 5 tuple G=(Sigma, Q, delta, Qo, Qm).
1015  * <Documentation/>
1016  *
1017  * <Keywords> "generator" "language" </Keywords>
1018  *
1019  * </TypeDefinition>
1020  * @endcode
1021  *
1022  * Technical detail: Documentation is derived from Type for the purpose of token IO. We
1023  * still implement the faudes type interface to make it a fully qualified faudes data type.
1024  *
1025  * Technical detail: To facilitate inheritance, token io of member data and token io of
1026  * the section tags is separated.
1027  */
1028 
1030 
1031  // std faudes type interface
1033 
1034 public:
1035 
1036  using Type::operator=;
1037  using Type::operator==;
1038  using Type::operator!=;
1039 
1040 
1041  /** Constructor */
1042  Documentation(void);
1043 
1044  /** Copy constructor */
1045  Documentation(const Documentation& rOther);
1046 
1047  /** Destructor */
1048  virtual ~Documentation(void){};
1049 
1050  /**
1051  * Clear
1052  */
1053  void Clear(void);
1054 
1055  /**
1056  * Get name of the entety to document (aka faudes-type or faudes-function).
1057  *
1058  * @return
1059  * Name
1060  */
1061  const std::string& Name(void) const;
1062 
1063  /**
1064  * Get name of plugin.
1065  * The plugin name defaults to CoreFaudes.
1066  *
1067  * @return
1068  * Name
1069  */
1070  const std::string& PlugIn(void) const;
1071 
1072  /**
1073  * Get corresponding C++ type
1074  *
1075  * @return
1076  * CType, or "" if no such
1077  */
1078  const std::string& CType(void) const;
1079 
1080  /**
1081  * @return
1082  * Short textual documentation.
1083  */
1084  const std::string& TextDoc(void) const;
1085 
1086  /**
1087  * @return
1088  * Filename pointing to the html documentation.
1089  */
1090  const std::string& HtmlDoc(void) const;
1091 
1092  /**
1093  * @return
1094  * CSV-string containing keywords.
1095  */
1096  const std::string& Keywords(void) const;
1097 
1098  /**
1099  * Search comma-seperated keywords for a substring. This should be
1100  * extended to regular expressions in a future release.
1101  *
1102  * @param rPattern
1103  * String-pattern.
1104  *
1105  * @return
1106  * Matching keyword or "" if no match
1107  */
1108  std::string MatchKeyword(const std::string& rPattern) const;
1109 
1110  /**
1111  * Not implemented
1112  * @return
1113  * Number of keywords.
1114  */
1115  int KeywordsSize(void) const;
1116 
1117  /**
1118  * @param pos
1119  * Position of keyword
1120  * @return
1121  * Keyword at specified position (or "" if pos out of range)
1122  */
1123  std::string KeywordAt(int pos) const;
1124 
1125  /**
1126  * Get auto-register flag.
1127  *
1128  * This flag indicated that the respective type was (will be)
1129  * registered by a libFAUDES static initialisation protorype.
1130  *
1131  * @return
1132  * True <> C++-automatic-registration
1133  */
1134  bool AutoRegistered(void) const;
1135 
1136  /**
1137  * Get application-registered flag.
1138  *
1139  * @return
1140  * True <> registered by application
1141  */
1142  bool ApplicationRegistered(void) const;
1143 
1144  /**
1145  * Merge documentation from token stream.
1146  * An exception is thrown if the current type name differs from the one in the documentation.
1147  *
1148  * @param rTr
1149  * TokenReader to read from.
1150  *
1151  * @exception Exception
1152  * - Type mismatch (id )
1153  * - Token mismatch (id 50, 51, 52)
1154  * - IO Error (id 1)
1155  */
1156  virtual void MergeDocumentation(TokenReader& rTr);
1157 
1158 
1159 
1160  protected:
1161 
1162  /**
1163  * Set name.
1164  *
1165  * @param name
1166  * New name.
1167  */
1168  void Name(const std::string& name);
1169 
1170  /**
1171  * Set name of plugin
1172  *
1173  * @param plugin
1174  * New name.
1175  */
1176  void PlugIn(const std::string& plugin);
1177 
1178  /**
1179  * Set C++ type
1180  *
1181  * @param name
1182  * New ctype.
1183  */
1184  void CType(const std::string& name);
1185 
1186  /**
1187  * Set a short textual documentation.
1188  *
1189  * @param textdoc
1190  * New textual documentation.
1191  */
1192  void TextDoc(const std::string& textdoc);
1193 
1194  /**
1195  * Set auto-register flag.
1196  *
1197  * See also AutoRegistered(void)
1198  *
1199  * @param flag
1200  * Flag value.
1201  */
1202  void AutoRegistered(bool flag);
1203 
1204  /**
1205  * Set application-registered flag.
1206  *
1207  * See also AutoRegistered(void)
1208  *
1209  * @param flag
1210  * Flag value.
1211  */
1212  void ApplicationRegistered(bool flag);
1213 
1214  /**
1215  * Set name of file pointing to the html documentation.
1216  *
1217  * @param fname
1218  * Filename
1219  */
1220  void HtmlDoc(const std::string& fname);
1221 
1222  /**
1223  * Append keyword.
1224  *
1225  * @param rKeyword
1226  * Keyword
1227  */
1228  void AddKeyword(const std::string& rKeyword);
1229 
1230  /**
1231  * Std faudes type interface: assignment.
1232  *
1233  * @param rSrc
1234  * Source to copy from
1235  */
1236  void DoAssign(const Documentation& rSrc);
1237 
1238  /**
1239  * Std faudes type interface: test equality
1240  *
1241  * @param rOther
1242  * Other object to compare with.
1243  * @return
1244  * True on match.
1245  */
1246  bool DoEqual(const Documentation& rOther) const;
1247 
1248  /**
1249  * Read configuration data of this object from TokenReader.
1250  *
1251  * This virtual function reads documentation from a token stream.
1252  * The section defaults to Documentation. It invokes DoReadCore to
1253  * do the member data token reading.
1254  *
1255  * @param rTr
1256  * TokenReader to read from
1257  * @param rLabel
1258  * Section to read
1259  * @param pContext
1260  * Read context to provide contextual information (ignored)
1261  *
1262  * @exception Exception
1263  * - Token mismatch (id 50, 51, 52)
1264  * - IO Error (id 1)
1265  */
1266  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
1267 
1268  /**
1269  * Read configuration data of this object from TokenReader.
1270  *
1271  * This virtual function reads documentation member data only.
1272  * It does NOT read the enclosing begin and end tokens.
1273  *
1274  * @param rTr
1275  * TokenReader to read from
1276  *
1277  * @exception Exception
1278  * - Token mismatch (id 50, 51, 52)
1279  * - IO Error (id 1)
1280  */
1281  virtual void DoReadCore(TokenReader& rTr);
1282 
1283 
1284 
1285  /**
1286  * Write configuration data of this object to TokenWriter.
1287  *
1288  * This virtual function writes documentation to a token stream.
1289  * The section defaults to Documentation. It invokes DoWriteCore to
1290  * do the actual member data writing.
1291  *
1292  * @param rTw
1293  * Reference to TokenWriter
1294  * @param rLabel
1295  * Label of section to write
1296  * @param pContext
1297  * Write context to provide contextual information
1298  *
1299  * @exception Exception
1300  * - IO errors (id 2)
1301  */
1302  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
1303 
1304 
1305  /**
1306  * Write configuration data of this object to TokenWriter.
1307  *
1308  * This virtual function reads documentation members only.
1309  * It does NOT write enclosing begin and end tokens.
1310  *
1311  * @param rTw
1312  * Reference to TokenWriter
1313  *
1314  * @exception Exception
1315  * - IO errors (id 2)
1316  */
1317  virtual void DoWriteCore(TokenWriter& rTw) const;
1318 
1319 
1320  /** Faudes name. */
1321  std::string mName;
1322 
1323  /** Faudes plugin. */
1324  std::string mPlugIn;
1325 
1326  /** Corresponing C++ type, or "" if no such. */
1327  std::string mCType;
1328 
1329  /** String containing the text-documentation. */
1330  std::string mTextDoc;
1331 
1332  /** String containing the filename of the corresponding html-documentation. */
1333  std::string mHtmlDoc;
1334 
1335  /** Comma-seperated string containing all keywords. */
1336  std::string mKeywords;
1337 
1338  /** Constant characted used to seperate keywords */
1339  static const char mDelim = ';';
1340 
1341  /** Flag to indicate automated registration */
1343 
1344  /** Flag to indicate application registration */
1346 
1347 }; // Documentation
1348 
1349 
1350 
1351 /**
1352  * A TypeDefinition defines a faudes-type in that it specifies
1353  * a faudes-type name to identify the type and a method
1354  * NewObject() to instantiate objects of the respective type.
1355  * In this sense, TypeDefinition is a so called factory class.
1356  * Technically, the TypeDefinition holds one instance of the faude type,
1357  * the so called prototype object, and NewObject() invokes the New() method
1358  * of the prototype. Notebly, there is only one class TypeDefinition that by
1359  * parametrisation defins all derivates of Type.
1360  *
1361  * TypeDefinition is derived from faudes::Documentation and therefore additional
1362  * documentation-data can be associated.
1363  *
1364  *
1365  * @ingroup RunTimeInterface
1366  */
1367 
1369 
1370  // std faudes type interface
1372 
1373  // regisry is friend to set protected values
1374  friend class TypeRegistry;
1375 
1376  public:
1377 
1378  using Documentation::operator=;
1379  using Documentation::operator==;
1380  using Documentation::operator!=;
1381 
1382  /**
1383  * Constructor
1384  *
1385  * The default constructor instantiates an invalid type definition
1386  * without prototype. To construct
1387  * a valid type definition, use the static Constructor() template
1388  * function.
1389  */
1390  TypeDefinition(const std::string& name="") : Documentation(), mpType(NULL) {Name(name);};
1391 
1392  /**
1393  * Destructor.
1394  *
1395  * Delete prototype object.
1396  */
1397  virtual ~TypeDefinition(void){ Prototype(NULL); };
1398 
1399  /**
1400  * Construct empty TypeDefinition object.
1401  * The given template parameter denotes any libFAUDES class derived from faudes::Type
1402  * A new instance of this class is assigned to member variable (pType)
1403  * whereas the name is set as specified.
1404  *
1405  * @tparam T
1406  * Actual c class, derived from Type
1407  * @param rTypeName
1408  * Name to identify this faudes-type<; defaults to the plattform
1409  * dependand typeid from the c++ runtime type information system.
1410  * @return
1411  * Newly constructed type definition.
1412  *
1413  */
1414  template<class T>
1415  static TypeDefinition* Constructor(const std::string& rTypeName="");
1416 
1417  /**
1418  * Construct empty TypeDefinition object.
1419  * The given prototype is assigned to the member variable pType,
1420  *
1421  * @param pProto
1422  * Prototype, derived from Type
1423  * @param rTypeName
1424  * Name to identify this faudes-type<; defaults to the plattform
1425  * dependand typeid from the c++ runtime type information system.
1426  * @return
1427  * Newly constructed type definition.
1428  *
1429  */
1430  static TypeDefinition* Constructor(Type* pProto, const std::string& rTypeName="");
1431 
1432  /**
1433  * Construct TypeDefinition object and read name and
1434  * documentation-data from TokenReader.
1435  *
1436  * @tparam T
1437  * Actual c class, derived from Type
1438  * @param rFileName
1439  * Name of file to read.
1440  * @return
1441  * Newly constructed type definition.
1442  *
1443  * @exception Exception
1444  * - Token mismatch (id 50, 51, 52)
1445  * - IO Error (id 1)
1446  */
1447  template<class T>
1448  static TypeDefinition* FromFile(const std::string& rFileName);
1449 
1450 
1451  /**
1452  * Return pointer to faudes-object prototype
1453  *
1454  * Note: this method is meant for inspection only, control over
1455  * the prototype remains with the TypeDefinition. Use
1456  * NewObject() to instantiate a new faudes-object.
1457  *
1458  * @return
1459  * Reference to prototype object
1460  */
1461  const Type* Prototype(void) const;
1462 
1463 
1464  /**
1465  * Construct faudes-object on heap.
1466  * Return pointer to new instance of assigned Type class.
1467  *
1468  * Note: If no prototype is installed, NULL is returned.
1469  *
1470  * @return
1471  * Pointer to new Type instance.
1472  */
1473  Type* NewObject(void) const;
1474 
1475 
1476  /**
1477  * Parameter access: Xml Element Tag
1478  *
1479  * This parameter is used for Xml IO of sets and vectors. It determines
1480  * the tag to used for individual elments.
1481  *
1482  * @return
1483  * Tag parameter.
1484  */
1485  const std::string& XElementTag(void) const;
1486 
1487  /**
1488  * Parameter access: Xml Element Tag
1489  *
1490  * @param rTag
1491  * New tag parameter
1492  */
1493  void XElementTag(const std::string& rTag);
1494 
1495 protected:
1496 
1497 
1498  /**
1499  * Std faudes type interface: assignment.
1500  *
1501  * @param rSrc
1502  * Source to copy from
1503  */
1504  void DoAssign(const TypeDefinition& rSrc);
1505 
1506  /**
1507  * Std faudes type interface: test equality
1508  *
1509  * @param rOther
1510  * Other object to compare with.
1511  * @return
1512  * True on match.
1513  */
1514  bool DoEqual(const TypeDefinition& rOther) const;
1515 
1516  /** Disable copy constructor */
1517  TypeDefinition(const TypeDefinition& rOther) : Documentation(rOther) {}; // todo: implement ?? for stl maps ?
1518 
1519  /**
1520  * Clear documentation-data; do *NOT* delete prototype (this is for using Read to
1521  * merge/overwrite documentation)
1522  */
1523  void Clear(void);
1524 
1525  /**
1526  * Use given object as prototype.
1527  *
1528  * The TypeDefinition takes ownership of the
1529  * provided object.
1530  *
1531  * @param pType
1532  * Any class that inherits Type.
1533  */
1534  virtual void Prototype(Type* pType);
1535 
1536  /**
1537  * Read configuration data of this object from TokenReader.
1538  *
1539  * The section defaults to "TypeDefinition", context ignored.
1540  * Actual reading is done by DoReadCore.
1541  *
1542  * @param rTr
1543  * TokenReader to read from
1544  * @param rLabel
1545  * Section to read
1546  * @param pContext
1547  * Read context to provide contextual information (ignored)
1548  *
1549  * @exception Exception
1550  * - Token mismatch (id 50, 51, 52)
1551  * - IO error (id 1)
1552  */
1553  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
1554 
1555  /**
1556  * Read configuration data of this object from TokenReader.
1557  *
1558  * This method reads members only, it does not read the section.
1559  *
1560  * @param rTr
1561  * TokenReader to read from
1562  *
1563  * @exception Exception
1564  * - Token mismatch (id 50, 51, 52)
1565  * - IO error (id 1)
1566  */
1567  virtual void DoReadCore(TokenReader& rTr);
1568 
1569  /**
1570  * Write configuration data of this object to TokenWriter.
1571  *
1572  * The section defaults to "TypeDefinition", context ignored.
1573  * Actual writing is done by DoWriteCore.
1574  *
1575  * @param rTw
1576  * Reference to TokenWriter
1577  * @param rLabel
1578  * Label of section to write
1579  * @param pContext
1580  * Write context to provide contextual information
1581  *
1582  * @exception Exception
1583  * - IO errors (id 2)
1584  */
1585  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
1586 
1587  /**
1588  * Write configuration data of this object to TokenWriter.
1589  *
1590  * This method wrtite plain member data, the section lables are not
1591  * written.
1592  *
1593  * @param rTw
1594  * Reference to TokenWriter
1595  *
1596  * @exception Exception
1597  * - IO errors (id 2)
1598  */
1599  virtual void DoWriteCore(TokenWriter& rTw) const;
1600 
1601  /** Type-pointer tp prototype instance */
1603 
1604  /** Extra documentation/parameter: Xml Element Tag */
1605  std::string mXElementTag;
1606 
1607 }; //TypeDefinition
1608 
1609 
1610 
1611 
1612 /**********************************************************************************************
1613 ***********************************************************************************************
1614 ***********************************************************************************************
1615 
1616 Implemention of template members functions
1617 
1618 ***********************************************************************************************
1619 ***********************************************************************************************
1620 **********************************************************************************************/
1621 
1622 
1623 // Typedefinition constructor function
1624 template<class T>
1625 TypeDefinition* TypeDefinition::Constructor(const std::string& rTypeName){
1626  FD_DRTI("TypeDefinition::Construct<" << typeid(T).name() << ">(" << rTypeName << ")");
1627  return Constructor(new T, rTypeName);
1628 }
1629 
1630 
1631 // Type definition constructor function
1632 template<class T>
1633 TypeDefinition* TypeDefinition::FromFile(const std::string& rFileName){
1634  FD_DRTI("TypeDefinition::FromFile<" << typeid(T).name() << ">()");
1635  // construct with fallback name
1636  TypeDefinition* td = Constructor<T>();
1637  // read docu, incl actual name
1638  td->Read(rFileName);
1639  // done
1640  return(td);
1641 }
1642 
1643 
1644 
1645 
1646 
1647 } // namespace
1648 
1649 #endif /* FAUDES_RTITYPES_H */
#define FD_DRTI(message)
#define FAUDES_API
Definition: cfl_platform.h:80
Class Token.
Class TokenReader.
Class TokenWriter.
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition: cfl_types.h:872
std::string mTextDoc
Definition: cfl_types.h:1330
std::string mKeywords
Definition: cfl_types.h:1336
virtual ~Documentation(void)
Definition: cfl_types.h:1048
std::string mCType
Definition: cfl_types.h:1327
std::string mHtmlDoc
Definition: cfl_types.h:1333
std::string mPlugIn
Definition: cfl_types.h:1324
virtual ~TypeDefinition(void)
Definition: cfl_types.h:1397
static TypeDefinition * FromFile(const std::string &rFileName)
Definition: cfl_types.h:1633
TypeDefinition(const TypeDefinition &rOther)
Definition: cfl_types.h:1517
std::string mXElementTag
Definition: cfl_types.h:1605
static TypeDefinition * Constructor(const std::string &rTypeName="")
Definition: cfl_types.h:1625
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Definition: cfl_types.cpp:262
static std::string msStringEmpty
Definition: cfl_types.h:859
static std::string msStringVoid
Definition: cfl_types.h:858

libFAUDES 2.33b --- 2025.05.07 --- c++ api documentaion by doxygen