summaryrefslogtreecommitdiff
path: root/cosv
diff options
context:
space:
mode:
authorJens-Heiner Rechtien <hr@openoffice.org>2007-11-02 16:43:39 +0000
committerJens-Heiner Rechtien <hr@openoffice.org>2007-11-02 16:43:39 +0000
commitc7e1e9abee93841422c73ca3e99e7176312c60f2 (patch)
treeb4ab81b78da615761af8129566321d82a4d9ad60 /cosv
parentd49c24df5656f53488b661da5f93daa032254b76 (diff)
INTEGRATION: CWS adc18 (1.1.2); FILE ADDED
2007/10/19 12:17:14 np 1.1.2.2: #i81775# 2007/09/20 12:05:36 np 1.1.2.1: #i81775#
Diffstat (limited to 'cosv')
-rw-r--r--cosv/inc/cosv/tpl/funcall.hxx315
1 files changed, 315 insertions, 0 deletions
diff --git a/cosv/inc/cosv/tpl/funcall.hxx b/cosv/inc/cosv/tpl/funcall.hxx
new file mode 100644
index 000000000000..9360096f22de
--- /dev/null
+++ b/cosv/inc/cosv/tpl/funcall.hxx
@@ -0,0 +1,315 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: funcall.hxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: hr $ $Date: 2007-11-02 17:43:39 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#ifndef CSV_TPL_FUNCALL_HXX
+#define CSV_TPL_FUNCALL_HXX
+
+// BASE CLASSES
+#include <algorithm>
+
+
+
+
+namespace csv
+{
+namespace func
+{
+
+
+/** @concept "csv:: Function Objects"
+
+ A set of function objects that can be generated from any kind of
+ function or member function with none or one parameter by the
+ helper function ->make_func().
+
+ Naming Scheme
+ =============
+
+ The naming scheme consists of three variables
+ f - the kind of function
+ p - the parameter of the function
+ c - call operator() of the function object with these arguments
+
+ Each of those may have the following values:
+ f:
+ f - free, no owning class
+ c - const member function of a class
+ m - modifying member function of a class
+ p:
+ n - no parameter
+ c - const parameter by reference
+ m - modifyable parameter by reference,
+ v - parameter by value
+ c:
+ n - none
+ o - the owning object on which the function shall be called
+ a - the argument of the function
+ b - both, the object on which the function shall be called
+ and the argument of the function
+
+ Which gives the following 35 possible combinations:
+ ff_pn_cn
+ ff_pc_cn
+ ff_pc_ca
+ ff_pm_cn
+ ff_pm_ca
+ ff_pv_cn
+ ff_pv_ca
+
+ fc_pn_cn
+ fc_pn_co
+ fc_pc_cn
+ fc_pc_co
+ fc_pc_ca
+ fc_pc_cb
+ fc_pm_cn
+ fc_pm_co
+ fc_pm_ca
+ fc_pm_cb
+ fc_pv_cn
+ fc_pv_co
+ fc_pv_ca
+ fc_pv_cb
+
+ fm_pn_cn
+ fm_pn_co
+ fm_pc_cn
+ fm_pc_co
+ fm_pc_ca
+ fm_pc_cb
+ fm_pm_cn
+ fm_pm_co
+ fm_pm_ca
+ fm_pm_cb
+ fm_pv_cn
+ fm_pv_co
+ fm_pv_ca
+ fm_pv_cb
+
+ These function objects are complicate to handle, so they can be created
+ with the overloaded function
+ <function_object> csv::make_func(<function_type>, <argument_types>);
+
+ For the rare, but possible case that the owning class and the function
+ argument have the same type, these clarifying variations to make_func()
+ can be used:
+ make_func_callwith_obj(), make_func_callwith_arg().
+*/
+
+
+/** Function object.
+
+ @concept ->"csv::func Function Objects"
+ @see csv::make_func()
+*/
+template <class R>
+struct ff_pn_cn
+{
+ typedef R result_type;
+ typedef R (* function_type )();
+
+ R operator()() const
+ { return (*f)(); }
+
+ ff_pn_cn(
+ function_type i_f)
+ : f(i_f) {}
+ private:
+ function_type f;
+};
+
+
+/** Function object.
+
+ @concept ->"csv::func Function Objects"
+ @see csv::make_func()
+*/
+template <class R, class C>
+struct fc_pn_co
+{
+ typedef R result_type;
+ typedef R (C::* function_type )() const;
+
+ R operator()(
+ const C & i_c ) const
+ { return (i_c.*f)(); }
+
+ fc_pn_co(
+ function_type i_f)
+ : f(i_f) {}
+ private:
+ function_type f;
+};
+
+
+
+/** Function object.
+
+ @concept ->"csv::func Function Objects"
+ @see csv::make_func()
+*/
+template <class R, class C, class P>
+struct fc_pm_co
+{
+ typedef R result_type;
+ typedef R (C::* function_type )(P&) const;
+
+ R operator()(
+ const C & i_c ) const
+ { return (i_c.*f)(p); }
+
+ fc_pm_co(
+ function_type i_f,
+ P & i_p)
+ : f(i_f), p(i_p) {}
+ private:
+ function_type f;
+ P & p;
+};
+
+
+
+
+
+
+
+} // namespace func
+
+
+/** Creates a function object of type ff_pn_cn.
+ @concept ->"csv::func Function Objects"
+*/
+template <class R>
+inline func::ff_pn_cn<R>
+make_func( R(*i_f)() )
+{
+ return func::ff_pn_cn<R>(i_f);
+}
+
+///** Creates a function object of type ff_py_cn.
+// @concept ->"csv::func Function Objects"
+//*/
+//template <class R, class P>
+//inline func::ff_py_cn<R,P>
+//make_func( R(*i_f)(P), P i_p )
+//{
+// return func::ff_py_cn<R,A>(i_f, i_p);
+//}
+//
+///** Creates a function object of type ff_py_ca.
+// @concept ->"csv::func Function Objects"
+//*/
+//template <class R, class P>
+//inline func::ff_py_ca<R,P>
+//make_func( R(*i_f)(P) )
+//{
+// return func::ff_py_ca<R,P>(i_f);
+//}
+
+
+/** Creates a function object of type fc_pn_co.
+ @concept ->"csv::func Function Objects"
+*/
+template <class R, class C>
+inline func::fc_pn_co<R,C>
+make_func( R(C::*i_f)() const )
+{
+ return func::fc_pn_co<R,C>(i_f);
+}
+
+
+
+/** Creates a function object of type fc_pm_co.
+ @concept ->"csv::func Function Objects"
+*/
+template <class R, class C, class P>
+inline func::fc_pm_co<R,C,P>
+make_func( R(C::*i_f)(P &) const, P & i_p)
+{
+ return func::fc_pm_co<R,C,P>(i_f, i_p);
+}
+
+
+
+/* Because std::for_each is defined as a non-modifying algorithm
+ it is redefined here. It is also provided for containers.
+*/
+
+template <class I, class F>
+F
+for_each(I i_itBegin, I i_itEnd, F io_functionToBeCalled)
+{
+ for (I it = i_itBegin; it != i_itEnd; ++it)
+ {
+ io_functionToBeCalled(*it);
+ }
+ return io_functionToBeCalled;
+}
+
+template <class C, class F>
+F
+for_each_in(const C & i_container, F io_functionToBeCalled)
+{
+ typename C::const_iterator const
+ itEnd = i_container.end();
+ for ( typename C::const_iterator it = i_container.begin();
+ it != itEnd;
+ ++it )
+ {
+ io_functionToBeCalled(*it);
+ }
+ return io_functionToBeCalled;
+}
+
+template <class C, class F>
+F
+for_each_in(C & i_container, F io_functionToBeCalled)
+{
+ typename C::iterator const
+ itEnd = i_container.end();
+ for ( typename C::iterator it = i_container.begin();
+ it != itEnd;
+ ++it )
+ {
+ io_functionToBeCalled(*it);
+ }
+ return io_functionToBeCalled;
+}
+
+
+
+
+} // namespace csv
+#endif