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 
45 class Parameter {
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 Signature : public Type {
221 
222  // std faudes type interface (cannot autoregister)
228 
229 public:
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  * @return Reference to this object.
310  */
311  virtual void DoAssign(const Signature& rSrc);
312 
313  /**
314  * Std faudes type interface: test equality
315  *
316  * @param rOther
317  * Other object to compare with.
318  * @return
319  * True on match.
320  */
321  virtual bool DoEqual(const Signature& rOther) const;
322 
323  /**
324  * Read signature from from TokenReader.
325  *
326  * The section is hardcoded to "Signature", context is ignored.
327  *
328  * @param rTr
329  * TokenReader to read from
330  * @param rLabel
331  * Section to read
332  * @param pContext
333  * Read context to provide contextual information (ignored)
334  *
335  * @exception Exception
336  * - IO error (id 1)
337  * - Token mismatch (id 50, 51, 52)
338  */
339  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
340 
341  /**
342  * Write configuration data of this object to TokenWriter.
343  *
344  * The section is hardcoded to "Signature", context is ignored.
345  *
346  * @param rTw
347  * Reference to TokenWriter
348  * @param rLabel
349  * Label of section to write
350  * @param pContext
351  * Write context to provide contextual information
352  *
353  * @exception Exception
354  * - IO errors (id 2)
355  */
356  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
357 
358  /** Variable to store name */
359  std::string mName;
360 
361  /** Vector of Parameter-objects */
362  std::vector<Parameter> mParameters;
363 
364 }; // Signature
365 
366 
367 
368 // forward
369 class Function;
370 
371 
372 /**
373  * A FunctionDefinition defines the interface to a faudes-function.
374  * The latter consists of a descriptive name to identify the function and
375  * a list of Signatures the function can operate on.
376  * Technically, the class FunctionDefinition is derived from Documentation and
377  * thereby inherits members for additional
378  * documentation-data.
379  *
380  * Similar to Type and TypeDefinition, a FunctionDefinition uses a prototype object to
381  * provide the method NewFunction() which instantiates the corresponding Function object.
382  *
383  * FunctionDefinition inherits the token io interface from Type, however, the class is
384  * not intended to register as a faudes type. The token io format is demonstrated by the
385  * following example:
386  *
387  * @code
388  * <FunctionDefinition name="CoreFaudes::IntegerSum" ctype="faudes::IntegerSum">
389  *
390  * <Documentation ref="integersum.html">
391  * Returns the sum of integer arguments.
392  * <Documentation/>
393  *
394  * <Keywords> "integer" "elemetary types" </Keywords>
395  *
396  * <VariantSignatures>
397  *
398  * <Signature name="Two arguments">
399  * <Parameter name="Arg1" ftype="Integer" access="In">
400  * <Parameter name="Arg2" ftype="Integer" access="In">
401  * <Parameter name="Res" ftype="Integer" access="Out" creturn="true">
402  * </Signature>
403  *
404  * <Signature name="Three arguments">
405  * <Parameter name="Arg1" ftype="Integer" access="In">
406  * <Parameter name="Arg2" ftype="Integer" access="In">
407  * <Parameter name="Arg3" ftype="Integer" access="In">
408  * <Parameter name="Res" ftype="Integer" access="Out" creturn="true">
409  * </Signature>
410  *
411  * </VariantSignatures>
412  *
413  * </FunctionDefinition>
414  * @endcode
415  *
416  *
417  * @ingroup RunTimeInterface
418  */
419 
421 
422  // std faudes type interface (cannot autoregister)
428 
429 public:
430 
431  /**
432  * Constructor
433  *
434  * The default constructor instantiates an invalid function definition
435  * without prototype. To construct a valid function definition, use the static
436  * Constructor() template function.
437  */
438  FunctionDefinition(const std::string& name="");
439 
440  /**
441  * Copy Constructor
442  *
443  * The copy constructor copies all members one-to-one, except for
444  * the prototype object. The latter is re-created using its factory function.
445  */
447 
448  /**
449  * Destructor
450  */
451  virtual ~FunctionDefinition(){ Prototype(NULL);};
452 
453  /**
454  * Construct empty FunctionDefinition object.
455  * The given template parameter denotes a Function class.
456  * Member variable (mpFunction) is set to a new instance of that class
457  * whereas the name is set as specified. No further documentation
458  * or signatures are recorded.
459  *
460  * @tparam T
461  * Actual function class, derived from Function
462  * @param rFunctName
463  * Name to identify this faudes-function
464  * @return
465  * Newly constructed function definition.
466  */
467  template<class T>
468  static FunctionDefinition* Constructor(const std::string& rFunctName="");
469 
470  /**
471  * Construct FunctionDefinition object and get name and docu from file.
472  *
473  * The member variable mpFunction is set to a new instance of class T.
474  * which must be derived from Function. The function name, any documentation
475  * as well as supported signatures are read from the specified file.
476  *
477  * @tparam T
478  * Actual function class, derived from Function
479  * @param rFileName
480  * File to read documentation and signatures from.
481  * @return
482  * Newly constructed function definition.
483  */
484  template<class T>
485  static FunctionDefinition* FromFile(const std::string& rFileName);
486 
487  /**
488  * Clear documentation-data and signature (keep prototype)
489  */
490  virtual void Clear(void);
491 
492 
493  /**
494  * Clear variants (keep docu and prototype)
495  */
496  virtual void ClearVariants(void);
497 
498  /**
499  * Return pointer to function object prototype
500  *
501  * Note: this method is meant for inspection only, control over
502  * the prototype remains with the FunctionDefinition. Use
503  * NewFunction() to instantiate a new function object.
504  *
505  * @return
506  * Reference to prototype function.
507  */
508  const Function* Prototype(void) const;
509 
510  /**
511  * Construct function on heap.
512  * Return pointer to new instance of assigned Function class.
513  *
514  * Note: If no prototype is installed, NULL is returned.
515  *
516  * @return
517  * Pointer to new Function instance.
518  */
519  Function* NewFunction() const;
520 
521 
522  /**
523  * Return number of supported Signature instances.
524  *
525  * @return
526  * Size of signature vector.
527  */
528  int VariantsSize(void) const;
529 
530  /**
531  * Test existence of variant by its name.
532  *
533  * @return
534  * True if variant exists
535  */
536  bool ExistsVariant(const std::string& varname) const;
537 
538  /**
539  * Return index of Signature by name.
540  *
541  * @param rName
542  * Name of signature to search.
543  * @return
544  * Index of signature, or -1 if not existant
545  */
546  int VariantIndex(const std::string& rName) const;
547 
548  /**
549  * Return reference to Signature by name.
550  *
551  * @param rName
552  * Name of signature to search.
553  * @return
554  * Reference to Signature
555  * @exception Exception
556  * - No such signature (id 47)
557  */
558  const Signature& Variant(const std::string& rName) const;
559 
560  /**
561  * Return reference to Signature by index.
562  *
563  * @param n
564  * Index to look up
565  * @return
566  * Reference to Signature
567  * @exception Exception
568  * - Index out of range (id 47)
569  */
570  const Signature& Variant(int n) const;
571 
572  /**
573  * Add Signature to function definition.
574  *
575  * @param pVar
576  * Signature to insert
577  * @exception Exception
578  * - Signature with same name exists (id 47)
579  */
580  virtual void AppendVariant(const Signature& pVar);
581 
582 protected:
583 
584  /**
585  * Std faudes type interface: assignment.
586  *
587  * @param rSrc
588  * Source to copy from
589  * @return Reference to this object.
590  */
591  virtual void DoAssign(const FunctionDefinition& rSrc);
592 
593  /**
594  * Std faudes type interface: test equality
595  *
596  * @param rOther
597  * Other object to compare with.
598  * @return
599  * True on match.
600  */
601  virtual bool DoEqual(const FunctionDefinition& rOther) const;
602 
603  /**
604  * Read configuration data of this object from TokenReader.
605  * Actual reading is done by DoReadCore.
606  *
607  * The section defaults to "FunctionDefinition", context ignored.
608  *
609  * @param rTr
610  * TokenReader to read from
611  * @param rLabel
612  * Section to read
613  * @param pContext
614  * Read context to provide contextual information (ignored)
615  *
616  * @exception Exception
617  * - Token mismatch (id 50, 51, 52)
618  * - IO error (id 1)
619  */
620  virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
621 
622  /**
623  * Read configuration data of this object from TokenReader.
624  *
625  * This method reads members only, it does not read the section.
626  *
627  * @param rTr
628  * TokenReader to read from
629  *
630  * @exception Exception
631  * - Token mismatch (id 50, 51, 52)
632  * - IO error (id 1)
633  */
634  virtual void DoReadCore(TokenReader& rTr);
635 
636  /**
637  * Write configuration data of this object to TokenWriter.
638  *
639  * The section defaults to "FunctionDefinition", context ignored.
640  *
641  * @param rTw
642  * Reference to TokenWriter
643  * @param rLabel
644  * Label of section to write
645  * @param pContext
646  * Write context to provide contextual information
647  *
648  * @exception Exception
649  * - IO errors (id 2)
650  */
651  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
652 
653  /**
654  * Write configuration data of this object to TokenWriter.
655  *
656  * This method writes plain member data, the section lables are not
657  * written.
658  *
659  * @param rTw
660  * Reference to TokenWriter
661  *
662  * @exception Exception
663  * - IO errors (id 2)
664  */
665  virtual void DoWriteCore(TokenWriter& rTw) const;
666 
667  /**
668  * Assign prototype object
669  *
670  * @param pFunc
671  * Function instance
672  *
673  */
674  virtual void Prototype(Function* pFunc);
675 
676  /** Prototype instance */
678 
679  /** Vector containing all supported Signatures */
680  std::vector<faudes::Signature> mVariants;
681 
682  /** Variant name to index map */
683  std::map<std::string,int> mVariantIndexMap;
684 
685 }; // FunctionDefinition
686 
687 
688 
689 /**
690  * A faudes-function hosts parameter values of some faudes type and provides
691  * a method to perform an operation on the specified paramters, e.g. the
692  * parallel composition on two generators. The class Function is the base
693  * for all faudes-functions, which essenitally differ in the operation method.
694  *
695  * The base class provides an application interface to
696  * - select a variant signature, see Variant();
697  * - set and get parameter values of any faudes type, see ParamValue();
698  * - type check the provided parameter values, see TypeCheck();
699  * - perform the operation, see Execute().
700  *
701  * Derivates of the base class, that acually implement an operation,
702  * are required to cast the parameter values to the corresponding c types and then
703  * call the respective c function. To derive a class from Function, one will
704  * reimplment three virtual functions:
705  * - DoTypeCheck() to perform the cast
706  * - DoExecute() to call the c function.
707  * - the constructor New() to replicate the function object.
708  *
709  * See IntegerSum in the autogenerated ./include/rtiautoload.h" for a simple example
710  * of a derived faudes-function.
711  *
712  *
713  * Technichal note: In contrast to faudes objects (derivates from Type), a faudes-function
714  * must be provided a reference to the corresponding FunctionDefinition. This is because
715  * a function must be aware of its signature(s). You must not delete
716  * the FunctionDefinition object during the lifetime of a faudes-function.
717  *
718  *
719  * @ingroup RunTimeInterface
720  */
721 
722 class Function : public Type {
723 
724  public:
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 
1037 Implemention of template members functions
1038 
1039 ***********************************************************************************************
1040 ***********************************************************************************************
1041 **********************************************************************************************/
1042 
1043 
1044 // typedefinition constructor function
1045 template<class T>
1046 FunctionDefinition* 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
1062 template<class T>
1063 FunctionDefinition* FunctionDefinition::FromFile(const std::string& rFileName){
1064  FD_DRTI("FunctionDefinition::FromFile<" << typeid(T).name() << ">()");
1065  // construct with fallback name
1066  FunctionDefinition* td = Constructor<T>();
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 */

libFAUDES 2.24g --- 2014.09.15 --- c++ api documentaion by doxygen