};
};
+
+/**
+ * Class to store the parameters of a function with 6 arguments. For more
+ * information on use and internals of this class see the report on
+ * this subject.
+ *
+ * @author Ralf Hartmann, 2000
+ */
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ class FunData6 : public FunDataBase
+ {
+ public:
+ /**
+ * Typedef a pointer to a global
+ * function which we will call
+ * from this class.
+ */
+ typedef RetType (*FunPtr) (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6);
+
+ /**
+ * Constructor. Store pointer to
+ * the function and the values of
+ * the arguments.
+ */
+ FunData6 (FunPtr fun_ptr,
+ Arg1 arg1,
+ Arg2 arg2,
+ Arg3 arg3,
+ Arg4 arg4,
+ Arg5 arg5,
+ Arg6 arg6);
+
+ /**
+ * Copy constructor.
+ */
+ FunData6 (const FunData6 &fun_data6);
+
+ /**
+ * Virtual constructor.
+ */
+ virtual FunDataBase * clone () const;
+
+ private:
+
+ /**
+ * Pointer to the function to be
+ * called and values of the
+ * arguments to be passed.
+ */
+ FunPtr fun_ptr;
+
+ /**
+ * Values of the arguments of the
+ * function to be called.
+ */
+ Arg1 arg1;
+ Arg2 arg2;
+ Arg3 arg3;
+ Arg4 arg4;
+ Arg5 arg5;
+ Arg6 arg6;
+
+ /**
+ * Static function used as entry
+ * point for the new thread.
+ */
+ static void * thread_entry_point (void *arg);
+
+ /**
+ * Helper class, used to collect
+ * the values of the parameters
+ * which we will pass to the
+ * function, once we know its
+ * type.
+ */
+ class ArgCollector
+ {
+ public:
+ /**
+ * Typedef the function
+ * pointer type of the
+ * underlying class to a
+ * local type.
+ */
+ typedef FunData6<Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::FunPtr FunPtr;
+
+ /**
+ * Constructor. Take and store a
+ * pointer to the function which
+ * is to be called.
+ */
+ ArgCollector (FunPtr fun_ptr);
+
+ /**
+ * Take the arguments with
+ * which we want to call the
+ * function and produce and
+ * object of the desired type
+ * from that.
+ */
+ FunEncapsulation collect_args (Arg1 arg1,
+ Arg2 arg2,
+ Arg3 arg3,
+ Arg4 arg4,
+ Arg5 arg5,
+ Arg6 arg6);
+
+ private:
+ /**
+ * Space to temporarily store
+ * the function pointer.
+ */
+ FunPtr fun_ptr;
+ };
+ };
/**
};
};
+
+
+/**
+ * Class to store the parameters of a function with 6 arguments. For
+ * more information on use and internals of this class see the report
+ * on this subject.
+ *
+ * @author Ralf Hartmann, 2000
+ */
+ template <class Class, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ class MemFunData6 : public FunDataBase
+ {
+ public:
+ /**
+ * Typedef a pointer to a global
+ * function which we will call
+ * from this class.
+ */
+ typedef RetType (Class::*FunPtr) (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6);
+
+ /**
+ * Constructor. Store pointer to
+ * the function and the values of
+ * the arguments.
+ */
+ MemFunData6 (FunPtr fun_ptr,
+ Class *object,
+ Arg1 arg1,
+ Arg2 arg2,
+ Arg3 arg3,
+ Arg4 arg4,
+ Arg5 arg5,
+ Arg6 arg6);
+
+ /**
+ * Copy constructor.
+ */
+ MemFunData6 (const MemFunData6 &fun_data6);
+
+ /**
+ * Virtual constructor.
+ */
+ virtual FunDataBase * clone () const;
+
+ private:
+
+ /**
+ * Pointer to the function to be
+ * called and values of the
+ * arguments to be passed.
+ */
+ FunPtr fun_ptr;
+
+ /**
+ * Pointer to the object which
+ * we shall work on.
+ */
+ Class *object;
+
+ /**
+ * Values of the arguments of the
+ * function to be called.
+ */
+ Arg1 arg1;
+ Arg2 arg2;
+ Arg3 arg3;
+ Arg4 arg4;
+ Arg5 arg5;
+ Arg6 arg6;
+
+ /**
+ * Static function used as entry
+ * point for the new thread.
+ */
+ static void * thread_entry_point (void *arg);
+
+ /**
+ * Helper class, used to collect
+ * the values of the parameters
+ * which we will pass to the
+ * function, once we know its
+ * type.
+ */
+ class ArgCollector
+ {
+ public:
+ /**
+ * Typedef the function
+ * pointer type of the
+ * underlying class to a
+ * local type.
+ */
+ typedef MemFunData6<Class,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::FunPtr FunPtr;
+
+ /**
+ * Constructor. Take and store a
+ * pointer to the function which
+ * is to be called.
+ */
+ ArgCollector (FunPtr fun_ptr);
+
+ /**
+ * Take the arguments with
+ * which we want to call the
+ * function and produce and
+ * object of the desired type
+ * from that.
+ */
+ FunEncapsulation collect_args (Class *object,
+ Arg1 arg1,
+ Arg2 arg2,
+ Arg3 arg3,
+ Arg4 arg4,
+ Arg5 arg5,
+ Arg6 arg6);
+
+ private:
+ /**
+ * Space to temporarily store
+ * the function pointer.
+ */
+ FunPtr fun_ptr;
+ };
+ };
+
/**
* Encapsulate a function pointer
*/
template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
typename FunData5<Arg1,Arg2,Arg3,Arg4,Arg5,void>::ArgCollector
- encapsulate (void (*fun_ptr)(Arg1, Arg2, Arg3, Arg4,Arg5));
+ encapsulate (void (*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5));
+
+
+ /**
+ * Encapsulate a function pointer
+ * into an object with which a new
+ * thread can later be spawned.
+ * For more information on use and
+ * internals of this class see the
+ * report on this subject.
+ *
+ * This function exists once for
+ * each number of parameters.
+ */
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6>
+ typename FunData6<Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,void>::ArgCollector
+ encapsulate (void (*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6));
/**
encapsulate (void (Class::*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5));
+ /**
+ * Encapsulate a member function
+ * pointer into an object with
+ * which a new thread can later be
+ * spawned. For more information
+ * on use and internals of this
+ * class see the report on this
+ * subject.
+ *
+ * This function exists once for
+ * each number of parameters.
+ */
+ template <class Class, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6>
+ typename MemFunData6<Class,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,void>::ArgCollector
+ encapsulate (void (Class::*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6));
+
/**
* Spawn a new thread using the
* function and parameters
return new FunData5<Arg1,Arg2,Arg3,Arg4,Arg5,void>(fun_ptr, arg1, arg2,
arg3, arg4, arg5);
};
+
+
+
+
+/* ---------------------- FunData6 implementation ------------------------ */
+
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ FunData6<Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::FunData6 (FunPtr fun_ptr,
+ Arg1 arg1,
+ Arg2 arg2,
+ Arg3 arg3,
+ Arg4 arg4,
+ Arg5 arg5,
+ Arg6 arg6) :
+ FunDataBase (&FunData6<Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::thread_entry_point),
+ fun_ptr (fun_ptr),
+ arg1 (arg1),
+ arg2 (arg2),
+ arg3 (arg3),
+ arg4 (arg4),
+ arg5 (arg5),
+ arg6 (arg6)
+ {};
+
+
+
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ FunData6<Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::FunData6 (const FunData6 &fun_data) :
+ FunDataBase (fun_data),
+ fun_ptr (fun_data.fun_ptr),
+ arg1 (fun_data.arg1),
+ arg2 (fun_data.arg2),
+ arg3 (fun_data.arg3),
+ arg4 (fun_data.arg4),
+ arg5 (fun_data.arg5),
+ arg6 (fun_data.arg6)
+ {};
+
+
+
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ FunDataBase *
+ FunData6<Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::clone () const
+ {
+ return new FunData6 (*this);
+ };
+
+
+
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ void *
+ FunData6<Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::thread_entry_point (void *arg)
+ {
+ // convenience typedef, since we
+ // will need that class name
+ // several times below
+ typedef FunData6<Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType> ThisClass;
+
+ FunEncapsulation *fun_encapsulation
+ = reinterpret_cast<FunEncapsulation*>(arg);
+ const ThisClass *fun_data
+ = dynamic_cast<const ThisClass*> (fun_encapsulation->fun_data_base);
+
+ // copy the parameters
+ ThisClass::FunPtr fun_ptr = fun_data->fun_ptr;
+ Arg1 arg1 = fun_data->arg1;
+ Arg2 arg2 = fun_data->arg2;
+ Arg3 arg3 = fun_data->arg3;
+ Arg4 arg4 = fun_data->arg4;
+ Arg5 arg5 = fun_data->arg5;
+ Arg6 arg6 = fun_data->arg6;
+
+
+ // copying of parameters is done,
+ // now we can release the lock on
+ // #fun_data#
+ fun_data->lock.release ();
+
+ // call the function
+ (*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6);
+
+ return 0;
+ };
+
+
+
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ FunData6<Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::ArgCollector::ArgCollector (FunPtr fun_ptr) :
+ fun_ptr (fun_ptr)
+ {};
+
+
+
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ FunEncapsulation
+ FunData6<Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::ArgCollector::collect_args (Arg1 arg1,
+ Arg2 arg2,
+ Arg3 arg3,
+ Arg4 arg4,
+ Arg5 arg5,
+ Arg6 arg6)
+ {
+ return new FunData6<Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,void>(fun_ptr, arg1, arg2,
+ arg3, arg4, arg5, arg6);
+ };
+
+/* ---------------------- MemFunData6 implementation ------------------------ */
+
+ template <class Class, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ MemFunData6<Class,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::MemFunData6 (FunPtr fun_ptr,
+ Class *object,
+ Arg1 arg1,
+ Arg2 arg2,
+ Arg3 arg3,
+ Arg4 arg4,
+ Arg5 arg5,
+ Arg6 arg6) :
+ FunDataBase (&MemFunData6<Class,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::thread_entry_point),
+ fun_ptr (fun_ptr),
+ object (object),
+ arg1 (arg1),
+ arg2 (arg2),
+ arg3 (arg3),
+ arg4 (arg4),
+ arg5 (arg5),
+ arg6 (arg6)
+ {};
+
+
+
+ template <class Class, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ MemFunData6<Class,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::MemFunData6 (const MemFunData6 &fun_data) :
+ FunDataBase (fun_data),
+ fun_ptr (fun_data.fun_ptr),
+ object (fun_data.object),
+ arg1 (fun_data.arg1),
+ arg2 (fun_data.arg2),
+ arg3 (fun_data.arg3),
+ arg4 (fun_data.arg4),
+ arg5 (fun_data.arg5),
+ arg6 (fun_data.arg6)
+ {};
+
+
+
+ template <class Class, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ FunDataBase *
+ MemFunData6<Class,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::clone () const
+ {
+ return new MemFunData6 (*this);
+ };
+
+
+
+ template <class Class, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ void *
+ MemFunData6<Class,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::thread_entry_point (void *arg)
+ {
+ // convenience typedef, since we
+ // will need that class name
+ // several times below
+ typedef MemFunData6<Class,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType> ThisClass;
+
+ FunEncapsulation *fun_encapsulation
+ = reinterpret_cast<FunEncapsulation*>(arg);
+ const ThisClass *fun_data
+ = dynamic_cast<const ThisClass*> (fun_encapsulation->fun_data_base);
+
+ // copy the parameters
+ ThisClass::FunPtr fun_ptr = fun_data->fun_ptr;
+ Class *object = fun_data->object;
+ Arg1 arg1 = fun_data->arg1;
+ Arg2 arg2 = fun_data->arg2;
+ Arg3 arg3 = fun_data->arg3;
+ Arg4 arg4 = fun_data->arg4;
+ Arg5 arg5 = fun_data->arg5;
+ Arg6 arg6 = fun_data->arg6;
+
+
+ // copying of parameters is done,
+ // now we can release the lock on
+ // #fun_data#
+ fun_data->lock.release ();
+
+ // call the function
+ (object->*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6);
+
+ return 0;
+ };
+
+
+
+ template <class Class, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ MemFunData6<Class,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::ArgCollector::ArgCollector (FunPtr fun_ptr) :
+ fun_ptr (fun_ptr)
+ {};
+
+
+
+ template <class Class, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6, typename RetType>
+ FunEncapsulation
+ MemFunData6<Class,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,RetType>::ArgCollector::collect_args (Class *object,
+ Arg1 arg1,
+ Arg2 arg2,
+ Arg3 arg3,
+ Arg4 arg4,
+ Arg5 arg5,
+ Arg6 arg6)
+ {
+ return new MemFunData6<Class,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,void>(fun_ptr, object,
+ arg1, arg2, arg3, arg4, arg5, arg6);
+ };
+
+
+
/* ---------------------------------------------------------------- */
return fun_ptr;
};
+
template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5>
FunData5<Arg1,Arg2,Arg3,Arg4,Arg5,void>::ArgCollector
{
return fun_ptr;
};
+
+
+ template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6>
+ FunData6<Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,void>::ArgCollector
+ encapsulate (void (*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6))
+ {
+ return fun_ptr;
+ };
+
+
template <class Class>
MemFunData0<Class,void>::ArgCollector
+ template <class Class, typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6>
+ MemFunData6<Class,Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,void>::ArgCollector
+ encapsulate (void (Class::*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6))
+ {
+ return fun_ptr;
+ };
+
+
+
template <typename ForwardIterator>
vector<pair<ForwardIterator,ForwardIterator> >
split_range (const ForwardIterator &begin, const ForwardIterator &end,