cfl_functions.h
Go to the documentation of this file.
1/** @file cfl_functions.h Runtime interface, operations on faudes types */
2
3/* FAU Discrete Event Systems Library (libfaudes)
4
5Copyright (C) 2009 Ruediger Berndt
6Copyright (C) 2010 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_RTIFNCTS_H
24#define FAUDES_RTIFNCTS_H
25
26// todo: fix/hide copy constructor
27
28#include "cfl_types.h"
29
30namespace faudes{
31
32/**
33 * Structure to model a parameter type within the Signature of a
34 * Function.
35 * A Parameter is made of a descriptive name, a faudes type and
36 * an io-attribute. The latter specifies whether the parameter
37 * is a const argument (<tt>In</tt>), a result (<tt>Out</tt>) or a both-ways
38 * parameter (<tt>InOut</tt>). To support the code generators of the run-time-interface,
39 * you may use the CReturn flag to indicate that the parameter is implemented
40 * as the return value in the corresponding C function. The current version of the
41 * code generators will handle this case for the elementary types Integer, Boolean and
42 * String. They will, however, fail on any other faudes types.
43 */
44
46
47 public:
48
49 /**
50 * A function parameter has has one out of four so called io-attrributes;
51 */
53 In, //// Input parameter, aka argument, remains constant while execution
54 Out, //// Output parameter, aka result, is generated during function execution
55 InOut, //// InOut parameter, is interpreted and possibly altered during execution
56 UnDef //// UnDef parameter indicates unconfigured signature
57 };
58
59 /** Constructor, default */
60 Parameter(void);
61
62 /** Constructor, by member values */
63 Parameter(const std::string& rName, const std::string& rTypeName,
64 ParamAttr attr=UnDef, bool cret=false);
65
66 /** Desctructor */
67 ~Parameter(void);
68
69 /**
70 * Get name
71 *
72 * @return
73 * Name of parameter
74 */
75 const std::string& Name(void) const;
76
77 /**
78 * Set name
79 *
80 * @param rName
81 * New name of parameter
82 */
83 void Name(const std::string& rName);
84
85 /**
86 * Get type
87 *
88 * @return
89 * Faudes type of parameter
90 */
91 const std::string& Type(void) const;
92
93 /**
94 * Set type
95 *
96 * @param rTypeName
97 * New faudes type of parameter
98 */
99 void Type(const std::string& rTypeName);
100
101 /**
102 * Get Attribute
103 *
104 * @return
105 * In/Out/InOut attribute of parameter.
106 */
107 const ParamAttr& Attribute(void) const;
108
109 /**
110 * Set Attribute
111 *
112 * @param rAttr
113 * In/Out/InOut attribute of parameter.
114 */
115 void Attribute(const ParamAttr& rAttr);
116
117 /**
118 * Set Attribute by string.
119 * Convenience method, defaults to UnDef.
120 *
121 * @param rAttrStr
122 * In/Out/InOut attribute of parameter.
123 */
124 void Attribute(const std::string& rAttrStr);
125
126 /**
127 * Get C-Return flag.
128 *
129 * @return
130 * C-Return flag
131 */
132 bool CReturn(void) const;
133
134 /**
135 * Set C-Return flag.
136 *
137 * @param cret
138 * New value of C-Return flag.
139 */
140 void CReturn(bool cret);
141
142 /**
143 * Convenience method to produce a textual representation of an io attribute.
144 *
145 * @param attr
146 * Enum value denoting the attribute.
147 * @return
148 * Parameter IO attribute as std::string
149 */
150 static std::string AStr(Parameter::ParamAttr attr);
151
152 /**
153 * Convenience method to produce a textual representation of a parameter.
154 *
155 */
156 std::string Str(void) const;
157
158 /**
159 * Set to "undefined"
160 */
161 void Clear();
162
163 /**
164 * Test equality
165 *
166 * @param rOther
167 * Other signature to compare with.
168 */
169 bool operator==(const Parameter& rOther) const;
170
171protected:
172
173 /** Name */
174 std::string mName;
175
176 /** Faudes type */
177 std::string mTDName;
178
179 /** IO-Attribute */
181
182 /** C-Return flag */
184
185}; // Parameter
186
187
188
189
190/**
191 * Signature of a Function.
192 *
193 * A Signature describes the faudes types of the positional
194 * parameters. Tecnically, a Signature is a vector of Parameters.
195 * Each Function may execute serveral variants indicated by setting
196 * a particular Signature. A list of valid Signatures is maintained in
197 * the coresponding FunctionDefinition.
198 *
199 * Core members are
200 * - mName: string to identify ths signature
201 * - mParameters: vector of Paramters.
202 *
203 * The Signature is formally derived from Type to inherit the std token io
204 * interface. It is not meant to be registered as a faudes type.
205 * The token io format is demonstrated by the following example:
206 *
207 * @code
208 * <Signature name="Sum of two integers">
209 * <Parameter name="arg1" ftype="Integer" access="InOut"/>
210 * <Parameter name="arg2" ftype="Integer" access="In"/>
211 * <Parameter name="res" ftype="String" access="Out" creturn="true"/>
212 * </Signature>
213 * @endcode
214 *
215 * Technical note: the variable parameter feature offered by FunctionDefinition is a purely
216 * cosmetic hack implemented in FunctionDefinition:MergeDocumentation. It is superseeded
217 * by vector parameters and will hence disappear in a future implementation.
218 */
219
220class FAUDES_API Signature : public Type {
221
222 // std faudes type interface
224
225public:
226
227 using Type::operator=;
228 using Type::operator==;
229 using Type::operator!=;
230
231 /** Constructor */
232 Signature(void);
233
234 /** Copy constructor */
235 Signature(const Signature& rSrc);
236
237 /** Destructor */
238 ~Signature(void){};
239
240 /**
241 * Return signature name.
242 *
243 * @return
244 * Name
245 */
246 const std::string& Name(void) const;
247
248 /**
249 * Set signature name.
250 *
251 * @param
252 * rName
253 */
254 void Name(const std::string& rName);
255
256 /**
257 * Clear signature
258 */
259 void Clear(void);
260
261 /**
262 * Return number of parameters.
263 *
264 * @return
265 * int
266 */
267 int Size(void) const;
268
269 /**
270 * Get parameter type by position.
271 *
272 * @param n
273 * Position of patameter.
274 *
275 * @exception Exception
276 * - Index out of range
277 */
278 const Parameter& At(int n) const;
279
280 /**
281 * Set parameter type by position.
282 *
283 * @param n
284 * Position of patameter.
285 * @param rParam
286 * Paraeter value
287 *
288 * @exception Exception
289 * - Index out of range
290 */
291 void At(int n,const Parameter& rParam);
292
293 /**
294 * Append positional parameter.
295 *
296 * @param rParam
297 * Parameter to append
298 */
299 void Append(const Parameter& rParam);
300
301
302 protected:
303
304 /**
305 * Std faudes type interface: assignment.
306 *
307 * @param rSrc
308 * Source to copy from
309 */
310 void DoAssign(const Signature& rSrc);
311
312 /**
313 * Std faudes type interface: test equality
314 *
315 * @param rOther
316 * Other object to compare with.
317 * @return
318 * True on match.
319 */
320 bool DoEqual(const Signature& rOther) const;
321
322 /**
323 * Read signature from from TokenReader.
324 *
325 * The section is hardcoded to "Signature", context is ignored.
326 *
327 * @param rTr
328 * TokenReader to read from
329 * @param rLabel
330 * Section to read
331 * @param pContext
332 * Read context to provide contextual information (ignored)
333 *
334 * @exception Exception
335 * - IO error (id 1)
336 * - Token mismatch (id 50, 51, 52)
337 */
338 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
339
340 /**
341 * Write configuration data of this object to TokenWriter.
342 *
343 * The section is hardcoded to "Signature", context is ignored.
344 *
345 * @param rTw
346 * Reference to TokenWriter
347 * @param rLabel
348 * Label of section to write
349 * @param pContext
350 * Write context to provide contextual information
351 *
352 * @exception Exception
353 * - IO errors (id 2)
354 */
355 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
356
357 /** Variable to store name */
358 std::string mName;
359
360 /** Vector of Parameter-objects */
361 std::vector<Parameter> mParameters;
362
363}; // Signature
364
365
366
367// forward
368class Function;
369
370
371/**
372 * A FunctionDefinition defines the interface to a faudes-function.
373 * The latter consists of a descriptive name to identify the function and
374 * a list of Signatures the function can operate on.
375 * Technically, the class FunctionDefinition is derived from Documentation and
376 * thereby inherits members for additional
377 * documentation-data.
378 *
379 * Similar to Type and TypeDefinition, a FunctionDefinition uses a prototype object to
380 * provide the method NewFunction() which instantiates the corresponding Function object.
381 *
382 * FunctionDefinition inherits the token io interface from Type, however, the class is
383 * not intended to register as a faudes type. The token io format is demonstrated by the
384 * following example:
385 *
386 * @code
387 * <FunctionDefinition name="CoreFaudes::IntegerSum" ctype="faudes::IntegerSum">
388 *
389 * <Documentation ref="integersum.html">
390 * Returns the sum of integer arguments.
391 * <Documentation/>
392 *
393 * <Keywords> "integer" "elemetary types" </Keywords>
394 *
395 * <VariantSignatures>
396 *
397 * <Signature name="Two arguments">
398 * <Parameter name="Arg1" ftype="Integer" access="In">
399 * <Parameter name="Arg2" ftype="Integer" access="In">
400 * <Parameter name="Res" ftype="Integer" access="Out" creturn="true">
401 * </Signature>
402 *
403 * <Signature name="Three arguments">
404 * <Parameter name="Arg1" ftype="Integer" access="In">
405 * <Parameter name="Arg2" ftype="Integer" access="In">
406 * <Parameter name="Arg3" ftype="Integer" access="In">
407 * <Parameter name="Res" ftype="Integer" access="Out" creturn="true">
408 * </Signature>
409 *
410 * </VariantSignatures>
411 *
412 * </FunctionDefinition>
413 * @endcode
414 *
415 *
416 * @ingroup RunTimeInterface
417 */
418
420
421 // std faudes type interface
423
424public:
425
426 using Documentation::operator=;
427 using Documentation::operator==;
428 using Documentation::operator!=;
429
430 /**
431 * Constructor
432 *
433 * The default constructor instantiates an invalid function definition
434 * without prototype. To construct a valid function definition, use the static
435 * Constructor() template function.
436 */
437 FunctionDefinition(const std::string& name="");
438
439 /**
440 * Copy Constructor
441 *
442 * The copy constructor copies all members one-to-one, except for
443 * the prototype object. The latter is re-created using its factory function.
444 */
446
447 /**
448 * Destructor
449 */
450 virtual ~FunctionDefinition(){ Prototype(NULL);};
451
452 /**
453 * Construct empty FunctionDefinition object.
454 * The given template parameter denotes a Function class.
455 * Member variable (mpFunction) is set to a new instance of that class
456 * whereas the name is set as specified. No further documentation
457 * or signatures are recorded.
458 *
459 * @tparam T
460 * Actual function class, derived from Function
461 * @param rFunctName
462 * Name to identify this faudes-function
463 * @return
464 * Newly constructed function definition.
465 */
466 template<class T>
467 static FunctionDefinition* Constructor(const std::string& rFunctName="");
468
469 /**
470 * Construct FunctionDefinition object and get name and docu from file.
471 *
472 * The member variable mpFunction is set to a new instance of class T.
473 * which must be derived from Function. The function name, any documentation
474 * as well as supported signatures are read from the specified file.
475 *
476 * @tparam T
477 * Actual function class, derived from Function
478 * @param rFileName
479 * File to read documentation and signatures from.
480 * @return
481 * Newly constructed function definition.
482 */
483 template<class T>
484 static FunctionDefinition* FromFile(const std::string& rFileName);
485
486 /**
487 * Clear documentation-data and signature (keep prototype)
488 */
489 virtual void Clear(void);
490
491
492 /**
493 * Clear variants (keep docu and prototype)
494 */
495 virtual void ClearVariants(void);
496
497 /**
498 * Return pointer to function object prototype
499 *
500 * Note: this method is meant for inspection only, control over
501 * the prototype remains with the FunctionDefinition. Use
502 * NewFunction() to instantiate a new function object.
503 *
504 * @return
505 * Reference to prototype function.
506 */
507 const Function* Prototype(void) const;
508
509 /**
510 * Construct function on heap.
511 * Return pointer to new instance of assigned Function class.
512 *
513 * Note: If no prototype is installed, NULL is returned.
514 *
515 * @return
516 * Pointer to new Function instance.
517 */
518 Function* NewFunction() const;
519
520
521 /**
522 * Return number of supported Signature instances.
523 *
524 * @return
525 * Size of signature vector.
526 */
527 int VariantsSize(void) const;
528
529 /**
530 * Test existence of variant by its name.
531 *
532 * @return
533 * True if variant exists
534 */
535 bool ExistsVariant(const std::string& varname) const;
536
537 /**
538 * Return index of Signature by name.
539 *
540 * @param rName
541 * Name of signature to search.
542 * @return
543 * Index of signature, or -1 if not existant
544 */
545 int VariantIndex(const std::string& rName) const;
546
547 /**
548 * Return reference to Signature by name.
549 *
550 * @param rName
551 * Name of signature to search.
552 * @return
553 * Reference to Signature
554 * @exception Exception
555 * - No such signature (id 47)
556 */
557 const Signature& Variant(const std::string& rName) const;
558
559 /**
560 * Return reference to Signature by index.
561 *
562 * @param n
563 * Index to look up
564 * @return
565 * Reference to Signature
566 * @exception Exception
567 * - Index out of range (id 47)
568 */
569 const Signature& Variant(int n) const;
570
571 /**
572 * Add Signature to function definition.
573 *
574 * @param pVar
575 * Signature to insert
576 * @exception Exception
577 * - Signature with same name exists (id 47)
578 */
579 virtual void AppendVariant(const Signature& pVar);
580
581protected:
582
583 /**
584 * Std faudes type interface: assignment.
585 *
586 * @param rSrc
587 * Source to copy from
588 */
589 void DoAssign(const FunctionDefinition& rSrc);
590
591 /**
592 * Std faudes type interface: test equality
593 *
594 * @param rOther
595 * Other object to compare with.
596 * @return
597 * True on match.
598 */
599 bool DoEqual(const FunctionDefinition& rOther) const;
600
601 /**
602 * Read configuration data of this object from TokenReader.
603 * Actual reading is done by DoReadCore.
604 *
605 * The section defaults to "FunctionDefinition", context ignored.
606 *
607 * @param rTr
608 * TokenReader to read from
609 * @param rLabel
610 * Section to read
611 * @param pContext
612 * Read context to provide contextual information (ignored)
613 *
614 * @exception Exception
615 * - Token mismatch (id 50, 51, 52)
616 * - IO error (id 1)
617 */
618 virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
619
620 /**
621 * Read configuration data of this object from TokenReader.
622 *
623 * This method reads members only, it does not read the section.
624 *
625 * @param rTr
626 * TokenReader to read from
627 *
628 * @exception Exception
629 * - Token mismatch (id 50, 51, 52)
630 * - IO error (id 1)
631 */
632 virtual void DoReadCore(TokenReader& rTr);
633
634 /**
635 * Write configuration data of this object to TokenWriter.
636 *
637 * The section defaults to "FunctionDefinition", context ignored.
638 *
639 * @param rTw
640 * Reference to TokenWriter
641 * @param rLabel
642 * Label of section to write
643 * @param pContext
644 * Write context to provide contextual information
645 *
646 * @exception Exception
647 * - IO errors (id 2)
648 */
649 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
650
651 /**
652 * Write configuration data of this object to TokenWriter.
653 *
654 * This method writes plain member data, the section lables are not
655 * written.
656 *
657 * @param rTw
658 * Reference to TokenWriter
659 *
660 * @exception Exception
661 * - IO errors (id 2)
662 */
663 virtual void DoWriteCore(TokenWriter& rTw) const;
664
665 /**
666 * Assign prototype object
667 *
668 * @param pFunc
669 * Function instance
670 *
671 */
672 virtual void Prototype(Function* pFunc);
673
674 /** Prototype instance */
676
677 /** Vector containing all supported Signatures */
678 std::vector<faudes::Signature> mVariants;
679
680 /** Variant name to index map */
681 std::map<std::string,int> mVariantIndexMap;
682
683}; // FunctionDefinition
684
685
686
687/**
688 * A faudes-function hosts parameter values of some faudes type and provides
689 * a method to perform an operation on the specified paramters, e.g. the
690 * parallel composition on two generators. The class Function is the base
691 * for all faudes-functions, which essenitally differ in the operation method.
692 *
693 * The base class provides an application interface to
694 * - select a variant signature, see Variant();
695 * - set and get parameter values of any faudes type, see ParamValue();
696 * - type check the provided parameter values, see TypeCheck();
697 * - perform the operation, see Execute().
698 *
699 * Derivates of the base class, that acually implement an operation,
700 * are required to cast the parameter values to the corresponding c types and then
701 * call the respective c function. To derive a class from Function, one will
702 * reimplment three virtual functions:
703 * - DoTypeCheck() to perform the cast
704 * - DoExecute() to call the c function.
705 * - the constructor New() to replicate the function object.
706 *
707 * See IntegerSum in the autogenerated ./include/rtiautoload.h" for a simple example
708 * of a derived faudes-function.
709 *
710 *
711 * Technichal note: In contrast to faudes objects (derivates from Type), a faudes-function
712 * must be provided a reference to the corresponding FunctionDefinition. This is because
713 * a function must be aware of its signature(s). You must not delete
714 * the FunctionDefinition object during the lifetime of a faudes-function.
715 *
716 *
717 * @ingroup RunTimeInterface
718 */
719
720class FAUDES_API Function : public Type {
721
722 public:
723
724 using Type::operator=;
725 /**
726 * Constructor
727 * For the function to be operational, a valid reference to the corresponding
728 * FunctionDefinition is required. The only exception is the prototype function
729 * object used in the FunctionDefinition itself.
730 */
731 Function(const FunctionDefinition* fdef);
732
733 /** Destructor */
735
736 /**
737 * Construct on heap.
738 * Create a new instance of this function class and return pointer.
739 * The new instance will use the same function definition as this instance.
740 *
741 * @return
742 * Pointer to faudes::Function instance.
743 *
744 */
745 virtual Function* New() const = 0;
746
747
748 /**
749 * Set function definition.
750 * Normally, functions are provided with a function definition on construction.
751 * The only exception are prototype objects used in function definitions themselfs
752 * and in the function registry.
753 *
754 * @param fdef
755 * Function definition to set.
756 *
757 */
758 virtual void Definition(const FunctionDefinition* fdef);
759
760
761 /**
762 * Get function definition.
763 *
764 * @return
765 * Function definition used by this function.
766 *
767 */
768 const FunctionDefinition* Definition(void) const;
769
770
771 /**
772 * Return number of variants.
773 *
774 * @return
775 * Size of vector.
776 */
777 int VariantsSize(void) const;
778
779 /**
780 * Set signature from function definition.
781 *
782 * The index n refers this function's FunctionDefinition.
783 * An exception is thrown if no such FunctionDefinition is set, as it
784 * is the case for prototype instances.
785 *
786 * @param n
787 * Variant index
788 *
789 * @exception Exception
790 * - No function definition available (id 47)
791 * - No such variant (id 48)
792 */
793 void Variant(int n);
794
795
796 /**
797 * Set signature from function definition.
798 *
799 * The name refers to this function's FunctionDefinition.
800 * An exception is thrown if no such FunctionDefinition is set, as it
801 * is the case for prototype instances.
802 *
803 * @param rVariantName
804 * Variant name
805 *
806 * @exception Exception
807 * - No function definition available (id 47)
808 * - No such variant (id 48)
809 */
810 void Variant(const std::string& rVariantName);
811
812
813 /**
814 * Return pointer to assigned faudes::Signature.
815 *
816 * @return
817 * Pointer to faudes::Signature.
818 */
819 const Signature* Variant(void) const;
820
821
822 /**
823 * Return number of parameters with current signature.
824 *
825 * @return
826 * Size of vector.
827 */
828 int ParamsSize(void) const;
829
830 /**
831 * Set parameter at certain position.
832 *
833 * Sets the internal refernce of the parameter value
834 * at the spcefied index. The ownership of the value remains with
835 * the caller, ie it will not be deleted in the destructor of the
836 * function object.
837 * You may set the parameter value to any faudes type
838 * (classes derived from Type). A type check will be performed before the function
839 * is executed.
840 *
841 * @param n
842 * Position index of parameter
843 * @param param
844 * Pointer to faudes object.
845 *
846 * @exception Exception
847 * - Index out of range (id 47)
848 * - No variant set (id 47)
849 */
850 void ParamValue(int n, Type* param);
851
852 /**
853 * Get parameter value.
854 * Returns a reference to the parameter value at the specified position.
855 *
856 * @param n
857 * Position index of parameter.
858 *
859 * @exception Exception
860 * - Index out of range (id 47)
861 */
862 Type* ParamValue(int n) const;
863
864 /**
865 * Construct parameter values.
866 *
867 * This is a convenience method to allocate faudes objects for
868 * parameter values with the type specified by the current signature.
869 * Note that the function does not take ownetship of the parameter values and
870 * it is the callers responsibility to delete them when no longer required.
871 *
872 */
873 void AllocateValues(void);
874 void AllocateValue(int i);
875
876 /**
877 * Destruct parameter values.
878 *
879 * This is a convenience method to delete the assigned paramer values.
880 *
881 */
882 void FreeValues(void);
883
884 /**
885 * Perform a type check one parameter value.
886 *
887 * The type check is based on c type cast and should accept any types
888 * derived from the type given in the signature.
889 *
890 * @param n
891 * Position of parameter to check
892 * @return
893 * True if type matches
894 *
895 * @exception Exception
896 * - No variant specified (id 48)
897 * - Number of parameter is outside the specified signature (id 48)
898 *
899 */
900 bool TypeCheck(int n);
901
902 /**
903 * Perform a type check on the list of current parameter values.
904 *
905 * The type check is based on c type cast and should accept any types
906 * derived from those given in the signature.
907 *
908 * @return
909 * True if all parameter types matche the signature
910 *
911 * @exception Exception
912 * - No variant specified (id 48)
913 * - Number of parameters does not match signature (id 48)
914 *
915 */
916 bool TypeCheck(void);
917
918 /**
919 * Perform operation.
920 *
921 * Runs a type check and then the actual function.
922 *
923 * @exception Exception
924 * - No variant specified (id 48)
925 * - Parameter position out of range (id 48)
926 * - Type mismatch (id 48)
927 * - Any other exception thrown ba the actual function (id xxx)
928 */
929 void Execute(void);
930
931
932 protected:
933
934 /**
935 * Helper: generate typed reference for parameter.
936 *
937 * @param n
938 * Parameter position to cast
939 * @param rTypedRef
940 * Typed reference to generyte
941 * @tparam T
942 * c type to use for cast
943 * @return
944 * True if cast succeeded.
945 * @exception Exception
946 * - No variant specified (id 48)
947 * - Parameter position out of range (id 48)
948 */
949 template<class T>
950 bool DoTypeCast(int n, T*& rTypedRef) {
951 if(!Variant()) {
952 std::stringstream err;
953 err << "No variant specified";
954 throw Exception("Function::DoTypeCast()", err.str(), 48);
955 }
956 if(n<0 || n >= ParamsSize()) {
957 std::stringstream err;
958 err << "Parameter position out of range";
959 throw Exception("Function::DoTypeCast()", err.str(), 48);
960 }
961 rTypedRef=dynamic_cast<T*>(ParamValue(n));
962 return rTypedRef!=NULL;
963 }
964
965 /*
966 * Do set variant from function definition.
967 *
968 * The index n refers this function's FunctionDefinition.
969 * An exception is thrown if no FunctionDefinition is set, as it
970 * is the case for prototype instances.
971 *
972 * @param n
973 * Variant index
974 *
975 * @exception Exception
976 * - No function definition available (id 47)
977 * - No such variant (id 48)
978 */
979 virtual void DoVariant(int n);
980
981 /**
982 * Method to test the type of an assigned parameter with the
983 * specified faudes::Signature (i.e. their TypeDefinition label).
984 *
985 * Note: this method is called by Function::Execute() before actual function
986 * execution via DoExecute(). It may be used to perform a dynamic cast in
987 * preparation of DoExecute(). The latter is only called, if all types match.
988 *
989 * @param n
990 * Position of parameter to check
991 * @return
992 * True if type matches signature.
993 *
994 * @exception Exception
995 * - Signature undefined (id 48)
996 * - Parameter number out of range (id 48)
997 */
998 virtual bool DoTypeCheck(int n) = 0;
999
1000 /**
1001 * Executes code of reimplemented method of child class(es).
1002 */
1003 virtual void DoExecute() = 0;
1004
1005 /**
1006 * Write function-data (typeid-name of arguments) to TokenWriter.
1007 *
1008 * @param rTw
1009 * Reference to Tokenwriter.
1010 * @param rLabel
1011 * Label of section to write.
1012 * @param pContext
1013 * Context pointer, ignored
1014 *
1015 * @exception Exception
1016 * - IO Error
1017 */
1018 void DoWrite(TokenWriter& rTw, const std::string& rLabel = "", const Type* pContext=0) const;
1019
1020 /** corresponding function definition */
1022
1023 /** current variant aka signature as index w.r.t. the function definition */
1025
1026 /** Vector of arguments. */
1027 std::vector<Type*> mParameterValues;
1028
1029}; // Function
1030
1031
1032
1033/**********************************************************************************************
1034***********************************************************************************************
1035***********************************************************************************************
1036
1037Implemention of template members functions
1038
1039***********************************************************************************************
1040***********************************************************************************************
1041**********************************************************************************************/
1042
1043
1044// typedefinition constructor function
1045template<class T>
1046FunctionDefinition* FunctionDefinition::Constructor(const std::string& rFunctionName){
1047 FD_DRTI("FunctionDefinition::Construct<" << typeid(T).name() << ">()");
1048 // construct void definition
1050 // set its prototype object (note the 0 param in the new constructor)
1051 td->Prototype(new T(0));
1052 // set minmum values ie the function name
1053 std::string name=rFunctionName;
1054 if(name=="") name=typeid(T).name();
1055 td->Name(name);
1056 FD_DRTI("FunctionDefinition::Constructor<" << typeid(T).name() << ">(): done");
1057 return(td);
1058}
1059
1060
1061// function definition constructor function
1062template<class T>
1064 FD_DRTI("FunctionDefinition::FromFile<" << typeid(T).name() << ">()");
1065 // construct with fallback name
1067 // read docu, incl actual name
1068 td->Read(rFileName);
1069 // done
1070 FD_DRTI("FunctionDefinition::FromFile<" << typeid(T).name() << ">(): done");
1071 return(td);
1072}
1073
1074
1075} // namespace
1076
1077
1078#endif /* FAUDES_FUNCTIONS_H */
#define FD_DRTI(message)
#define FAUDES_API
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition cfl_types.h:879
const std::string & Name(void) const
const Function * Prototype(void) const
static FunctionDefinition * FromFile(const std::string &rFileName)
std::map< std::string, int > mVariantIndexMap
FunctionDefinition(const std::string &name="")
static FunctionDefinition * Constructor(const std::string &rFunctName="")
std::vector< faudes::Signature > mVariants
virtual Function * New() const =0
virtual bool DoTypeCheck(int n)=0
const FunctionDefinition * pFuncDef
bool DoTypeCast(int n, T *&rTypedRef)
std::vector< Type * > mParameterValues
virtual void DoExecute()=0
std::string mTDName
std::vector< Parameter > mParameters
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)

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