Aria  2.8.0
ArFunctor Class Referenceabstract

An object which allows storing a generalized reference to a method with an object instance to call later (used for callback functions) More...

#include <ArFunctor.h>

Inherited by ArConstFunctorC< T >, ArConstFunctorC< ArBatteryConnector >, ArConstFunctorC< ArDaemonizer >, ArConstFunctorC< ArLaserConnector >, ArConstFunctorC< ArLCDConnector >, ArConstFunctorC< ArPTZConnector >, ArConstFunctorC< ArRobotConnector >, ArConstFunctorC< ArSonarConnector >, ArFunctor1< P1 >, ArFunctor1< ArNMEAParser::Message >, ArFunctor1< ArRobotPacket *>, ArFunctor1< ArRobotParams * >, ArFunctor1< char * >, ArFunctor1< char ** >, ArFunctor1< const char * >, ArFunctor1< const char *>, ArFunctor1< double >, ArFunctor1< int >, ArFunctor1< PacketType >, ArFunctorC< T >, ArFunctorC< ArActionAvoidFront >, ArFunctorC< ArActionKeydrive >, ArFunctorC< ArActionRobotJoydrive >, ArFunctorC< ArACTS_1_2 >, ArFunctorC< ArAnalogGyro >, ArFunctorC< ArBatteryMTX >, ArFunctorC< ArBumpers >, ArFunctorC< ArCompassConnector >, ArFunctorC< ArDataLogger >, ArFunctorC< ArDPPTU >, ArFunctorC< ArForbiddenRangeDevice >, ArFunctorC< ArGPSConnector >, ArFunctorC< ArGripper >, ArFunctorC< ArIRs >, ArFunctorC< ArKeyHandler >, ArFunctorC< ArLaserFilter >, ArFunctorC< ArLaserLogger >, ArFunctorC< ArLaserReflectorDevice >, ArFunctorC< ArLCDMTX >, ArFunctorC< ArLMS1XX >, ArFunctorC< ArLMS2xx >, ArFunctorC< ArMode >, ArFunctorC< ArModeActs >, ArFunctorC< ArModeCamera >, ArFunctorC< ArModeCommand >, ArFunctorC< ArModeConfig >, ArFunctorC< ArModeGripper >, ArFunctorC< ArModeIO >, ArFunctorC< ArModeLaser >, ArFunctorC< ArModePosition >, ArFunctorC< ArModeSonar >, ArFunctorC< ArNetServer >, ArFunctorC< ArPTZ >, ArFunctorC< ArRangeDevice >, ArFunctorC< ArRatioInputJoydrive >, ArFunctorC< ArRatioInputKeydrive >, ArFunctorC< ArRatioInputRobotJoydrive >, ArFunctorC< ArRobot >, ArFunctorC< ArRobotBatteryPacketReader >, ArFunctorC< ArRobotConfig >, ArFunctorC< ArRobotConfigPacketReader >, ArFunctorC< ArRobotJoyHandler >, ArFunctorC< ArS3Series >, ArFunctorC< ArSonarAutoDisabler >, ArFunctorC< ArSonarDevice >, ArFunctorC< ArSonarMTX >, ArFunctorC< ArSpeechSynth >, ArFunctorC< ArSZSeries >, ArFunctorC< ArTCM2 >, ArFunctorC< ArUrg >, ArFunctorC< ArUrg_2_0 >, ArFunctorC< ArVCC4 >, ArFunctorC< ConnHandler >, ArFunctorC< GPSLogTask >, ArFunctorC< GripperControlHandler >, ArFunctorC< GyroTask >, ArFunctorC< Joydrive >, ArFunctorC< KeyPTU >, ArFunctorC< PrintGripStatus >, ArFunctorC< PrintingTask >, ArGlobalFunctor, ArRetFunctor< Ret >, ArRetFunctor< ArBatteryMTX * >, ArRetFunctor< ArDeviceConnection * >, ArRetFunctor< ArLaser * >, ArRetFunctor< ArLCDMTX * >, ArRetFunctor< ArSonarMTX * >, ArRetFunctor< bool >, ArRetFunctor< const std::list< ArArgumentBuilder * > * >, ArRetFunctor< const std::list< ArArgumentBuilder *> *>, ArRetFunctor< double >, ArRetFunctor< int >, ArRetFunctor< State >, ArRetFunctor< unsigned int >, ArRetFunctor< unsigned long >, and ArRetFunctor< void * >.

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. More...
virtual ~ArFunctor ()

Protected Attributes

std::string myName

Detailed Description

An object which allows storing a generalized reference to a method with an object instance to call later (used for callback functions)

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

Member Function Documentation

◆ setNameVar()

virtual void ArFunctor::setNameVar ( const char *  name,

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: