Aria: ArFunctor Class Reference

- Main Page
- Classes
- Files
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# ArFunctor Class Reference

`#include <ArFunctor.h>`

Inheritance diagram for ArFunctor:

List of all members.

## Detailed Description

Base class for functors.

Functors are meant to encapsulate the idea of a pointer to a function which is a member of a class. To use a pointer to a member function, you must have a C style function pointer, 'void(Class::*)()', and a pointer to an instance of the class in which the function is a member of. This is because all non-static member functions must have a 'this' pointer. If they dont and if the member function uses any member data or even other member functions it will not work right and most likely crash. This is because the 'this' pointer is not the correct value and is most likely a random uninitialized value. The virtue of static member functions is that they do not require a 'this' pointer to be run. But the compiler will never let you access any member data or functions from within a static member function.

Because of the design of C++ never allowed for encapsulating these two pointers together into one language supported construct, this has to be done by hand. For conviences sake, there are functors (ArGlobalFunctor, ArGlobalRetFunctor) which take a pure C style function pointer (a non-member function). This is in case you want to use a functor that refers to a global C style function.

Aria makes use of functors by using them as callback functions. Since Aria is programmed using the object oriented programming paradigm, all the callback functions need to be tied to an object and a particular instance. Thus the need for functors. Most of the use of callbacks simply take an ArFunctor, which is the base class for all the functors. This class only has the ability to invoke a functor. All the derivitave functors have the ability to invoke the correct function on the correct object.

Because functions have different signatures because they take different types of parameters and have different number of parameters, templates were used to create the functors. These are the base classes for the functors. These classes encapsulate everything except for the class type that the member function is a member of. This allows someone to accept a functor of type ArFunctor1<int> which has one parameter of type 'int'. But they never have to know that the function is a member function of class 'SomeUnknownType'. These classes are:

ArFunctor, ArFunctor1, ArFunctor2, ArFunctor3 ArRetFunctor, ArRetFunctor1, ArRetFunctor2, ArRetFunctor3

These 8 functors are the only thing a piece of code that wants a functor will ever need. But these classes are abstract classes and can not be instantiated. On the other side, the piece of code that wants to be called back will need the functor classes that know about the class type. These functors are:

ArFunctorC, ArFunctor1C, ArFunctor2C, ArFunctor3C ArRetFunctorC, ArRetFunctor1C, ArRetFunctor2C, ArRetFunctor3C

These functors are meant to be instantiated and passed of to a piece of code that wants to use them. That piece of code should only know the functor as one of the functor classes without the 'C' in it.

Note that you can create these FunctorC instances with default arguments that are then used when the invoke is called without those arguments... These are quite useful since if you have a class that expects an ArFunctor you can make an ArFunctor1C with default arguments and pass it as an ArFunctor... and it will get called with that default argument, this is useful for having multiple functors use the same function with different arguments and results (just takes one functor each).

Functors now have a getName() method, this is useful as an aid to debugging, allowing you to display the name of some functor being used.

Java Wrapper Library: You can subclass ArFunctor and override invoke().

See also:
  functorExample::cpp

## Public Member Functions
virtual const char * | getName (void)
| Gets the name of the functor.
virtual void | invoke (void)=0
| Invokes the functor.
virtual void | setName (const char *name)
| Sets the name of the functor.
virtual void | setNameVar (const char *name,...)
| Sets the name of the functor with formatting.
virtual | ~ArFunctor ()
| Destructor.
## Protected Attributes
std::string | myName

## Member Function Documentation

virtual void ArFunctor::setNameVar | ( | const char * | name,
|  |  | ... |
| ) |  |  | `[inline, virtual]`

Sets the name of the functor with formatting.

Java and Python Wrappers: Not available in Java or Python wrapper libraries. use setName()

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

- ArFunctor.h