Class FPValidator

3DS Max Plug-In SDK

Class FPValidator

See Also: Class InterfaceServer, Class FPInterfaceDesc, Class FPValue, Class Interface_ID, Function Publishing System.

class FPValidator : public InterfaceServer

Description:

This class is available in release 4.0 and later only.

An interface descriptor may contain validation information for individual parameters, so that clients (such as MAXScript) can validate values given as parameters to FPInterface calls, prior to making the call. The validation information can be in the form of a range of values for int and float types, or more generally, a validator object that is called to the validate a parameter value.

The validation info is specified in the FPInterface descriptor in optional tagged entries following the parameters to be validated. The two possible tags are f_range and f_validator. An instance of this class is used when f_validator is specified.

Here's an example from a possible mixin interface to Cylinder:

static FPInterfaceDesc cylfpi (

CYL_INTERFACE, _T("cylMixin"), 0, &cylinderDesc, FP_MIXIN,

...

cyl_setRadius, _T("setRadius"), 0, TYPE_VOID, 0, 1,

_T("radius"), 0, TYPE_FLOAT,

f_range, 0.0, 10000.0,

cyl_setDirection, _T("setDirection"), 0, TYPE_VOID, 0, 1,

_T("vector"), 0, TYPE_POINT3,

f_validator, &cylValidator,

...

end

);

The "vector" parameter in the above example has a validator object specified. This must be a pointer to an instance of a class derived from the new class, FPValidator, defined in I\MAXSDK\INCLUDE\iFnPub.h. This is a virtual base class, containing a single method, Validate(), that is called to validate a prospective value for a parameter. You would typically subclass FPValidator in your code and provide an implementation of Validate() to do the validation.

Methods:

public:

Prototype:

virtual bool Validate(FPInterface* fpi, FunctionID fid, int paramNum, FPValue& val, TSTR& msg)=0;

Remarks:

This method is called to validate the value val passed for the given parameter in the function whose ID is passed in the specified interface passed. If there are many parameters to validate this way, developers can choose to provide a separate subclass for each parameter or a single subclass and switch on the parameter identification supplied.

Parameters:

FPInterface* fpi

Points to the interface the function is a part of.

FunctionID fid

The ID of the function within the interface above.

int paramNum

Identifies which parameter within the function above to validate.

FPValue& val

The value to validate.

TSTR& msg

Update this string with an error message if needed. The user of the Validator can then display this string.

Return Value:

Returns true if the value was valid; false if invalid.