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 
5 Copyright (C) 2009 Ruediger Berndt
6 Copyright (C) 2010 Thomas Moor
7 
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12 
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
21 
22 
23 #ifndef FAUDES_RTIFNCTS_H
24 #define FAUDES_RTIFNCTS_H
25 
26 // todo: fix/hide copy constructor
27 
28 #include "cfl_types.h"
29 
30 namespace 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  */
52  enum ParamAttr{
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 
171 protected:
172 
173  /** Name */
174  std::string mName;
175 
176  /** Faudes type */
177  std::string mTDName;
178 
179  /** IO-Attribute */
181 
182  /** C-Return flag */
183  bool mCReturn;
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 
220 class FAUDES_API Signature : public Type {
221 
222  // std faudes type interface
224 
225 public:
226 
227  /** Constructor */
228  Signature(void);
229 
230  /** Copy constructor */
231  Signature(const Signature& rSrc);
232 
233  /** Destructor */
234  ~Signature(void){};
235 
236  /**
237  * Return signature name.
238  *
239  * @return
240  * Name
241  */
242  const std::string& Name(void) const;
243 
244  /**
245  * Set signature name.
246  *
247  * @param
248  * rName
249  */
250  void Name(const std::string& rName);
251 
252  /**
253  * Clear signature
254  */
255  void Clear(void);
256 
257  /**
258  * Return number of parameters.
259  *
260  * @return
261  * int
262  */
263  int Size(void) const;
264 
265  /**
266  * Get parameter type by position.
267  *
268  * @param n
269  * Position of patameter.
270  *
271  * @exception Exception
272  * - Index out of range
273  */
274  const Parameter& At(int n) const;
275 
276  /**
277  * Set parameter type by position.
278  *
279  * @param n
280  * Position of patameter.
281  * @param rParam
282  * Paraeter value
283  *
284  * @exception Exception
285  * - Index out of range
286  */
287  void At(int n,const Parameter& rParam);
288 
289  /**
290  * Append positional parameter.
291  *
292  * @param rParam
293  * Parameter to append
294  */
295  void Append(const Parameter& rParam);
296 
297 
298  protected:
299 
300  /**
301  * Std faudes type interface: assignment.
302  *
303  * @param rSrc
304  * Source to copy from
305  * @return Reference to this object.
306  */
307  void DoAssign(const Signature& rSrc);
308 
309  /**
310  * Std faudes type interface: test equality
311  *
312  * @param rOther
313  * Other object to compare with.
314  * @return
315  * True on match.
316  */
317  bool DoEqual(const Signature& rOther) const;
318 
319  /**
320  * Read signature from from TokenReader.
321  *
322  * The section is hardcoded to "Signature", context is ignored.
323  *
324  * @param rTr
325  * TokenReader to read from
326  * @param rLabel
327  * Section to read
328  * @param pContext
329  * Read context to provide contextual information (ignored)
330  *
331  * @exception Exception
332  * - IO error (id 1)
333  * - Token mismatch (id 50, 51, 52)
334  */
335  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
336 
337  /**
338  * Write configuration data of this object to TokenWriter.
339  *
340  * The section is hardcoded to "Signature", context is ignored.
341  *
342  * @param rTw
343  * Reference to TokenWriter
344  * @param rLabel
345  * Label of section to write
346  * @param pContext
347  * Write context to provide contextual information
348  *
349  * @exception Exception
350  * - IO errors (id 2)
351  */
352  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
353 
354  /** Variable to store name */
355  std::string mName;
356 
357  /** Vector of Parameter-objects */
358  std::vector<Parameter> mParameters;
359 
360 }; // Signature
361 
362 
363 
364 // forward
365 class Function;
366 
367 
368 /**
369  * A FunctionDefinition defines the interface to a faudes-function.
370  * The latter consists of a descriptive name to identify the function and
371  * a list of Signatures the function can operate on.
372  * Technically, the class FunctionDefinition is derived from Documentation and
373  * thereby inherits members for additional
374  * documentation-data.
375  *
376  * Similar to Type and TypeDefinition, a FunctionDefinition uses a prototype object to
377  * provide the method NewFunction() which instantiates the corresponding Function object.
378  *
379  * FunctionDefinition inherits the token io interface from Type, however, the class is
380  * not intended to register as a faudes type. The token io format is demonstrated by the
381  * following example:
382  *
383  * @code
384  * <FunctionDefinition name="CoreFaudes::IntegerSum" ctype="faudes::IntegerSum">
385  *
386  * <Documentation ref="integersum.html">
387  * Returns the sum of integer arguments.
388  * <Documentation/>
389  *
390  * <Keywords> "integer" "elemetary types" </Keywords>
391  *
392  * <VariantSignatures>
393  *
394  * <Signature name="Two arguments">
395  * <Parameter name="Arg1" ftype="Integer" access="In">
396  * <Parameter name="Arg2" ftype="Integer" access="In">
397  * <Parameter name="Res" ftype="Integer" access="Out" creturn="true">
398  * </Signature>
399  *
400  * <Signature name="Three arguments">
401  * <Parameter name="Arg1" ftype="Integer" access="In">
402  * <Parameter name="Arg2" ftype="Integer" access="In">
403  * <Parameter name="Arg3" ftype="Integer" access="In">
404  * <Parameter name="Res" ftype="Integer" access="Out" creturn="true">
405  * </Signature>
406  *
407  * </VariantSignatures>
408  *
409  * </FunctionDefinition>
410  * @endcode
411  *
412  *
413  * @ingroup RunTimeInterface
414  */
415 
417 
418  // std faudes type interface
420 
421 public:
422 
423  /**
424  * Constructor
425  *
426  * The default constructor instantiates an invalid function definition
427  * without prototype. To construct a valid function definition, use the static
428  * Constructor() template function.
429  */
430  FunctionDefinition(const std::string& name="");
431 
432  /**
433  * Copy Constructor
434  *
435  * The copy constructor copies all members one-to-one, except for
436  * the prototype object. The latter is re-created using its factory function.
437  */
439 
440  /**
441  * Destructor
442  */
443  virtual ~FunctionDefinition(){ Prototype(NULL);};
444 
445  /**
446  * Construct empty FunctionDefinition object.
447  * The given template parameter denotes a Function class.
448  * Member variable (mpFunction) is set to a new instance of that class
449  * whereas the name is set as specified. No further documentation
450  * or signatures are recorded.
451  *
452  * @tparam T
453  * Actual function class, derived from Function
454  * @param rFunctName
455  * Name to identify this faudes-function
456  * @return
457  * Newly constructed function definition.
458  */
459  template<class T>
460  static FunctionDefinition* Constructor(const std::string& rFunctName="");
461 
462  /**
463  * Construct FunctionDefinition object and get name and docu from file.
464  *
465  * The member variable mpFunction is set to a new instance of class T.
466  * which must be derived from Function. The function name, any documentation
467  * as well as supported signatures are read from the specified file.
468  *
469  * @tparam T
470  * Actual function class, derived from Function
471  * @param rFileName
472  * File to read documentation and signatures from.
473  * @return
474  * Newly constructed function definition.
475  */
476  template<class T>
477  static FunctionDefinition* FromFile(const std::string& rFileName);
478 
479  /**
480  * Clear documentation-data and signature (keep prototype)
481  */
482  virtual void Clear(void);
483 
484 
485  /**
486  * Clear variants (keep docu and prototype)
487  */
488  virtual void ClearVariants(void);
489 
490  /**
491  * Return pointer to function object prototype
492  *
493  * Note: this method is meant for inspection only, control over
494  * the prototype remains with the FunctionDefinition. Use
495  * NewFunction() to instantiate a new function object.
496  *
497  * @return
498  * Reference to prototype function.
499  */
500  const Function* Prototype(void) const;
501 
502  /**
503  * Construct function on heap.
504  * Return pointer to new instance of assigned Function class.
505  *
506  * Note: If no prototype is installed, NULL is returned.
507  *
508  * @return
509  * Pointer to new Function instance.
510  */
511  Function* NewFunction() const;
512 
513 
514  /**
515  * Return number of supported Signature instances.
516  *
517  * @return
518  * Size of signature vector.
519  */
520  int VariantsSize(void) const;
521 
522  /**
523  * Test existence of variant by its name.
524  *
525  * @return
526  * True if variant exists
527  */
528  bool ExistsVariant(const std::string& varname) const;
529 
530  /**
531  * Return index of Signature by name.
532  *
533  * @param rName
534  * Name of signature to search.
535  * @return
536  * Index of signature, or -1 if not existant
537  */
538  int VariantIndex(const std::string& rName) const;
539 
540  /**
541  * Return reference to Signature by name.
542  *
543  * @param rName
544  * Name of signature to search.
545  * @return
546  * Reference to Signature
547  * @exception Exception
548  * - No such signature (id 47)
549  */
550  const Signature& Variant(const std::string& rName) const;
551 
552  /**
553  * Return reference to Signature by index.
554  *
555  * @param n
556  * Index to look up
557  * @return
558  * Reference to Signature
559  * @exception Exception
560  * - Index out of range (id 47)
561  */
562  const Signature& Variant(int n) const;
563 
564  /**
565  * Add Signature to function definition.
566  *
567  * @param pVar
568  * Signature to insert
569  * @exception Exception
570  * - Signature with same name exists (id 47)
571  */
572  virtual void AppendVariant(const Signature& pVar);
573 
574 protected:
575 
576  /**
577  * Std faudes type interface: assignment.
578  *
579  * @param rSrc
580  * Source to copy from
581  * @return Reference to this object.
582  */
583  void DoAssign(const FunctionDefinition& rSrc);
584 
585  /**
586  * Std faudes type interface: test equality
587  *
588  * @param rOther
589  * Other object to compare with.
590  * @return
591  * True on match.
592  */
593  bool DoEqual(const FunctionDefinition& rOther) const;
594 
595  /**
596  * Read configuration data of this object from TokenReader.
597  * Actual reading is done by DoReadCore.
598  *
599  * The section defaults to "FunctionDefinition", context ignored.
600  *
601  * @param rTr
602  * TokenReader to read from
603  * @param rLabel
604  * Section to read
605  * @param pContext
606  * Read context to provide contextual information (ignored)
607  *
608  * @exception Exception
609  * - Token mismatch (id 50, 51, 52)
610  * - IO error (id 1)
611  */
612  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
613 
614  /**
615  * Read configuration data of this object from TokenReader.
616  *
617  * This method reads members only, it does not read the section.
618  *
619  * @param rTr
620  * TokenReader to read from
621  *
622  * @exception Exception
623  * - Token mismatch (id 50, 51, 52)
624  * - IO error (id 1)
625  */
626  virtual void DoReadCore(TokenReader& rTr);
627 
628  /**
629  * Write configuration data of this object to TokenWriter.
630  *
631  * The section defaults to "FunctionDefinition", context ignored.
632  *
633  * @param rTw
634  * Reference to TokenWriter
635  * @param rLabel
636  * Label of section to write
637  * @param pContext
638  * Write context to provide contextual information
639  *
640  * @exception Exception
641  * - IO errors (id 2)
642  */
643  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
644 
645  /**
646  * Write configuration data of this object to TokenWriter.
647  *
648  * This method writes plain member data, the section lables are not
649  * written.
650  *
651  * @param rTw
652  * Reference to TokenWriter
653  *
654  * @exception Exception
655  * - IO errors (id 2)
656  */
657  virtual void DoWriteCore(TokenWriter& rTw) const;
658 
659  /**
660  * Assign prototype object
661  *
662  * @param pFunc
663  * Function instance
664  *
665  */
666  virtual void Prototype(Function* pFunc);
667 
668  /** Prototype instance */
670 
671  /** Vector containing all supported Signatures */
672  std::vector<faudes::Signature> mVariants;
673 
674  /** Variant name to index map */
675  std::map<std::string,int> mVariantIndexMap;
676 
677 }; // FunctionDefinition
678 
679 
680 
681 /**
682  * A faudes-function hosts parameter values of some faudes type and provides
683  * a method to perform an operation on the specified paramters, e.g. the
684  * parallel composition on two generators. The class Function is the base
685  * for all faudes-functions, which essenitally differ in the operation method.
686  *
687  * The base class provides an application interface to
688  * - select a variant signature, see Variant();
689  * - set and get parameter values of any faudes type, see ParamValue();
690  * - type check the provided parameter values, see TypeCheck();
691  * - perform the operation, see Execute().
692  *
693  * Derivates of the base class, that acually implement an operation,
694  * are required to cast the parameter values to the corresponding c types and then
695  * call the respective c function. To derive a class from Function, one will
696  * reimplment three virtual functions:
697  * - DoTypeCheck() to perform the cast
698  * - DoExecute() to call the c function.
699  * - the constructor New() to replicate the function object.
700  *
701  * See IntegerSum in the autogenerated ./include/rtiautoload.h" for a simple example
702  * of a derived faudes-function.
703  *
704  *
705  * Technichal note: In contrast to faudes objects (derivates from Type), a faudes-function
706  * must be provided a reference to the corresponding FunctionDefinition. This is because
707  * a function must be aware of its signature(s). You must not delete
708  * the FunctionDefinition object during the lifetime of a faudes-function.
709  *
710  *
711  * @ingroup RunTimeInterface
712  */
713 
714 class FAUDES_API Function : public Type {
715 
716  public:
717  /**
718  * Constructor
719  * For the function to be operational, a valid reference to the corresponding
720  * FunctionDefinition is required. The only exception is the prototype function
721  * object used in the FunctionDefinition itself.
722  */
723  Function(const FunctionDefinition* fdef);
724 
725  /** Destructor */
727 
728  /**
729  * Construct on heap.
730  * Create a new instance of this function class and return pointer.
731  * The new instance will use the same function definition as this instance.
732  *
733  * @return
734  * Pointer to faudes::Function instance.
735  *
736  */
737  virtual Function* New() const = 0;
738 
739 
740  /**
741  * Set function definition.
742  * Normally, functions are provided with a function definition on construction.
743  * The only exception are prototype objects used in function definitions themselfs
744  * and in the function registry.
745  *
746  * @param fdef
747  * Function definition to set.
748  *
749  */
750  virtual void Definition(const FunctionDefinition* fdef);
751 
752 
753  /**
754  * Get function definition.
755  *
756  * @return
757  * Function definition used by this function.
758  *
759  */
760  const FunctionDefinition* Definition(void) const;
761 
762 
763  /**
764  * Return number of variants.
765  *
766  * @return
767  * Size of vector.
768  */
769  int VariantsSize(void) const;
770 
771  /**
772  * Set signature from function definition.
773  *
774  * The index n refers this function's FunctionDefinition.
775  * An exception is thrown if no such FunctionDefinition is set, as it
776  * is the case for prototype instances.
777  *
778  * @param n
779  * Variant index
780  *
781  * @exception Exception
782  * - No function definition available (id 47)
783  * - No such variant (id 48)
784  */
785  void Variant(int n);
786 
787 
788  /**
789  * Set signature from function definition.
790  *
791  * The name refers to this function's FunctionDefinition.
792  * An exception is thrown if no such FunctionDefinition is set, as it
793  * is the case for prototype instances.
794  *
795  * @param rVariantName
796  * Variant name
797  *
798  * @exception Exception
799  * - No function definition available (id 47)
800  * - No such variant (id 48)
801  */
802  void Variant(const std::string& rVariantName);
803 
804 
805  /**
806  * Return pointer to assigned faudes::Signature.
807  *
808  * @return
809  * Pointer to faudes::Signature.
810  */
811  const Signature* Variant(void) const;
812 
813 
814  /**
815  * Return number of parameters with current signature.
816  *
817  * @return
818  * Size of vector.
819  */
820  int ParamsSize(void) const;
821 
822  /**
823  * Set parameter at certain position.
824  *
825  * Sets the internal refernce of the parameter value
826  * at the spcefied index. The ownership of the value remains with
827  * the caller, ie it will not be deleted in the destructor of the
828  * function object.
829  * You may set the parameter value to any faudes type
830  * (classes derived from Type). A type check will be performed before the function
831  * is executed.
832  *
833  * @param n
834  * Position index of parameter
835  * @param param
836  * Pointer to faudes object.
837  *
838  * @exception Exception
839  * - Index out of range (id 47)
840  * - No variant set (id 47)
841  */
842  void ParamValue(int n, Type* param);
843 
844  /**
845  * Get parameter value.
846  * Returns a reference to the parameter value at the specified position.
847  *
848  * @param n
849  * Position index of parameter.
850  *
851  * @exception Exception
852  * - Index out of range (id 47)
853  */
854  Type* ParamValue(int n) const;
855 
856  /**
857  * Construct parameter values.
858  *
859  * This is a convenience method to allocate faudes objects for
860  * parameter values with the type specified by the current signature.
861  * Note that the function does not take ownetship of the parameter values and
862  * it is the callers responsibility to delete them when no longer required.
863  *
864  */
865  void AllocateValues(void);
866  void AllocateValue(int i);
867 
868  /**
869  * Destruct parameter values.
870  *
871  * This is a convenience method to delete the assigned paramer values.
872  *
873  */
874  void FreeValues(void);
875 
876  /**
877  * Perform a type check one parameter value.
878  *
879  * The type check is based on c type cast and should accept any types
880  * derived from the type given in the signature.
881  *
882  * @param n
883  * Position of parameter to check
884  * @return
885  * True if type matches
886  *
887  * @exception Exception
888  * - No variant specified (id 48)
889  * - Number of parameter is outside the specified signature (id 48)
890  *
891  */
892  bool TypeCheck(int n);
893 
894  /**
895  * Perform a type check on the list of current parameter values.
896  *
897  * The type check is based on c type cast and should accept any types
898  * derived from those given in the signature.
899  *
900  * @return
901  * True if all parameter types matche the signature
902  *
903  * @exception Exception
904  * - No variant specified (id 48)
905  * - Number of parameters does not match signature (id 48)
906  *
907  */
908  bool TypeCheck(void);
909 
910  /**
911  * Perform operation.
912  *
913  * Runs a type check and then the actual function.
914  *
915  * @exception Exception
916  * - No variant specified (id 48)
917  * - Parameter position out of range (id 48)
918  * - Type mismatch (id 48)
919  * - Any other exception thrown ba the actual function (id xxx)
920  */
921  void Execute(void);
922 
923 
924  protected:
925 
926  /**
927  * Helper: generate typed reference for parameter.
928  *
929  * @param n
930  * Parameter position to cast
931  * @param rTypedRef
932  * Typed reference to generyte
933  * @tparam T
934  * c type to use for cast
935  * @return
936  * True if cast succeeded.
937  * @exception Exception
938  * - No variant specified (id 48)
939  * - Parameter position out of range (id 48)
940  */
941  template<class T>
942  bool DoTypeCast(int n, T*& rTypedRef) {
943  if(!Variant()) {
944  std::stringstream err;
945  err << "No variant specified";
946  throw Exception("Function::DoTypeCast()", err.str(), 48);
947  }
948  if(n<0 || n >= ParamsSize()) {
949  std::stringstream err;
950  err << "Parameter position out of range";
951  throw Exception("Function::DoTypeCast()", err.str(), 48);
952  }
953  rTypedRef=dynamic_cast<T*>(ParamValue(n));
954  return rTypedRef!=NULL;
955  }
956 
957  /*
958  * Do set variant from function definition.
959  *
960  * The index n refers this function's FunctionDefinition.
961  * An exception is thrown if no FunctionDefinition is set, as it
962  * is the case for prototype instances.
963  *
964  * @param n
965  * Variant index
966  *
967  * @exception Exception
968  * - No function definition available (id 47)
969  * - No such variant (id 48)
970  */
971  virtual void DoVariant(int n);
972 
973  /**
974  * Method to test the type of an assigned parameter with the
975  * specified faudes::Signature (i.e. their TypeDefinition label).
976  *
977  * Note: this method is called by Function::Execute() before actual function
978  * execution via DoExecute(). It may be used to perform a dynamic cast in
979  * preparation of DoExecute(). The latter is only called, if all types match.
980  *
981  * @param n
982  * Position of parameter to check
983  * @return
984  * True if type matches signature.
985  *
986  * @exception Exception
987  * - Signature undefined (id 48)
988  * - Parameter number out of range (id 48)
989  */
990  virtual bool DoTypeCheck(int n) = 0;
991 
992  /**
993  * Executes code of reimplemented method of child class(es).
994  */
995  virtual void DoExecute() = 0;
996 
997  /**
998  * Write function-data (typeid-name of arguments) to TokenWriter.
999  *
1000  * @param rTw
1001  * Reference to Tokenwriter.
1002  * @param rLabel
1003  * Label of section to write.
1004  * @param pContext
1005  * Context pointer, ignored
1006  *
1007  * @exception Exception
1008  * - IO Error
1009  */
1010  void DoWrite(TokenWriter& rTw, const std::string& rLabel = "", const Type* pContext=0) const;
1011 
1012  /** corresponding function definition */
1014 
1015  /** current variant aka signature as index w.r.t. the function definition */
1017 
1018  /** Vector of arguments. */
1019  std::vector<Type*> mParameterValues;
1020 
1021 }; // Function
1022 
1023 
1024 
1025 /**********************************************************************************************
1026 ***********************************************************************************************
1027 ***********************************************************************************************
1028 
1029 Implemention of template members functions
1030 
1031 ***********************************************************************************************
1032 ***********************************************************************************************
1033 **********************************************************************************************/
1034 
1035 
1036 // typedefinition constructor function
1037 template<class T>
1038 FunctionDefinition* FunctionDefinition::Constructor(const std::string& rFunctionName){
1039  FD_DRTI("FunctionDefinition::Construct<" << typeid(T).name() << ">()");
1040  // construct void definition
1042  // set its prototype object (note the 0 param in the new constructor)
1043  td->Prototype(new T(0));
1044  // set minmum values ie the function name
1045  std::string name=rFunctionName;
1046  if(name=="") name=typeid(T).name();
1047  td->Name(name);
1048  FD_DRTI("FunctionDefinition::Constructor<" << typeid(T).name() << ">(): done");
1049  return(td);
1050 }
1051 
1052 
1053 // function definition constructor function
1054 template<class T>
1055 FunctionDefinition* FunctionDefinition::FromFile(const std::string& rFileName){
1056  FD_DRTI("FunctionDefinition::FromFile<" << typeid(T).name() << ">()");
1057  // construct with fallback name
1058  FunctionDefinition* td = Constructor<T>();
1059  // read docu, incl actual name
1060  td->Read(rFileName);
1061  // done
1062  FD_DRTI("FunctionDefinition::FromFile<" << typeid(T).name() << ">(): done");
1063  return(td);
1064 }
1065 
1066 
1067 } // namespace
1068 
1069 
1070 #endif /* FAUDES_FUNCTIONS_H */
#define FD_DRTI(message)
Debug: optional on function and type definition.
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:81
Runtime interface, faudes types.
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
faudes type declaration macro
Definition: cfl_types.h:867
faudes type implementation macros, overall
Definition: cfl_types.h:1128
const std::string & Name(void) const
Get name of the entety to document (aka faudes-type or faudes-function).
Definition: cfl_types.cpp:396
Faudes exception class.
A FunctionDefinition defines the interface to a faudes-function.
const Function * Prototype(void) const
Return pointer to function object prototype.
static FunctionDefinition * FromFile(const std::string &rFileName)
Construct FunctionDefinition object and get name and docu from file.
std::map< std::string, int > mVariantIndexMap
Variant name to index map.
FunctionDefinition(const std::string &name="")
Constructor.
static FunctionDefinition * Constructor(const std::string &rFunctName="")
Construct empty FunctionDefinition object.
std::vector< faudes::Signature > mVariants
Vector containing all supported Signatures.
Function * mpFunction
Prototype instance.
virtual ~FunctionDefinition()
Destructor.
A faudes-function hosts parameter values of some faudes type and provides a method to perform an oper...
virtual bool DoTypeCheck(int n)=0
Method to test the type of an assigned parameter with the specified faudes::Signature (i....
const FunctionDefinition * pFuncDef
corresponding function definition
bool DoTypeCast(int n, T *&rTypedRef)
Helper: generate typed reference for parameter.
std::vector< Type * > mParameterValues
Vector of arguments.
int mVariantIndex
current variant aka signature as index w.r.t.
~Function()
Destructor.
virtual void DoExecute()=0
Executes code of reimplemented method of child class(es).
virtual Function * New() const =0
Construct on heap.
Structure to model a parameter type within the Signature of a Function.
Definition: cfl_functions.h:45
std::string mTDName
Faudes type.
bool mCReturn
C-Return flag.
std::string mName
Name.
ParamAttr
A function parameter has has one out of four so called io-attrributes;.
Definition: cfl_functions.h:52
ParamAttr mAttr
IO-Attribute.
Signature of a Function.
std::string mName
Variable to store name.
~Signature(void)
Destructor.
std::vector< Parameter > mParameters
Vector of Parameter-objects.
A TokenReader reads sequential tokens from a file or string.
A TokenWriter writes sequential tokens to a file, a string or stdout.
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
Definition: cfl_types.cpp:261
libFAUDES resides within the namespace faudes.

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen