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, 2024 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 and the
59graphical 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 DoRead(), DoWrite(), DoCopy(), DoEqual() and Clear() need to be implemented
231 * 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
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 may 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 a string.
717 * Note: this read function uses the virtual function DoRead(), to be
718 * reimplemented by derived classes.
719 *
720 * @param rString
721 * String to read from
722 * @param rLabel
723 * Section to read
724 * @param pContext
725 * Read context to provide contextual information
726 * @exception Exception
727 * - IO errors (id 1)
728 * - token mismatch from DoRead()
729 */
730 void FromString(const std::string& rString, const std::string& rLabel="", const Type* pContext=0);
731
732 /**
733 * Read configuration data from TokenReader with label sepcified.
734 * Note: all read functions use the virtual function DoRead(), to be
735 * reimplemented for by derived classes.
736 *
737 * @param rTr
738 * Reference to tokenreader
739 * @param rLabel
740 * Section to read
741 * @param pContext
742 * Read context to provide contextual information
743 *
744 * @exception Exception
745 * - IO errors (id 1)
746 * - token mismatch from DoRead()
747 */
748 void Read(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
749
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
1164protected:
1165
1166 /** Copy (no members, dummy) */
1167 void DoCopy(const AttrType& rSrc) { (void) rSrc; };
1168
1169 /** Test (no members, dummy) */
1170 bool DoEqual(const AttrType& rOther) const { (void) rOther; return true; }
1171
1172};
1173
1174
1175/**
1176 * This class extends the base Type by common features worthwhile for "large objects",
1177 * e.g., object name, a cache for the regsitry record and convenience access wrappers.
1178 *
1179 * @ingroup RunTimeInterface
1180 */
1181
1183
1184public:
1185
1186 using AttrType::operator=;
1187 using AttrType::operator==;
1188 using AttrType::operator!=;
1189
1190
1191 // std faudes type interface
1193
1194 /** Constructor */
1195 ExtType(void);
1196
1197 /** Copy constructor */
1198 ExtType(const ExtType& rType);
1199
1200 /** Destructor */
1201 virtual ~ExtType(void);
1202
1203 /**
1204 * Get objects name
1205 *
1206 * @return
1207 * Name
1208 */
1209 const std::string& Name(void) const;
1210
1211 /**
1212 * Set objects name
1213 *
1214 * @param rName
1215 * Name to set
1216 */
1217 void Name(const std::string& rName);
1218
1219
1220 /**
1221 * Get objects's type name.
1222 *
1223 * Retrieve the faudes-type name from the type registry.
1224 *
1225 * @return
1226 * Faudes-type name or empty string.
1227 */
1228 virtual const std::string& TypeName(void) const;
1229
1230 /**
1231 * Overwrite faudes-type name.
1232 *
1233 * This method is used to overwrite the faudes-type identifyer to account for
1234 * unregistered classe/
1235 *
1236 * @param rType
1237 * Faudes-type name to set
1238 */
1239 virtual void TypeName(const std::string& rType);
1240
1241 /**
1242 * Get the element name tag.
1243 *
1244 * Tags used for XML IO when eriting elements of a container class.
1245 * This is either the deribeved class default of found in the registry.
1246 *
1247 * @return
1248 * Tag
1249 */
1250 virtual const std::string& ElementTag(void) const;
1251 /**
1252 * Configure the element name tag.
1253 *
1254 * This method allows to overwrite the tag used for elements
1255 * in XML IO. For usual, you will register derived classes with
1256 * the run-time-interface and set the elemen tag for XML IO.
1257 *
1258 * @param rTag
1259 * Tag to set
1260 */
1261 virtual void ElementTag(const std::string& rTag);
1262
1263 /**
1264 * Get the element type.
1265 *
1266 * This should be found in the registry.
1267 *
1268 * @return
1269 * Tag
1270 */
1271 virtual const std::string& ElementType(void) const;
1272
1273 /**
1274 * Get registry record
1275 *
1276 * Returns nullptr if not registered
1277 *
1278 * @return
1279 * Pointer to registry entry
1280 */
1281 virtual const TypeDefinition* TypeDefinitionp(void) const;
1282
1283
1284private:
1285
1286 /** TypeDefinition cache (should use guarded pointer here) */
1288
1289 /** Current/cached faudes type-name */
1290 std::string mFaudesTypeName;
1291
1292 /** Current/cached name of elements (use protected accessor methods for caching) */
1293 std::string mElementTag;
1294
1295protected:
1296
1297 /** Current/cached name of elements (use protected accessor methods for caching) */
1298 std::string mElementType;
1299
1300 /** Defauft name of elements (if not over written manually or by registry) */
1301 std::string mElementTagDef;
1302
1303 /** object name */
1304 std::string mObjectName;
1305};
1306
1307
1308
1309
1310/**
1311 * Structure to hold documentation data relating to a faudes-type or -function.
1312 * This class is the common base for faudes::TypeDefinition and faudes::FunctionDefinition.
1313 * It supports token io as demonstrated by the follwoing example for a type defintion:
1314 *
1315 * @code
1316 * <TypeDefinition name="CoreFaudes::Generator" ctype="faudes::Generator">
1317 *
1318 * <Documentation ref="generators.html#plain">
1319 * The common 5 tuple G=(Sigma, Q, delta, Qo, Qm).
1320 * <Documentation/>
1321 *
1322 * <Keywords> "generator" "language" </Keywords>
1323 *
1324 * </TypeDefinition>
1325 * @endcode
1326 *
1327 * Technical detail: Documentation is derived from Type for the purpose of token IO. We
1328 * still implement the faudes type interface to make it a fully qualified faudes data type.
1329 *
1330 * Technical detail: To facilitate inheritance, token io of member data and token io of
1331 * the section tags is separated.
1332 */
1333
1335
1336 // std faudes type interface
1338
1339public:
1340
1341 using Type::operator=;
1342 using Type::operator==;
1343 using Type::operator!=;
1344
1345
1346 /** Constructor */
1347 Documentation(void);
1348
1349 /** Copy constructor */
1350 Documentation(const Documentation& rOther);
1351
1352 /** Destructor */
1353 virtual ~Documentation(void){};
1354
1355 /**
1356 * Clear
1357 */
1358 void Clear(void);
1359
1360 /**
1361 * Get name of the entity to document (aka faudes-type or faudes-function).
1362 *
1363 * @return
1364 * Name
1365 */
1366 const std::string& Name(void) const;
1367
1368 /**
1369 * Get name of plugin.
1370 * The plugin name defaults to CoreFaudes.
1371 *
1372 * @return
1373 * Name
1374 */
1375 const std::string& PlugIn(void) const;
1376
1377 /**
1378 * Get corresponding C++ type
1379 *
1380 * @return
1381 * CType, or "" if no such
1382 */
1383 const std::string& CType(void) const;
1384
1385 /**
1386 * @return
1387 * Short textual documentation.
1388 */
1389 const std::string& TextDoc(void) const;
1390
1391 /**
1392 * @return
1393 * Filename pointing to the html documentation.
1394 */
1395 const std::string& HtmlDoc(void) const;
1396
1397 /**
1398 * @return
1399 * CSV-string containing keywords.
1400 */
1401 const std::string& Keywords(void) const;
1402
1403 /**
1404 * Search comma-seperated keywords for a substring. This should be
1405 * extended to regular expressions in a future release.
1406 *
1407 * @param rPattern
1408 * String-pattern.
1409 *
1410 * @return
1411 * Matching keyword or "" if no match
1412 */
1413 std::string MatchKeyword(const std::string& rPattern) const;
1414
1415 /**
1416 * Not implemented
1417 * @return
1418 * Number of keywords.
1419 */
1420 int KeywordsSize(void) const;
1421
1422 /**
1423 * @param pos
1424 * Position of keyword
1425 * @return
1426 * Keyword at specified position (or "" if pos out of range)
1427 */
1428 std::string KeywordAt(int pos) const;
1429
1430 /**
1431 * Get auto-register flag.
1432 *
1433 * This flag indicated that the respective type was (will be)
1434 * registered by a libFAUDES static initialisation protorype.
1435 *
1436 * @return
1437 * True <> C++-automatic-registration
1438 */
1439 bool AutoRegistered(void) const;
1440
1441 /**
1442 * Get application-registered flag.
1443 *
1444 * @return
1445 * True <> registered by application
1446 */
1447 bool ApplicationRegistered(void) const;
1448
1449 /**
1450 * Merge documentation from token stream.
1451 * An exception is thrown if the current type name differs from the one in the documentation.
1452 *
1453 * @param rTr
1454 * TokenReader to read from.
1455 *
1456 * @exception Exception
1457 * - Type mismatch (id )
1458 * - Token mismatch (id 50, 51, 52)
1459 * - IO Error (id 1)
1460 */
1461 virtual void MergeDocumentation(TokenReader& rTr);
1462
1463
1464
1465 protected:
1466
1467 /**
1468 * Set name.
1469 *
1470 * @param name
1471 * New name.
1472 */
1473 void Name(const std::string& name);
1474
1475 /**
1476 * Set name of plugin
1477 *
1478 * @param plugin
1479 * New name.
1480 */
1481 void PlugIn(const std::string& plugin);
1482
1483 /**
1484 * Set C++ type
1485 *
1486 * @param name
1487 * New ctype.
1488 */
1489 void CType(const std::string& name);
1490
1491 /**
1492 * Set a short textual documentation.
1493 *
1494 * @param textdoc
1495 * New textual documentation.
1496 */
1497 void TextDoc(const std::string& textdoc);
1498
1499 /**
1500 * Set auto-register flag.
1501 *
1502 * See also AutoRegistered(void)
1503 *
1504 * @param flag
1505 * Flag value.
1506 */
1507 void AutoRegistered(bool flag);
1508
1509 /**
1510 * Set application-registered flag.
1511 *
1512 * See also AutoRegistered(void)
1513 *
1514 * @param flag
1515 * Flag value.
1516 */
1517 void ApplicationRegistered(bool flag);
1518
1519 /**
1520 * Set name of file pointing to the html documentation.
1521 *
1522 * @param fname
1523 * Filename
1524 */
1525 void HtmlDoc(const std::string& fname);
1526
1527 /**
1528 * Append keyword.
1529 *
1530 * @param rKeyword
1531 * Keyword
1532 */
1533 void AddKeyword(const std::string& rKeyword);
1534
1535 /**
1536 * Std faudes type interface: assignment.
1537 *
1538 * @param rSrc
1539 * Source to copy from
1540 */
1541 void DoCopy(const Documentation& rSrc);
1542
1543 /**
1544 * Std faudes type interface: test equality
1545 *
1546 * @param rOther
1547 * Other object to compare with.
1548 * @return
1549 * True on match.
1550 */
1551 bool DoEqual(const Documentation& rOther) const;
1552
1553 /**
1554 * Read configuration data of this object from TokenReader.
1555 *
1556 * This virtual function reads documentation from a token stream.
1557 * The section defaults to Documentation. It invokes DoReadCore to
1558 * do the member data token reading.
1559 *
1560 * @param rTr
1561 * TokenReader to read from
1562 * @param rLabel
1563 * Section to read
1564 * @param pContext
1565 * Read context to provide contextual information (ignored)
1566 *
1567 * @exception Exception
1568 * - Token mismatch (id 50, 51, 52)
1569 * - IO Error (id 1)
1570 */
1571 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
1572
1573 /**
1574 * Read configuration data of this object from TokenReader.
1575 *
1576 * This virtual function reads documentation member data only.
1577 * It does NOT read the enclosing begin and end tokens.
1578 *
1579 * @param rTr
1580 * TokenReader to read from
1581 *
1582 * @exception Exception
1583 * - Token mismatch (id 50, 51, 52)
1584 * - IO Error (id 1)
1585 */
1586 virtual void DoReadCore(TokenReader& rTr);
1587
1588
1589
1590 /**
1591 * Write configuration data of this object to TokenWriter.
1592 *
1593 * This virtual function writes documentation to a token stream.
1594 * The section defaults to Documentation. It invokes DoWriteCore to
1595 * do the actual member data writing.
1596 *
1597 * @param rTw
1598 * Reference to TokenWriter
1599 * @param rLabel
1600 * Label of section to write
1601 * @param pContext
1602 * Write context to provide contextual information
1603 *
1604 * @exception Exception
1605 * - IO errors (id 2)
1606 */
1607 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
1608
1609
1610 /**
1611 * Write configuration data of this object to TokenWriter.
1612 *
1613 * This virtual function reads documentation members only.
1614 * It does NOT write enclosing begin and end tokens.
1615 *
1616 * @param rTw
1617 * Reference to TokenWriter
1618 *
1619 * @exception Exception
1620 * - IO errors (id 2)
1621 */
1622 virtual void DoWriteCore(TokenWriter& rTw) const;
1623
1624
1625 /** Faudes name. */
1626 std::string mName;
1627
1628 /** Faudes plugin. */
1629 std::string mPlugIn;
1630
1631 /** Corresponing C++ type, or "" if no such. */
1632 std::string mCType;
1633
1634 /** String containing the text-documentation. */
1635 std::string mTextDoc;
1636
1637 /** String containing the filename of the corresponding html-documentation. */
1638 std::string mHtmlDoc;
1639
1640 /** Comma-seperated string containing all keywords. */
1641 std::string mKeywords;
1642
1643 /** Constant characted used to seperate keywords */
1644 static const char mDelim = ';';
1645
1646 /** Flag to indicate automated registration */
1648
1649 /** Flag to indicate application registration */
1651
1652}; // Documentation
1653
1654
1655
1656/**
1657 * A TypeDefinition defines a faudes-type in that it specifies
1658 * a faudes-type name to identify the type and a method
1659 * NewObject() to instantiate objects of the respective type.
1660 * In this sense, TypeDefinition is a so called factory class.
1661 * Technically, the TypeDefinition holds one instance of the faude type,
1662 * the so called prototype object, and NewObject() invokes the New() method
1663 * of the prototype. Notebly, there is only one class TypeDefinition that by
1664 * parametrisation defins all derivates of Type.
1665 *
1666 * TypeDefinition is derived from faudes::Documentation and therefore additional
1667 * documentation-data can be associated.
1668 *
1669 *
1670 * @ingroup RunTimeInterface
1671 */
1672
1674
1675 // std faudes type interface
1677
1678 // regisry is friend to set protected values
1679 friend class TypeRegistry;
1680
1681 public:
1682
1683 using Documentation::operator=;
1684 using Documentation::operator==;
1685 using Documentation::operator!=;
1686
1687 /**
1688 * Constructor
1689 *
1690 * The default constructor instantiates an invalid type definition
1691 * without prototype. To construct
1692 * a valid type definition, use the static Constructor() template
1693 * function.
1694 */
1695 TypeDefinition(const std::string& name="") : Documentation(), mpType(NULL) {Name(name);};
1696
1697 /**
1698 * Destructor.
1699 *
1700 * Delete prototype object.
1701 */
1702 virtual ~TypeDefinition(void){ Prototype(NULL); };
1703
1704 /**
1705 * Construct empty TypeDefinition object.
1706 * The given template parameter denotes any libFAUDES class derived from faudes::Type
1707 * A new instance of this class is assigned to member variable (pType)
1708 * whereas the name is set as specified.
1709 *
1710 * @tparam T
1711 * Actual c class, derived from Type
1712 * @param rTypeName
1713 * Name to identify this faudes-type<; defaults to the plattform
1714 * dependand typeid from the c++ runtime type information system.
1715 * @return
1716 * Newly constructed type definition.
1717 *
1718 */
1719 template<class T>
1720 static TypeDefinition* Constructor(const std::string& rTypeName="");
1721
1722 /**
1723 * Construct empty TypeDefinition object.
1724 * The given prototype is assigned to the member variable pType,
1725 *
1726 * @param pProto
1727 * Prototype, derived from Type
1728 * @param rTypeName
1729 * Name to identify this faudes-type<; defaults to the plattform
1730 * dependand typeid from the c++ runtime type information system.
1731 * @return
1732 * Newly constructed type definition.
1733 *
1734 */
1735 static TypeDefinition* Constructor(Type* pProto, const std::string& rTypeName="");
1736
1737 /**
1738 * Construct TypeDefinition object and read name and
1739 * documentation-data from TokenReader.
1740 *
1741 * @tparam T
1742 * Actual c class, derived from Type
1743 * @param rFileName
1744 * Name of file to read.
1745 * @return
1746 * Newly constructed type definition.
1747 *
1748 * @exception Exception
1749 * - Token mismatch (id 50, 51, 52)
1750 * - IO Error (id 1)
1751 */
1752 template<class T>
1753 static TypeDefinition* FromFile(const std::string& rFileName);
1754
1755
1756 /**
1757 * Return pointer to faudes-object prototype
1758 *
1759 * Note: this method is meant for inspection only, control over
1760 * the prototype remains with the TypeDefinition. Use
1761 * NewObject() to instantiate a new faudes-object.
1762 *
1763 * @return
1764 * Reference to prototype object
1765 */
1766 const Type* Prototype(void) const;
1767
1768
1769 /**
1770 * Construct faudes-object on heap.
1771 * Return pointer to new instance of assigned Type class.
1772 *
1773 * Note: If no prototype is installed, NULL is returned.
1774 *
1775 * @return
1776 * Pointer to new Type instance.
1777 */
1778 Type* NewObject(void) const;
1779
1780
1781 /**
1782 * Parameter access: Element Tag
1783 *
1784 * This parameter is used for IO of sets and vectors. It determines
1785 * the tag to used for individual elments.
1786 *
1787 * @return
1788 * Tag parameter.
1789 */
1790 const std::string& ElementTag(void) const;
1791
1792 /**
1793 * Parameter access: Element Tag
1794 *
1795 * @param rTag
1796 * New tag parameter
1797 */
1798 void ElementTag(const std::string& rTag);
1799
1800 /**
1801 * Parameter access: Element Tag
1802 *
1803 * This parameter is used for IO of sets and vectors. It determines
1804 * the type to used for individual elments.
1805 *
1806 * @return
1807 * Tag parameter.
1808 */
1809 const std::string& ElementType(void) const;
1810
1811 /**
1812 * Parameter access: Element Tag
1813 *
1814 * @param rTag
1815 * New tag parameter
1816 */
1817 void ElementType(const std::string& rEype);
1818
1819protected:
1820
1821
1822 /**
1823 * Std faudes type interface: assignment.
1824 *
1825 * @param rSrc
1826 * Source to copy from
1827 */
1828 void DoCopy(const TypeDefinition& rSrc);
1829
1830 /**
1831 * Std faudes type interface: test equality
1832 *
1833 * @param rOther
1834 * Other object to compare with.
1835 * @return
1836 * True on match.
1837 */
1838 bool DoEqual(const TypeDefinition& rOther) const;
1839
1840 /** Disable copy constructor */
1841 TypeDefinition(const TypeDefinition& rOther) : Documentation(rOther) {}; // todo: implement ?? for stl maps ?
1842
1843 /**
1844 * Clear documentation-data; do *NOT* delete prototype (this is for using Read to
1845 * merge/overwrite documentation)
1846 */
1847 void Clear(void);
1848
1849 /**
1850 * Use given object as prototype.
1851 *
1852 * The TypeDefinition takes ownership of the
1853 * provided object.
1854 *
1855 * @param pType
1856 * Any class that inherits Type.
1857 */
1858 virtual void Prototype(Type* pType);
1859
1860 /**
1861 * Read configuration data of this object from TokenReader.
1862 *
1863 * The section defaults to "TypeDefinition", context ignored.
1864 * Actual reading is done by DoReadCore.
1865 *
1866 * @param rTr
1867 * TokenReader to read from
1868 * @param rLabel
1869 * Section to read
1870 * @param pContext
1871 * Read context to provide contextual information (ignored)
1872 *
1873 * @exception Exception
1874 * - Token mismatch (id 50, 51, 52)
1875 * - IO error (id 1)
1876 */
1877 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
1878
1879 /**
1880 * Read configuration data of this object from TokenReader.
1881 *
1882 * This method reads members only, it does not read the section.
1883 *
1884 * @param rTr
1885 * TokenReader to read from
1886 *
1887 * @exception Exception
1888 * - Token mismatch (id 50, 51, 52)
1889 * - IO error (id 1)
1890 */
1891 virtual void DoReadCore(TokenReader& rTr);
1892
1893 /**
1894 * Write configuration data of this object to TokenWriter.
1895 *
1896 * The section defaults to "TypeDefinition", context ignored.
1897 * Actual writing is done by DoWriteCore.
1898 *
1899 * @param rTw
1900 * Reference to TokenWriter
1901 * @param rLabel
1902 * Label of section to write
1903 * @param pContext
1904 * Write context to provide contextual information
1905 *
1906 * @exception Exception
1907 * - IO errors (id 2)
1908 */
1909 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
1910
1911 /**
1912 * Write configuration data of this object to TokenWriter.
1913 *
1914 * This method wrtite plain member data, the section lables are not
1915 * written.
1916 *
1917 * @param rTw
1918 * Reference to TokenWriter
1919 *
1920 * @exception Exception
1921 * - IO errors (id 2)
1922 */
1923 virtual void DoWriteCore(TokenWriter& rTw) const;
1924
1925 /** Type-pointer tp prototype instance */
1927
1928 /** Extra documentation/parameter: Element Type */
1929 std::string mElementType;
1930
1931 /** Extra documentation/parameter: Element Tag */
1932 std::string mElementTag;
1933
1934}; //TypeDefinition
1935
1936
1937
1938
1939/**********************************************************************************************
1940***********************************************************************************************
1941***********************************************************************************************
1942
1943Implemention of template members functions
1944
1945***********************************************************************************************
1946***********************************************************************************************
1947**********************************************************************************************/
1948
1949
1950// Typedefinition constructor function
1951template<class T>
1952TypeDefinition* TypeDefinition::Constructor(const std::string& rTypeName){
1953 FD_DRTI("TypeDefinition::Construct<" << typeid(T).name() << ">(" << rTypeName << ")");
1954 TypeDefinition* ftd=Constructor(new T, rTypeName);
1955 /*
1956 cproto= *(ftd->Prototype());
1957 FD_WARN("TypeDefinition::Construct<>: fprototype " << typeid(cproto).name());
1958 */
1959 return ftd;
1960}
1961
1962
1963// Type definition constructor function
1964template<class T>
1965TypeDefinition* TypeDefinition::FromFile(const std::string& rFileName){
1966 FD_DRTI("TypeDefinition::FromFile<" << typeid(T).name() << ">()");
1967 // construct with fallback name
1968 TypeDefinition* td = Constructor<T>();
1969 // read docu, incl actual name
1970 td->Read(rFileName);
1971 // done
1972 return(td);
1973}
1974
1975
1976
1977
1978
1979} // namespace
1980
1981#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:1167
virtual bool IsDefault(void) const
Definition cfl_types.h:1148
bool DoEqual(const AttrType &rOther) const
Definition cfl_types.h:1170
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:1641
virtual ~Documentation(void)
Definition cfl_types.h:1353
std::string mElementTagDef
Definition cfl_types.h:1301
std::string mObjectName
Definition cfl_types.h:1304
std::string mElementType
Definition cfl_types.h:1298
std::string mElementTag
Definition cfl_types.h:1293
std::string mFaudesTypeName
Definition cfl_types.h:1290
const TypeDefinition * pTypeDefinition
Definition cfl_types.h:1287
std::string mElementTag
Definition cfl_types.h:1932
virtual ~TypeDefinition(void)
Definition cfl_types.h:1702
static TypeDefinition * FromFile(const std::string &rFileName)
Definition cfl_types.h:1965
TypeDefinition(const TypeDefinition &rOther)
Definition cfl_types.h:1841
std::string mElementType
Definition cfl_types.h:1929
static TypeDefinition * Constructor(const std::string &rTypeName="")
Definition cfl_types.h:1952
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

libFAUDES 2.34d --- 2026.03.11 --- c++ api documentaion by doxygen