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  /*virtual*/ 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  /*virtual*/ 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  /*virtual*/ 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 
866 /** faudes type declaration macro */
867 #define FAUDES_TYPE_DECLARATION(ftype,ctype,cbase) \
868  public: virtual ctype* New(void) const; \
869  public: virtual ctype* Copy(void) const; \
870  public: virtual const Type* Cast(const Type* pOther) const; \
871  public: virtual ctype& Assign(const Type& rSrc); \
872  public: virtual bool Equal(const Type& rOther) const; \
873  public: /*virtual*/ ctype& operator=(const ctype& rSrc); \
874  public: /*virtual*/ bool operator==(const ctype& rOther) const; \
875  public: /*virtual*/ bool operator!=(const ctype& rOther) const;
876 
877 /** faudes type declaration macro, template version */
878 #define FAUDES_TYPE_TDECLARATION(ftype,ctype,cbase) \
879  public: virtual ctype* New(void) const; \
880  public: virtual ctype* Copy(void) const; \
881  public: virtual const Type* Cast(const Type* pOther) const; \
882  public: virtual ctype& Assign(const Type& rSrc); \
883  public: virtual bool Equal(const Type& rOther) const; \
884  public: /*virtual*/ ctype& operator=(const ctype& rSrc); \
885  public: /*virtual*/ bool operator==(const ctype& rOther) const; \
886  public: /*virtual*/ bool operator!=(const ctype& rOther) const;
887 
888 /** faudes type implementation macros */
889 #define FAUDES_TYPE_IMPLEMENTATION_NEW(ftype,ctype,cbase) \
890  ctype* ctype::New(void) const { return new ctype(); }
891 #define FAUDES_TYPE_IMPLEMENTATION_COPY(ftype,ctype,cbase) \
892  ctype* ctype::Copy(void) const { return new ctype(*this); }
893 #define FAUDES_TYPE_IMPLEMENTATION_CAST(ftype,ctype,cbase) \
894  const Type* ctype::Cast(const Type* pOther) const { \
895  return dynamic_cast< const ctype * >(pOther); }
896 #define FAUDES_TYPE_IMPLEMENTATION_ASSIGN(ftype,ctype,cbase) \
897  ctype& ctype::Assign(const Type& rSrc) { \
898  if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
899  this->Clear(); DoAssign(*csattr);} \
900  else { \
901  cbase::Assign(rSrc);}; \
902  return *this;} \
903  ctype& ctype::operator=(const ctype& rSrc) { this->Clear(); DoAssign(rSrc); return *this; }
904 #define FAUDES_TYPE_IMPLEMENTATION_EQUAL(ftype,ctype,cbase) \
905  bool ctype::Equal(const Type& rOther) const { \
906  if(&rOther==this) return true; \
907  if(typeid(rOther) != typeid(*this)) return false; \
908  const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
909  if(!csattr) return false; \
910  if(!DoEqual(*csattr)) return false; \
911  return true;} \
912  bool ctype::operator==(const ctype& rOther) const { return DoEqual(rOther); } \
913  bool ctype::operator!=(const ctype& rOther) const { return !DoEqual(rOther); }
914 
915 /** faudes type implementation macros, template version */
916 #define FAUDES_TYPE_TIMPLEMENTATION_NEW(ftype,ctype,cbase,ctemp) \
917  ctemp ctype* ctype::New(void) const { \
918  return new ctype(); }
919 #define FAUDES_TYPE_TIMPLEMENTATION_COPY(ftype,ctype,cbase,ctemp) \
920  ctemp ctype* ctype::Copy(void) const { \
921  return new ctype(*this); }
922 #define FAUDES_TYPE_TIMPLEMENTATION_CAST(ftype,ctype,cbase,ctemp) \
923  ctemp const Type* ctype::Cast(const Type* pOther) const { \
924  return dynamic_cast< const ctype * >(pOther); }
925 #define FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(ftype,ctype,cbase,ctemp) \
926  ctemp ctype& ctype::Assign(const Type& rSrc) { \
927  if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
928  this->Clear(); DoAssign(*csattr);} \
929  else { \
930  cbase::Assign(rSrc);}; \
931  return *this;} \
932  ctemp ctype& ctype::operator=(const ctype& rSrc) { this->Clear(); DoAssign(rSrc); return *this; }
933 #define FAUDES_TYPE_TIMPLEMENTATION_EQUAL(ftype,ctype,cbase,ctemp) \
934  ctemp bool ctype::Equal(const Type& rOther) const { \
935  if(&rOther==this) return true; \
936  if(typeid(rOther) != typeid(*this)) return false; \
937  const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
938  if(!csattr) return false; \
939  if(!DoEqual(*csattr)) return false; \
940  return true;} \
941  ctemp bool ctype::operator==(const ctype& rOther) const { return DoEqual(rOther); } \
942  ctemp bool ctype::operator!=(const ctype& rOther) const { return !DoEqual(rOther); }
943 
944 
945 /** faudes type implementation macros, overall */
946 #define FAUDES_TYPE_IMPLEMENTATION(ftype,ctype,cbase) \
947  ctype* ctype::New(void) const { \
948  return new ctype(); } \
949  ctype* ctype::Copy(void) const { \
950  return new ctype(*this); } \
951  const Type* ctype::Cast(const Type* pOther) const { \
952  return dynamic_cast< const ctype * >(pOther); } \
953  ctype& ctype::Assign(const Type& rSrc) { \
954  if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
955  this->Clear(); this->DoAssign(*csattr);} \
956  else { \
957  cbase::Assign(rSrc);}; \
958  return *this;} \
959  ctype& ctype::operator=(const ctype& rSrc) { this->Clear(); this->DoAssign(rSrc); return *this; } \
960  bool ctype::Equal(const Type& rOther) const { \
961  if(&rOther==this) return true; \
962  if(typeid(rOther) != typeid(*this)) return false; \
963  const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
964  if(!csattr) return false; \
965  if(!this->DoEqual(*csattr)) return false; \
966  return true;} \
967  bool ctype::operator==(const ctype& rOther) const { return this->DoEqual(rOther); } \
968  bool ctype::operator!=(const ctype& rOther) const { return !this->DoEqual(rOther); }
969 
970 
971 /** faudes type implementation macros, overall */
972 #define FAUDES_TYPE_TIMPLEMENTATION(ftype,ctype,cbase,ctemp) \
973  ctemp ctype* ctype::New(void) const { \
974  return new ctype(); } \
975  ctemp ctype* ctype::Copy(void) const { \
976  return new ctype(*this); } \
977  ctemp const Type* ctype::Cast(const Type* pOther) const { \
978  return dynamic_cast< const ctype * >(pOther); } \
979  ctemp ctype& ctype::Assign(const Type& rSrc) { \
980  if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
981  this->Clear(); this->DoAssign(*csattr);} \
982  else { \
983  cbase::Assign(rSrc);}; \
984  return *this;} \
985  ctemp ctype& ctype::operator=(const ctype& rSrc) { this->Clear(); this->DoAssign(rSrc); return *this; } \
986  ctemp bool ctype::Equal(const Type& rOther) const { \
987  if(&rOther==this) return true; \
988  if(typeid(rOther) != typeid(*this)) return false; \
989  const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
990  if(!csattr) return false; \
991  if(!this->DoEqual(*csattr)) return false; \
992  return true;} \
993  ctemp bool ctype::operator==(const ctype& rOther) const { return this->DoEqual(rOther); } \
994  ctemp bool ctype::operator!=(const ctype& rOther) const { return !this->DoEqual(rOther); }
995 
996 
997 /** faudes type implementation macros, overall */
998 /*
999 #define FAUDES_TYPE_IMPLEMENTATION(ftype,ctype,cbase) \
1000  ctype* ctype::New(void) const { \
1001  return new ctype(); } \
1002  ctype* ctype::Copy(void) const { \
1003  return new ctype(*this); } \
1004  const Type* ctype::Cast(const Type* pOther) const { \
1005  return dynamic_cast<const ctype*>(pOther); } \
1006  ctype& ctype::Assign(const Type& rSrc) { \
1007  if(const ctype* csattr=dynamic_cast<const ctype*>(&rSrc)) \
1008  { this->Clear(); DoAssign(*csattr); return *this;} \
1009  cbase::Assign(rSrc); \
1010  return *this;} \
1011  ctype& ctype::operator=(const ctype& rSrc) { this->Clear(); DoAssign(rSrc); return *this;} \
1012  bool ctype::Equal(const Type& rOther) const { \
1013  if(&rOther==this) return true; \
1014  if(typeid(rOther) != typeid(*this)) return false; \
1015  const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
1016  if(!csattr) return false; \
1017  if(!DoEqual(*csattr)) return false; \
1018  return true;} \
1019  bool ctype::operator==(const ctype& rOther) const { return DoEqual(rOther); } \
1020  bool ctype::operator!=(const ctype& rOther) const { return !DoEqual(rOther); }
1021 */
1022 
1023 
1024 
1025 /** faudes type implementation macros, individual, template version */
1026 /*
1027 #define FAUDES_TYPE_TIMPLEMENTATION_NEW(ftype,ctype,cbase,ctemp) \
1028  ctemp ctype* ctype::New(void) const { \
1029  return new ctype(); }
1030 #define FAUDES_TYPE_TIMPLEMENTATION_COPY(ftype,ctype,cbase,ctemp) \
1031  ctemp ctype* ctype::Copy(void) const { \
1032  return new ctype(*this); }
1033 #define FAUDES_TYPE_TIMPLEMENTATION_CAST(ftype,ctype,cbase,ctemp) \
1034  ctemp const Type* ctype::Cast(const Type* pOther) const { \
1035  return dynamic_cast<const ctype*>(pOther);}
1036 #define FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(ftype,ctype,cbase,ctemp) \
1037  ctemp ctype& ctype::Assign(const Type& rSrc) { \
1038  if(const ctype* csattr=dynamic_cast<const ctype*>(&rSrc)) { \
1039  this->Clear(); DoAssign(*csattr); return *this;} \
1040  cbase::Assign(rSrc); \
1041  return *this;} \
1042  ctemp ctype& ctype::operator=(const ctype& rSrc) { this->Clear(); DoAssign(rSrc); return *this; }
1043 #define FAUDES_TYPE_TIMPLEMENTATION_EQUAL(ftype,ctype,cbase,ctemp) \
1044  ctemp bool ctype::Equal(const Type& rOther) const { \
1045  if(&rOther==this) return true; \
1046  if(typeid(rOther) != typeid(*this)) return false; \
1047  const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
1048  if(!csattr) return false; \
1049  if(!this->DoEqual(*csattr)) return false; \
1050  return true;} \
1051  ctemp bool ctype::operator==(const ctype& rOther) const { return this->DoEqual(rOther); } \
1052  ctemp bool ctype::operator!=(const ctype& rOther) const { return !this->DoEqual(rOther); }
1053 */
1054 
1055 
1056 /** faudes type implementation macros, overall, template version */
1057 /*
1058 #define FAUDES_TYPE_TIMPLEMENTATION(ftype,ctype,cbase,ctemp) \
1059  ctemp ctype* ctype::New(void) const { \
1060  return new ctype(); } \
1061  ctemp ctype* ctype::Copy(void) const { \
1062  return new ctype(*this); } \
1063  ctemp const Type* ctype::Cast(const Type* pOther) const { \
1064  return dynamic_cast<const ctype*>(pOther);} \
1065  ctemp ctype& ctype::Assign(const Type& rSrc) { \
1066  if(const ctype* csattr=dynamic_cast<const ctype*>(&rSrc)) \
1067  { this->Clear(); DoAssign(*csattr); return *this;} \
1068  cbase::Assign(rSrc); \
1069  return *this;} \
1070  ctemp ctype& ctype::operator=(const ctype& rSrc) { this->Clear(); DoAssign(rSrc); return *this; } \
1071  ctemp bool ctype::Equal(const Type& rOther) const { \
1072  if(&rOther==this) return true; \
1073  if(typeid(rOther) != typeid(*this)) return false; \
1074  const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
1075  if(!csattr) return false; \
1076  if(!this->DoEqual(*csattr)) return false; \
1077  return true;} \
1078  ctemp bool ctype::operator==(const ctype& rOther) const { return this->DoEqual(rOther); } \
1079  ctemp bool ctype::operator!=(const ctype& rOther) const{ return !this->DoEqual(rOther); }
1080 */
1081 
1082 /** faudes type implementation macros, overall, debug version */
1083 /*
1084 #define FAUDES_TYPE_IMPLEMENTATION(ctype,cbase,ctemp) \
1085  ctemp ctype* ctype::New(void) const { \
1086  return new ctype(); } \
1087  ctemp const ctype* ctype::Cast(const Type* pOther) const { \
1088  return dynamic_cast<const ctype*>(pOther);} \
1089  ctemp ctype& ctype::Assign(const Type& rSrc) { \
1090  FD_WARN("RTI "<< typeid(ctype).name() << "::ASSIGN() V: " << typeid(*this).name() << \
1091  " from " << typeid(rSrc).name()); \
1092  if(const ctype* csattr=dynamic_cast<const ctype*>(&rSrc)) { this->Clear(); return DoAssign(*csattr);} \
1093  cbase::Assign(rSrc); \
1094  return *this;} \
1095  ctemp ctype& ctype::operator=(const ctype& rSrc) { \
1096  FD_WARN("RTI "<< typeid(ctype).name() << "::ASSIGN() O: " << typeid(*this).name() << \
1097  " from " << typeid(rSrc).name()); \
1098  this->Clear(); \
1099  return DoAssign(rSrc); }
1100 */
1101 
1102 
1103 
1104 /**
1105  * Structure to hold documentation data relating to a faudes-type or -function.
1106  * This class is the common base for faudes::TypeDefinition and faudes::FunctionDefinition.
1107  * It supports token io as demonstrated by the follwoing example for a type defintion:
1108  *
1109  * @code
1110  * <TypeDefinition name="CoreFaudes::Generator" ctype="faudes::Generator">
1111  *
1112  * <Documentation ref="generators.html#plain">
1113  * The common 5 tuple G=(Sigma, Q, delta, Qo, Qm).
1114  * <Documentation/>
1115  *
1116  * <Keywords> "generator" "language" </Keywords>
1117  *
1118  * </TypeDefinition>
1119  * @endcode
1120  *
1121  * Technical detail: Documentation is derived from Type for the purpose of token IO. We
1122  * still implement the faudes type interface to make it a fully qualified faudes data type.
1123  *
1124  * Technical detail: To facilitate inheritance, token io of member data and token io of
1125  * the section tags is separated.
1126  */
1127 
1129 
1130  // std faudes type interface
1132 
1133 public:
1134 
1135  using Type::operator=;
1136  using Type::operator==;
1137  using Type::operator!=;
1138 
1139 
1140  /** Constructor */
1141  Documentation(void);
1142 
1143  /** Copy constructor */
1144  Documentation(const Documentation& rOther);
1145 
1146  /** Destructor */
1147  virtual ~Documentation(void){};
1148 
1149  /**
1150  * Clear
1151  */
1152  void Clear(void);
1153 
1154  /**
1155  * Get name of the entety to document (aka faudes-type or faudes-function).
1156  *
1157  * @return
1158  * Name
1159  */
1160  const std::string& Name(void) const;
1161 
1162  /**
1163  * Get name of plugin.
1164  * The plugin name defaults to CoreFaudes.
1165  *
1166  * @return
1167  * Name
1168  */
1169  const std::string& PlugIn(void) const;
1170 
1171  /**
1172  * Get corresponding C++ type
1173  *
1174  * @return
1175  * CType, or "" if no such
1176  */
1177  const std::string& CType(void) const;
1178 
1179  /**
1180  * @return
1181  * Short textual documentation.
1182  */
1183  const std::string& TextDoc(void) const;
1184 
1185  /**
1186  * @return
1187  * Filename pointing to the html documentation.
1188  */
1189  const std::string& HtmlDoc(void) const;
1190 
1191  /**
1192  * @return
1193  * CSV-string containing keywords.
1194  */
1195  const std::string& Keywords(void) const;
1196 
1197  /**
1198  * Search comma-seperated keywords for a substring. This should be
1199  * extended to regular expressions in a future release.
1200  *
1201  * @param rPattern
1202  * String-pattern.
1203  *
1204  * @return
1205  * Matching keyword or "" if no match
1206  */
1207  std::string MatchKeyword(const std::string& rPattern) const;
1208 
1209  /**
1210  * Not implemented
1211  * @return
1212  * Number of keywords.
1213  */
1214  int KeywordsSize(void) const;
1215 
1216  /**
1217  * @param pos
1218  * Position of keyword
1219  * @return
1220  * Keyword at specified position (or "" if pos out of range)
1221  */
1222  std::string KeywordAt(int pos) const;
1223 
1224  /**
1225  * Get auto-register flag.
1226  *
1227  * This flag indicated that the respective type was (will be)
1228  * registered by a libFAUDES static initialisation protorype.
1229  *
1230  * @return
1231  * True <> C++-automatic-registration
1232  */
1233  bool AutoRegistered(void) const;
1234 
1235  /**
1236  * Get application-registered flag.
1237  *
1238  * @return
1239  * True <> registered by application
1240  */
1241  bool ApplicationRegistered(void) const;
1242 
1243  /**
1244  * Merge documentation from token stream.
1245  * An exception is thrown if the current type name differs from the one in the documentation.
1246  *
1247  * @param rTr
1248  * TokenReader to read from.
1249  *
1250  * @exception Exception
1251  * - Type mismatch (id )
1252  * - Token mismatch (id 50, 51, 52)
1253  * - IO Error (id 1)
1254  */
1255  virtual void MergeDocumentation(TokenReader& rTr);
1256 
1257 
1258 
1259  protected:
1260 
1261  /**
1262  * Set name.
1263  *
1264  * @param name
1265  * New name.
1266  */
1267  void Name(const std::string& name);
1268 
1269  /**
1270  * Set name of plugin
1271  *
1272  * @param plugin
1273  * New name.
1274  */
1275  void PlugIn(const std::string& plugin);
1276 
1277  /**
1278  * Set C++ type
1279  *
1280  * @param name
1281  * New ctype.
1282  */
1283  void CType(const std::string& name);
1284 
1285  /**
1286  * Set a short textual documentation.
1287  *
1288  * @param textdoc
1289  * New textual documentation.
1290  */
1291  void TextDoc(const std::string& textdoc);
1292 
1293  /**
1294  * Set auto-register flag.
1295  *
1296  * See also AutoRegistered(void)
1297  *
1298  * @param flag
1299  * Flag value.
1300  */
1301  void AutoRegistered(bool flag);
1302 
1303  /**
1304  * Set application-registered flag.
1305  *
1306  * See also AutoRegistered(void)
1307  *
1308  * @param flag
1309  * Flag value.
1310  */
1311  void ApplicationRegistered(bool flag);
1312 
1313  /**
1314  * Set name of file pointing to the html documentation.
1315  *
1316  * @param fname
1317  * Filename
1318  */
1319  void HtmlDoc(const std::string& fname);
1320 
1321  /**
1322  * Append keyword.
1323  *
1324  * @param rKeyword
1325  * Keyword
1326  */
1327  void AddKeyword(const std::string& rKeyword);
1328 
1329  /**
1330  * Std faudes type interface: assignment.
1331  *
1332  * @param rSrc
1333  * Source to copy from
1334  */
1335  void DoAssign(const Documentation& rSrc);
1336 
1337  /**
1338  * Std faudes type interface: test equality
1339  *
1340  * @param rOther
1341  * Other object to compare with.
1342  * @return
1343  * True on match.
1344  */
1345  bool DoEqual(const Documentation& rOther) const;
1346 
1347  /**
1348  * Read configuration data of this object from TokenReader.
1349  *
1350  * This virtual function reads documentation from a token stream.
1351  * The section defaults to Documentation. It invokes DoReadCore to
1352  * do the member data token reading.
1353  *
1354  * @param rTr
1355  * TokenReader to read from
1356  * @param rLabel
1357  * Section to read
1358  * @param pContext
1359  * Read context to provide contextual information (ignored)
1360  *
1361  * @exception Exception
1362  * - Token mismatch (id 50, 51, 52)
1363  * - IO Error (id 1)
1364  */
1365  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
1366 
1367  /**
1368  * Read configuration data of this object from TokenReader.
1369  *
1370  * This virtual function reads documentation member data only.
1371  * It does NOT read the enclosing begin and end tokens.
1372  *
1373  * @param rTr
1374  * TokenReader to read from
1375  *
1376  * @exception Exception
1377  * - Token mismatch (id 50, 51, 52)
1378  * - IO Error (id 1)
1379  */
1380  virtual void DoReadCore(TokenReader& rTr);
1381 
1382 
1383 
1384  /**
1385  * Write configuration data of this object to TokenWriter.
1386  *
1387  * This virtual function writes documentation to a token stream.
1388  * The section defaults to Documentation. It invokes DoWriteCore to
1389  * do the actual member data writing.
1390  *
1391  * @param rTw
1392  * Reference to TokenWriter
1393  * @param rLabel
1394  * Label of section to write
1395  * @param pContext
1396  * Write context to provide contextual information
1397  *
1398  * @exception Exception
1399  * - IO errors (id 2)
1400  */
1401  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
1402 
1403 
1404  /**
1405  * Write configuration data of this object to TokenWriter.
1406  *
1407  * This virtual function reads documentation members only.
1408  * It does NOT write enclosing begin and end tokens.
1409  *
1410  * @param rTw
1411  * Reference to TokenWriter
1412  *
1413  * @exception Exception
1414  * - IO errors (id 2)
1415  */
1416  virtual void DoWriteCore(TokenWriter& rTw) const;
1417 
1418 
1419  /** Faudes name. */
1420  std::string mName;
1421 
1422  /** Faudes plugin. */
1423  std::string mPlugIn;
1424 
1425  /** Corresponing C++ type, or "" if no such. */
1426  std::string mCType;
1427 
1428  /** String containing the text-documentation. */
1429  std::string mTextDoc;
1430 
1431  /** String containing the filename of the corresponding html-documentation. */
1432  std::string mHtmlDoc;
1433 
1434  /** Comma-seperated string containing all keywords. */
1435  std::string mKeywords;
1436 
1437  /** Constant characted used to seperate keywords */
1438  static const char mDelim = ';';
1439 
1440  /** Flag to indicate automated registration */
1442 
1443  /** Flag to indicate application registration */
1445 
1446 }; // Documentation
1447 
1448 
1449 
1450 /**
1451  * A TypeDefinition defines a faudes-type in that it specifies
1452  * a faudes-type name to identify the type and a method
1453  * NewObject() to instantiate objects of the respective type.
1454  * In this sense, TypeDefinition is a so called factory class.
1455  * Technically, the TypeDefinition holds one instance of the faude type,
1456  * the so called prototype object, and NewObject() invokes the New() method
1457  * of the prototype. Notebly, there is only one class TypeDefinition that by
1458  * parametrisation defins all derivates of Type.
1459  *
1460  * TypeDefinition is derived from faudes::Documentation and therefore additional
1461  * documentation-data can be associated.
1462  *
1463  *
1464  * @ingroup RunTimeInterface
1465  */
1466 
1468 
1469  // std faudes type interface
1471 
1472  // regisry is friend to set protected values
1473  friend class TypeRegistry;
1474 
1475  public:
1476 
1477  using Documentation::operator=;
1478  using Documentation::operator==;
1479  using Documentation::operator!=;
1480 
1481  /**
1482  * Constructor
1483  *
1484  * The default constructor instantiates an invalid type definition
1485  * without prototype. To construct
1486  * a valid type definition, use the static Constructor() template
1487  * function.
1488  */
1489  TypeDefinition(const std::string& name="") : Documentation(), mpType(NULL) {Name(name);};
1490 
1491  /**
1492  * Destructor.
1493  *
1494  * Delete prototype object.
1495  */
1496  virtual ~TypeDefinition(void){ Prototype(NULL); };
1497 
1498  /**
1499  * Construct empty TypeDefinition object.
1500  * The given template parameter denotes any libFAUDES class derived from faudes::Type
1501  * A new instance of this class is assigned to member variable (pType)
1502  * whereas the name is set as specified.
1503  *
1504  * @tparam T
1505  * Actual c class, derived from Type
1506  * @param rTypeName
1507  * Name to identify this faudes-type<; defaults to the plattform
1508  * dependand typeid from the c++ runtime type information system.
1509  * @return
1510  * Newly constructed type definition.
1511  *
1512  */
1513  template<class T>
1514  static TypeDefinition* Constructor(const std::string& rTypeName="");
1515 
1516  /**
1517  * Construct empty TypeDefinition object.
1518  * The given prototype is assigned to the member variable pType,
1519  *
1520  * @param pProto
1521  * Prototype, derived from Type
1522  * @param rTypeName
1523  * Name to identify this faudes-type<; defaults to the plattform
1524  * dependand typeid from the c++ runtime type information system.
1525  * @return
1526  * Newly constructed type definition.
1527  *
1528  */
1529  static TypeDefinition* Constructor(Type* pProto, const std::string& rTypeName="");
1530 
1531  /**
1532  * Construct TypeDefinition object and read name and
1533  * documentation-data from TokenReader.
1534  *
1535  * @tparam T
1536  * Actual c class, derived from Type
1537  * @param rFileName
1538  * Name of file to read.
1539  * @return
1540  * Newly constructed type definition.
1541  *
1542  * @exception Exception
1543  * - Token mismatch (id 50, 51, 52)
1544  * - IO Error (id 1)
1545  */
1546  template<class T>
1547  static TypeDefinition* FromFile(const std::string& rFileName);
1548 
1549 
1550  /**
1551  * Return pointer to faudes-object prototype
1552  *
1553  * Note: this method is meant for inspection only, control over
1554  * the prototype remains with the TypeDefinition. Use
1555  * NewObject() to instantiate a new faudes-object.
1556  *
1557  * @return
1558  * Reference to prototype object
1559  */
1560  const Type* Prototype(void) const;
1561 
1562 
1563  /**
1564  * Construct faudes-object on heap.
1565  * Return pointer to new instance of assigned Type class.
1566  *
1567  * Note: If no prototype is installed, NULL is returned.
1568  *
1569  * @return
1570  * Pointer to new Type instance.
1571  */
1572  Type* NewObject(void) const;
1573 
1574 
1575  /**
1576  * Parameter access: Xml Element Tag
1577  *
1578  * This parameter is used for Xml IO of sets and vectors. It determines
1579  * the tag to used for individual elments.
1580  *
1581  * @return
1582  * Tag parameter.
1583  */
1584  const std::string& XElementTag(void) const;
1585 
1586  /**
1587  * Parameter access: Xml Element Tag
1588  *
1589  * @param rTag
1590  * New tag parameter
1591  */
1592  void XElementTag(const std::string& rTag);
1593 
1594 protected:
1595 
1596 
1597  /**
1598  * Std faudes type interface: assignment.
1599  *
1600  * @param rSrc
1601  * Source to copy from
1602  */
1603  void DoAssign(const TypeDefinition& rSrc);
1604 
1605  /**
1606  * Std faudes type interface: test equality
1607  *
1608  * @param rOther
1609  * Other object to compare with.
1610  * @return
1611  * True on match.
1612  */
1613  bool DoEqual(const TypeDefinition& rOther) const;
1614 
1615  /** Disable copy constructor */
1616  TypeDefinition(const TypeDefinition& rOther) : Documentation(rOther) {}; // todo: implement ?? for stl maps ?
1617 
1618  /**
1619  * Clear documentation-data; do *NOT* delete prototype (this is for using Read to
1620  * merge/overwrite documentation)
1621  */
1622  void Clear(void);
1623 
1624  /**
1625  * Use given object as prototype.
1626  *
1627  * The TypeDefinition takes ownership of the
1628  * provided object.
1629  *
1630  * @param pType
1631  * Any class that inherits Type.
1632  */
1633  virtual void Prototype(Type* pType);
1634 
1635  /**
1636  * Read configuration data of this object from TokenReader.
1637  *
1638  * The section defaults to "TypeDefinition", context ignored.
1639  * Actual reading is done by DoReadCore.
1640  *
1641  * @param rTr
1642  * TokenReader to read from
1643  * @param rLabel
1644  * Section to read
1645  * @param pContext
1646  * Read context to provide contextual information (ignored)
1647  *
1648  * @exception Exception
1649  * - Token mismatch (id 50, 51, 52)
1650  * - IO error (id 1)
1651  */
1652  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
1653 
1654  /**
1655  * Read configuration data of this object from TokenReader.
1656  *
1657  * This method reads members only, it does not read the section.
1658  *
1659  * @param rTr
1660  * TokenReader to read from
1661  *
1662  * @exception Exception
1663  * - Token mismatch (id 50, 51, 52)
1664  * - IO error (id 1)
1665  */
1666  virtual void DoReadCore(TokenReader& rTr);
1667 
1668  /**
1669  * Write configuration data of this object to TokenWriter.
1670  *
1671  * The section defaults to "TypeDefinition", context ignored.
1672  * Actual writing is done by DoWriteCore.
1673  *
1674  * @param rTw
1675  * Reference to TokenWriter
1676  * @param rLabel
1677  * Label of section to write
1678  * @param pContext
1679  * Write context to provide contextual information
1680  *
1681  * @exception Exception
1682  * - IO errors (id 2)
1683  */
1684  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
1685 
1686  /**
1687  * Write configuration data of this object to TokenWriter.
1688  *
1689  * This method wrtite plain member data, the section lables are not
1690  * written.
1691  *
1692  * @param rTw
1693  * Reference to TokenWriter
1694  *
1695  * @exception Exception
1696  * - IO errors (id 2)
1697  */
1698  virtual void DoWriteCore(TokenWriter& rTw) const;
1699 
1700  /** Type-pointer tp prototype instance */
1702 
1703  /** Extra documentation/parameter: Xml Element Tag */
1704  std::string mXElementTag;
1705 
1706 }; //TypeDefinition
1707 
1708 
1709 
1710 
1711 /**********************************************************************************************
1712 ***********************************************************************************************
1713 ***********************************************************************************************
1714 
1715 Implemention of template members functions
1716 
1717 ***********************************************************************************************
1718 ***********************************************************************************************
1719 **********************************************************************************************/
1720 
1721 
1722 // Typedefinition constructor function
1723 template<class T>
1724 TypeDefinition* TypeDefinition::Constructor(const std::string& rTypeName){
1725  FD_DRTI("TypeDefinition::Construct<" << typeid(T).name() << ">(" << rTypeName << ")");
1726  return Constructor(new T, rTypeName);
1727 }
1728 
1729 
1730 // Type definition constructor function
1731 template<class T>
1732 TypeDefinition* TypeDefinition::FromFile(const std::string& rFileName){
1733  FD_DRTI("TypeDefinition::FromFile<" << typeid(T).name() << ">()");
1734  // construct with fallback name
1735  TypeDefinition* td = Constructor<T>();
1736  // read docu, incl actual name
1737  td->Read(rFileName);
1738  // done
1739  return(td);
1740 }
1741 
1742 
1743 
1744 
1745 
1746 } // namespace
1747 
1748 #endif /* FAUDES_RTITYPES_H */
Compiletime options.
#define FD_DRTI(message)
Debug: optional on function and type definition.
Class Exception.
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:80
Class Token.
Class TokenReader.
Class TokenWriter.
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
faudes type declaration macro
Definition: cfl_types.h:867
faudes type implementation macros, overall
Definition: cfl_types.h:1128
bool mAutoRegistered
Flag to indicate automated registration.
Definition: cfl_types.h:1441
std::string mTextDoc
String containing the text-documentation.
Definition: cfl_types.h:1429
std::string mKeywords
Comma-seperated string containing all keywords.
Definition: cfl_types.h:1435
virtual ~Documentation(void)
Destructor.
Definition: cfl_types.h:1147
bool mApplicationRegistered
Flag to indicate application registration.
Definition: cfl_types.h:1444
std::string mCType
Corresponing C++ type, or "" if no such.
Definition: cfl_types.h:1426
std::string mHtmlDoc
String containing the filename of the corresponding html-documentation.
Definition: cfl_types.h:1432
std::string mName
Faudes name.
Definition: cfl_types.h:1420
std::string mPlugIn
Faudes plugin.
Definition: cfl_types.h:1423
A TokenReader reads sequential tokens from a file or string.
A TokenWriter writes sequential tokens to a file, a string or stdout.
Tokens model atomic data for stream IO.
Definition: cfl_token.h:54
A TypeDefinition defines a faudes-type in that it specifies a faudes-type name to identify the type a...
Definition: cfl_types.h:1467
Type * mpType
Type-pointer tp prototype instance.
Definition: cfl_types.h:1701
virtual ~TypeDefinition(void)
Destructor.
Definition: cfl_types.h:1496
static TypeDefinition * FromFile(const std::string &rFileName)
Construct TypeDefinition object and read name and documentation-data from TokenReader.
Definition: cfl_types.h:1732
TypeDefinition(const TypeDefinition &rOther)
Disable copy constructor.
Definition: cfl_types.h:1616
std::string mXElementTag
Extra documentation/parameter: Xml Element Tag.
Definition: cfl_types.h:1704
static TypeDefinition * Constructor(const std::string &rTypeName="")
Construct empty TypeDefinition object.
Definition: cfl_types.h:1724
The TypeRegistry registers faudes-types.
Definition: cfl_registry.h:47
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
Definition: cfl_types.cpp:261
static std::string msStringEmpty
Definition: cfl_types.h:859
static std::string msStringVoid
Definition: cfl_types.h:858
libFAUDES resides within the namespace faudes.

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