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
5Copyright (C) 2009 Ruediger Berndt
6Copyright (C) 2010-2026 Thomas Moor
7
8This library is free software; you can redistribute it and/or
9modify it under the terms of the GNU Lesser General Public
10License as published by the Free Software Foundation; either
11version 2.1 of the License, or (at your option) any later version.
12
13This library is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public
19License along with this library; if not, write to the Free Software
20Foundation, 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
44namespace faudes {
45
46
47/************************************************
48 ************************************************
49 ************************************************/
50
51
52/**
53@defgroup RunTimeInterface Run-Time Interface
54@section RunTimeInterface Run-Time Interface
55
56The libFAUDES run-time interface (RTI) facilitates the development
57of applications that are transparent to libFAUDES extensions, e.g.,
58the libFAUDES version of the Lua interpreter luafaudes, the Python module
59faudes and the graphical user interface DESTool.
60
61The run-time interface provides a TypeRegistry for the application
62to instantiate objects by specifying their type as a std::string.
63The TypeRegistry is accompanied by the FunctionRegistry for
64the application to execute functions by their name. Thus, a libFAUDES
65application can query both registries and provide the
66supported types and functions to the user.
67The <a href="../reference/index.html">libFAUDES user-reference</a>
68is set up by the build system to represent the contents of both
69registries.
70
71The run-time interface is implemented
72by the following components:
73- base class faudes::Type for RTI enabled classes (faudes-types)
74- documentation class faudes::TypeDefinition to accompany faudes-types;
75- container class faudes::TypeRegistry to hold faudes::TypeDefintiion objects;
76- base class faudes::Function for RTI enabled function wrappers (faudes-functions);
77- documentation class faudes::FunctionDefinition to accompany faudes-functions;
78- container class faudes::FunctionRegistry to hold FunctionDefintiion objects.
79
80@subsection RunTimeInterfaceSec2 Faudes-Types
81
82Classes that participate in the run-time interface are referred to
83as faudes-types, instances are so called faudes-objects. Any faudes-type must
84be derived from the base class faudes::Type. A faudes-type inherits
85the convenience interface for token IO from Type, and, most relevent for the run-time
86interface, the factory function New(): each faudes-types must reimplement New()
87to allocate a new object of their respective type on heap. For a fully functional
88faudes-type, also an appropriate assignment operator and a copy constructor
89are required.
90
91
92@subsection RunTimeInterfaceSec3 Faudes-Type Definitions
93
94A faudes-type is accompanied by an instance of faudes::TypeDefinition. It holds
95a name (std::string) to identify the faudes-type,
96documentation (short text and html reference),
97and one faudes-object of the respective faudes-type.
98The latter is referred to as the prototype object and its New() method is used to construct
99new faudes-objects of the respective faudes-type. Thus, given a TypeDefinition,
100one can instantiate a corresponding faudes-object. To setup a
101TypeDefinition, you are meant to provide the faudes-type name, the protototype
102and a file from which to read the documentation.
103
104
105@subsection RunTimeInterfaceSec4 Faudes-Functions and Faudes-Function Definitions
106
107Functions that participate in the run-time interface are organized similar
108to faudes-types. There is a base class faudes::Function from which to derive
109particular faudes-functions. The base class provides an interface to set
110function parameter values and to actually execute the function on the parameters.
111To derive a class from Function, you must reimplement the methods New(), DoTypeCheck(),
112and DoExecute(). The DoTypeCheck() method is supposed to use a dynamic cast
113to initialize typed references to the function parameters. The DoExecute method
114then executes the function, typically by invoking a function via its
115C++ API. Each Function class is accompanied by a faudes::FunctionDefinition instance
116which holds a prototype, basic documentation and a list of valid signatures. Each signature
117represents a valid parameter type configurations in terms of faudes-types.
118
119@subsection RunTimeInterfaceSec5 Type- and Function-Registry
120
121The faudes::TypeRegistry and the faudes::FunctionRegistry are containers for TypeDefinition
122and FunctionDefinition instances, respectively. Applications access the registries via
123faudes-type names and faudes-function names, see e.g. the global functions NewObject() and
124NewFunction(). There is also in interface to iterate through the regsitries and
125to test for the existence of an entry. However, while both registries inherit the std token-io
126interface, neither registry can be fully configured by reading from file. This is because
127each entry requires not only data (documentation, signature, etc) but also a prototype
128instance. The std C++ run-time type information (RTTI) does not provide a mechanism
129to instantiate an object of a class that is specified at runtime. Thus, each protototype
130must be defined at compiletime. The global function LoadRegistry() is automatically
131set-up by the build system to gather all relevant prototypes, insert them in the
132registries and to subsequently read further documentation from a configuration
133file.
134
135@subsection RunTimeInterfaceSec6 RTI and the Build System
136
137At stage <tt>make configure</tt>, the build system sets up the function LoadRegistry()
138by
139- setting the macro FAUDES_PLUGINS_RTILOAD to a list of function calls in order to invoke
140 one load function per plugin;
141- running the tool <tt>rti2code</tt> to generate c code to register faudes-types and-functions
142 found in the configuration file ("libfaudes.rti").
143
144Code generation should work for all types and functions with documentation entry "CType()" specified.
145Since there is only one CType() entry, all signatures of a function must be implemented by a single
146c-function. The generated code is placed at "./include/rtiautoload.*". The build system also provides
147support to merge the configuration "libfaudes.rti" file from various sources, incl. plugins.
148
149To have your C++ class participate in the libFAUDES run-time interface:
150
151-# derive your class from faudes::Type;
152-# make sure your class has a public default constructor and a public copy constructor;
153-# use the provided macros to reimplement the virtual functions New(), NewCpy(), Cast(),
154 Copy(), Equal(), and the according operators =, == and !=;
155-# reimplement the virtual functions DoCopy(), DoEqual(), DoRead(), DoWrite() and Clear();
156-# optionally, reimplement the alternative output formats DoDWrite(), DoSWrite(), DoXWrite()
157-# provide an .rti file for the formal TypeDefinition;
158-# supplement your .rti file by an HTML formated documentation text;
159
160You will need to inspect and edit the main Makefile or your plugin's Makefile
161to advertise your additional sources. A <tt>make configure</tt> will then
162assemble all the bits and pieces.
163
164To have your C++ function participate in the libFAUDES run-time interface:
165
166-# make sure all your parameters are faudes-types (exceptions being
167 the elementary types bool, string and integer, which are converted automatically);
168-# provide an .rti file for the formal FunctionDefinition, advertise this file;
169 either in the main Makefile or in the Makefile of your plugin;
170-# supplement yout .rti file by an html formated documentation text;
171
172
173*/
174
175// forward
176class TypeDefinition;
177
178/**
179 * Base class of all libFAUDES objects that participate in
180 * the run-time interface. Eg, generator, alphabet, attributes etc.
181 * The class is designed to impose as little overhead as possible, and
182 * hence, does not hold any data. It does, however, provide a
183 * uniform interface for assignment, factory functions, and token IO.
184 * There is a tread-off in designing a common base class regarding features
185 * vs. overhead. We provide a comparatively light faudes::Type with minimal
186 * overhead and a more featured version faudes::FullType.
187 *
188 * We think of a faudes-typed object to be configured by defining
189 * data and, in due course, manipulated via its public interface
190 * by faudes-functions. Any faudes-type must provide a Clear() method that
191 * resets the object configuration to a unique default value.
192 * It is the configuration data that can be read from and written to token
193 * streams, and it is the configuration data that is used for assigments.
194 * Any additional data a faudes-typed object may host, is ignored by the
195 * interface inherited from the the base faudes::Type. Examples for such
196 * additional data is the unique id of a Generator, and the deferred copy
197 * pointers in faudes sets derived from faudes::TBaseSet.
198 *
199 * The faudes::Type assignment semantics are not meant to create exact copies
200 * of a given source object. Thogether with the uniquely defined default value,
201 * we can have assignments by both up- and downcasts. A faudes::Generator can be
202 * assigned from the derived faudes::System (a Generator with controllability
203 * attributes) by dropping the extra features. Vice versa, when a System is assigned
204 * from a plain Generator, any extra features take their respective default values.
205 * This relaxed interpretation of assignments is implemented by the method
206 * Copy(). The token format for file IO is organised in a similar fashion: any generator
207 * derivate can be configured from the token stream produced by any other generator class.
208 * In contrast, faudes-typed objects also implement an assignment operator
209 * that uses the standard C++ conventions.
210 *
211 * The following methods are used to implement the faudes::Type interface:
212 *
213 * - DoRead() to read the defining data from a token stream
214 * - DoWrite() to write the defining data to a token stream
215 * - DoXWrite() to write the defining data to a token stream in an alternative XML format
216 * - DoSWrite() and DoDWrite() for alternative output formats (statistical summary and debugging)
217 *
218 * - Name() to get/set the name of an optional (and purely cosmetic) object name
219 * - Clear() to reset all configuration data default,
220 * - IsDefault() test for default configuration data,
221 * - New() to construct an object of identical type on heap (factory method),
222 * - NewCpy() to construct an object of identical type and configuration on heap (factory method),
223 * - Cast() to dynamically cast another object to this type (type check method)
224 * - Copy() to do an assignment from any castable Type derivate
225 * - DoCopy(), or the operator "=", to assign from an object with identical type.
226 * - DoMove(), or the operator "=", for a destructive copy from an object with identical type.
227 * - Equal() to test relaxed equality with any castable Type derivate
228 * - DoEqual(), or the operators "==" and "!=", to test exact equality of configuration data
229 *
230 * In most cases, only Clear(), DoRead(), DoWrite(), DoCopy(), DoMove(), and DoEqual() need
231 * to be implemented manualy. The other methods can be declared and implemented by macros
232 * FAUDES_TYPE_DELARATION and FAUDES_TYPE_IMPLEMENTATION, respectively. The various
233 * attribute classes illustrate their ussage; see e.g. AttributeFlags.
234 *
235 *
236 *
237 * Note on token IO: In libFAUDES 2.16e, implementation of a new file format is prepared
238 * by the virtual function interface DoXWrite(). The intention is to better support advanced
239 * XML editors, in particular for configuration files. When implementing DoXWrite() for a
240 * derived class, make sure that DoRead() will gracefully accept tokens written by both DoWrite()
241 * and DoXWrite(), as a basis for a fileformat conversion tool. Future versions of libFAUDES will drop
242 * compatibility with the old token format, except for model data (generators, alphabets).
243 *
244 * @ingroup RunTimeInterface
245 */
246
248
249 public:
250
251 /** Constructor */
252 Type(void);
253
254 /** Copy constructor */
255 Type(const Type& rType);
256
257 /** Destructor */
258 virtual ~Type(void);
259
260 /**
261 * Construct on heap.
262 * Technically not a constructor, this function creates an object with the
263 * same type Type. New() is defined as a virtual function and derived
264 * classes are meant to re-implement with the appropiate constructor.
265 * This can be done via the provided macros FAUDES_TYPE_DECLARATION and
266 * FAUDES_TYPE_IMPLEMENTATION.
267 * As with new, it is the callers reponsabilty to delete the object when no longer needed.
268 *
269 * @return
270 * Pointer to new Type object
271 */
272 virtual Type* New(void) const;
273
274 /**
275 * Construct on heap.
276 * Technically not a constructor, this function creates an object with the
277 * same type Type and the same configuration. NewCpy() is defined as a virtual function and derived
278 * classes are meant to re-implement with the appropiate copy constructor.
279 * This can be done via the provided macros FAUDES_TYPE_DECLARATION and
280 * FAUDES_TYPE_IMPLEMENTATION.
281 * As with new, it is the callers reponsabilty to delete the object when no longer needed.
282 *
283 * @return
284 * Pointer to new Type object
285 */
286 virtual Type* NewCpy(void) const;
287
288 /**
289 * Cast other object to this type.
290 * Enables the run-time interface to test whether pObject is derived
291 * from this object. This feature is used e.g. in the faudes container
292 * classes to test attributes. Derived classes must reimplement this
293 * function using the appropriate dynamic cast.
294 *
295 * Re-implementation can be done via the convenience macros
296 * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
297 *
298 * @return
299 * Typed pointer object (NULL if the cast failed)
300 */
301 virtual const Type* Cast(const Type* pOther) const;
302
303 /**
304 * Clear configuration data to default. Derived classes should re-implement this
305 * method to ensure some consistent configuration data.
306 */
307 virtual void Clear(void);
308
309 /**
310 * Test for default configuration data. Derived classes may reimplement this
311 * conservatively, i.e., false negatives should be acceptable.
312 ^
313 * Note: should we refactor to IsClear[ed]()?
314 */
315 virtual bool IsDefault(void) const;
316
317 /**
318 * Copy configuration data from other object.
319 * Derived classes should reimplement this method to first try to cast
320 * the source to the respective class. If successful, the protected
321 * function DoCopy() is invoked to perform the actual assignment. If the cast fails,
322 * the Copy method of the parent class is called. Thus, faudes
323 * objects are up- and downcatsed for assignment, maintaining as much of
324 * the source data as digestable by the destination object.
325 *
326 * Re-implementation can be done via the convenience macros
327 * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
328 *
329 * @param rSrc
330 * Source to copy from
331 * @return Reference to this object.
332 */
333 virtual Type& Copy(const Type& rSrc);
334
335
336 /**
337 * Move configuration data from other object (destructive)
338 * Derived classes should reimplement this method to first try to cast
339 * the source to the respective class. If successful, the protected
340 * function DoMove is invoked to perform the actual assignment. If the cast fails,
341 * the Move method of the parent class is called. Thus, faudes
342 * objects are up- and downcatsed for assignment, maintaining as much of
343 * the source data as digestable by the destination object.
344 *
345 * Re-implementation can be done via the convenience macros
346 * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
347 *
348 * @param rSrc
349 * Source to copy from
350 * @return Reference to this object.
351 */
352 virtual Type& Move(Type& rSrc);
353
354
355 /**
356 * Copy configuration data from other object.
357 * Derived classes should implement at least the signature with matching source
358 * and destination types via the DoCopy method. Additionally, one may implement
359 * variants with a base class as source, as mong as meaningul assigment is possible.
360 *
361 * Re-implementation can be done via the convenience macros
362 * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
363 *
364 * @param rSrc
365 * Source to copy from
366 * @return Reference to this object.
367 */
368 Type& operator=(const Type& rSrc);
369
370 /**
371 * Copy configuration data from other object (destructive)
372 * Derived classes should implement at least the signature with matching source
373 * and destination types via the DoCopy method. Additionally, one may implement
374 * variants with a base class as source, as mong as meaningul assigment is possible.
375 *
376 * Re-implementation can be done via the convenience macros
377 * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
378 *
379 * @param rSrc
380 * Source to copy from
381 * @return Reference to this object.
382 */
383 Type& operator=(Type&& rSrc);
384
385 /**
386 * Test equality of configuration data.
387 * Derived classes should reimplement this method to return true
388 * if both actual types and configuration data match.
389 * The object name or id (if any) is not considered in the test.
390 *
391 * This method calls the virtual method DoEqual(). Re-implementation can
392 * be done via the convenience macros
393 * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
394 *
395 * @param rOther
396 * Other object to compare with.
397 * @return
398 * True on match.
399 */
400 virtual bool Equal(const Type& rOther) const;
401
402 /**
403 * Test equality of configuration data.
404 * The operator form of the equality test is only defined for matching
405 * types, no cast will be performed. Thus, the test will be optimistic
406 * if the type is not known at compiletime.
407 * The object name or id is not considered in the test.
408 *
409 * This operator calls DoEqual(). Re-implementation can
410 * be done via the convenience macros
411 * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
412 *
413 * @param rOther
414 * Other object to compare with.
415 * @return
416 * True on match.
417 */
418 bool operator==(const Type& rOther) const;
419
420
421 /**
422 * Test equality of configuration data.
423 * See operator==(const Type&).
424 *
425 * This operator calls DoEqual(). Re-implementation can
426 * be done via the convenience macros
427 * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
428 *
429 * @param rOther
430 * Other objevt to compare with.
431 * @return
432 * True on mismatch.
433 */
434 bool operator!=(const Type& rOther) const;
435
436
437 /**
438 * Set the objects's name.
439 *
440 * faudes::Type does not implement an object name,
441 * derivatives usually do so. See also faudes::Type.
442 *
443 * @param rName
444 * Name
445 */
446 virtual void Name(const std::string& rName);
447
448 /**
449 * Get objects's name.
450 *
451 * faudes::Type does not implement an object name,
452 * derivatives usually do so. See also faudes::Type.
453 *
454 * @return
455 * Name of object
456 */
457 virtual const std::string& Name(void) const;
458
459 /**
460 * Get objects's type name.
461 *
462 * Retrieve the faudes-type name from the type registry.
463 * This method silently returns the empty string if the type is
464 * not (yet) registered. The derived class faudes::Type implements
465 * a cache to avoid repeating the log-n lookup.
466 *
467 * @return
468 * Faudes-type name or empty string.
469 */
470 virtual const std::string& TypeName(void) const;
471
472 /**
473 * Write configuration data to console.
474 * Note: this write function uses the virtual function DoWrite(), to be
475 * reimplemented by derived classes.
476 *
477 * @param pContext
478 * Write context to provide contextual information
479 *
480 */
481 void Write(const Type* pContext=0) const;
482
483 /**
484 * Write configuration data to a file.
485 * Note: this write function uses the virtual function DoWrite(), to be
486 * reimplemented by derived classes.
487 *
488 * @param pFileName
489 * Name of file
490 * @param rLabel
491 * Label of section to write
492 * @param pContext
493 * Write context to provide contextual information
494 * @param openmode
495 * ios::openmode
496 *
497 * @exception Exception
498 * - IO errors (id 2)
499 */
500 void Write(const std::string& pFileName, const std::string& rLabel="",
501 const Type* pContext=0, std::ios::openmode openmode = std::ios::out|std::ios::trunc) const;
502
503 /**
504 * Write configuration data to a file.
505 * Note: this write function uses the virtual function DoWrite(), to be
506 * reimplemented by derived classes.
507 *
508 * @param pFileName
509 * Name of file
510 * @param openmode
511 * ios::openmode
512 *
513 * @exception Exception
514 * - IO errors (id 2)
515 */
516 void Write(const std::string& pFileName, std::ios::openmode openmode) const;
517
518 /**
519 * Write configuration data to TokenWriter.
520 * Note: this write function uses the virtual function DoWrite(), to be
521 * reimplemented by derived classes.
522 *
523 * @param rTw
524 * Reference to TokenWriter
525 * @param rLabel
526 * Label of section to write
527 * @param pContext
528 * Write context to provide contextual information
529 *
530 * @exception Exception
531 * - IO errors (id 2)
532 */
533 void Write(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
534
535 /**
536 * Write configuration data to an XML file.
537 * Note: this method uses the faudes type to set a DOCTYPE markup; for derived classes
538 * which do not report their faudes type, you should reimplement this
539 * function. Actual token io is done via DoXWrite().
540 *
541 * @param pFileName
542 * Name of file
543 * @param rLabel
544 * Label of section to write
545 * @param pContext
546 * Write context to provide contextual information
547 *
548 * @exception Exception
549 * - IO errors (id 2)
550 */
551 virtual void XWrite(const std::string& pFileName, const std::string& rLabel="",
552 const Type* pContext=0) const;
553
554 /**
555 * Write configuration data in XML format to concole
556 * Note: this write function uses the virtual function DoXWrite(), to be
557 * reimplemented by derived classes. No DOCTYPE markup will be written.
558 *
559 * @param pContext
560 * Write context to provide contextual information
561 *
562 */
563 void XWrite(const Type* pContext=0) const;
564
565 /**
566 * Write configuration data in XML format to TokenWriter.
567 * Note: this write function uses the virtual function DoXWrite(), to be
568 * reimplemented by derived classes.
569 *
570 * @param rTw
571 * Reference to TokenWriter
572 * @param rLabel
573 * Label of section to write
574 * @param pContext
575 * Write context to provide contextual information
576 *
577 * @exception Exception
578 * - IO errors (id 2)
579 */
580 void XWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
581
582 /**
583 * Write configuration data to a string.
584 * Note: this write function uses the virtual function DoWrite(), to be
585 * reimplemented by derived classes.
586 *
587 * @param rLabel
588 * Label of section to write
589 * @param pContext
590 * Write context to provide contextual information
591 * @return
592 * output string
593 * @exception Exception
594 * - IO errors (id 2)
595 */
596 std::string ToString(const std::string& rLabel="", const Type* pContext=0) const;
597
598 /**
599 * Write configuration data to a formated string.
600 * In contrast to ToString, ToText does not suppress comments and
601 * End-Of-Line marks.
602 * Note: this write function uses the virtual function DoWrite(), to be
603 * reimplemented by derived classes.
604 *
605 * @param rLabel
606 * Label of section to write
607 * @param pContext
608 * Write context to provide contextual information
609 * @return
610 * output string
611 * @exception Exception
612 * - IO errors (id 2)
613 */
614 std::string ToText(const std::string& rLabel="", const Type* pContext=0) const;
615
616 /**
617 * Write configuration data to console, debugging format.
618 * Note: this write function uses the virtual function DoDWrite(), to be
619 * reimplemented by derived classes.
620 *
621 * @param pContext
622 * Write context to provide contextual information
623 *
624 */
625 void DWrite(const Type* pContext=0) const;
626
627 /**
628 * Write configuration data to a file, debugging format.
629 * Note: this write function uses the virtual function DoDWrite(), to be
630 * reimplemented by derived classes.
631 *
632 * @param pFileName
633 * Name of file
634 * @param rLabel
635 * Label of section to write
636 * @param pContext
637 * Write context to provide contextual information
638 * @param openmode
639 * ios::openmode
640 *
641 * @exception Exception
642 * - IO errors (id 2)
643 */
644 void DWrite(const std::string& pFileName, const std::string& rLabel="",
645 const Type* pContext=0, std::ios::openmode openmode = std::ios::out|std::ios::trunc) const;
646
647 /**
648 * Write configuration data in debug format to TokenWriter.
649 * Note: this write function uses the virtual function DoWrite(), to be
650 * reimplemented by derived classes.
651 *
652 * @param rTw
653 * Reference to TokenWriter
654 * @param rLabel
655 * Label of section to write
656 * @param pContext
657 * Write context to provide contextual information
658 *
659 * @exception Exception
660 * - IO errors (id 2)
661 */
662 void DWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
663
664 /**
665 * Write statistics comment to TokenWriter.
666 * Note: this write function use the virtual function DoSWrite(), to be
667 * reimplemented by derived classes.
668 *
669 * @param rTw
670 * Reference to TokenWriter
671 *
672 * @exception Exception
673 * - IO errors (id 2)
674 */
675 void SWrite(TokenWriter& rTw) const;
676
677 /**
678 * Write statistics comment to console.
679 * Note: this write function uses the virtual function DoSWrite(), to be
680 * reimplemented by derived classes.
681 *
682 */
683 void SWrite(void) const;
684
685 /**
686 * Write statistics to a string.
687 * Note: this write function uses the virtual function DoSWrite(), to be
688 * reimplemented by derived classes.
689 *
690 * @return
691 * output string
692 * @exception Exception
693 * - IO errors (id 2)
694 */
695 std::string ToSText(void) const;
696
697 /**
698 * Read configuration data from file with label specified.
699 * Note: all read functions use the virtual function DoRead(), to be
700 * reimplemented for by derived classes.
701 *
702 * @param rFileName
703 * Name of file
704 * @param rLabel
705 * Section to read from
706 * @param pContext
707 * Read context to provide contextual information
708 *
709 * @exception Exception
710 * - IO errors (id 1)
711 * - token mismatch from DoRead()
712 */
713 void Read(const std::string& rFileName, const std::string& rLabel = "", const Type* pContext=0);
714
715 /**
716 * Read configuration data from TokenReader with label sepcified.
717 * Note: all read functions use the virtual function DoRead(), to be
718 * reimplemented for by derived classes.
719 *
720 * @param rTr
721 * Reference to tokenreader
722 * @param rLabel
723 * Section to read
724 * @param pContext
725 * Read context to provide contextual information
726 *
727 * @exception Exception
728 * - IO errors (id 1)
729 * - token mismatch from DoRead()
730 */
731 void Read(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
732
733
734 /**
735 * Read configuration data from a string.
736 * Note: this read function uses the virtual function DoRead(), to be
737 * reimplemented by derived classes.
738 *
739 * @param rString
740 * String to read from
741 * @param rLabel
742 * Section to read
743 * @param pContext
744 * Read context to provide contextual information
745 * @exception Exception
746 * - IO errors (id 1)
747 * - token mismatch from DoRead()
748 */
749 void FromString(const std::string& rString, const std::string& rLabel="", const Type* pContext=0);
750
751 protected:
752
753 /**
754 * Copy configuration data from other object.
755 *
756 * Reimplement this function to copy all configuration data from
757 * another faudes object. Typically, you will first call the base class'
758 * DoCopy, which includes a Clear(). Then, you will set up any additional members.
759 *
760 * @param rSrc
761 * Source to copy from
762 */
763 void DoCopy(const Type& rSrc);
764
765 /**
766 * Copy configuration data from other object (destructive)
767 *
768 * Reimplement this function to copy implement a destructive copy. If not reimplemented,
769 * defaults to DoCopy();
770 *
771 * @param rSrc
772 * Source to copy from
773 */
774 void DoMove(Type& rSrc);
775
776 /**
777 * Test equality of configuration data.
778 * Derived classes should reimplement this method to compare all relevant
779 * configuration, except the name.
780 *
781 * @param rOther
782 * Other object to compare with.
783 * @return
784 * True on match.
785 */
786 bool DoEqual(const Type& rOther) const;
787
788
789 /**
790 * Read configuration data of this object from TokenReader.
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 rTr
796 * TokenReader to read from
797 * @param rLabel
798 * Section to read
799 * @param pContext
800 * Read context to provide contextual information
801 *
802 * @exception Exception
803 * - IO error (id 1)
804 */
805 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
806
807 /**
808 * Write configuration data of this object 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 * @param rLabel
816 * Label of section to write
817 * @param pContext
818 * Write context to provide contextual information
819 *
820 * @exception Exception
821 * - IO errors (id 2)
822 */
823 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
824
825 /**
826 * Write configuration data of this object to TokenWriter in XML format.
827 *
828 * Reimplement this method in derived classes to provide the XML
829 * token io interface defined in the public section of Type. The default implementation
830 * invokes the std token output via
831 * DoWrite(TokenWriter&, const std::string&,const Type* )
832 *
833 * @param rTw
834 * Reference to TokenWriter
835 * @param rLabel
836 * Label of section to write
837 * @param pContext
838 * Write context to provide contextual information
839 *
840 * @exception Exception
841 * - IO errors (id 2)
842 */
843 virtual void DoXWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
844
845 /**
846 * Write configuration data in debugging format to TokenWriter.
847 *
848 * Reimplement this method in derived classes to provide the std token io
849 * interface defined in the public section of Type.
850 *
851 * @param rTw
852 * Reference to TokenWriter
853 * @param rLabel
854 * Label of section to write
855 * @param pContext
856 * Write context to provide contextual information
857 *
858 * @exception Exception
859 * - IO errors (id 2)
860 */
861 virtual void DoDWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
862
863 /**
864 * Write statistical data as a comment to TokenWriter.
865 *
866 * Reimplement this method in derived classes to provide the std token io
867 * interface defined in the public section of Type.
868 *
869 * @param rTw
870 * Reference to TokenWriter
871 *
872 * @exception Exception
873 * - IO errors (id 2)
874 */
875 virtual void DoSWrite(TokenWriter& rTw) const;
876
877 /**
878 * Get objects's type definition.
879 *
880 * Returns the type definition corresponding to this object, or
881 * NULL if the object is not of a registered type.
882 *
883 * Technical note: for minimal memory requirement, the type definition
884 * is not cached but retrieved on every invokation of this method.
885 * The derived class faudes::Type introduces a cache.
886 *
887 * @return
888 * Type definition reference.
889 */
890 virtual const TypeDefinition* TypeDefinitionp(void) const;
891
892
893 /*
894 * Convenience function to set up std begin token
895 * for XML mode token I/O.
896 *
897 * @param rLabel
898 * User specified label
899 * @param rFallbackLabel
900 * Class defined fallback label
901 * @return
902 * Configured begin token
903 */
904 virtual Token XBeginTag(const std::string& rLabel="", const std::string& rFallbackLabel="") const;
905
906
907private:
908
909 // static string constant.
910 static std::string msStringVoid;
911 static std::string msStringEmpty;
912
913};
914
915
916
917/** faudes type declaration macro */
918#define FAUDES_TYPE_DECLARATION(ftype,ctype,cbase) \
919 public: virtual ctype* New(void) const; \
920 public: virtual ctype* NewCpy(void) const; \
921 public: virtual const Type* Cast(const Type* pOther) const; \
922 public: virtual ctype& Copy(const Type& rSrc); \
923 public: virtual ctype& Move(Type& rSrc); \
924 public: virtual bool Equal(const Type& rOther) const; \
925 public: ctype& operator=(const ctype& rSrc); \
926 public: ctype& operator=(ctype&& rSrc); \
927 public: bool operator==(const ctype& rOther) const; \
928 public: bool operator!=(const ctype& rOther) const;
929
930/** faudes type declaration macro, template version */
931#define FAUDES_TYPE_TDECLARATION(ftype,ctype,cbase) \
932 public: virtual ctype* New(void) const; \
933 public: virtual ctype* NewCpy(void) const; \
934 public: virtual const Type* Cast(const Type* pOther) const; \
935 public: virtual ctype& Copy(const Type& rSrc); \
936 public: virtual ctype& Move(Type& rSrc); \
937 public: virtual bool Equal(const Type& rOther) const; \
938 public: ctype& operator=(const ctype& rSrc); \
939 public: ctype& operator=(ctype&& rSrc); \
940 public: bool operator==(const ctype& rOther) const; \
941 public: bool operator!=(const ctype& rOther) const;
942
943/** faudes type implementation macros */
944#define FAUDES_TYPE_IMPLEMENTATION_NEW(ftype,ctype,cbase) \
945 ctype* ctype::New(void) const { return new ctype(); }
946#define FAUDES_TYPE_IMPLEMENTATION_NEWCOPY(ftype,ctype,cbase) \
947 ctype* ctype::NewCpy(void) const { return new ctype(*this); }
948#define FAUDES_TYPE_IMPLEMENTATION_CAST(ftype,ctype,cbase) \
949 const Type* ctype::Cast(const Type* pOther) const { \
950 return dynamic_cast< const ctype * >(pOther); }
951#define FAUDES_TYPE_IMPLEMENTATION_ASSIGN(ftype,ctype,cbase) \
952 ctype& ctype::Copy(const Type& rSrc) { \
953 if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
954 DoCopy(*csattr);} \
955 else { \
956 cbase::Copy(rSrc);}; \
957 return *this;} \
958 ctype& ctype::operator=(const ctype& rSrc) { DoCopy(rSrc); return *this; }
959#define FAUDES_TYPE_IMPLEMENTATION_MOVE(ftype,ctype,cbase) \
960 ctype& ctype::Move(Type& rSrc) { \
961 if(ctype* csattr=dynamic_cast< ctype * >(&rSrc)) { \
962 DoMove(*csattr);} \
963 else { \
964 cbase::Move(rSrc);}; \
965 return *this;} \
966 ctype& ctype::operator=(ctype&& rSrc) { DoMove(rSrc); return *this; }
967#define FAUDES_TYPE_IMPLEMENTATION_EQUAL(ftype,ctype,cbase) \
968 bool ctype::Equal(const Type& rOther) const { \
969 if(&rOther==this) return true; \
970 if(typeid(rOther) != typeid(*this)) return false; \
971 const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
972 if(!csattr) return false; \
973 if(!DoEqual(*csattr)) return false; \
974 return true;} \
975 bool ctype::operator==(const ctype& rOther) const { return DoEqual(rOther); } \
976 bool ctype::operator!=(const ctype& rOther) const { return !DoEqual(rOther); }
977
978/** faudes type implementation macros, template version */
979#define FAUDES_TYPE_TIMPLEMENTATION_NEW(ftype,ctype,cbase,ctemp) \
980 ctemp ctype* ctype::New(void) const { \
981 return new ctype(); }
982#define FAUDES_TYPE_TIMPLEMENTATION_NEWCOPY(ftype,ctype,cbase,ctemp) \
983 ctemp ctype* ctype::NewCpy(void) const { \
984 return new ctype(*this); }
985#define FAUDES_TYPE_TIMPLEMENTATION_CAST(ftype,ctype,cbase,ctemp) \
986 ctemp const Type* ctype::Cast(const Type* pOther) const { \
987 return dynamic_cast< const ctype * >(pOther); }
988#define FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(ftype,ctype,cbase,ctemp) \
989 ctemp ctype& ctype::Copy(const Type& rSrc) { \
990 if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
991 DoCopy(*csattr);} \
992 else { \
993 cbase::Copy(rSrc);}; \
994 return *this;} \
995 ctemp ctype& ctype::operator=(const ctype& rSrc) { DoCopy(rSrc); return *this; }
996#define FAUDES_TYPE_TIMPLEMENTATION_MOVE(ftype,ctype,cbase,ctemp) \
997 ctemp ctype& ctype::Move(Type& rSrc) { \
998 if(ctype* csattr=dynamic_cast< ctype * >(&rSrc)) { \
999 DoMove(*csattr);} \
1000 else { \
1001 cbase::Move(rSrc);}; \
1002 return *this;} \
1003 ctemp ctype& ctype::operator=(ctype&& rSrc) { DoMove(rSrc); return *this; }
1004#define FAUDES_TYPE_TIMPLEMENTATION_EQUAL(ftype,ctype,cbase,ctemp) \
1005 ctemp bool ctype::Equal(const Type& rOther) const { \
1006 if(&rOther==this) return true; \
1007 if(typeid(rOther) != typeid(*this)) return false; \
1008 const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
1009 if(!csattr) return false; \
1010 if(!DoEqual(*csattr)) return false; \
1011 return true;} \
1012 ctemp bool ctype::operator==(const ctype& rOther) const { return DoEqual(rOther); } \
1013 ctemp bool ctype::operator!=(const ctype& rOther) const { return !DoEqual(rOther); }
1014
1015
1016/** faudes type implementation macros, overall */
1017#define FAUDES_TYPE_IMPLEMENTATION(ftype,ctype,cbase) \
1018 ctype* ctype::New(void) const { \
1019 return new ctype(); } \
1020 ctype* ctype::NewCpy(void) const { \
1021 return new ctype(*this); } \
1022 const Type* ctype::Cast(const Type* pOther) const { \
1023 return dynamic_cast< const ctype * >(pOther); } \
1024 ctype& ctype::Copy(const Type& rSrc) { \
1025 if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
1026 this->DoCopy(*csattr);} \
1027 else { \
1028 cbase::Copy(rSrc);}; \
1029 return *this;} \
1030 ctype& ctype::operator=(const ctype& rSrc) { this->DoCopy(rSrc); return *this; } \
1031 ctype& ctype::Move(Type& rSrc) { \
1032 if(ctype* csattr=dynamic_cast< ctype * >(&rSrc)) { \
1033 this->DoMove(*csattr);} \
1034 else { \
1035 cbase::Move(rSrc);}; \
1036 return *this;} \
1037 ctype& ctype::operator=(ctype&& rSrc) { this->DoMove(rSrc); return *this; } \
1038 bool ctype::Equal(const Type& rOther) const { \
1039 if(&rOther==this) return true; \
1040 if(typeid(rOther) != typeid(*this)) return false; \
1041 const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
1042 if(!csattr) return false; \
1043 if(!this->DoEqual(*csattr)) return false; \
1044 return true;} \
1045 bool ctype::operator==(const ctype& rOther) const { return this->DoEqual(rOther); } \
1046 bool ctype::operator!=(const ctype& rOther) const { return !this->DoEqual(rOther); }
1047
1048
1049/** faudes type implementation macros, overall */
1050#define FAUDES_TYPE_TIMPLEMENTATION(ftype,ctype,cbase,ctemp) \
1051 ctemp ctype* ctype::New(void) const { \
1052 return new ctype(); } \
1053 ctemp ctype* ctype::NewCpy(void) const { \
1054 return new ctype(*this); } \
1055 ctemp const Type* ctype::Cast(const Type* pOther) const { \
1056 return dynamic_cast< const ctype * >(pOther); } \
1057 ctemp ctype& ctype::Copy(const Type& rSrc) { \
1058 if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
1059 /* this->Clear(); */ this->DoCopy(*csattr);} \
1060 else { \
1061 cbase::Copy(rSrc);}; \
1062 return *this;} \
1063 ctemp ctype& ctype::operator=(const ctype& rSrc) { this->DoCopy(rSrc); return *this; } \
1064 ctemp ctype& ctype::Move(Type& rSrc) { \
1065 if(ctype* csattr=dynamic_cast< ctype * >(&rSrc)) { \
1066 this->DoMove(*csattr);} \
1067 else { \
1068 cbase::Move(rSrc);}; \
1069 return *this;} \
1070 ctemp ctype& ctype::operator=(ctype&& rSrc) { this->DoMove(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/**
1083 * Wrapper for dynamivc_cast<Type*>() that returns a nullptr when the argument is not a
1084 * polymorphic class (instead of a compile-time error). See TBaseSet::DoWrite() for the
1085 * use case that triggered this wrapper.
1086 */
1087template<class T, bool = std::is_polymorphic<T>::value>
1089};
1090template<class T>
1091class CastToType<T, true> {
1092public:
1093 static Type* Pointer(T* ptr) {return dynamic_cast<Type*>(ptr);};
1094 static const Type* ConstPointer(const T* ptr) {return dynamic_cast<const Type*>(ptr);};
1095};
1096template<class T>
1097 class CastToType<T,false> {
1098public:
1099 static Type* Pointer(T* ptr) {(void) ptr; return nullptr;};
1100 static const Type* ConstPointer(const T* ptr) {(void) ptr; return nullptr;};
1101};
1102
1103
1104
1105/**
1106 * Extended Type to base Attributes. Attributes are used as template parameters for
1107 * faudes containers and facilitate the modelling of customized properties of events,
1108 * states and transitions. See the class faudes::AttributeFlags for a non-trivial example.
1109 *
1110 * To derive a class from faudes::AttrType you should reimplement the virtual
1111 * interface
1112 * - virtual methods DoRead and DoWrite for token io (as in faudes::Type)
1113 * - virtual methods for DoCopy() (as in faudes::Type)
1114 * - the factory method New() (use provided macro from faudes::Type)
1115 * - the rti typecast method Cast() (use provided macro from faudes::Type)
1116 * - user level Copy() method (use provided macro from faudes::Type)
1117 * Use the FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION macros to generate
1118 * the API methods.
1119 *
1120 * The class faudes::AttrType extends the base Type marginally to distinguish void attributes
1121 * from plain type objects; i.e., we introduce a marker in the type hierarchy. There is (almost)
1122 * nothing functional about this class and we should find ways to go without.
1123 *
1124 * @ingroup RunTimeInterface
1125 */
1126
1127
1128class FAUDES_API AttrType : public Type {
1129
1131
1132public:
1133
1134 using Type::operator=;
1135 using Type::operator==;
1136 using Type::operator!=;
1137
1138 /** Constructor */
1139 AttrType(void);
1140
1141 /** Copy Constructor */
1142 AttrType(const AttrType& rSrc);
1143
1144 /** Destructor */
1145 virtual ~AttrType(void);
1146
1147 /** Test for default value. */
1148 virtual bool IsDefault(void) const {return true;};
1149
1150 /**
1151 * Skip attribute tokens.
1152 *
1153 * Helper method to be called after all sttribute derived classes had their
1154 * chance to read their data. It skips all tokens and sections until it reaches a
1155 * String or decimal Integer. This should go to BaseSet.
1156 *
1157 * @param rTr
1158 * TokenReader to read from
1159 * @exception Exception
1160 * - IO error (id 1)
1161 */
1162 static void Skip(TokenReader& rTr);
1163
1164 /**
1165 * Pretty print.
1166 *
1167 * Reimplement for subclasses to produce concise human readable representation
1168 *
1169 */
1170 virtual std::string Str(void) const;
1171
1172protected:
1173
1174 /** Copy (no members, dummy) */
1175 void DoCopy(const AttrType& rSrc) { (void) rSrc; };
1176
1177 /** Test (no members, dummy) */
1178 bool DoEqual(const AttrType& rOther) const { (void) rOther; return true; }
1179
1180};
1181
1182
1183/**
1184 * This class extends the base Type by common features worthwhile for "large objects",
1185 * e.g., object name, a cache for the regsitry record and convenience access wrappers.
1186 *
1187 * @ingroup RunTimeInterface
1188 */
1189
1190 class FAUDES_API ExtType : public AttrType {
1191
1192public:
1193
1194 using AttrType::operator=;
1195 using AttrType::operator==;
1196 using AttrType::operator!=;
1197
1198
1199 // std faudes type interface
1201
1202 /** Constructor */
1203 ExtType(void);
1204
1205 /** Copy constructor */
1206 ExtType(const ExtType& rType);
1207
1208 /** Destructor */
1209 virtual ~ExtType(void);
1210
1211 /**
1212 * Get objects name
1213 *
1214 * @return
1215 * Name
1216 */
1217 const std::string& Name(void) const;
1218
1219 /**
1220 * Set objects name
1221 *
1222 * @param rName
1223 * Name to set
1224 */
1225 void Name(const std::string& rName);
1226
1227
1228 /**
1229 * Get objects's type name.
1230 *
1231 * Retrieve the faudes-type name from the type registry.
1232 *
1233 * @return
1234 * Faudes-type name or empty string.
1235 */
1236 virtual const std::string& TypeName(void) const;
1237
1238 /**
1239 * Overwrite faudes-type name.
1240 *
1241 * This method is used to overwrite the faudes-type identifyer to account for
1242 * unregistered classe/
1243 *
1244 * @param rType
1245 * Faudes-type name to set
1246 */
1247 virtual void TypeName(const std::string& rType);
1248
1249 /**
1250 * Get the element name tag.
1251 *
1252 * Tags used for XML IO when eriting elements of a container class.
1253 * This is either the deribeved class default of found in the registry.
1254 *
1255 * @return
1256 * Tag
1257 */
1258 virtual const std::string& ElementTag(void) const;
1259 /**
1260 * Configure the element name tag.
1261 *
1262 * This method allows to overwrite the tag used for elements
1263 * in XML IO. For usual, you will register derived classes with
1264 * the run-time-interface and set the elemen tag for XML IO.
1265 *
1266 * @param rTag
1267 * Tag to set
1268 */
1269 virtual void ElementTag(const std::string& rTag);
1270
1271 /**
1272 * Get the element type.
1273 *
1274 * This should be found in the registry.
1275 *
1276 * @return
1277 * Tag
1278 */
1279 virtual const std::string& ElementType(void) const;
1280
1281 /**
1282 * Get registry record
1283 *
1284 * Returns nullptr if not registered
1285 *
1286 * @return
1287 * Pointer to registry entry
1288 */
1289 virtual const TypeDefinition* TypeDefinitionp(void) const;
1290
1291
1292private:
1293
1294 /** TypeDefinition cache (should use guarded pointer here) */
1296
1297 /** Current/cached faudes type-name */
1298 std::string mFaudesTypeName;
1299
1300 /** Current/cached name of elements (use protected accessor methods for caching) */
1301 std::string mElementTag;
1302
1303protected:
1304
1305 /**
1306 * Write statistical data as a comment to TokenWriter.
1307 *
1308 * An ExtType can at least report the object type and name
1309 *
1310 * @param rTw
1311 * Reference to TokenWriter
1312 *
1313 * @exception Exception
1314 * - IO errors (id 2)
1315 */
1316 virtual void DoSWrite(TokenWriter& rTw) const;
1317
1318 /** Current/cached name of elements (use protected accessor methods for caching) */
1319 std::string mElementType;
1320
1321 /** Defauft name of elements (if not over written manually or by registry) */
1322 std::string mElementTagDef;
1323
1324 /** object name */
1325 std::string mObjectName;
1326};
1327
1328
1329
1330
1331/**
1332 * Structure to hold documentation data relating to a faudes-type or -function.
1333 * This class is the common base for faudes::TypeDefinition and faudes::FunctionDefinition.
1334 * It supports token io as demonstrated by the follwoing example for a type defintion:
1335 *
1336 * @code
1337 * <TypeDefinition name="CoreFaudes::Generator" ctype="faudes::Generator">
1338 *
1339 * <Documentation ref="generators.html#plain">
1340 * The common 5 tuple G=(Sigma, Q, delta, Qo, Qm).
1341 * <Documentation/>
1342 *
1343 * <Keywords> "generator" "language" </Keywords>
1344 *
1345 * </TypeDefinition>
1346 * @endcode
1347 *
1348 * Technical detail: Documentation is derived from Type for the purpose of token IO. We
1349 * still implement the faudes type interface to make it a fully qualified faudes data type.
1350 *
1351 * Technical detail: To facilitate inheritance, token io of member data and token io of
1352 * the section tags is separated.
1353 */
1354
1356
1357 // std faudes type interface
1359
1360public:
1361
1362 using Type::operator=;
1363 using Type::operator==;
1364 using Type::operator!=;
1365
1366
1367 /** Constructor */
1368 Documentation(void);
1369
1370 /** Copy constructor */
1371 Documentation(const Documentation& rOther);
1372
1373 /** Destructor */
1374 virtual ~Documentation(void){};
1375
1376 /**
1377 * Clear
1378 */
1379 void Clear(void);
1380
1381 /**
1382 * Get name of the entity to document (aka faudes-type or faudes-function).
1383 *
1384 * @return
1385 * Name
1386 */
1387 const std::string& Name(void) const;
1388
1389 /**
1390 * Get name of plugin.
1391 * The plugin name defaults to CoreFaudes.
1392 *
1393 * @return
1394 * Name
1395 */
1396 const std::string& PlugIn(void) const;
1397
1398 /**
1399 * Get corresponding C++ type
1400 *
1401 * @return
1402 * CType, or "" if no such
1403 */
1404 const std::string& CType(void) const;
1405
1406 /**
1407 * @return
1408 * Short textual documentation.
1409 */
1410 const std::string& TextDoc(void) const;
1411
1412 /**
1413 * @return
1414 * Filename pointing to the html documentation.
1415 */
1416 const std::string& HtmlDoc(void) const;
1417
1418 /**
1419 * @return
1420 * CSV-string containing keywords.
1421 */
1422 const std::string& Keywords(void) const;
1423
1424 /**
1425 * Search comma-seperated keywords for a substring. This should be
1426 * extended to regular expressions in a future release.
1427 *
1428 * @param rPattern
1429 * String-pattern.
1430 *
1431 * @return
1432 * Matching keyword or "" if no match
1433 */
1434 std::string MatchKeyword(const std::string& rPattern) const;
1435
1436 /**
1437 * Not implemented
1438 * @return
1439 * Number of keywords.
1440 */
1441 int KeywordsSize(void) const;
1442
1443 /**
1444 * @param pos
1445 * Position of keyword
1446 * @return
1447 * Keyword at specified position (or "" if pos out of range)
1448 */
1449 std::string KeywordAt(int pos) const;
1450
1451 /**
1452 * Get auto-register flag.
1453 *
1454 * This flag indicated that the respective type was (will be)
1455 * registered by a libFAUDES static initialisation protorype.
1456 *
1457 * @return
1458 * True <> C++-automatic-registration
1459 */
1460 bool AutoRegistered(void) const;
1461
1462 /**
1463 * Get application-registered flag.
1464 *
1465 * @return
1466 * True <> registered by application
1467 */
1468 bool ApplicationRegistered(void) const;
1469
1470 /**
1471 * Merge documentation from token stream.
1472 * An exception is thrown if the current type name differs from the one in the documentation.
1473 *
1474 * @param rTr
1475 * TokenReader to read from.
1476 *
1477 * @exception Exception
1478 * - Type mismatch (id )
1479 * - Token mismatch (id 50, 51, 52)
1480 * - IO Error (id 1)
1481 */
1482 virtual void MergeDocumentation(TokenReader& rTr);
1483
1484
1485
1486 protected:
1487
1488 /**
1489 * Set name.
1490 *
1491 * @param name
1492 * New name.
1493 */
1494 void Name(const std::string& name);
1495
1496 /**
1497 * Set name of plugin
1498 *
1499 * @param plugin
1500 * New name.
1501 */
1502 void PlugIn(const std::string& plugin);
1503
1504 /**
1505 * Set C++ type
1506 *
1507 * @param name
1508 * New ctype.
1509 */
1510 void CType(const std::string& name);
1511
1512 /**
1513 * Set a short textual documentation.
1514 *
1515 * @param textdoc
1516 * New textual documentation.
1517 */
1518 void TextDoc(const std::string& textdoc);
1519
1520 /**
1521 * Set auto-register flag.
1522 *
1523 * See also AutoRegistered(void)
1524 *
1525 * @param flag
1526 * Flag value.
1527 */
1528 void AutoRegistered(bool flag);
1529
1530 /**
1531 * Set application-registered flag.
1532 *
1533 * See also AutoRegistered(void)
1534 *
1535 * @param flag
1536 * Flag value.
1537 */
1538 void ApplicationRegistered(bool flag);
1539
1540 /**
1541 * Set name of file pointing to the html documentation.
1542 *
1543 * @param fname
1544 * Filename
1545 */
1546 void HtmlDoc(const std::string& fname);
1547
1548 /**
1549 * Append keyword.
1550 *
1551 * @param rKeyword
1552 * Keyword
1553 */
1554 void AddKeyword(const std::string& rKeyword);
1555
1556 /**
1557 * Std faudes type interface: assignment.
1558 *
1559 * @param rSrc
1560 * Source to copy from
1561 */
1562 void DoCopy(const Documentation& rSrc);
1563
1564 /**
1565 * Std faudes type interface: test equality
1566 *
1567 * @param rOther
1568 * Other object to compare with.
1569 * @return
1570 * True on match.
1571 */
1572 bool DoEqual(const Documentation& rOther) const;
1573
1574 /**
1575 * Read configuration data of this object from TokenReader.
1576 *
1577 * This virtual function reads documentation from a token stream.
1578 * The section defaults to Documentation. It invokes DoReadCore to
1579 * do the member data token reading.
1580 *
1581 * @param rTr
1582 * TokenReader to read from
1583 * @param rLabel
1584 * Section to read
1585 * @param pContext
1586 * Read context to provide contextual information (ignored)
1587 *
1588 * @exception Exception
1589 * - Token mismatch (id 50, 51, 52)
1590 * - IO Error (id 1)
1591 */
1592 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
1593
1594 /**
1595 * Read configuration data of this object from TokenReader.
1596 *
1597 * This virtual function reads documentation member data only.
1598 * It does NOT read the enclosing begin and end tokens.
1599 *
1600 * @param rTr
1601 * TokenReader to read from
1602 *
1603 * @exception Exception
1604 * - Token mismatch (id 50, 51, 52)
1605 * - IO Error (id 1)
1606 */
1607 virtual void DoReadCore(TokenReader& rTr);
1608
1609
1610
1611 /**
1612 * Write configuration data of this object to TokenWriter.
1613 *
1614 * This virtual function writes documentation to a token stream.
1615 * The section defaults to Documentation. It invokes DoWriteCore to
1616 * do the actual member data writing.
1617 *
1618 * @param rTw
1619 * Reference to TokenWriter
1620 * @param rLabel
1621 * Label of section to write
1622 * @param pContext
1623 * Write context to provide contextual information
1624 *
1625 * @exception Exception
1626 * - IO errors (id 2)
1627 */
1628 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
1629
1630
1631 /**
1632 * Write configuration data of this object to TokenWriter.
1633 *
1634 * This virtual function reads documentation members only.
1635 * It does NOT write enclosing begin and end tokens.
1636 *
1637 * @param rTw
1638 * Reference to TokenWriter
1639 *
1640 * @exception Exception
1641 * - IO errors (id 2)
1642 */
1643 virtual void DoWriteCore(TokenWriter& rTw) const;
1644
1645
1646 /** Faudes name. */
1647 std::string mName;
1648
1649 /** Faudes plugin. */
1650 std::string mPlugIn;
1651
1652 /** Corresponing C++ type, or "" if no such. */
1653 std::string mCType;
1654
1655 /** String containing the text-documentation. */
1656 std::string mTextDoc;
1657
1658 /** String containing the filename of the corresponding html-documentation. */
1659 std::string mHtmlDoc;
1660
1661 /** Comma-seperated string containing all keywords. */
1662 std::string mKeywords;
1663
1664 /** Constant characted used to seperate keywords */
1665 static const char mDelim = ';';
1666
1667 /** Flag to indicate automated registration */
1669
1670 /** Flag to indicate application registration */
1672
1673}; // Documentation
1674
1675
1676
1677/**
1678 * A TypeDefinition defines a faudes-type in that it specifies
1679 * a faudes-type name to identify the type and a method
1680 * NewObject() to instantiate objects of the respective type.
1681 * In this sense, TypeDefinition is a so called factory class.
1682 * Technically, the TypeDefinition holds one instance of the faude type,
1683 * the so called prototype object, and NewObject() invokes the New() method
1684 * of the prototype. Notebly, there is only one class TypeDefinition that by
1685 * parametrisation defins all derivates of Type.
1686 *
1687 * TypeDefinition is derived from faudes::Documentation and therefore additional
1688 * documentation-data can be associated.
1689 *
1690 *
1691 * @ingroup RunTimeInterface
1692 */
1693
1695
1696 // std faudes type interface
1698
1699 // regisry is friend to set protected values
1700 friend class TypeRegistry;
1701
1702 public:
1703
1704 using Documentation::operator=;
1705 using Documentation::operator==;
1706 using Documentation::operator!=;
1707
1708 /**
1709 * Constructor
1710 *
1711 * The default constructor instantiates an invalid type definition
1712 * without prototype. To construct
1713 * a valid type definition, use the static Constructor() template
1714 * function.
1715 */
1716 TypeDefinition(const std::string& name="") : Documentation(), mpType(NULL) {Name(name);};
1717
1718 /**
1719 * Destructor.
1720 *
1721 * Delete prototype object.
1722 */
1723 virtual ~TypeDefinition(void){ Prototype(NULL); };
1724
1725 /**
1726 * Construct empty TypeDefinition object.
1727 * The given template parameter denotes any libFAUDES class derived from faudes::Type
1728 * A new instance of this class is assigned to member variable (pType)
1729 * whereas the name is set as specified.
1730 *
1731 * @tparam T
1732 * Actual c class, derived from Type
1733 * @param rTypeName
1734 * Name to identify this faudes-type<; defaults to the plattform
1735 * dependand typeid from the c++ runtime type information system.
1736 * @return
1737 * Newly constructed type definition.
1738 *
1739 */
1740 template<class T>
1741 static TypeDefinition* Constructor(const std::string& rTypeName="");
1742
1743 /**
1744 * Construct empty TypeDefinition object.
1745 * The given prototype is assigned to the member variable pType,
1746 *
1747 * @param pProto
1748 * Prototype, derived from Type
1749 * @param rTypeName
1750 * Name to identify this faudes-type<; defaults to the plattform
1751 * dependand typeid from the c++ runtime type information system.
1752 * @return
1753 * Newly constructed type definition.
1754 *
1755 */
1756 static TypeDefinition* Constructor(Type* pProto, const std::string& rTypeName="");
1757
1758 /**
1759 * Construct TypeDefinition object and read name and
1760 * documentation-data from TokenReader.
1761 *
1762 * @tparam T
1763 * Actual c class, derived from Type
1764 * @param rFileName
1765 * Name of file to read.
1766 * @return
1767 * Newly constructed type definition.
1768 *
1769 * @exception Exception
1770 * - Token mismatch (id 50, 51, 52)
1771 * - IO Error (id 1)
1772 */
1773 template<class T>
1774 static TypeDefinition* FromFile(const std::string& rFileName);
1775
1776
1777 /**
1778 * Return pointer to faudes-object prototype
1779 *
1780 * Note: this method is meant for inspection only, control over
1781 * the prototype remains with the TypeDefinition. Use
1782 * NewObject() to instantiate a new faudes-object.
1783 *
1784 * @return
1785 * Reference to prototype object
1786 */
1787 const Type* Prototype(void) const;
1788
1789
1790 /**
1791 * Construct faudes-object on heap.
1792 * Return pointer to new instance of assigned Type class.
1793 *
1794 * Note: If no prototype is installed, NULL is returned.
1795 *
1796 * @return
1797 * Pointer to new Type instance.
1798 */
1799 Type* NewObject(void) const;
1800
1801
1802 /**
1803 * Parameter access: Element Tag
1804 *
1805 * This parameter is used for IO of sets and vectors. It determines
1806 * the tag to used for individual elments.
1807 *
1808 * @return
1809 * Tag parameter.
1810 */
1811 const std::string& ElementTag(void) const;
1812
1813 /**
1814 * Parameter access: Element Tag
1815 *
1816 * @param rTag
1817 * New tag parameter
1818 */
1819 void ElementTag(const std::string& rTag);
1820
1821 /**
1822 * Parameter access: Element Tag
1823 *
1824 * This parameter is used for IO of sets and vectors. It determines
1825 * the type to used for individual elments.
1826 *
1827 * @return
1828 * Tag parameter.
1829 */
1830 const std::string& ElementType(void) const;
1831
1832 /**
1833 * Parameter access: Element Tag
1834 *
1835 * @param rTag
1836 * New tag parameter
1837 */
1838 void ElementType(const std::string& rEype);
1839
1840protected:
1841
1842
1843 /**
1844 * Std faudes type interface: assignment.
1845 *
1846 * @param rSrc
1847 * Source to copy from
1848 */
1849 void DoCopy(const TypeDefinition& rSrc);
1850
1851 /**
1852 * Std faudes type interface: test equality
1853 *
1854 * @param rOther
1855 * Other object to compare with.
1856 * @return
1857 * True on match.
1858 */
1859 bool DoEqual(const TypeDefinition& rOther) const;
1860
1861 /** Disable copy constructor */
1862 TypeDefinition(const TypeDefinition& rOther) : Documentation(rOther) {}; // todo: implement ?? for stl maps ?
1863
1864 /**
1865 * Clear documentation-data; do *NOT* delete prototype (this is for using Read to
1866 * merge/overwrite documentation)
1867 */
1868 void Clear(void);
1869
1870 /**
1871 * Use given object as prototype.
1872 *
1873 * The TypeDefinition takes ownership of the
1874 * provided object.
1875 *
1876 * @param pType
1877 * Any class that inherits Type.
1878 */
1879 virtual void Prototype(Type* pType);
1880
1881 /**
1882 * Read configuration data of this object from TokenReader.
1883 *
1884 * The section defaults to "TypeDefinition", context ignored.
1885 * Actual reading is done by DoReadCore.
1886 *
1887 * @param rTr
1888 * TokenReader to read from
1889 * @param rLabel
1890 * Section to read
1891 * @param pContext
1892 * Read context to provide contextual information (ignored)
1893 *
1894 * @exception Exception
1895 * - Token mismatch (id 50, 51, 52)
1896 * - IO error (id 1)
1897 */
1898 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
1899
1900 /**
1901 * Read configuration data of this object from TokenReader.
1902 *
1903 * This method reads members only, it does not read the section.
1904 *
1905 * @param rTr
1906 * TokenReader to read from
1907 *
1908 * @exception Exception
1909 * - Token mismatch (id 50, 51, 52)
1910 * - IO error (id 1)
1911 */
1912 virtual void DoReadCore(TokenReader& rTr);
1913
1914 /**
1915 * Write configuration data of this object to TokenWriter.
1916 *
1917 * The section defaults to "TypeDefinition", context ignored.
1918 * Actual writing is done by DoWriteCore.
1919 *
1920 * @param rTw
1921 * Reference to TokenWriter
1922 * @param rLabel
1923 * Label of section to write
1924 * @param pContext
1925 * Write context to provide contextual information
1926 *
1927 * @exception Exception
1928 * - IO errors (id 2)
1929 */
1930 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
1931
1932 /**
1933 * Write configuration data of this object to TokenWriter.
1934 *
1935 * This method wrtite plain member data, the section lables are not
1936 * written.
1937 *
1938 * @param rTw
1939 * Reference to TokenWriter
1940 *
1941 * @exception Exception
1942 * - IO errors (id 2)
1943 */
1944 virtual void DoWriteCore(TokenWriter& rTw) const;
1945
1946 /** Type-pointer tp prototype instance */
1948
1949 /** Extra documentation/parameter: Element Type */
1950 std::string mElementType;
1951
1952 /** Extra documentation/parameter: Element Tag */
1953 std::string mElementTag;
1954
1955}; //TypeDefinition
1956
1957
1958
1959
1960/**********************************************************************************************
1961***********************************************************************************************
1962***********************************************************************************************
1963
1964Implemention of template members functions
1965
1966***********************************************************************************************
1967***********************************************************************************************
1968**********************************************************************************************/
1969
1970
1971// Type definition constructor function (initialise with type name)
1972template<class T>
1973TypeDefinition* TypeDefinition::Constructor(const std::string& rTypeName){
1974 FD_DRTI("TypeDefinition::Construct<" << typeid(T).name() << ">(" << rTypeName << ")");
1975 TypeDefinition* ftd=Constructor(new T, rTypeName);
1976 /*
1977 cproto= *(ftd->Prototype());
1978 FD_WARN("TypeDefinition::Construct<>: fprototype " << typeid(cproto).name());
1979 */
1980 return ftd;
1981}
1982
1983
1984// Type definition constructor function (read from file)
1985template<class T>
1986TypeDefinition* TypeDefinition::FromFile(const std::string& rFileName){
1987 FD_DRTI("TypeDefinition::FromFile<" << typeid(T).name() << ">()");
1988 // construct with fallback name
1989 TypeDefinition* td = Constructor<T>();
1990 // read docu, incl actual name
1991 td->Read(rFileName);
1992 // done
1993 return(td);
1994}
1995
1996
1997
1998
1999
2000} // namespace
2001
2002#endif /* FAUDES_RTITYPES_H */
#define FD_DRTI(message)
#define FAUDES_API
Class Token.
Class TokenReader.
Class TokenWriter.
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition cfl_types.h:918
void DoCopy(const AttrType &rSrc)
Definition cfl_types.h:1175
virtual bool IsDefault(void) const
Definition cfl_types.h:1148
bool DoEqual(const AttrType &rOther) const
Definition cfl_types.h:1178
static Type * Pointer(T *ptr)
Definition cfl_types.h:1099
static const Type * ConstPointer(const T *ptr)
Definition cfl_types.h:1100
static const Type * ConstPointer(const T *ptr)
Definition cfl_types.h:1094
static Type * Pointer(T *ptr)
Definition cfl_types.h:1093
std::string mKeywords
Definition cfl_types.h:1662
virtual ~Documentation(void)
Definition cfl_types.h:1374
std::string mElementTagDef
Definition cfl_types.h:1322
std::string mObjectName
Definition cfl_types.h:1325
std::string mElementType
Definition cfl_types.h:1319
std::string mElementTag
Definition cfl_types.h:1301
std::string mFaudesTypeName
Definition cfl_types.h:1298
const TypeDefinition * pTypeDefinition
Definition cfl_types.h:1295
std::string mElementTag
Definition cfl_types.h:1953
virtual ~TypeDefinition(void)
Definition cfl_types.h:1723
static TypeDefinition * FromFile(const std::string &rFileName)
Definition cfl_types.h:1986
TypeDefinition(const TypeDefinition &rOther)
Definition cfl_types.h:1862
std::string mElementType
Definition cfl_types.h:1950
static TypeDefinition * Constructor(const std::string &rTypeName="")
Definition cfl_types.h:1973
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
static std::string msStringEmpty
Definition cfl_types.h:911
static std::string msStringVoid
Definition cfl_types.h:910
const std::string & TypeName(const Type &rObject)
Type * NewObject(const Type &rSample)

libFAUDES 2.34g --- 2026.03.30 --- c++ api documentaion by doxygen