Rogue Wave Views
Foundation Package API Reference Guide
Product Documentation:

Rogue Wave Views
Documentation Home
List of all members | Public Member Functions
IlvScriptFunction Class Referenceabstract

Scripting class. More...

#include <ilviews/base/script.h>

Inheritance diagram for IlvScriptFunction:
IlvValueInterface

Public Member Functions

 IlvScriptFunction (IlvScriptContext *context, const char *functionName, IlvValueTypeClass *retType, IlInt nParams, IlInt reqParams,...)
 Constructor. More...
 
virtual IlBoolean applyValue (const IlvValue &val)
 Apply an accessor. More...
 
virtual IlBoolean call (IlvValue &retVal, IlInt count, IlvValue *args)=0
 Defines the function. More...
 
virtual IlvValuequeryValue (IlvValue &value) const
 Retrieves an accessor value. More...
 
- Public Member Functions inherited from IlvValueInterface
virtual IlBoolean changeValue (const IlvValue &val)
 Changes the value of an accessor. More...
 
virtual IlBoolean changeValues (const IlvValue *values, IlUShort count=0)
 Changes several accessor values simultaneously. More...
 
virtual void getAccessors (const IlSymbol *const **names, const IlvValueTypeClass *const **types, IlUInt &count) const
 Retrieves the list of available accessors of an object. More...
 
virtual const char * getName () const
 Returns the name of the instance. The semantic and implementation of this method are defined by concrete subclasses. The default implementation returns 0. More...
 
virtual void queryValues (IlvValue *values, IlUShort count) const
 Retrieves multiple accessor values simultaneously. More...
 

Detailed Description

Scripting class.

Library: xviews or winviews or mviews (mutually exclusive)

The class IlvScriptFunction is an abstract class that you must derive to access C++ code from scripting languages.

See also
IlvScriptContext.

Constructor & Destructor Documentation

§ IlvScriptFunction()

IlvScriptFunction::IlvScriptFunction ( IlvScriptContext context,
const char *  functionName,
IlvValueTypeClass retType,
IlInt  nParams,
IlInt  reqParams,
  ... 
)

Constructor.

This constructor initializes a new instance of a subtype of the class IlvScriptFunction declaring a new function. This function can be accessed from the scripting language that you use, in the indicated context.

Parameters
contextThe script context where this function is defined.
functionNameThe name of this new function. The string is copied.
retTypeA pointer to the instance of the return type of this function.
nParamsThe maximum number of parameters that this function can take.
reqParamsSpecifies how many parameters are actually required, the other parameters being optional.

The ellipses must be replaced with pairs of nParams parameters. The first of the two parameters is a pointer to the expected parameter type, and the second is a string that names the parameter. The following function, for example, takes three parameters of the integer type and an optional parameter. It returns an integer.

class MyFunction
MyFunction(IlvScriptContext* context,
const char* functionName)
: IlvScriptFunction(context, functionName,
IlvValueIntType, 3, 2,
IlvValueIntType, "first",
IlvValueIntType, "second",
IlvValueIntType, "third")
{ .... }
};

Member Function Documentation

§ applyValue()

virtual IlBoolean IlvScriptFunction::applyValue ( const IlvValue value)
virtual

Apply an accessor.

This member function is called by changeValue() and changeValues() methods. It must not be called directly.
This method must be overriden by subclasses wishing to add a new accessor modifiable by changeValue().

Parameters
valueThe new value of the accessor.
Returns
IlTrue on success, otherwise IlFalse.

Reimplemented from IlvValueInterface.

§ call()

virtual IlBoolean IlvScriptFunction::call ( IlvValue retVal,
IlInt  count,
IlvValue args 
)
pure virtual

Defines the function.

This member function is the only one that must be implemented to perform the task for which the scripting function is designed. It is called by the script interpreter with the parameters provided by the user (the number and the types of arguments are implicitly checked). Let us suppose that the scripting function presented above adds the values of the first two parameters and divides the result by the third argument, if any. Here is how we would implement the call function:

MyFunction::call(IlvValue& ret, IlInt count, IlvValue* args)
{
ret = ((IlInt)args[0])+((IlInt)args[1]);
if (count == 3) { // Third parameter was provided
IlInt div = (IlInt)args[2];
if (div) // Is it a valid divider?
ret = (IlInt)ret/div;
else
return IlFalse; // Failure, Zero divide
}
return IlTrue;
}
Parameters
retValThe return value of this function.
countThe number of parameters provided to this function.
argsAn array of at least count values that are used as the parameters of the function.
Returns
IlTrue on success and IlFalse on failure.

§ queryValue()

virtual IlvValue& IlvScriptFunction::queryValue ( IlvValue val) const
virtual

Retrieves an accessor value.

The queryValue() method can be used in the following way:

IlvValue arg("label");
char* label = (char*)labelObject->queryValue(arg);

This method must be overriden by subclasses wishing to add a new readable accessor.

Parameters
valThe IlvValue used both to identify the accessor and to store the return value.
Returns
A reference to val, which contains the resulting value.
See also
IlvValue.

Reimplemented from IlvValueInterface.


© Copyright 2017, Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.