rwlogo
SourcePro C++ 12.0

SourcePro® C++ API Reference Guide



   SourcePro C++
Documentation Home

RWTFunctor2< S1, S2 > Class Template Reference
[Functors]

A functor that is invoked with two arguments, and whose invocation returns no value. More...

#include <rw/functor/RWTFunctor2.h>

Inheritance diagram for RWTFunctor2< S1, S2 >:
RWHandleBase RWTFunctorList2< S1, S2 >

List of all members.

Public Types

typedef void(* CallerSignature )(S1, S2)
typedef S1 S1Type
typedef S2 S2Type

Public Member Functions

 ~RWTFunctor2 (void)
 RWTFunctor2 (void)
 RWTFunctor2 (RWStaticCtor)
 RWTFunctor2 (RWTFunctor2Imp< S1, S2 > *functorImp)
 RWTFunctor2 (const RWTFunctor2< S1, S2 > &second)
RWTFunctor2< S1, S2 > & operator= (const RWTFunctor2< S1, S2 > &second)
void operator() (S1 s1, S2 s2) const
RWTFunctor2Imp< S1, S2 > & body (void) const

Detailed Description

template<class S1, class S2>
class RWTFunctor2< S1, S2 >

RWTFunctor2<S1,S2> represents the group of functors that are invoked with two arguments, and whose invocation returns no value.

A function object, or a functor, encapsulates a call to an associated global or member function. When a functor is invoked, it calls the associated function.

Instances of class RWTFunctor2 act as handles to functor implementations or bodies. Such implementations are created by using either the rwtMakeFunctor2() global functions or macros. Each of these methods creates a new body instance, and returns the handle to that instance. See the example below.

Note that although an instance of this class is invoked with two arguments and returns no value, the encapsulated function may have more arguments and a return value.

The additional arguments to be passed to the encapsulated function are provided to the functor at the time of creation. They are stored within the functor object, and are retrieved at the time of invocation.

Any return value that the function may have is ignored by the functor, and hence not passed back to the user. (If you are interested in the function's return value, consider the RWTFunctorR1 group of classes.)

Examples

 #include <iostream.h>
 #include <rw/functor/functor2.h>
 
 void foo(int x, short y){
    cout << "x is " << x << ", y is " << y << endl;
 }
 
 int main () {
    // Create a handle and assign a new body to it.
    RWTFunctor2<int,short> functor = rwtMakeFunctor2( (void(*)(int,short))0, foo );
 
    // Invoke the functor with two caller arguments.
    functor(42,3);
    return 0;
 }
 
 Output:
    x is 42, y is 3
See also:
rwtMakeFunctor2()

Member Typedef Documentation

template<class S1, class S2>
typedef void(* RWTFunctor2< S1, S2 >::CallerSignature)(S1, S2)

The signature of the functor invocation.

template<class S1, class S2>
typedef S1 RWTFunctor2< S1, S2 >::S1Type

The type of the first caller argument.

template<class S1, class S2>
typedef S2 RWTFunctor2< S1, S2 >::S2Type

The type of the second caller argument.


Constructor & Destructor Documentation

template<class S1, class S2>
RWTFunctor2< S1, S2 >::~RWTFunctor2 ( void   ) 

Destructor.

template<class S1, class S2>
RWTFunctor2< S1, S2 >::RWTFunctor2 ( void   ) 

Constructs an empty, invalid, handle instance. To create a viable handle, use the rwtMakeFunctor2() global function or macros.

template<class S1, class S2>
RWTFunctor2< S1, S2 >::RWTFunctor2 ( RWStaticCtor   ) 

Constructs a global static handle instance. Constructor does not reset any values that may have been set in invocations prior to the constructor call.

template<class S1, class S2>
RWTFunctor2< S1, S2 >::RWTFunctor2 ( RWTFunctor2Imp< S1, S2 > *  functorImp  ) 

Body constructor. Constructs a new RWTFunctor2 handle from an existing body.

template<class S1, class S2>
RWTFunctor2< S1, S2 >::RWTFunctor2 ( const RWTFunctor2< S1, S2 > &  second  ) 

Copy constructor. Binds a new handle instance to the functor body instance, if any, associated with the second handle instance.


Member Function Documentation

template<class S1 , class S2 >
RWTFunctor2Imp< S1, S2 > & RWTFunctor2< S1, S2 >::body ( void   )  const [inline]

Gets a reference for the body instance, if any; otherwise, throws an RWTHRInvalidPointer exception.

Reimplemented from RWHandleBase.

Reimplemented in RWTFunctorList2< S1, S2 >, and RWTFunctorMap2< Key, S1 >.

template<class S1, class S2>
void RWTFunctor2< S1, S2 >::operator() ( S1  s1,
S2  s2 
) const [inline]

Invokes the functor, calling the encapsulated function. Throws an RWTHRInvalidPointer if the handle has no associated body.

Reimplemented in RWTFunctorList2< S1, S2 >, and RWTFunctorMap2< Key, S1 >.

template<class S1, class S2>
RWTFunctor2<S1, S2>& RWTFunctor2< S1, S2 >::operator= ( const RWTFunctor2< S1, S2 > &  second  ) 

Assignment operator. Detaches this handle instance from any functor body instance it currently references, and binds it to the functor body instance, if any, associated with the second handle instance.

 All Classes Functions Variables Typedefs Enumerations Enumerator Friends

© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.