libFAUDES

Sections

Index

faudes::FunctionDefinition Class Reference
[Run-Time Interface]

#include <rtifncts.h>

Inherits faudes::Documentation.

List of all members.


Detailed Description

A FunctionDefinition defines the interface to a faudes-function.

The latter consists of a descriptive name to identify the function and a list of Signatures the function can operate on. Technically, the class FunctionDefinition is derived from Documentation and thereby inherits members for additional documentation-data.

Similar to Type and TypeDefinition, a FunctionDefinition uses a prototype object to provide the method NewFunction() which instantiates the corresponding Function object.

FunctionDefinition inherits the token io interface from Type, however, the class is not intended to register as a faudes type. The token io format is demonstrated by the following example:

 <FunctionDefinition>
 "CoreFaudes::IntegerSum"

 <TextDoc> "Returns the sum of integer arguments." </TextDoc>
 <HtmlDoc> "integersum.html" </HtmlDoc>
 <Keywords> "integer" "elemetary types" </Keywords>

 <VariantSignatures>
 <Signature>
 "Two arguments"
 "Arg1"  "Integer"   +In+
 "Arg2"  "Integer"   +In+
 "Res"   "Integer"   +Out+
 </Signature>

 <Signature>          
 "Three arguments"
 "Arg1"  "Integer"   +In+
 "Arg2"  "Integer"   +In+
 "Arg3"  "Integer"   +In+
 "Res"   "Integer"   +Out+
 </Signature>
 </VariantSignatures>

 </FunctionDefinition>

For functions that allow for a variable number of arguments of thesame type, there is a purely cosmetic hack: when in a function definition a signature has a double hash "##" in its name, any parameters with a "##" can apprear repeatedly. This short cut is expanded by the token input function MergeDocumentation, that actually inserts the respective signatures. The compile time option FD_RTIMAXPARAMS defines how many copies of the parameter can appear. Obviously, this only makes sense if the corresponding Function object supports every automatically generated signature. Example from IntegerSum

 <Signature>
 "Ires=Sum_(i=1)^(##) Ii"
 "Arg##" "Integer"   +In+
 "Res"   "Integer"   +Out+
 </Signature>

Definition at line 322 of file rtifncts.h.


Public Member Functions

 FunctionDefinition (const std::string &name="")
 Constructor.
virtual ~FunctionDefinition ()
 Destructor.
void Clear (void)
 Clear documentation-data and signature (keep prototype).
void MergeDocumentationBody (TokenReader &rTr)
 Merge documentation and signatures from token stream.
const FunctionPrototype (void) const
 Return pointer to function object prototype.
FunctionNewFunction () const
 Construct function on heap.
int VariantsSize (void) const
 Return number of supported Signature instances.
bool ExistsVariant (const std::string &varname) const
 Test existence of variant by its name.
int VariantIndex (const std::string &rName) const
 Return index of Signature by name.
const SignatureVariant (const std::string &rName) const
 Return reference to Signature by name.
const SignatureVariant (int n) const
 Return reference to Signature by index.

Static Public Member Functions

template<class T>
static FunctionDefinitionConstructor (const std::string &rFunctName="")
 Construct empty FunctionDefinition object.
template<class T>
static FunctionDefinitionFromFile (const std::string &rFileName)
 Construct FunctionDefinition object and get name and docu from file.

Protected Member Functions

virtual void DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data of this object from TokenReader.
virtual void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data of this object to TokenWriter.
void AppendVariant (const Signature &pVar)
 Add Signature to function definition.
 FunctionDefinition (const FunctionDefinition &rOther)
 Disable Copy Constructor.
void Prototype (Function *pFunc)
 Assign prototype object.

Protected Attributes

FunctionmpFunction
 Prototype instance.
std::vector< faudes::SignaturemVariants
 Vector containing all supported Signatures.
std::map< std::string, int > mVariantIndexMap
 Variant name to index map.

Constructor & Destructor Documentation

faudes::FunctionDefinition::FunctionDefinition ( const std::string &  name = ""  )  [inline]

Constructor.

The default constructor instantiates an invalid function definition without prototype. To construct a valid type definition, use the static Constructor() template function.

Definition at line 334 of file rtifncts.h.

virtual faudes::FunctionDefinition::~FunctionDefinition (  )  [inline, virtual]

Destructor.

Definition at line 339 of file rtifncts.h.

faudes::FunctionDefinition::FunctionDefinition ( const FunctionDefinition rOther  )  [inline, protected]

Disable Copy Constructor.

Definition at line 521 of file rtifncts.h.


Member Function Documentation

template<class T>
FunctionDefinition * faudes::FunctionDefinition::Constructor ( const std::string &  rFunctName = ""  )  [inline, static]

Construct empty FunctionDefinition object.

The given template parameter denotes a Function class. Member variable (mpFunction) is set to a new instance of that class whereas the name is set as specified. No further documentation or signatures are recorded.

Template Parameters:
T Actual function class, derived from Function
Parameters:
rFunctName Name to identify this faudes-function
Returns:
Newly constructed function definition.

Definition at line 885 of file rtifncts.h.

template<class T>
FunctionDefinition * faudes::FunctionDefinition::FromFile ( const std::string &  rFileName  )  [inline, static]

Construct FunctionDefinition object and get name and docu from file.

The member variable mpFunction is set to a new instance of class T. which must be derived from Function. The function name, any documentation as well as supported signatures are read from the specified file.

Template Parameters:
T Actual function class, derived from Function
Parameters:
rFileName File to read documentation and signatures from.
Returns:
Newly constructed function definition.

Definition at line 902 of file rtifncts.h.

void faudes::FunctionDefinition::Clear ( void   )  [virtual]

Clear documentation-data and signature (keep prototype).

Reimplemented from faudes::Documentation.

Definition at line 162 of file rtifncts.cpp.

void faudes::FunctionDefinition::MergeDocumentationBody ( TokenReader rTr  ) 

Merge documentation and signatures from token stream.

This member reads the body of the FunctionDefinition token format and sets the function name, any further documentation and the supported signatures accordingly. An exception is thrown if the current function name differs from the one in the documentation.

Parameters:
rTr TokenReader to read from.
Exceptions:
Exception 
  • Type mismatch (id )
  • Token mismatch (id 50, 51, 52)
  • IO Error (id 1)

Definition at line 253 of file rtifncts.cpp.

const Function * faudes::FunctionDefinition::Prototype ( void   )  const

Return pointer to function object prototype.

Note: this method is meant for inspection only, control over the prototype remains with the FunctionDefinition. Use NewFunction() to instantiate a new function object.

Returns:
Reference to prototype function.

Definition at line 172 of file rtifncts.cpp.

Function * faudes::FunctionDefinition::NewFunction (  )  const

Construct function on heap.

Return pointer to new instance of assigned Function class.

Note: If no prototype is installed, NULL is returned.

Returns:
Pointer to new Function instance.

Definition at line 189 of file rtifncts.cpp.

int faudes::FunctionDefinition::VariantsSize ( void   )  const

Return number of supported Signature instances.

Returns:
Size of signature vector.

Definition at line 197 of file rtifncts.cpp.

bool faudes::FunctionDefinition::ExistsVariant ( const std::string &  varname  )  const

Test existence of variant by its name.

Returns:
True if variant exists

Definition at line 202 of file rtifncts.cpp.

int faudes::FunctionDefinition::VariantIndex ( const std::string &  rName  )  const

Return index of Signature by name.

Parameters:
rName Name of signature to search.
Returns:
Index of signature, or -1 if not existant

Definition at line 207 of file rtifncts.cpp.

const Signature & faudes::FunctionDefinition::Variant ( const std::string &  rName  )  const

Return reference to Signature by name.

Parameters:
rName Name of signature to search.
Returns:
Reference to Signature
Exceptions:
Exception 
  • No such signature (id 47)

Definition at line 229 of file rtifncts.cpp.

const Signature & faudes::FunctionDefinition::Variant ( int  n  )  const

Return reference to Signature by index.

Parameters:
n Index to look up
Returns:
Reference to Signature
Exceptions:
Exception 
  • Index out of range (id 47)

Definition at line 241 of file rtifncts.cpp.

void faudes::FunctionDefinition::DoRead ( TokenReader rTr,
const std::string &  rLabel = "",
const Type pContext = 0 
) [protected, virtual]

Read configuration data of this object from TokenReader.

The section is hardcode to "FunctionDefinition", context ignored.

Parameters:
rTr TokenReader to read from
rLabel Section to read
pContext Read context to provide contextual information (ignored)
Exceptions:
Exception 
  • IO error (id 1)

Reimplemented from faudes::Documentation.

Definition at line 308 of file rtifncts.cpp.

void faudes::FunctionDefinition::DoWrite ( TokenWriter rTw,
const std::string &  rLabel = "",
const Type pContext = 0 
) const [protected, virtual]

Write configuration data of this object to TokenWriter.

The section is hardcode to "FunctionDefinition", context ignored.

Parameters:
rTw Reference to TokenWriter
rLabel Label of section to write
pContext Write context to provide contextual information
Exceptions:
Exception 
  • IO errors (id 2)

Reimplemented from faudes::Documentation.

Definition at line 329 of file rtifncts.cpp.

void faudes::FunctionDefinition::AppendVariant ( const Signature pVar  )  [protected]

Add Signature to function definition.

Parameters:
pVar Signature to insert
Exceptions:
Exception 

Definition at line 214 of file rtifncts.cpp.

void faudes::FunctionDefinition::Prototype ( Function pFunc  )  [protected]

Assign prototype object.

Parameters:
pFunc Function instance

Definition at line 177 of file rtifncts.cpp.


Member Data Documentation

Prototype instance.

Definition at line 534 of file rtifncts.h.

Vector containing all supported Signatures.

Definition at line 537 of file rtifncts.h.

std::map<std::string,int> faudes::FunctionDefinition::mVariantIndexMap [protected]

Variant name to index map.

Definition at line 540 of file rtifncts.h.


The documentation for this class was generated from the following files:

libFAUDES 2.14g --- 2009-12-3 --- c++ source docu by doxygen 1.5.6