EvolvingObjects
eo::mpi::SharedDataFunction< JobData, Wrapped > Struct Template Reference

Base class for the 4 algorithm functors. More...

#include <eoMpi.h>

List of all members.

Public Member Functions

 SharedDataFunction (Wrapped *w=0)
 Default constructor.
virtual ~SharedDataFunction ()
 Destructor.
void wrapped (Wrapped *w)
 Setter for the wrapped function.
void data (JobData *d)
 Setter for the data present in the functor.
bool needDelete ()
 Returns true if we need to use operator delete on this wrapper, false otherwise.
void needDelete (bool b)

Protected Attributes

JobData * _data
Wrapped * _wrapped
bool _needDelete

Detailed Description

template<typename JobData, typename Wrapped>
struct eo::mpi::SharedDataFunction< JobData, Wrapped >

Base class for the 4 algorithm functors.

This class can embed a data (JobData) and a wrapper, so as to make all the 4 functors wrappable. We can add a wrapper at initialization or at any time when executing the program.

According to RAII, the boolean needDelete helps to know if we have to use the operator delete on the wrapper or not. Hence, if any functor is wrapped, user has just to put this boolean to true, to indicate to wrapper that it should call delete. This allows to mix wrapper initialized in the heap (with new) or in the stack.

Parameters:
JobDataa Data type, which can have any form. It can a struct, a single int, anything.
Wrappedthe type of the functor, which will be stored as a pointer under the name _wrapped. This allows to wrap directly the functor in functors of the same type here, instead of dealing with SharedDataFunction* that we would have to cast all the time. Doing also allows to handle the wrapped functor as the functor we're writing, when coding the wrappers, instead of doing some static_cast. For instance, if there are 2 functors subclasses, fA and fB, fA implementing doFa() and fB implementing doFb(), we could have the following code:
 struct fA_wrapper
 {
   // some code
   void doFa()
   {
      _wrapped->doFa();
      std::cout << "I'm a fA wrapper!" << std::endl;
      // if we didn't have the second template parameter, but a SharedDataFunction, we would have to do this:
      static_cast<fA*>(_wrapped)->doFa();
      // do other things (it's a wrapper)
   }
 };

 struct fB_wrapper
 {
  // some code
  void doFb()
  {
      _wrapped->doFb(); // and not: static_cast<fB*>(_wrapped)->doFb();
  }
 };
This makes the code easier to write for the user.

Definition at line 218 of file eoMpi.h.


Constructor & Destructor Documentation

template<typename JobData, typename Wrapped>
eo::mpi::SharedDataFunction< JobData, Wrapped >::SharedDataFunction ( Wrapped *  w = 0) [inline]

Default constructor.

The user is not bound to give a wrapped functor.

Definition at line 225 of file eoMpi.h.

template<typename JobData, typename Wrapped>
virtual eo::mpi::SharedDataFunction< JobData, Wrapped >::~SharedDataFunction ( ) [inline, virtual]

Destructor.

Calls delete on the wrapped function, only if necessary.

Definition at line 235 of file eoMpi.h.


Member Function Documentation

template<typename JobData, typename Wrapped>
void eo::mpi::SharedDataFunction< JobData, Wrapped >::wrapped ( Wrapped *  w) [inline]

Setter for the wrapped function.

It doesn't do anything on the current wrapped function, like deleting it.

Definition at line 248 of file eoMpi.h.

template<typename JobData, typename Wrapped>
void eo::mpi::SharedDataFunction< JobData, Wrapped >::data ( JobData *  d) [inline]

Setter for the data present in the functor.

Calls the setter on the functor and on the wrapped functors, in a Composite pattern fashion.

Definition at line 258 of file eoMpi.h.

template<typename JobData, typename Wrapped>
bool eo::mpi::SharedDataFunction< JobData, Wrapped >::needDelete ( ) [inline]

Returns true if we need to use operator delete on this wrapper, false otherwise.

Allows the user to reject delete responsability to the framework, by setting this value to true.

Definition at line 272 of file eoMpi.h.

Referenced by eo::mpi::ParallelApplyStore< EOT >::ParallelApplyStore().


The documentation for this struct was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Friends