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 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 FType(), 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  /** Constructor */
1135  Documentation(void);
1136 
1137  /** Copy constructor */
1138  Documentation(const Documentation& rOther);
1139 
1140  /** Destructor */
1141  virtual ~Documentation(void){};
1142 
1143  /**
1144  * Clear
1145  */
1146  void Clear(void);
1147 
1148  /**
1149  * Get name of the entety to document (aka faudes-type or faudes-function).
1150  *
1151  * @return
1152  * Name
1153  */
1154  const std::string& Name(void) const;
1155 
1156  /**
1157  * Get name of plugin.
1158  * The plugin name defaults to CoreFaudes.
1159  *
1160  * @return
1161  * Name
1162  */
1163  const std::string& PlugIn(void) const;
1164 
1165  /**
1166  * Get corresponding C++ type
1167  *
1168  * @return
1169  * CType, or "" if no such
1170  */
1171  const std::string& CType(void) const;
1172 
1173  /**
1174  * @return
1175  * Short textual documentation.
1176  */
1177  const std::string& TextDoc(void) const;
1178 
1179  /**
1180  * @return
1181  * Filename pointing to the html documentation.
1182  */
1183  const std::string& HtmlDoc(void) const;
1184 
1185  /**
1186  * @return
1187  * CSV-string containing keywords.
1188  */
1189  const std::string& Keywords(void) const;
1190 
1191  /**
1192  * Search comma-seperated keywords for a substring. This should be
1193  * extended to regular expressions in a future release.
1194  *
1195  * @param rPattern
1196  * String-pattern.
1197  *
1198  * @return
1199  * Matching keyword or "" if no match
1200  */
1201  std::string MatchKeyword(const std::string& rPattern) const;
1202 
1203  /**
1204  * Not implemented
1205  * @return
1206  * Number of keywords.
1207  */
1208  int KeywordsSize(void) const;
1209 
1210  /**
1211  * @param pos
1212  * Position of keyword
1213  * @return
1214  * Keyword at specified position (or "" if pos out of range)
1215  */
1216  std::string KeywordAt(int pos) const;
1217 
1218  /**
1219  * Get auto-register flag.
1220  *
1221  * This flag indicated that the respective type was (will be)
1222  * registered by a libFAUDES static initialisation protorype.
1223  *
1224  * @return
1225  * True <> C++-automatic-registration
1226  */
1227  bool AutoRegistered(void) const;
1228 
1229  /**
1230  * Get application-registered flag.
1231  *
1232  * @return
1233  * True <> registered by application
1234  */
1235  bool ApplicationRegistered(void) const;
1236 
1237  /**
1238  * Merge documentation from token stream.
1239  * An exception is thrown if the current type name differs from the one in the documentation.
1240  *
1241  * @param rTr
1242  * TokenReader to read from.
1243  *
1244  * @exception Exception
1245  * - Type mismatch (id )
1246  * - Token mismatch (id 50, 51, 52)
1247  * - IO Error (id 1)
1248  */
1249  virtual void MergeDocumentation(TokenReader& rTr);
1250 
1251 
1252 
1253  protected:
1254 
1255  /**
1256  * Set name.
1257  *
1258  * @param name
1259  * New name.
1260  */
1261  void Name(const std::string& name);
1262 
1263  /**
1264  * Set name of plugin
1265  *
1266  * @param plugin
1267  * New name.
1268  */
1269  void PlugIn(const std::string& plugin);
1270 
1271  /**
1272  * Set C++ type
1273  *
1274  * @param name
1275  * New ctype.
1276  */
1277  void CType(const std::string& name);
1278 
1279  /**
1280  * Set a short textual documentation.
1281  *
1282  * @param textdoc
1283  * New textual documentation.
1284  */
1285  void TextDoc(const std::string& textdoc);
1286 
1287  /**
1288  * Set auto-register flag.
1289  *
1290  * See also AutoRegistered(void)
1291  *
1292  * @param flag
1293  * Flag value.
1294  */
1295  void AutoRegistered(bool flag);
1296 
1297  /**
1298  * Set application-registered flag.
1299  *
1300  * See also AutoRegistered(void)
1301  *
1302  * @param flag
1303  * Flag value.
1304  */
1305  void ApplicationRegistered(bool flag);
1306 
1307  /**
1308  * Set name of file pointing to the html documentation.
1309  *
1310  * @param fname
1311  * Filename
1312  */
1313  void HtmlDoc(const std::string& fname);
1314 
1315  /**
1316  * Append keyword.
1317  *
1318  * @param rKeyword
1319  * Keyword
1320  */
1321  void AddKeyword(const std::string& rKeyword);
1322 
1323  /**
1324  * Std faudes type interface: assignment.
1325  *
1326  * @param rSrc
1327  * Source to copy from
1328  * @return Reference to this object.
1329  */
1330  void DoAssign(const Documentation& rSrc);
1331 
1332  /**
1333  * Std faudes type interface: test equality
1334  *
1335  * @param rOther
1336  * Other object to compare with.
1337  * @return
1338  * True on match.
1339  */
1340  bool DoEqual(const Documentation& rOther) const;
1341 
1342  /**
1343  * Read configuration data of this object from TokenReader.
1344  *
1345  * This virtual function reads documentation from a token stream.
1346  * The section defaults to Documentation. It invokes DoReadCore to
1347  * do the member data token reading.
1348  *
1349  * @param rTr
1350  * TokenReader to read from
1351  * @param rLabel
1352  * Section to read
1353  * @param pContext
1354  * Read context to provide contextual information (ignored)
1355  *
1356  * @exception Exception
1357  * - Token mismatch (id 50, 51, 52)
1358  * - IO Error (id 1)
1359  */
1360  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
1361 
1362  /**
1363  * Read configuration data of this object from TokenReader.
1364  *
1365  * This virtual function reads documentation member data only.
1366  * It does NOT read the enclosing begin and end tokens.
1367  *
1368  * @param rTr
1369  * TokenReader to read from
1370  *
1371  * @exception Exception
1372  * - Token mismatch (id 50, 51, 52)
1373  * - IO Error (id 1)
1374  */
1375  virtual void DoReadCore(TokenReader& rTr);
1376 
1377 
1378 
1379  /**
1380  * Write configuration data of this object to TokenWriter.
1381  *
1382  * This virtual function writes documentation to a token stream.
1383  * The section defaults to Documentation. It invokes DoWriteCore to
1384  * do the actual member data writing.
1385  *
1386  * @param rTw
1387  * Reference to TokenWriter
1388  * @param rLabel
1389  * Label of section to write
1390  * @param pContext
1391  * Write context to provide contextual information
1392  *
1393  * @exception Exception
1394  * - IO errors (id 2)
1395  */
1396  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
1397 
1398 
1399  /**
1400  * Write configuration data of this object to TokenWriter.
1401  *
1402  * This virtual function reads documentation members only.
1403  * It does NOT write enclosing begin and end tokens.
1404  *
1405  * @param rTw
1406  * Reference to TokenWriter
1407  *
1408  * @exception Exception
1409  * - IO errors (id 2)
1410  */
1411  virtual void DoWriteCore(TokenWriter& rTw) const;
1412 
1413 
1414  /** Faudes name. */
1415  std::string mName;
1416 
1417  /** Faudes plugin. */
1418  std::string mPlugIn;
1419 
1420  /** Corresponing C++ type, or "" if no such. */
1421  std::string mCType;
1422 
1423  /** String containing the text-documentation. */
1424  std::string mTextDoc;
1425 
1426  /** String containing the filename of the corresponding html-documentation. */
1427  std::string mHtmlDoc;
1428 
1429  /** Comma-seperated string containing all keywords. */
1430  std::string mKeywords;
1431 
1432  /** Constant characted used to seperate keywords */
1433  static const char mDelim = ';';
1434 
1435  /** Flag to indicate automated registration */
1437 
1438  /** Flag to indicate application registration */
1440 
1441 }; // Documentation
1442 
1443 
1444 
1445 /**
1446  * A TypeDefinition defines a faudes-type in that it specifies
1447  * a faudes-type name to identify the type and a method
1448  * NewObject() to instantiate objects of the respective type.
1449  * In this sense, TypeDefinition is a so called factory class.
1450  * Technically, the TypeDefinition holds one instance of the faude type,
1451  * the so called prototype object, and NewObject() invokes the New() method
1452  * of the prototype. Notebly, there is only one class TypeDefinition that by
1453  * parametrisation defins all derivates of Type.
1454  *
1455  * TypeDefinition is derived from faudes::Documentation and therefore additional
1456  * documentation-data can be associated.
1457  *
1458  *
1459  * @ingroup RunTimeInterface
1460  */
1461 
1463 
1464  // std faudes type interface
1466 
1467  // regisry is friend to set protected values
1468  friend class TypeRegistry;
1469 
1470  public:
1471 
1472  /**
1473  * Constructor
1474  *
1475  * The default constructor instantiates an invalid type definition
1476  * without prototype. To construct
1477  * a valid type definition, use the static Constructor() template
1478  * function.
1479  */
1480  TypeDefinition(const std::string& name="") : Documentation(), mpType(NULL) {Name(name);};
1481 
1482  /**
1483  * Destructor.
1484  *
1485  * Delete prototype object.
1486  */
1487  virtual ~TypeDefinition(void){ Prototype(NULL); };
1488 
1489  /**
1490  * Construct empty TypeDefinition object.
1491  * The given template parameter denotes any libFAUDES class derived from faudes::Type
1492  * A new instance of this class is assigned to member variable (pType)
1493  * whereas the name is set as specified.
1494  *
1495  * @tparam T
1496  * Actual c class, derived from Type
1497  * @param rTypeName
1498  * Name to identify this faudes-type<; defaults to the plattform
1499  * dependand typeid from the c++ runtime type information system.
1500  * @return
1501  * Newly constructed type definition.
1502  *
1503  */
1504  template<class T>
1505  static TypeDefinition* Constructor(const std::string& rTypeName="");
1506 
1507  /**
1508  * Construct empty TypeDefinition object.
1509  * The given prototype is assigned to the member variable pType,
1510  *
1511  * @param pProto
1512  * Prototype, derived from Type
1513  * @param rTypeName
1514  * Name to identify this faudes-type<; defaults to the plattform
1515  * dependand typeid from the c++ runtime type information system.
1516  * @return
1517  * Newly constructed type definition.
1518  *
1519  */
1520  static TypeDefinition* Constructor(Type* pProto, const std::string& rTypeName="");
1521 
1522  /**
1523  * Construct TypeDefinition object and read name and
1524  * documentation-data from TokenReader.
1525  *
1526  * @tparam T
1527  * Actual c class, derived from Type
1528  * @param rFileName
1529  * Name of file to read.
1530  * @return
1531  * Newly constructed type definition.
1532  *
1533  * @exception Exception
1534  * - Token mismatch (id 50, 51, 52)
1535  * - IO Error (id 1)
1536  */
1537  template<class T>
1538  static TypeDefinition* FromFile(const std::string& rFileName);
1539 
1540 
1541  /**
1542  * Return pointer to faudes-object prototype
1543  *
1544  * Note: this method is meant for inspection only, control over
1545  * the prototype remains with the TypeDefinition. Use
1546  * NewObject() to instantiate a new faudes-object.
1547  *
1548  * @return
1549  * Reference to prototype object
1550  */
1551  const Type* Prototype(void) const;
1552 
1553 
1554  /**
1555  * Construct faudes-object on heap.
1556  * Return pointer to new instance of assigned Type class.
1557  *
1558  * Note: If no prototype is installed, NULL is returned.
1559  *
1560  * @return
1561  * Pointer to new Type instance.
1562  */
1563  Type* NewObject(void) const;
1564 
1565 
1566  /**
1567  * Parameter access: Xml Element Tag
1568  *
1569  * This parameter is used for Xml IO of sets and vectors. It determines
1570  * the tag to used for individual elments.
1571  *
1572  * @return
1573  * Tag parameter.
1574  */
1575  const std::string& XElementTag(void) const;
1576 
1577  /**
1578  * Parameter access: Xml Element Tag
1579  *
1580  * @param rTag
1581  * New tag parameter
1582  */
1583  void XElementTag(const std::string& rTag);
1584 
1585 protected:
1586 
1587 
1588  /**
1589  * Std faudes type interface: assignment.
1590  *
1591  * @param rSrc
1592  * Source to copy from
1593  * @return Reference to this object.
1594  */
1595  void DoAssign(const TypeDefinition& rSrc);
1596 
1597  /**
1598  * Std faudes type interface: test equality
1599  *
1600  * @param rOther
1601  * Other object to compare with.
1602  * @return
1603  * True on match.
1604  */
1605  bool DoEqual(const TypeDefinition& rOther) const;
1606 
1607  /** Disable copy constructor */
1608  TypeDefinition(const TypeDefinition& rOther) : Documentation(rOther) {}; // todo: implement ?? for stl maps ?
1609 
1610  /**
1611  * Clear documentation-data; do *NOT* delete prototype (this is for using Read to
1612  * merge/overwrite documentation)
1613  */
1614  void Clear(void);
1615 
1616  /**
1617  * Use given object as prototype.
1618  *
1619  * The TypeDefinition takes ownership of the
1620  * provided object.
1621  *
1622  * @param pType
1623  * Any class that inherits Type.
1624  */
1625  virtual void Prototype(Type* pType);
1626 
1627  /**
1628  * Read configuration data of this object from TokenReader.
1629  *
1630  * The section defaults to "TypeDefinition", context ignored.
1631  * Actual reading is done by DoReadCore.
1632  *
1633  * @param rTr
1634  * TokenReader to read from
1635  * @param rLabel
1636  * Section to read
1637  * @param pContext
1638  * Read context to provide contextual information (ignored)
1639  *
1640  * @exception Exception
1641  * - Token mismatch (id 50, 51, 52)
1642  * - IO error (id 1)
1643  */
1644  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
1645 
1646  /**
1647  * Read configuration data of this object from TokenReader.
1648  *
1649  * This method reads members only, it does not read the section.
1650  *
1651  * @param rTr
1652  * TokenReader to read from
1653  *
1654  * @exception Exception
1655  * - Token mismatch (id 50, 51, 52)
1656  * - IO error (id 1)
1657  */
1658  virtual void DoReadCore(TokenReader& rTr);
1659 
1660  /**
1661  * Write configuration data of this object to TokenWriter.
1662  *
1663  * The section defaults to "TypeDefinition", context ignored.
1664  * Actual writing is done by DoWriteCore.
1665  *
1666  * @param rTw
1667  * Reference to TokenWriter
1668  * @param rLabel
1669  * Label of section to write
1670  * @param pContext
1671  * Write context to provide contextual information
1672  *
1673  * @exception Exception
1674  * - IO errors (id 2)
1675  */
1676  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
1677 
1678  /**
1679  * Write configuration data of this object to TokenWriter.
1680  *
1681  * This method wrtite plain member data, the section lables are not
1682  * written.
1683  *
1684  * @param rTw
1685  * Reference to TokenWriter
1686  *
1687  * @exception Exception
1688  * - IO errors (id 2)
1689  */
1690  virtual void DoWriteCore(TokenWriter& rTw) const;
1691 
1692  /** Type-pointer tp prototype instance */
1694 
1695  /** Extra documentation/parameter: Xml Element Tag */
1696  std::string mXElementTag;
1697 
1698 }; //TypeDefinition
1699 
1700 
1701 
1702 
1703 /**********************************************************************************************
1704 ***********************************************************************************************
1705 ***********************************************************************************************
1706 
1707 Implemention of template members functions
1708 
1709 ***********************************************************************************************
1710 ***********************************************************************************************
1711 **********************************************************************************************/
1712 
1713 
1714 // Typedefinition constructor function
1715 template<class T>
1716 TypeDefinition* TypeDefinition::Constructor(const std::string& rTypeName){
1717  FD_DRTI("TypeDefinition::Construct<" << typeid(T).name() << ">(" << rTypeName << ")");
1718  return Constructor(new T, rTypeName);
1719 }
1720 
1721 
1722 // Type definition constructor function
1723 template<class T>
1724 TypeDefinition* TypeDefinition::FromFile(const std::string& rFileName){
1725  FD_DRTI("TypeDefinition::FromFile<" << typeid(T).name() << ">()");
1726  // construct with fallback name
1727  TypeDefinition* td = Constructor<T>();
1728  // read docu, incl actual name
1729  td->Read(rFileName);
1730  // done
1731  return(td);
1732 }
1733 
1734 
1735 
1736 
1737 
1738 } // namespace
1739 
1740 #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:81
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:1436
std::string mTextDoc
String containing the text-documentation.
Definition: cfl_types.h:1424
std::string mKeywords
Comma-seperated string containing all keywords.
Definition: cfl_types.h:1430
virtual ~Documentation(void)
Destructor.
Definition: cfl_types.h:1141
bool mApplicationRegistered
Flag to indicate application registration.
Definition: cfl_types.h:1439
std::string mCType
Corresponing C++ type, or "" if no such.
Definition: cfl_types.h:1421
std::string mHtmlDoc
String containing the filename of the corresponding html-documentation.
Definition: cfl_types.h:1427
std::string mName
Faudes name.
Definition: cfl_types.h:1415
std::string mPlugIn
Faudes plugin.
Definition: cfl_types.h:1418
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:53
A TypeDefinition defines a faudes-type in that it specifies a faudes-type name to identify the type a...
Definition: cfl_types.h:1462
Type * mpType
Type-pointer tp prototype instance.
Definition: cfl_types.h:1693
virtual ~TypeDefinition(void)
Destructor.
Definition: cfl_types.h:1487
static TypeDefinition * FromFile(const std::string &rFileName)
Construct TypeDefinition object and read name and documentation-data from TokenReader.
Definition: cfl_types.h:1724
TypeDefinition(const TypeDefinition &rOther)
Disable copy constructor.
Definition: cfl_types.h:1608
std::string mXElementTag
Extra documentation/parameter: Xml Element Tag.
Definition: cfl_types.h:1696
static TypeDefinition * Constructor(const std::string &rTypeName="")
Construct empty TypeDefinition object.
Definition: cfl_types.h:1716
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.32b --- 2024.03.01 --- c++ api documentaion by doxygen