fwCtrlUtils  8.5.0
CtrlOOUtils library reference

RTTI Functions

The following functions are related to the RunTime Type Information functionality.

bool fwClassExists (string className)
 
dyn_string fwClassNames ()
 
shared_ptr< className > fwCreateInstance (string className)
 
dyn_string fwClassMemberVars (string className)
 
dyn_string fwClassMemberFuncs (string className)
 
string fwGetBaseClass (string className)
 
bool fwIsInstanceOf (const anytype &obj|const shared_ptr<> obj, string className)
 
string fwGetClass (const anytype &obj|const shared_ptr<> obj)
 
function_ptr fwGetFuncPtr (string funcName)
 
anytype fwInvokeMethod (anytype &obj|shared_ptr<> obj, string method,...)
 

Exceptions and Stack Trace

The following functions are related to effective handling of exceptions and stack traces.

void fwRethrow ()
 
void fwThrowWithStackTrace (errClass|dyn_errClass exception, dyn_string stackTrace|int cutFrames)
 

Detailed Description

CtrlOOUtils module extends the tools related to Object-Oriented programming in CTRL++.

Please refer to the CtrlOOUtils Programmer Manual section for a comprehensive programmer's guide.

Function Documentation

bool fwClassExists ( string  className)

Check if specified class or struct exists

Parameters
[in]classNamethe name of the class to be checked
Exceptions
errClass(ErrCode=76)on invalid or missing input parameter (ErrCode::ILLEGAL_ARG)
Returns
TRUE if the class or struct specified in className is known to the CTRL interpretter
dyn_string fwClassNames ( )

Returns the list of all class and struct names

The function returns the list of all CTRL++ class and struct names currently known to the CTRL interpretter.

Returns
the list of the class/struct names
shared_ptr<className> fwCreateInstance ( string  className)

Creates a share'able object of specified class

The function creates a new object of the class which names is specified as a parameter. The object is created WITHOUT a call to the constructor. You may want to use fwInvokeMethod to call the constructor explicitly, specifying the name of the class as method name, and passing any arguments you wish.

Note
the fact that the object is created without a constructor likely means that it is likely treated in the same way as objects created through the asssignment operator, ie. destructor may not be called for them (not checked).

The object is sharea'able, ie. suitable to be used through a shared_ptr.

Parameters
[in]classNamethe name of the class of which the object will be created
Exceptions
errClass(ErrCode=76)on invalid or missing input parameters (ErrCode::ILLEGAL_ARG)
Returns
a shared pointer to the new instance of the object
dyn_string fwClassMemberVars ( string  className)

Returns the list of member variables of a class

The function returns the list of names of all member variables for a specified class. Only the names of the members are returned, not their full declarations (types, visibility)

Parameters
[in]classNamespecifies the name of the class
Returns
a list of names of member variables
Exceptions
errClass(ErrCode=76)on invalid or missing input parameter (ErrCode::ILLEGAL_ARG)
dyn_string fwClassMemberFuncs ( string  className)

Returns the list of methods of a class

The function returns the list of names of all methods for a specified class. Only the names of the methods, not their full declarations (types, parameters, etc)

Parameters
[in]classNamespecifies the name of the class
Returns
a list of names of method names
Exceptions
errClass(ErrCode=76)on invalid or missing input parameter (ErrCode::ILLEGAL_ARG)
string fwGetBaseClass ( string  className)

Returns the base name of a base class

The function returns the name of the direct base class of the specified class.

Parameters
[in]classNamespecifies the name of the class
Returns
the name of the base class
Exceptions
errClass(ErrCode=76)on invalid or missing input parameter (ErrCode::ILLEGAL_ARG)
bool fwIsInstanceOf ( const anytype &obj|const shared_ptr<>  obj,
string  className 
)

Checks if object is derived from specified base class

Checks whether the object passed in the parameter is an instance of a specific class or of a class that is derived from specified class. For example, the function could be used to check if a particular object follows an interface that is specified by defining a base class, or if it could be safely casted.

Parameters
[in]objis the object or a shared pointer to an object which is going to be inspected
[in]classNamethe name of the class
Exceptions
errClass(ErrCode=76)on invalid or missing input parameter (ErrCode::ILLEGAL_ARG)
Returns
TRUE if it is derived or it is an instance of the specific class
string fwGetClass ( const anytype &obj|const shared_ptr<>  obj)

Return the class name of the object

The function returns the name of the class or struct for the object, without additional decorators ("class").

Parameters
[in]objis the object or a shared pointer to an object which is going to be inspected
Exceptions
errClass(ErrCode=76)on invalid or missing input parameter (ErrCode::ILLEGAL_ARG)
Returns
the name of the class
function_ptr fwGetFuncPtr ( string  funcName)

Gets a function_ptr for a function

The function returns a function pointer for requested function. This compensates for lacking WinCC OA feature, whereby one could only pass static method of class to certain objects, and not functions for which one specifies the name. It also allows for meta-programming (resolving the function name at runtime) without the need for evalScript()

Parameters
[in]funcNamethe name of the function
Exceptions
errClass(ErrCode=76)on invalid or missing input parameter (ErrCode::ILLEGAL_ARG)
Returns
the function pointer
anytype fwInvokeMethod ( anytype &obj|shared_ptr<>  obj,
string  method,
  ... 
)

Invokes a named method on an object

The function allows to invoke a method on an object, with the method name passed as a parameter; method parameters (including references for in-out values) may be passed, and the value returned by the invoked method is returned to the caller. The function is notably relevant for metaprogramming use cases.

Note
At the moment the public/protected/private classifiers of the method are ignored.
Parameters
objobject or shared pointer to the object on which the method is invoked
methodthe name of the method to be invoked
...all the rest of parameters will be passed to the invoked method
Returns
the value returned by the invoked method
void fwRethrow ( )

Rethrows exception with proper stack trace

The function should be used in the exception catch block to properly rethrow the current exception, without altering the call stack information. It works around the missing functionality reported in the ETM-1710 issue.

Exceptions
errClasswith exception that is currently present in the catch block
void fwThrowWithStackTrace ( errClass|dyn_errClass  exception,
dyn_string stackTrace|int  cutFrames 
)

Throws exception with specified stackTrace

The function allows to throw an exception passing a custom stack trace as a parameter. It is of particular interest to the fwCore functionality of exceptions, whereby one wants to cut-off the unnecessary stack frames of the exception-throwing method itself. It also compensates for the missing functionality of defining or setting the stackTrace information of a errClass variable.

Either the stackTrace or framesToCut parameter may be specified, and the actual behaviour is determined by the type of the parameter passed to the function (see description of the parameters).

Parameters
[in]exceptionthe errClass variable already containing details of the exception to be thrown
[in]stackTracea dyn_string which should contain the stack frames; it will be put into the exception before it is thrown
[in]cutFrames=0if the parameter passed to the function is on the int-type the current stack is taken, then the number of stack frames specified in this parameter are truncated from its top, and then the resulting exception is thrown. If the parameter is skipped, or the cutFrames parameters is zero then the current stack trace will be used.
Exceptions
exceptionthat was passed as the argument, with its stack trace set to the stackTrace or truncated by cutFrames
errClass(ErrCode=75,76)on invalid or missing input parameters (ErrCode::ARG_MISSING,ErrCode::ILLEGAL_ARG)