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(), Copy(), Cast(),
154 Assign(), Equal(), and the acording operators =, == and !=;
155-# reimplement the virtual functions DoAssign(), 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 * Assign(). 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 * - Copy() 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 * - Assign() to do an assignment from any castable Type derivate
225 * - DoAssign(), or the operator "=", to assign from an object with identical type.
226 * - Equal() to test relaxed equality with any castable Type derivate
227 * - DoEqual(), or the operators "==" and "!=", to test exact equality of configuration data
228 *
229 * In most cases, only DoRead(), DoWrite(), DoAssign(), DoEqual() and Clear() need to be implemented
230 * manualy. The other methods can be declared and implemented by macros
231 * FAUDES_TYPE_DELARATION and FAUDES_TYPE_IMPLEMENTATION, respectively. The various
232 * attribute classes illustrate their ussage; see e.g. AttributeFlags.
233 *
234 *
235 *
236 * Note on token IO: In libFAUDES 2.16e, implementation of a new file format is prepared
237 * by the virtual function interface DoXWrite(). The intention is to better support advanced
238 * XML editors, in particular for configuration files. When implementing DoXWrite() for a
239 * derived class, make sure that DoRead() will gracefully accept tokens written by both DoWrite()
240 * and DoXWrite(), as a basis for a fileformat conversion tool. Future versions of libFAUDES will drop
241 * compatibility with the old token format, except for model data (generators, alphabets).
242 *
243 * @ingroup RunTimeInterface
244 */
245
247
248 public:
249
250 /** Constructor */
251 Type(void);
252
253 /** Copy constructor */
254 Type(const Type& rType);
255
256 /** Destructor */
257 virtual ~Type(void);
258
259 /**
260 * Construct on heap.
261 * Technically not a constructor, this function creates an object with the
262 * same type Type. New() is defined as a virtual function and derived
263 * classes are meant to re-implement with the appropiate constructor.
264 * This can be done via the provided macros FAUDES_TYPE_DECLARATION and
265 * FAUDES_TYPE_IMPLEMENTATION.
266 * As with new, it is the callers reponsabilty to delete the object when no longer needed.
267 *
268 * @return
269 * Pointer to new Type object
270 */
271 virtual Type* New(void) const;
272
273 /**
274 * Construct on heap.
275 * Technically not a constructor, this function creates an object with the
276 * same type Type and the same configuration. Copy() is defined as a virtual function and derived
277 * classes are meant to re-implement with the appropiate copy constructor.
278 * This can be done via the provided macros FAUDES_TYPE_DECLARATION and
279 * FAUDES_TYPE_IMPLEMENTATION.
280 * As with new, it is the callers reponsabilty to delete the object when no longer needed.
281 *
282 * @return
283 * Pointer to new Type object
284 */
285 virtual Type* Copy(void) const;
286
287 /**
288 * Cast other object to this type.
289 * Enables the run-time interface to test whether pObject is derived
290 * from this object. This feature is used e.g. in the faudes container
291 * classes to test attributes. Derived classes must reimplement this
292 * function using the appropriate dynamic cast.
293 *
294 * Re-implementation can be done via the convenience macros
295 * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
296 *
297 * @return
298 * Typed pointer object
299 */
300 virtual const Type* Cast(const Type* pOther) const;
301
302 /**
303 * Clear configuration data to default. Derived classes should re-implement this
304 * method to ensure some consistent configuration data.
305 */
306 virtual void Clear(void);
307
308 /**
309 * Test for default configuration data. Derived classes may reimplement this
310 * conservatively, i.e., false negatives should be acceptable.
311 ^
312 * Note may refactor to IsClear[ed]()?
313 */
314 virtual bool IsDefault(void) const;
315
316 /**
317 * Assign configuration data from other object.
318 * Derived classes should reimplement this method to first try to cast
319 * the source to the respective class. If successful, the protected
320 * function DoAssign is invoked to perform the actual assignment. If the cast fails,
321 * the Assign method of the parent class is called. Thus, faudes
322 * objects are up- and downcatsed for assignment, maintaining as much of
323 * the source data as digestable by the destination object. On the downside,
324 * there is no sensible typechecking at compile-time.
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& Assign(const Type& rSrc);
334
335
336 /**
337 * Assign configurationdata from other object.
338 * Derived classes should implement the operator form for the assignment
339 * for each source type which allows for a non-trivial assignment. This includes
340 * the particular case were the source and destination types match exactly. In the
341 * latter case the DoAssign method should be invoked. In contrast to
342 * the Assign function, the operator form must not be reimplemented for
343 * missmatched source types: the operator form only accepts sensible source types.
344 * This allows for compiletime typeckecking. However, the downside is that
345 * when the type is not known at compiletime, configuration is not properly
346 * assigned.
347 *
348 * Re-implementation can be done via the convenience macros
349 * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
350 *
351 * @param rSrc
352 * Source to copy from
353 * @return Reference to this object.
354 */
355 Type& operator=(const Type& rSrc);
356
357 /**
358 * Test equality of configuration data.
359 * Derived classes should reimplement this method to return true
360 * if both actual types and configuration data match.
361 * The object name or id (if any) is not considered in the test.
362 *
363 * This method calls the virtual method DoEqual(). Re-implementation can
364 * be done via the convenience macros
365 * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
366 *
367 * @param rOther
368 * Other object to compare with.
369 * @return
370 * True on match.
371 */
372 virtual bool Equal(const Type& rOther) const;
373
374 /**
375 * Test equality of configuration data.
376 * The operator form of the equality test is only defined for matching
377 * types, no cast will be performed. Thus, the test will be optimistic
378 * if the type is not known at compiletime.
379 * The object name or id is not considered in the test.
380 *
381 * This methoc calls the virtual method DoEqual(). Re-implementation can
382 * be done via the convenience macros
383 * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
384 *
385 * @param rOther
386 * Other object to compare with.
387 * @return
388 * True on match.
389 */
390 bool operator==(const Type& rOther) const;
391
392
393 /**
394 * Test equality of configuration data.
395 * See operator==(const Type&).
396 *
397 * This method calls the virtual method DoEqual(). Re-implementation can
398 * be done via the convenience macros
399 * FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION.
400 *
401 * @param rOther
402 * Other objevt to compare with.
403 * @return
404 * True on mismatch.
405 */
406 bool operator!=(const Type& rOther) const;
407
408
409 /**
410 * Set the objects's name.
411 *
412 * faudes::Type does not implement an object name,
413 * derivatives usually do so. See also faudes::Type.
414 *
415 * @param rName
416 * Name
417 */
418 virtual void Name(const std::string& rName);
419
420 /**
421 * Get objects's name.
422 *
423 * faudes::Type does not implement an object name,
424 * derivatives usually do so. See also faudes::Type.
425 *
426 * @return
427 * Name of object
428 */
429 virtual const std::string& Name(void) const;
430
431 /**
432 * Get objects's type name.
433 *
434 * Retrieve the faudes-type name from the type registry.
435 * This method silently returns the empty string if the type is
436 * not (yet) registered. The derived class faudes::Type implements
437 * a cache to avoid repeating the log-n lookup.
438 *
439 * @return
440 * Faudes-type name or empty string.
441 */
442 virtual const std::string& TypeName(void) const;
443
444 /**
445 * Write configuration data to console.
446 * Note: this write function uses the virtual function DoWrite(), to be
447 * reimplemented by derived classes.
448 *
449 * @param pContext
450 * Write context to provide contextual information
451 *
452 */
453 void Write(const Type* pContext=0) const;
454
455 /**
456 * Write configuration data to a file.
457 * Note: this write function uses the virtual function DoWrite(), to be
458 * reimplemented by derived classes.
459 *
460 * @param pFileName
461 * Name of file
462 * @param rLabel
463 * Label of section to write
464 * @param pContext
465 * Write context to provide contextual information
466 * @param openmode
467 * ios::openmode
468 *
469 * @exception Exception
470 * - IO errors (id 2)
471 */
472 void Write(const std::string& pFileName, const std::string& rLabel="",
473 const Type* pContext=0, std::ios::openmode openmode = std::ios::out|std::ios::trunc) const;
474
475 /**
476 * Write configuration data to a file.
477 * Note: this write function uses the virtual function DoWrite(), to be
478 * reimplemented by derived classes.
479 *
480 * @param pFileName
481 * Name of file
482 * @param openmode
483 * ios::openmode
484 *
485 * @exception Exception
486 * - IO errors (id 2)
487 */
488 void Write(const std::string& pFileName, std::ios::openmode openmode) const;
489
490 /**
491 * Write configuration data to TokenWriter.
492 * Note: this write function uses the virtual function DoWrite(), to be
493 * reimplemented by derived classes.
494 *
495 * @param rTw
496 * Reference to TokenWriter
497 * @param rLabel
498 * Label of section to write
499 * @param pContext
500 * Write context to provide contextual information
501 *
502 * @exception Exception
503 * - IO errors (id 2)
504 */
505 void Write(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
506
507 /**
508 * Write configuration data to an XML file.
509 * Note: this method uses the faudes type to set a DOCTYPE markup; for derived classes
510 * which do not report their faudes type, you should reimplement this
511 * function. Actual token io is done via DoXWrite().
512 *
513 * @param pFileName
514 * Name of file
515 * @param rLabel
516 * Label of section to write
517 * @param pContext
518 * Write context to provide contextual information
519 *
520 * @exception Exception
521 * - IO errors (id 2)
522 */
523 virtual void XWrite(const std::string& pFileName, const std::string& rLabel="",
524 const Type* pContext=0) const;
525
526 /**
527 * Write configuration data in XML format to concole
528 * Note: this write function uses the virtual function DoXWrite(), to be
529 * reimplemented by derived classes. No DOCTYPE markup will be written.
530 *
531 * @param pContext
532 * Write context to provide contextual information
533 *
534 */
535 void XWrite(const Type* pContext=0) const;
536
537 /**
538 * Write configuration data in XML format to TokenWriter.
539 * Note: this write function uses the virtual function DoXWrite(), to be
540 * reimplemented by derived classes.
541 *
542 * @param rTw
543 * Reference to TokenWriter
544 * @param rLabel
545 * Label of section to write
546 * @param pContext
547 * Write context to provide contextual information
548 *
549 * @exception Exception
550 * - IO errors (id 2)
551 */
552 void XWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
553
554 /**
555 * Write configuration data to a string.
556 * Note: this write function uses the virtual function DoWrite(), to be
557 * reimplemented by derived classes.
558 *
559 * @param rLabel
560 * Label of section to write
561 * @param pContext
562 * Write context to provide contextual information
563 * @return
564 * output string
565 * @exception Exception
566 * - IO errors (id 2)
567 */
568 std::string ToString(const std::string& rLabel="", const Type* pContext=0) const;
569
570 /**
571 * Write configuration data to a formated string.
572 * In contrast to ToString, ToText does not suppress comments and
573 * End-Of-Line marks.
574 * Note: this write function uses the virtual function DoWrite(), to be
575 * reimplemented by derived classes.
576 *
577 * @param rLabel
578 * Label of section to write
579 * @param pContext
580 * Write context to provide contextual information
581 * @return
582 * output string
583 * @exception Exception
584 * - IO errors (id 2)
585 */
586 std::string ToText(const std::string& rLabel="", const Type* pContext=0) const;
587
588 /**
589 * Write configuration data to console, debugging format.
590 * Note: this write function uses the virtual function DoDWrite(), to be
591 * reimplemented by derived classes.
592 *
593 * @param pContext
594 * Write context to provide contextual information
595 *
596 */
597 void DWrite(const Type* pContext=0) const;
598
599 /**
600 * Write configuration data to a file, debugging format.
601 * Note: this write function uses the virtual function DoDWrite(), to be
602 * reimplemented by derived classes.
603 *
604 * @param pFileName
605 * Name of file
606 * @param rLabel
607 * Label of section to write
608 * @param pContext
609 * Write context to provide contextual information
610 * @param openmode
611 * ios::openmode
612 *
613 * @exception Exception
614 * - IO errors (id 2)
615 */
616 void DWrite(const std::string& pFileName, const std::string& rLabel="",
617 const Type* pContext=0, std::ios::openmode openmode = std::ios::out|std::ios::trunc) const;
618
619 /**
620 * Write configuration data in debug format to TokenWriter.
621 * Note: this write function uses the virtual function DoWrite(), to be
622 * reimplemented by derived classes.
623 *
624 * @param rTw
625 * Reference to TokenWriter
626 * @param rLabel
627 * Label of section to write
628 * @param pContext
629 * Write context to provide contextual information
630 *
631 * @exception Exception
632 * - IO errors (id 2)
633 */
634 void DWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
635
636 /**
637 * Write statistics comment to TokenWriter.
638 * Note: this write function use the virtual function DoSWrite(), to be
639 * reimplemented by derived classes.
640 *
641 * @param rTw
642 * Reference to TokenWriter
643 *
644 * @exception Exception
645 * - IO errors (id 2)
646 */
647 void SWrite(TokenWriter& rTw) const;
648
649 /**
650 * Write statistics comment to console.
651 * Note: this write function uses the virtual function DoSWrite(), to be
652 * reimplemented by derived classes.
653 *
654 */
655 void SWrite(void) const;
656
657 /**
658 * Write statistics to a string.
659 * Note: this write function uses the virtual function DoSWrite(), to be
660 * reimplemented by derived classes.
661 *
662 * @return
663 * output string
664 * @exception Exception
665 * - IO errors (id 2)
666 */
667 std::string ToSText(void) const;
668
669 /**
670 * Read configuration data from file with label specified.
671 * Note: all read functions use the virtual function DoRead(), to be
672 * reimplemented for by derived classes.
673 *
674 * @param rFileName
675 * Name of file
676 * @param rLabel
677 * Section to read from
678 * @param pContext
679 * Read context to provide contextual information
680 *
681 * @exception Exception
682 * - IO errors (id 1)
683 * - token mismatch from DoRead()
684 */
685 void Read(const std::string& rFileName, const std::string& rLabel = "", const Type* pContext=0);
686
687 /**
688 * Read configuration data from a string.
689 * Note: this read function uses the virtual function DoRead(), to be
690 * reimplemented by derived classes.
691 *
692 * @param rString
693 * String to read from
694 * @param rLabel
695 * Section to read
696 * @param pContext
697 * Read context to provide contextual information
698 * @exception Exception
699 * - IO errors (id 1)
700 * - token mismatch from DoRead()
701 */
702 void FromString(const std::string& rString, const std::string& rLabel="", const Type* pContext=0);
703
704 /**
705 * Read configuration data from TokenReader with label sepcified.
706 * Note: all read functions use the virtual function DoRead(), to be
707 * reimplemented for by derived classes.
708 *
709 * @param rTr
710 * Reference to tokenreader
711 * @param rLabel
712 * Section to read
713 * @param pContext
714 * Read context to provide contextual information
715 *
716 * @exception Exception
717 * - IO errors (id 1)
718 * - token mismatch from DoRead()
719 */
720 void Read(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
721
722
723 protected:
724
725 /**
726 * Assign configuration data from other object.
727 *
728 * Reimplement this function to copy all configuration data from
729 * another faudes object. Typically, you will first call the base class'
730 * DoAssign, which includes a Clear(). Then, you will set up any additional members.
731 *
732 * @param rSrc
733 * Source to copy from
734 */
735 void DoAssign(const Type& rSrc);
736
737 /**
738 * Test equality of configuration data.
739 * Derived classes should reimplement this method to compare all relevant
740 * configuration, except the name.
741 *
742 * @param rOther
743 * Other object to compare with.
744 * @return
745 * True on match.
746 */
747 bool DoEqual(const Type& rOther) const;
748
749
750 /**
751 * Read configuration data of this object from TokenReader.
752 *
753 * Reimplement this method in derived classes to provide the std token io
754 * interface defined in the public section of Type.
755 *
756 * @param rTr
757 * TokenReader to read from
758 * @param rLabel
759 * Section to read
760 * @param pContext
761 * Read context to provide contextual information
762 *
763 * @exception Exception
764 * - IO error (id 1)
765 */
766 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
767
768 /**
769 * Write configuration data of this object to TokenWriter.
770 *
771 * Reimplement this method in derived classes to provide the std token io
772 * interface defined in the public section of Type.
773 *
774 * @param rTw
775 * Reference to TokenWriter
776 * @param rLabel
777 * Label of section to write
778 * @param pContext
779 * Write context to provide contextual information
780 *
781 * @exception Exception
782 * - IO errors (id 2)
783 */
784 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
785
786 /**
787 * Write configuration data of this object to TokenWriter in XML format.
788 *
789 * Reimplement this method in derived classes to provide the XML
790 * token io interface defined in the public section of Type. The default implementation
791 * invokes the std token output via
792 * DoWrite(TokenWriter&, const std::string&,const Type* )
793 *
794 * @param rTw
795 * Reference to TokenWriter
796 * @param rLabel
797 * Label of section to write
798 * @param pContext
799 * Write context to provide contextual information
800 *
801 * @exception Exception
802 * - IO errors (id 2)
803 */
804 virtual void DoXWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
805
806 /**
807 * Write configuration data in debugging format to TokenWriter.
808 *
809 * Reimplement this method in derived classes to provide the std token io
810 * interface defined in the public section of Type.
811 *
812 * @param rTw
813 * Reference to TokenWriter
814 * @param rLabel
815 * Label of section to write
816 * @param pContext
817 * Write context to provide contextual information
818 *
819 * @exception Exception
820 * - IO errors (id 2)
821 */
822 virtual void DoDWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
823
824 /**
825 * Write statistical data as a comment to TokenWriter.
826 *
827 * Reimplement this method in derived classes to provide the std token io
828 * interface defined in the public section of Type.
829 *
830 * @param rTw
831 * Reference to TokenWriter
832 *
833 * @exception Exception
834 * - IO errors (id 2)
835 */
836 virtual void DoSWrite(TokenWriter& rTw) const;
837
838 /**
839 * Get objects's type definition.
840 *
841 * Returns the type definition corresponding to this object, or
842 * NULL if the object is not of a registered type.
843 *
844 * Technical note: for minimal memory requirement, the type definition
845 * is not cached but retrieved on every invokation of this method.
846 * The derived class faudes::Type introduces a cache.
847 *
848 * @return
849 * Type definition reference.
850 */
851 virtual const TypeDefinition* TypeDefinitionp(void) const;
852
853
854 /*
855 * Convenience function to set up std begin token
856 * for XML mode token I/O.
857 *
858 * @param rLabel
859 * User specified label
860 * @param rFallbackLabel
861 * Class defined fallback label
862 * @return
863 * Configured begin token
864 */
865 virtual Token XBeginTag(const std::string& rLabel="", const std::string& rFallbackLabel="") const;
866
867
868private:
869
870 // static string constant.
871 static std::string msStringVoid;
872 static std::string msStringEmpty;
873
874};
875
876
877
878/** faudes type declaration macro */
879#define FAUDES_TYPE_DECLARATION(ftype,ctype,cbase) \
880 public: virtual ctype* New(void) const; \
881 public: virtual ctype* Copy(void) const; \
882 public: virtual const Type* Cast(const Type* pOther) const; \
883 public: virtual ctype& Assign(const Type& rSrc); \
884 public: virtual bool Equal(const Type& rOther) const; \
885 public: ctype& operator=(const ctype& rSrc); \
886 public: bool operator==(const ctype& rOther) const; \
887 public: bool operator!=(const ctype& rOther) const;
888
889/** faudes type declaration macro, template version */
890#define FAUDES_TYPE_TDECLARATION(ftype,ctype,cbase) \
891 public: virtual ctype* New(void) const; \
892 public: virtual ctype* Copy(void) const; \
893 public: virtual const Type* Cast(const Type* pOther) const; \
894 public: virtual ctype& Assign(const Type& rSrc); \
895 public: virtual bool Equal(const Type& rOther) const; \
896 public: ctype& operator=(const ctype& rSrc); \
897 public: bool operator==(const ctype& rOther) const; \
898 public: bool operator!=(const ctype& rOther) const;
899
900/** faudes type implementation macros */
901#define FAUDES_TYPE_IMPLEMENTATION_NEW(ftype,ctype,cbase) \
902 ctype* ctype::New(void) const { return new ctype(); }
903#define FAUDES_TYPE_IMPLEMENTATION_COPY(ftype,ctype,cbase) \
904 ctype* ctype::Copy(void) const { return new ctype(*this); }
905#define FAUDES_TYPE_IMPLEMENTATION_CAST(ftype,ctype,cbase) \
906 const Type* ctype::Cast(const Type* pOther) const { \
907 return dynamic_cast< const ctype * >(pOther); }
908#define FAUDES_TYPE_IMPLEMENTATION_ASSIGN(ftype,ctype,cbase) \
909 ctype& ctype::Assign(const Type& rSrc) { \
910 if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
911 /* this->Clear(); */ DoAssign(*csattr);} \
912 else { \
913 cbase::Assign(rSrc);}; \
914 return *this;} \
915 ctype& ctype::operator=(const ctype& rSrc) { /* this->Clear() */; DoAssign(rSrc); return *this; }
916#define FAUDES_TYPE_IMPLEMENTATION_EQUAL(ftype,ctype,cbase) \
917 bool ctype::Equal(const Type& rOther) const { \
918 if(&rOther==this) return true; \
919 if(typeid(rOther) != typeid(*this)) return false; \
920 const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
921 if(!csattr) return false; \
922 if(!DoEqual(*csattr)) return false; \
923 return true;} \
924 bool ctype::operator==(const ctype& rOther) const { return DoEqual(rOther); } \
925 bool ctype::operator!=(const ctype& rOther) const { return !DoEqual(rOther); }
926
927/** faudes type implementation macros, template version */
928#define FAUDES_TYPE_TIMPLEMENTATION_NEW(ftype,ctype,cbase,ctemp) \
929 ctemp ctype* ctype::New(void) const { \
930 return new ctype(); }
931#define FAUDES_TYPE_TIMPLEMENTATION_COPY(ftype,ctype,cbase,ctemp) \
932 ctemp ctype* ctype::Copy(void) const { \
933 return new ctype(*this); }
934#define FAUDES_TYPE_TIMPLEMENTATION_CAST(ftype,ctype,cbase,ctemp) \
935 ctemp const Type* ctype::Cast(const Type* pOther) const { \
936 return dynamic_cast< const ctype * >(pOther); }
937#define FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(ftype,ctype,cbase,ctemp) \
938 ctemp ctype& ctype::Assign(const Type& rSrc) { \
939 if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
940 /* this->Clear(); */ DoAssign(*csattr);} \
941 else { \
942 cbase::Assign(rSrc);}; \
943 return *this;} \
944 ctemp ctype& ctype::operator=(const ctype& rSrc) { /* this->Clear(); */ DoAssign(rSrc); return *this; }
945#define FAUDES_TYPE_TIMPLEMENTATION_EQUAL(ftype,ctype,cbase,ctemp) \
946 ctemp bool ctype::Equal(const Type& rOther) const { \
947 if(&rOther==this) return true; \
948 if(typeid(rOther) != typeid(*this)) return false; \
949 const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
950 if(!csattr) return false; \
951 if(!DoEqual(*csattr)) return false; \
952 return true;} \
953 ctemp bool ctype::operator==(const ctype& rOther) const { return DoEqual(rOther); } \
954 ctemp bool ctype::operator!=(const ctype& rOther) const { return !DoEqual(rOther); }
955
956
957/** faudes type implementation macros, overall */
958#define FAUDES_TYPE_IMPLEMENTATION(ftype,ctype,cbase) \
959 ctype* ctype::New(void) const { \
960 return new ctype(); } \
961 ctype* ctype::Copy(void) const { \
962 return new ctype(*this); } \
963 const Type* ctype::Cast(const Type* pOther) const { \
964 return dynamic_cast< const ctype * >(pOther); } \
965 ctype& ctype::Assign(const Type& rSrc) { \
966 if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
967 /* this->Clear(); */ this->DoAssign(*csattr);} \
968 else { \
969 cbase::Assign(rSrc);}; \
970 return *this;} \
971 ctype& ctype::operator=(const ctype& rSrc) { /* this->Clear(); */ this->DoAssign(rSrc); return *this; } \
972 bool ctype::Equal(const Type& rOther) const { \
973 if(&rOther==this) return true; \
974 if(typeid(rOther) != typeid(*this)) return false; \
975 const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
976 if(!csattr) return false; \
977 if(!this->DoEqual(*csattr)) return false; \
978 return true;} \
979 bool ctype::operator==(const ctype& rOther) const { return this->DoEqual(rOther); } \
980 bool ctype::operator!=(const ctype& rOther) const { return !this->DoEqual(rOther); }
981
982
983/** faudes type implementation macros, overall */
984#define FAUDES_TYPE_TIMPLEMENTATION(ftype,ctype,cbase,ctemp) \
985 ctemp ctype* ctype::New(void) const { \
986 return new ctype(); } \
987 ctemp ctype* ctype::Copy(void) const { \
988 return new ctype(*this); } \
989 ctemp const Type* ctype::Cast(const Type* pOther) const { \
990 return dynamic_cast< const ctype * >(pOther); } \
991 ctemp ctype& ctype::Assign(const Type& rSrc) { \
992 if(const ctype* csattr=dynamic_cast< const ctype * >(&rSrc)) { \
993 /* this->Clear(); */ this->DoAssign(*csattr);} \
994 else { \
995 cbase::Assign(rSrc);}; \
996 return *this;} \
997 ctemp ctype& ctype::operator=(const ctype& rSrc) { /* this->Clear(); */ this->DoAssign(rSrc); return *this; } \
998 ctemp bool ctype::Equal(const Type& rOther) const { \
999 if(&rOther==this) return true; \
1000 if(typeid(rOther) != typeid(*this)) return false; \
1001 const ctype* csattr=dynamic_cast<const ctype*>(&rOther); \
1002 if(!csattr) return false; \
1003 if(!this->DoEqual(*csattr)) return false; \
1004 return true;} \
1005 ctemp bool ctype::operator==(const ctype& rOther) const { return this->DoEqual(rOther); } \
1006 ctemp bool ctype::operator!=(const ctype& rOther) const { return !this->DoEqual(rOther); }
1007
1008
1009/**
1010 * Wrapper for dynamivc_cast<Type*>() that returns a nullptr when the argument is not a
1011 * polymorphic class (instead of a compile-time error). See TBaseSet::DoWrite() for the
1012 * use case that triggered this wrapper.
1013 */
1014template<class T, bool = std::is_polymorphic<T>::value>
1016};
1017template<class T>
1018class CastToType<T, true> {
1019public:
1020 static Type* Pointer(T* ptr) {return dynamic_cast<Type*>(ptr);};
1021 static const Type* ConstPointer(const T* ptr) {return dynamic_cast<const Type*>(ptr);};
1022};
1023template<class T>
1024 class CastToType<T,false> {
1025public:
1026 static Type* Pointer(T* ptr) {(void) ptr; return nullptr;};
1027 static const Type* ConstPointer(const T* ptr) {(void) ptr; return nullptr;};
1028};
1029
1030
1031
1032/**
1033 * Extended Type to base Attributes. Attributes are used as template parameters for
1034 * faudes containers and facilitate the modelling of customized properties of events,
1035 * states and transitions. See the class faudes::AttributeFlags for a non-trivial example.
1036 *
1037 * To derive a class from faudes::AttrType you should reimplement the virtual
1038 * interface
1039 * - virtual methods DoRead and DoWrite for token io (as in faudes::Type)
1040 * - virtual methods for DoAssign() (as in faudes::Type)
1041 * - the factory method New() (use provided macro from faudes::Type)
1042 * - the rti typecast method Cast() (use provided macro from faudes::Type)
1043 * - user level Assign() method (use provided macro from faudes::Type)
1044 * Use the FAUDES_TYPE_DECLARATION and FAUDES_TYPE_IMPLEMENTATION macros to generate
1045 * the API methods.
1046 *
1047 * The class faudes::AttrType extends the base Type marginally to distinguish void attributes
1048 * from plain type objects; i.e., we introduce a marker in the type hierarchy. There is (almost)
1049 * nothing functional about this class and we should find ways to go without.
1050 *
1051 * @ingroup RunTimeInterface
1052 */
1053
1054
1055class FAUDES_API AttrType : public Type {
1056
1058
1059public:
1060
1061 using Type::operator=;
1062 using Type::operator==;
1063 using Type::operator!=;
1064
1065 /** Constructor */
1066 AttrType(void);
1067
1068 /** Copy Constructor */
1069 AttrType(const AttrType& rSrc);
1070
1071 /** Destructor */
1072 virtual ~AttrType(void);
1073
1074 /** Test for default value. */
1075 virtual bool IsDefault(void) const {return true;};
1076
1077 /**
1078 * Skip attribute tokens.
1079 *
1080 * Helper method to be called after all sttribute derived classes had their
1081 * chance to read their data. It skips all tokens and sections until it reaches a
1082 * String or decimal Integer. This should go to BaseSet.
1083 *
1084 * @param rTr
1085 * TokenReader to read from
1086 * @exception Exception
1087 * - IO error (id 1)
1088 */
1089 static void Skip(TokenReader& rTr);
1090
1091protected:
1092
1093 /** Assign (no members, dummy) */
1094 void DoAssign(const AttrType& rSrc) { (void) rSrc; };
1095
1096 /** Test (no members, dummy) */
1097 bool DoEqual(const AttrType& rOther) const { (void) rOther; return true; }
1098
1099};
1100
1101
1102/**
1103 * This class extends the base Type by common features worthwhile for "large objects",
1104 * e.g., object name, a cache for the regsitry record and convenience access wrappers.
1105 *
1106 * @ingroup RunTimeInterface
1107 */
1108
1110
1111public:
1112
1113 using AttrType::operator=;
1114 using AttrType::operator==;
1115 using AttrType::operator!=;
1116
1117
1118 // std faudes type interface
1120
1121 /** Constructor */
1122 ExtType(void);
1123
1124 /** Copy constructor */
1125 ExtType(const ExtType& rType);
1126
1127 /** Destructor */
1128 virtual ~ExtType(void);
1129
1130 /**
1131 * Get objects name
1132 *
1133 * @return
1134 * Name
1135 */
1136 const std::string& Name(void) const;
1137
1138 /**
1139 * Set objects name
1140 *
1141 * @param rName
1142 * Name to set
1143 */
1144 void Name(const std::string& rName);
1145
1146
1147 /**
1148 * Get objects's type name.
1149 *
1150 * Retrieve the faudes-type name from the type registry.
1151 *
1152 * @return
1153 * Faudes-type name or empty string.
1154 */
1155 virtual const std::string& TypeName(void) const;
1156
1157 /**
1158 * Overwrite faudes-type name.
1159 *
1160 * This method is used to overwrite the faudes-type identifyer to account for
1161 * unregistered classe/
1162 *
1163 * @param rType
1164 * Faudes-type name to set
1165 */
1166 virtual void TypeName(const std::string& rType);
1167
1168 /**
1169 * Get the element name tag.
1170 *
1171 * Tags used for XML IO when eriting elements of a container class.
1172 * This is either the deribeved class default of found in the registry.
1173 *
1174 * @return
1175 * Tag
1176 */
1177 virtual const std::string& ElementTag(void) const;
1178 /**
1179 * Configure the element name tag.
1180 *
1181 * This method allows to overwrite the tag used for elements
1182 * in XML IO. For usual, you will register derived classes with
1183 * the run-time-interface and set the elemen tag for XML IO.
1184 *
1185 * @param rTag
1186 * Tag to set
1187 */
1188 virtual void ElementTag(const std::string& rTag);
1189
1190 /**
1191 * Get the element type.
1192 *
1193 * This should be found in the registry.
1194 *
1195 * @return
1196 * Tag
1197 */
1198 virtual const std::string& ElementType(void) const;
1199
1200 /**
1201 * Get registry record
1202 *
1203 * Returns nullptr if not registered
1204 *
1205 * @return
1206 * Pointer to registry entry
1207 */
1208 virtual const TypeDefinition* TypeDefinitionp(void) const;
1209
1210
1211private:
1212
1213 /** TypeDefinition cache (should use guarded pointer here) */
1215
1216 /** Current/cached faudes type-name */
1217 std::string mFaudesTypeName;
1218
1219 /** Current/cached name of elements (use protected accessor methods for caching) */
1220 std::string mElementTag;
1221
1222protected:
1223
1224 /** Current/cached name of elements (use protected accessor methods for caching) */
1225 std::string mElementType;
1226
1227 /** Defauft name of elements (if not over written manually or by registry) */
1228 std::string mElementTagDef;
1229
1230 /** object name */
1231 std::string mObjectName;
1232};
1233
1234
1235
1236
1237/**
1238 * Structure to hold documentation data relating to a faudes-type or -function.
1239 * This class is the common base for faudes::TypeDefinition and faudes::FunctionDefinition.
1240 * It supports token io as demonstrated by the follwoing example for a type defintion:
1241 *
1242 * @code
1243 * <TypeDefinition name="CoreFaudes::Generator" ctype="faudes::Generator">
1244 *
1245 * <Documentation ref="generators.html#plain">
1246 * The common 5 tuple G=(Sigma, Q, delta, Qo, Qm).
1247 * <Documentation/>
1248 *
1249 * <Keywords> "generator" "language" </Keywords>
1250 *
1251 * </TypeDefinition>
1252 * @endcode
1253 *
1254 * Technical detail: Documentation is derived from Type for the purpose of token IO. We
1255 * still implement the faudes type interface to make it a fully qualified faudes data type.
1256 *
1257 * Technical detail: To facilitate inheritance, token io of member data and token io of
1258 * the section tags is separated.
1259 */
1260
1262
1263 // std faudes type interface
1265
1266public:
1267
1268 using Type::operator=;
1269 using Type::operator==;
1270 using Type::operator!=;
1271
1272
1273 /** Constructor */
1274 Documentation(void);
1275
1276 /** Copy constructor */
1277 Documentation(const Documentation& rOther);
1278
1279 /** Destructor */
1280 virtual ~Documentation(void){};
1281
1282 /**
1283 * Clear
1284 */
1285 void Clear(void);
1286
1287 /**
1288 * Get name of the entity to document (aka faudes-type or faudes-function).
1289 *
1290 * @return
1291 * Name
1292 */
1293 const std::string& Name(void) const;
1294
1295 /**
1296 * Get name of plugin.
1297 * The plugin name defaults to CoreFaudes.
1298 *
1299 * @return
1300 * Name
1301 */
1302 const std::string& PlugIn(void) const;
1303
1304 /**
1305 * Get corresponding C++ type
1306 *
1307 * @return
1308 * CType, or "" if no such
1309 */
1310 const std::string& CType(void) const;
1311
1312 /**
1313 * @return
1314 * Short textual documentation.
1315 */
1316 const std::string& TextDoc(void) const;
1317
1318 /**
1319 * @return
1320 * Filename pointing to the html documentation.
1321 */
1322 const std::string& HtmlDoc(void) const;
1323
1324 /**
1325 * @return
1326 * CSV-string containing keywords.
1327 */
1328 const std::string& Keywords(void) const;
1329
1330 /**
1331 * Search comma-seperated keywords for a substring. This should be
1332 * extended to regular expressions in a future release.
1333 *
1334 * @param rPattern
1335 * String-pattern.
1336 *
1337 * @return
1338 * Matching keyword or "" if no match
1339 */
1340 std::string MatchKeyword(const std::string& rPattern) const;
1341
1342 /**
1343 * Not implemented
1344 * @return
1345 * Number of keywords.
1346 */
1347 int KeywordsSize(void) const;
1348
1349 /**
1350 * @param pos
1351 * Position of keyword
1352 * @return
1353 * Keyword at specified position (or "" if pos out of range)
1354 */
1355 std::string KeywordAt(int pos) const;
1356
1357 /**
1358 * Get auto-register flag.
1359 *
1360 * This flag indicated that the respective type was (will be)
1361 * registered by a libFAUDES static initialisation protorype.
1362 *
1363 * @return
1364 * True <> C++-automatic-registration
1365 */
1366 bool AutoRegistered(void) const;
1367
1368 /**
1369 * Get application-registered flag.
1370 *
1371 * @return
1372 * True <> registered by application
1373 */
1374 bool ApplicationRegistered(void) const;
1375
1376 /**
1377 * Merge documentation from token stream.
1378 * An exception is thrown if the current type name differs from the one in the documentation.
1379 *
1380 * @param rTr
1381 * TokenReader to read from.
1382 *
1383 * @exception Exception
1384 * - Type mismatch (id )
1385 * - Token mismatch (id 50, 51, 52)
1386 * - IO Error (id 1)
1387 */
1388 virtual void MergeDocumentation(TokenReader& rTr);
1389
1390
1391
1392 protected:
1393
1394 /**
1395 * Set name.
1396 *
1397 * @param name
1398 * New name.
1399 */
1400 void Name(const std::string& name);
1401
1402 /**
1403 * Set name of plugin
1404 *
1405 * @param plugin
1406 * New name.
1407 */
1408 void PlugIn(const std::string& plugin);
1409
1410 /**
1411 * Set C++ type
1412 *
1413 * @param name
1414 * New ctype.
1415 */
1416 void CType(const std::string& name);
1417
1418 /**
1419 * Set a short textual documentation.
1420 *
1421 * @param textdoc
1422 * New textual documentation.
1423 */
1424 void TextDoc(const std::string& textdoc);
1425
1426 /**
1427 * Set auto-register flag.
1428 *
1429 * See also AutoRegistered(void)
1430 *
1431 * @param flag
1432 * Flag value.
1433 */
1434 void AutoRegistered(bool flag);
1435
1436 /**
1437 * Set application-registered flag.
1438 *
1439 * See also AutoRegistered(void)
1440 *
1441 * @param flag
1442 * Flag value.
1443 */
1444 void ApplicationRegistered(bool flag);
1445
1446 /**
1447 * Set name of file pointing to the html documentation.
1448 *
1449 * @param fname
1450 * Filename
1451 */
1452 void HtmlDoc(const std::string& fname);
1453
1454 /**
1455 * Append keyword.
1456 *
1457 * @param rKeyword
1458 * Keyword
1459 */
1460 void AddKeyword(const std::string& rKeyword);
1461
1462 /**
1463 * Std faudes type interface: assignment.
1464 *
1465 * @param rSrc
1466 * Source to copy from
1467 */
1468 void DoAssign(const Documentation& rSrc);
1469
1470 /**
1471 * Std faudes type interface: test equality
1472 *
1473 * @param rOther
1474 * Other object to compare with.
1475 * @return
1476 * True on match.
1477 */
1478 bool DoEqual(const Documentation& rOther) const;
1479
1480 /**
1481 * Read configuration data of this object from TokenReader.
1482 *
1483 * This virtual function reads documentation from a token stream.
1484 * The section defaults to Documentation. It invokes DoReadCore to
1485 * do the member data token reading.
1486 *
1487 * @param rTr
1488 * TokenReader to read from
1489 * @param rLabel
1490 * Section to read
1491 * @param pContext
1492 * Read context to provide contextual information (ignored)
1493 *
1494 * @exception Exception
1495 * - Token mismatch (id 50, 51, 52)
1496 * - IO Error (id 1)
1497 */
1498 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
1499
1500 /**
1501 * Read configuration data of this object from TokenReader.
1502 *
1503 * This virtual function reads documentation member data only.
1504 * It does NOT read the enclosing begin and end tokens.
1505 *
1506 * @param rTr
1507 * TokenReader to read from
1508 *
1509 * @exception Exception
1510 * - Token mismatch (id 50, 51, 52)
1511 * - IO Error (id 1)
1512 */
1513 virtual void DoReadCore(TokenReader& rTr);
1514
1515
1516
1517 /**
1518 * Write configuration data of this object to TokenWriter.
1519 *
1520 * This virtual function writes documentation to a token stream.
1521 * The section defaults to Documentation. It invokes DoWriteCore to
1522 * do the actual member data writing.
1523 *
1524 * @param rTw
1525 * Reference to TokenWriter
1526 * @param rLabel
1527 * Label of section to write
1528 * @param pContext
1529 * Write context to provide contextual information
1530 *
1531 * @exception Exception
1532 * - IO errors (id 2)
1533 */
1534 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
1535
1536
1537 /**
1538 * Write configuration data of this object to TokenWriter.
1539 *
1540 * This virtual function reads documentation members only.
1541 * It does NOT write enclosing begin and end tokens.
1542 *
1543 * @param rTw
1544 * Reference to TokenWriter
1545 *
1546 * @exception Exception
1547 * - IO errors (id 2)
1548 */
1549 virtual void DoWriteCore(TokenWriter& rTw) const;
1550
1551
1552 /** Faudes name. */
1553 std::string mName;
1554
1555 /** Faudes plugin. */
1556 std::string mPlugIn;
1557
1558 /** Corresponing C++ type, or "" if no such. */
1559 std::string mCType;
1560
1561 /** String containing the text-documentation. */
1562 std::string mTextDoc;
1563
1564 /** String containing the filename of the corresponding html-documentation. */
1565 std::string mHtmlDoc;
1566
1567 /** Comma-seperated string containing all keywords. */
1568 std::string mKeywords;
1569
1570 /** Constant characted used to seperate keywords */
1571 static const char mDelim = ';';
1572
1573 /** Flag to indicate automated registration */
1575
1576 /** Flag to indicate application registration */
1578
1579}; // Documentation
1580
1581
1582
1583/**
1584 * A TypeDefinition defines a faudes-type in that it specifies
1585 * a faudes-type name to identify the type and a method
1586 * NewObject() to instantiate objects of the respective type.
1587 * In this sense, TypeDefinition is a so called factory class.
1588 * Technically, the TypeDefinition holds one instance of the faude type,
1589 * the so called prototype object, and NewObject() invokes the New() method
1590 * of the prototype. Notebly, there is only one class TypeDefinition that by
1591 * parametrisation defins all derivates of Type.
1592 *
1593 * TypeDefinition is derived from faudes::Documentation and therefore additional
1594 * documentation-data can be associated.
1595 *
1596 *
1597 * @ingroup RunTimeInterface
1598 */
1599
1601
1602 // std faudes type interface
1604
1605 // regisry is friend to set protected values
1606 friend class TypeRegistry;
1607
1608 public:
1609
1610 using Documentation::operator=;
1611 using Documentation::operator==;
1612 using Documentation::operator!=;
1613
1614 /**
1615 * Constructor
1616 *
1617 * The default constructor instantiates an invalid type definition
1618 * without prototype. To construct
1619 * a valid type definition, use the static Constructor() template
1620 * function.
1621 */
1622 TypeDefinition(const std::string& name="") : Documentation(), mpType(NULL) {Name(name);};
1623
1624 /**
1625 * Destructor.
1626 *
1627 * Delete prototype object.
1628 */
1629 virtual ~TypeDefinition(void){ Prototype(NULL); };
1630
1631 /**
1632 * Construct empty TypeDefinition object.
1633 * The given template parameter denotes any libFAUDES class derived from faudes::Type
1634 * A new instance of this class is assigned to member variable (pType)
1635 * whereas the name is set as specified.
1636 *
1637 * @tparam T
1638 * Actual c class, derived from Type
1639 * @param rTypeName
1640 * Name to identify this faudes-type<; defaults to the plattform
1641 * dependand typeid from the c++ runtime type information system.
1642 * @return
1643 * Newly constructed type definition.
1644 *
1645 */
1646 template<class T>
1647 static TypeDefinition* Constructor(const std::string& rTypeName="");
1648
1649 /**
1650 * Construct empty TypeDefinition object.
1651 * The given prototype is assigned to the member variable pType,
1652 *
1653 * @param pProto
1654 * Prototype, derived from Type
1655 * @param rTypeName
1656 * Name to identify this faudes-type<; defaults to the plattform
1657 * dependand typeid from the c++ runtime type information system.
1658 * @return
1659 * Newly constructed type definition.
1660 *
1661 */
1662 static TypeDefinition* Constructor(Type* pProto, const std::string& rTypeName="");
1663
1664 /**
1665 * Construct TypeDefinition object and read name and
1666 * documentation-data from TokenReader.
1667 *
1668 * @tparam T
1669 * Actual c class, derived from Type
1670 * @param rFileName
1671 * Name of file to read.
1672 * @return
1673 * Newly constructed type definition.
1674 *
1675 * @exception Exception
1676 * - Token mismatch (id 50, 51, 52)
1677 * - IO Error (id 1)
1678 */
1679 template<class T>
1680 static TypeDefinition* FromFile(const std::string& rFileName);
1681
1682
1683 /**
1684 * Return pointer to faudes-object prototype
1685 *
1686 * Note: this method is meant for inspection only, control over
1687 * the prototype remains with the TypeDefinition. Use
1688 * NewObject() to instantiate a new faudes-object.
1689 *
1690 * @return
1691 * Reference to prototype object
1692 */
1693 const Type* Prototype(void) const;
1694
1695
1696 /**
1697 * Construct faudes-object on heap.
1698 * Return pointer to new instance of assigned Type class.
1699 *
1700 * Note: If no prototype is installed, NULL is returned.
1701 *
1702 * @return
1703 * Pointer to new Type instance.
1704 */
1705 Type* NewObject(void) const;
1706
1707
1708 /**
1709 * Parameter access: Element Tag
1710 *
1711 * This parameter is used for IO of sets and vectors. It determines
1712 * the tag to used for individual elments.
1713 *
1714 * @return
1715 * Tag parameter.
1716 */
1717 const std::string& ElementTag(void) const;
1718
1719 /**
1720 * Parameter access: Element Tag
1721 *
1722 * @param rTag
1723 * New tag parameter
1724 */
1725 void ElementTag(const std::string& rTag);
1726
1727 /**
1728 * Parameter access: Element Tag
1729 *
1730 * This parameter is used for IO of sets and vectors. It determines
1731 * the type to used for individual elments.
1732 *
1733 * @return
1734 * Tag parameter.
1735 */
1736 const std::string& ElementType(void) const;
1737
1738 /**
1739 * Parameter access: Element Tag
1740 *
1741 * @param rTag
1742 * New tag parameter
1743 */
1744 void ElementType(const std::string& rEype);
1745
1746protected:
1747
1748
1749 /**
1750 * Std faudes type interface: assignment.
1751 *
1752 * @param rSrc
1753 * Source to copy from
1754 */
1755 void DoAssign(const TypeDefinition& rSrc);
1756
1757 /**
1758 * Std faudes type interface: test equality
1759 *
1760 * @param rOther
1761 * Other object to compare with.
1762 * @return
1763 * True on match.
1764 */
1765 bool DoEqual(const TypeDefinition& rOther) const;
1766
1767 /** Disable copy constructor */
1768 TypeDefinition(const TypeDefinition& rOther) : Documentation(rOther) {}; // todo: implement ?? for stl maps ?
1769
1770 /**
1771 * Clear documentation-data; do *NOT* delete prototype (this is for using Read to
1772 * merge/overwrite documentation)
1773 */
1774 void Clear(void);
1775
1776 /**
1777 * Use given object as prototype.
1778 *
1779 * The TypeDefinition takes ownership of the
1780 * provided object.
1781 *
1782 * @param pType
1783 * Any class that inherits Type.
1784 */
1785 virtual void Prototype(Type* pType);
1786
1787 /**
1788 * Read configuration data of this object from TokenReader.
1789 *
1790 * The section defaults to "TypeDefinition", context ignored.
1791 * Actual reading is done by DoReadCore.
1792 *
1793 * @param rTr
1794 * TokenReader to read from
1795 * @param rLabel
1796 * Section to read
1797 * @param pContext
1798 * Read context to provide contextual information (ignored)
1799 *
1800 * @exception Exception
1801 * - Token mismatch (id 50, 51, 52)
1802 * - IO error (id 1)
1803 */
1804 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
1805
1806 /**
1807 * Read configuration data of this object from TokenReader.
1808 *
1809 * This method reads members only, it does not read the section.
1810 *
1811 * @param rTr
1812 * TokenReader to read from
1813 *
1814 * @exception Exception
1815 * - Token mismatch (id 50, 51, 52)
1816 * - IO error (id 1)
1817 */
1818 virtual void DoReadCore(TokenReader& rTr);
1819
1820 /**
1821 * Write configuration data of this object to TokenWriter.
1822 *
1823 * The section defaults to "TypeDefinition", context ignored.
1824 * Actual writing is done by DoWriteCore.
1825 *
1826 * @param rTw
1827 * Reference to TokenWriter
1828 * @param rLabel
1829 * Label of section to write
1830 * @param pContext
1831 * Write context to provide contextual information
1832 *
1833 * @exception Exception
1834 * - IO errors (id 2)
1835 */
1836 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
1837
1838 /**
1839 * Write configuration data of this object to TokenWriter.
1840 *
1841 * This method wrtite plain member data, the section lables are not
1842 * written.
1843 *
1844 * @param rTw
1845 * Reference to TokenWriter
1846 *
1847 * @exception Exception
1848 * - IO errors (id 2)
1849 */
1850 virtual void DoWriteCore(TokenWriter& rTw) const;
1851
1852 /** Type-pointer tp prototype instance */
1854
1855 /** Extra documentation/parameter: Element Type */
1856 std::string mElementType;
1857
1858 /** Extra documentation/parameter: Element Tag */
1859 std::string mElementTag;
1860
1861}; //TypeDefinition
1862
1863
1864
1865
1866/**********************************************************************************************
1867***********************************************************************************************
1868***********************************************************************************************
1869
1870Implemention of template members functions
1871
1872***********************************************************************************************
1873***********************************************************************************************
1874**********************************************************************************************/
1875
1876
1877// Typedefinition constructor function
1878template<class T>
1879TypeDefinition* TypeDefinition::Constructor(const std::string& rTypeName){
1880 FD_DRTI("TypeDefinition::Construct<" << typeid(T).name() << ">(" << rTypeName << ")");
1881 TypeDefinition* ftd=Constructor(new T, rTypeName);
1882 /*
1883 cproto= *(ftd->Prototype());
1884 FD_WARN("TypeDefinition::Construct<>: fprototype " << typeid(cproto).name());
1885 */
1886 return ftd;
1887}
1888
1889
1890// Type definition constructor function
1891template<class T>
1892TypeDefinition* TypeDefinition::FromFile(const std::string& rFileName){
1893 FD_DRTI("TypeDefinition::FromFile<" << typeid(T).name() << ">()");
1894 // construct with fallback name
1896 // read docu, incl actual name
1897 td->Read(rFileName);
1898 // done
1899 return(td);
1900}
1901
1902
1903
1904
1905
1906} // namespace
1907
1908#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:879
void DoAssign(const AttrType &rSrc)
Definition cfl_types.h:1094
virtual bool IsDefault(void) const
Definition cfl_types.h:1075
bool DoEqual(const AttrType &rOther) const
Definition cfl_types.h:1097
static Type * Pointer(T *ptr)
Definition cfl_types.h:1026
static const Type * ConstPointer(const T *ptr)
Definition cfl_types.h:1027
static const Type * ConstPointer(const T *ptr)
Definition cfl_types.h:1021
static Type * Pointer(T *ptr)
Definition cfl_types.h:1020
std::string mKeywords
Definition cfl_types.h:1568
virtual ~Documentation(void)
Definition cfl_types.h:1280
std::string mElementTagDef
Definition cfl_types.h:1228
std::string mObjectName
Definition cfl_types.h:1231
std::string mElementType
Definition cfl_types.h:1225
std::string mElementTag
Definition cfl_types.h:1220
std::string mFaudesTypeName
Definition cfl_types.h:1217
const TypeDefinition * pTypeDefinition
Definition cfl_types.h:1214
std::string mElementTag
Definition cfl_types.h:1859
virtual ~TypeDefinition(void)
Definition cfl_types.h:1629
static TypeDefinition * FromFile(const std::string &rFileName)
Definition cfl_types.h:1892
TypeDefinition(const TypeDefinition &rOther)
Definition cfl_types.h:1768
std::string mElementType
Definition cfl_types.h:1856
static TypeDefinition * Constructor(const std::string &rTypeName="")
Definition cfl_types.h:1879
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
static std::string msStringEmpty
Definition cfl_types.h:872
static std::string msStringVoid
Definition cfl_types.h:871

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen