cNedFunction Class Reference

API: cNedFunction Class Reference
API
cNedFunction Class Reference
Inheritance diagram for cNedFunction:
[legend]

Public Member Functions

Constructors, destructor, assignment
 cNedFunction (NedFunction f, const char *signature, const char *category=nullptr, const char *description=nullptr)
 cNedFunction (NedFunctionExt f, const char *signature, const char *category=nullptr, const char *description=nullptr)
virtual ~cNedFunction ()
Redefined cObject member functions.
virtual std::string str () const override
Public Member Functions inherited from cNoncopyableOwnedObject
 cNoncopyableOwnedObject (const char *name=nullptr, bool namepooling=true)
virtual cNoncopyableOwnedObjectdup () const override
Public Member Functions inherited from cOwnedObject
 cOwnedObject ()
 cOwnedObject (const char *name, bool namepooling=true)
 cOwnedObject (const cOwnedObject &obj)
virtual ~cOwnedObject ()
cOwnedObjectoperator= (const cOwnedObject &o)
virtual cObjectgetOwner () const override
virtual bool isOwnedObject () const override
Public Member Functions inherited from cNamedObject
 cNamedObject ()
 cNamedObject (const char *name, bool namepooling=true)
 cNamedObject (const cNamedObject &obj)
virtual ~cNamedObject ()
cNamedObjectoperator= (const cNamedObject &o)
virtual void setName (const char *s)
virtual const char * getName () const override
virtual void setNamePooling (bool b)
virtual bool getNamePooling ()
Public Member Functions inherited from cObject
 cObject ()
 cObject (const cObject &other)=default
virtual ~cObject ()
virtual const char * getClassName () const
bool isName (const char *s) const
virtual const char * getFullName () const
virtual std::string getFullPath () const
virtual std::string getClassAndFullName () const
virtual std::string getClassAndFullPath () const
const cObjectgetThisPtr () const
virtual std::ostream & printOn (std::ostream &os) const
virtual bool isSoftOwner () const
virtual void forEachChild (cVisitor *v)
cObjectfindObject (const char *name, bool deep=true)
virtual cClassDescriptorgetDescriptor () const
void copyNotSupported () const

Member access.

cValue invoke (cExpression::Context *context, cValue argv[], int argc)
NedFunction getFunctionPointer () const
const char * getSignature () const
Type getReturnType () const
Type getArgType (int k) const
int getMinArgs () const
int getMaxArgs () const
bool hasVarArgs () const
bool acceptsArgCount (int argCount)
const char * getCategory () const
const char * getDescription () const
static cNedFunctionfind (const char *name)
static cNedFunctionfind (const char *name, int argCount)
static cNedFunctionget (const char *name)
static cNedFunctionget (const char *name, int argCount)
static cNedFunctionfindByPointer (NedFunction f)

Additional Inherited Members

Static Public Member Functions inherited from cOwnedObject
static long getTotalObjectCount ()
static long getLiveObjectCount ()
static void resetObjectCounters ()
static cSoftOwnergetOwningContext ()
Protected Member Functions inherited from cObject
virtual void take (cOwnedObject *obj)
virtual void drop (cOwnedObject *obj)
void dropAndDelete (cOwnedObject *obj)

Description

Registration class for extending NED with arbitrary new functions.

Objects of this class are usually created via the Define_NED_Function() macro.

Constructor & Destructor Documentation

◆ cNedFunction() [1/2]

cNedFunction ( NedFunction f,
const char * signature,
const char * category = nullptr,
const char * description = nullptr )

Constructor. Signature is expected in the following syntax: returntype name(argtype argname,...), where types can be bool, long, double, quantity, intquantity, string, xml, any; names of optional arguments end in '?'. The object name will be the function name, as extracted from the signature string. The signature may end in an ellipsis, i.e. "...", to mean that any number of extra args of unspecified types should be accepted. (When there are both optional args and an ellipsis, then extra arguments can only be passed when all optional arguments are all supplied.)

Examples: "quantity uniform(quantity a, quantity b, long rng?)" "string sprintf(format, ...)" "any max(...)"

Referenced by find(), find(), findByPointer(), get(), and get().

◆ cNedFunction() [2/2]

cNedFunction ( NedFunctionExt f,
const char * signature,
const char * category = nullptr,
const char * description = nullptr )

Alternative constructor. Usage is similar to the first constructor, except that it takes a function with a slightly different signature (NedFunctionExt instead of NedFunction).

◆ ~cNedFunction()

virtual ~cNedFunction ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ str()

virtual std::string str ( ) const
overridevirtual

Produces a one-line description of the object's contents.

Reimplemented from cObject.

◆ invoke()

cValue invoke ( cExpression::Context * context,
cValue argv[],
int argc )

Performs argument type checking, and invokes the function.

◆ getFunctionPointer()

NedFunction getFunctionPointer ( ) const
inline

Returns the function pointer. Do not call the function directly, because that would bypass argument type validation.

◆ getSignature()

const char * getSignature ( ) const
inline

Returns the functions signature, as passed to the constructor

◆ getReturnType()

Type getReturnType ( ) const
inline

Returns the function return type.

◆ getArgType()

Type getArgType ( int k) const
inline

Returns the type of the kth argument.

◆ getMinArgs()

int getMinArgs ( ) const
inline

Returns the minimum number of arguments (i.e. the number of mandatory arguments).

◆ getMaxArgs()

int getMaxArgs ( ) const
inline

Returns the maximum number of typed arguments (i.e. the last max-min args are optional). If hasVarArgs() is true, the function actually accepts more than getMaxArgs() arguments.

◆ hasVarArgs()

bool hasVarArgs ( ) const
inline

Returns true if the function signature ends in an ellipsis ("..."), that is, the function supports varargs.

◆ acceptsArgCount()

bool acceptsArgCount ( int argCount)
inline

Convenience method: Returns true if the function accepts the given number of arguments.

◆ getCategory()

const char * getCategory ( ) const
inline

Returns a string that can be useful in classifying NED functions, e.g. "trigonometric".

◆ getDescription()

const char * getDescription ( ) const
inline

Returns the function's documentation as a string.

◆ find() [1/2]

cNedFunction * find ( const char * name)
static

Finds a registered function by name. Returns nullptr if not found.

References cNedFunction().

◆ find() [2/2]

cNedFunction * find ( const char * name,
int argCount )
static

Finds a registered function with the given name that accepts the given number or arguments. Returns nullptr if not found.

References cNedFunction().

◆ get() [1/2]

cNedFunction * get ( const char * name)
static

Finds a registered function by name. Throws an error if not found.

References cNedFunction().

◆ get() [2/2]

cNedFunction * get ( const char * name,
int argCount )
static

Finds a registered function with the given name that accepts the given number or arguments. Throws an error if not found.

References cNedFunction().

◆ findByPointer()

cNedFunction * findByPointer ( NedFunction f)
static

Finds a registered function by function pointer.

References cNedFunction().