[ VIGRA Homepage | Class Index | Function Index | File Index | Main Page ]

details vigra/functortraits.hxx VIGRA

00001 /************************************************************************/
00002 /*                                                                      */
00003 /*               Copyright 1998-2005 by Ullrich Koethe                  */
00004 /*       Cognitive Systems Group, University of Hamburg, Germany        */
00005 /*                                                                      */
00006 /*    This file is part of the VIGRA computer vision library.           */
00007 /*    ( Version 1.3.2, Jan 27 2005 )                                    */
00008 /*    You may use, modify, and distribute this software according       */
00009 /*    to the terms stated in the LICENSE file included in               */
00010 /*    the VIGRA distribution.                                           */
00011 /*                                                                      */
00012 /*    The VIGRA Website is                                              */
00013 /*        http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/      */
00014 /*    Please direct questions, bug reports, and contributions to        */
00015 /*        koethe@informatik.uni-hamburg.de                              */
00016 /*                                                                      */
00017 /*  THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR          */
00018 /*  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED      */
00019 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
00020 /*                                                                      */
00021 /************************************************************************/
00022 
00023 
00024 #ifndef VIGRA_FUNCTORTRAITS_HXX
00025 #define VIGRA_FUNCTORTRAITS_HXX
00026 
00027 #include <functional>
00028 #include <vigra/metaprogramming.hxx>
00029 
00030 namespace vigra {
00031 
00032 template <class T>
00033 class FunctorTraitsBase
00034 {
00035   public:
00036     typedef T type;
00037     
00038     typedef VigraFalseType isInitializer;
00039     
00040     typedef VigraFalseType isUnaryFunctor;
00041     typedef VigraFalseType isBinaryFunctor;
00042     typedef VigraFalseType isTernaryFunctor;
00043     
00044     typedef VigraFalseType isUnaryAnalyser;
00045     typedef VigraFalseType isBinaryAnalyser;
00046     typedef VigraFalseType isTernaryAnalyser;
00047 };
00048 
00049 
00050 
00051 /** \addtogroup Functors
00052 */
00053 //@{
00054 /** \brief Export associated information for a functor.
00055 
00056     The FunctorTraits class contains the following fields:
00057 
00058     \code
00059     template <class T>
00060     struct FunctorTraits
00061     {
00062         typedef T type;
00063         
00064         typedef ... isInitializer;
00065 
00066         typedef ... isUnaryFunctor;
00067         typedef ... isBinaryFunctor;
00068         typedef ... isTernaryFunctor;
00069         
00070         typedef ... isUnaryAnalyser;
00071         typedef ... isBinaryAnalyser;
00072         typedef ... isTernaryAnalyser;
00073     };
00074     \endcode
00075 
00076     Where the dots are either <tt>VigraTrueType</tt> or <tt>VigraFalseType</tt>
00077     depending on whether the functor supports the respective functionality or not.
00078     If a functor <tt>f<tt> is a model of these categories, it supports the following
00079     calls (<tt>v</tt> is a variable such that the result type of the functor
00080     calls can be converted into <tt>v</tt>'s type, and <tt>a1, a2, a3</tt> are
00081     variables convertible into the functor's argument types):
00082     
00083     <DL>
00084     <DT><b>Initializer</b>
00085         <DD> <tt>v = f()</tt> (used with initImageWithFunctor())
00086     <DT><b>UnaryFunctor</b>
00087         <DD> <tt>v = f(a1)</tt> (used with transformImage())
00088     <DT><b>BinaryFunctor</b>
00089         <DD> <tt>v = f(a1, a2)</tt> (used with combineTwoImages())
00090     <DT><b>TernaryFunctor</b>
00091         <DD> <tt>v = f(a1, a2, a3)</tt> (used with combineThreeImages())
00092     <DT><b>UnaryAnalyser</b>
00093         <DD> <tt>f(a1)</tt> (return type <tt>void>/tt>, used with inspectImage())
00094     <DT><b>BinaryAnalyser</b>
00095         <DD> <tt>f(a1, a2)</tt> (return type <tt>void>/tt>, used with inspectTwoImages())
00096     <DT><b>TernaryAnalyser</b>
00097         <DD> <tt>f(a1, a2, a3)</tt> (return type <tt>void>/tt>)
00098     </DL>
00099     
00100     It should be noted that the functor's argument and result types are not contained
00101     in the traits class: Since the function calls are often member template functions in 
00102     VIGRA, many functors do not have fixed argument types. Neither are the result
00103     types fixed in this case because they are computed (via a template meta-program)
00104     from the argument types.
00105 
00106     <b>\#include</b> "<a href="functortraits_8hxx-source.html">vigra/functortraits.hxx</a>"
00107     Namespace: vigra
00108 */
00109 template <class T>
00110 class FunctorTraits
00111 : public FunctorTraitsBase<T>
00112 {};
00113 
00114 #define VIGRA_DEFINE_STL_FUNCTOR(name, unary, binary) \
00115 template <class T> \
00116 class FunctorTraits<name<T> > \
00117 { \
00118   public: \
00119     typedef T type; \
00120      \
00121     typedef VigraFalseType isInitializer; \
00122      \
00123     typedef unary          isUnaryFunctor; \
00124     typedef binary         isBinaryFunctor; \
00125     typedef VigraFalseType isTernaryFunctor; \
00126      \
00127     typedef VigraFalseType isUnaryAnalyser; \
00128     typedef VigraFalseType isBinaryAnalyser; \
00129     typedef VigraFalseType isTernaryAnalyser; \
00130 };
00131 
00132 // ???TODO: these should also be specialized for the ptr_fun and mem_fun_ptr wrappers
00133 VIGRA_DEFINE_STL_FUNCTOR(std::plus, VigraFalseType, VigraTrueType)
00134 VIGRA_DEFINE_STL_FUNCTOR(std::minus, VigraFalseType, VigraTrueType)
00135 VIGRA_DEFINE_STL_FUNCTOR(std::multiplies, VigraFalseType, VigraTrueType)
00136 VIGRA_DEFINE_STL_FUNCTOR(std::divides, VigraFalseType, VigraTrueType)
00137 VIGRA_DEFINE_STL_FUNCTOR(std::modulus, VigraFalseType, VigraTrueType)
00138 VIGRA_DEFINE_STL_FUNCTOR(std::equal_to, VigraFalseType, VigraTrueType)
00139 VIGRA_DEFINE_STL_FUNCTOR(std::not_equal_to, VigraFalseType, VigraTrueType)
00140 VIGRA_DEFINE_STL_FUNCTOR(std::greater, VigraFalseType, VigraTrueType)
00141 VIGRA_DEFINE_STL_FUNCTOR(std::less, VigraFalseType, VigraTrueType)
00142 VIGRA_DEFINE_STL_FUNCTOR(std::greater_equal, VigraFalseType, VigraTrueType)
00143 VIGRA_DEFINE_STL_FUNCTOR(std::less_equal, VigraFalseType, VigraTrueType)
00144 VIGRA_DEFINE_STL_FUNCTOR(std::logical_and, VigraFalseType, VigraTrueType)
00145 VIGRA_DEFINE_STL_FUNCTOR(std::logical_or, VigraFalseType, VigraTrueType)
00146 VIGRA_DEFINE_STL_FUNCTOR(std::binary_negate, VigraFalseType, VigraTrueType)
00147 
00148 VIGRA_DEFINE_STL_FUNCTOR(std::negate, VigraTrueType, VigraFalseType)
00149 VIGRA_DEFINE_STL_FUNCTOR(std::logical_not, VigraTrueType, VigraFalseType)
00150 VIGRA_DEFINE_STL_FUNCTOR(std::unary_negate, VigraTrueType, VigraFalseType)
00151 VIGRA_DEFINE_STL_FUNCTOR(std::binder1st, VigraTrueType, VigraFalseType)
00152 VIGRA_DEFINE_STL_FUNCTOR(std::binder2nd, VigraTrueType, VigraFalseType)
00153 #undef VIGRA_DEFINE_STL_FUNCTOR
00154 
00155 template <class R>
00156 class FunctorTraits<R (*)()>
00157 {
00158   public:
00159     typedef R (*type)();
00160     
00161     typedef VigraTrueType  isInitializer;
00162     typedef VigraFalseType isUnaryFunctor;
00163     typedef VigraFalseType isBinaryFunctor;
00164     typedef VigraFalseType isTernaryFunctor;
00165     typedef VigraFalseType isUnaryAnalyser;
00166     typedef VigraFalseType isBinaryAnalyser;
00167     typedef VigraFalseType isTernaryAnalyser;
00168 };
00169 
00170 template <class R, class T>
00171 class FunctorTraits<R (*)(T)>
00172 {
00173   public:
00174     typedef R (*type)(T);
00175     
00176     typedef VigraFalseType isInitializer;
00177     typedef VigraTrueType  isUnaryFunctor;
00178     typedef VigraFalseType isBinaryFunctor;
00179     typedef VigraFalseType isTernaryFunctor;
00180     typedef VigraFalseType isUnaryAnalyser;
00181     typedef VigraFalseType isBinaryAnalyser;
00182     typedef VigraFalseType isTernaryAnalyser;
00183 };
00184 
00185 template <class R, class T1, class T2>
00186 class FunctorTraits<R (*)(T1, T2)>
00187 {
00188   public:
00189     typedef R (*type)(T1, T2);
00190     
00191     typedef VigraFalseType isInitializer;
00192     typedef VigraFalseType isUnaryFunctor;
00193     typedef VigraTrueType  isBinaryFunctor;
00194     typedef VigraFalseType isTernaryFunctor;
00195     typedef VigraFalseType isUnaryAnalyser;
00196     typedef VigraFalseType isBinaryAnalyser;
00197     typedef VigraFalseType isTernaryAnalyser;
00198 };
00199 
00200 template <class R, class T1, class T2, class T3>
00201 class FunctorTraits<R (*)(T1, T2, T3)>
00202 {
00203   public:
00204     typedef R (*type)(T1, T2, T3);
00205     
00206     typedef VigraFalseType isInitializer;
00207     typedef VigraFalseType isUnaryFunctor;
00208     typedef VigraFalseType isBinaryFunctor;
00209     typedef VigraTrueType  isTernaryFunctor;
00210     typedef VigraFalseType isUnaryAnalyser;
00211     typedef VigraFalseType isBinaryAnalyser;
00212     typedef VigraFalseType isTernaryAnalyser;
00213 };
00214 
00215 //@}
00216 
00217 } // namespace vigra
00218 
00219 #endif // VIGRA_FUNCTORTRAITS_HXX

© Ullrich Köthe (koethe@informatik.uni-hamburg.de)
Cognitive Systems Group, University of Hamburg, Germany

html generated using doxygen and Python
VIGRA 1.3.2 (27 Jan 2005)