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

# vigra/functortraits.hxx

    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.6.0, Aug 13 2008 )                                    */
    00008 /*    The VIGRA Website is                                              */
    00009 /*        http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/      */
    00010 /*    Please direct questions, bug reports, and contributions to        */
    00011 /*        ullrich.koethe@iwr.uni-heidelberg.de    or                    */
    00012 /*        vigra@informatik.uni-hamburg.de                               */
    00013 /*                                                                      */
    00014 /*    Permission is hereby granted, free of charge, to any person       */
    00015 /*    obtaining a copy of this software and associated documentation    */
    00016 /*    files (the "Software"), to deal in the Software without           */
    00017 /*    restriction, including without limitation the rights to use,      */
    00018 /*    copy, modify, merge, publish, distribute, sublicense, and/or      */
    00019 /*    sell copies of the Software, and to permit persons to whom the    */
    00020 /*    Software is furnished to do so, subject to the following          */
    00021 /*    conditions:                                                       */
    00022 /*                                                                      */
    00023 /*    The above copyright notice and this permission notice shall be    */
    00024 /*    included in all copies or substantial portions of the             */
    00025 /*    Software.                                                         */
    00026 /*                                                                      */
    00027 /*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
    00028 /*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
    00029 /*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
    00030 /*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
    00031 /*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
    00032 /*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
    00033 /*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
    00034 /*    OTHER DEALINGS IN THE SOFTWARE.                                   */
    00035 /*                                                                      */
    00036 /************************************************************************/
    00037
    00038
    00039 #ifndef VIGRA_FUNCTORTRAITS_HXX
    00040 #define VIGRA_FUNCTORTRAITS_HXX
    00041
    00042 #include <functional>
    00043 #include "metaprogramming.hxx"
    00044
    00045 namespace vigra {
    00046
    00047 template <class T>
    00048 class FunctorTraitsBase
    00049 {
    00050   public:
    00051     typedef T type;
    00052
    00053     typedef VigraFalseType isInitializer;
    00054
    00055     typedef VigraFalseType isUnaryFunctor;
    00056     typedef VigraFalseType isBinaryFunctor;
    00057     typedef VigraFalseType isTernaryFunctor;
    00058
    00059     typedef VigraFalseType isUnaryAnalyser;
    00060     typedef VigraFalseType isBinaryAnalyser;
    00061     typedef VigraFalseType isTernaryAnalyser;
    00062 };
    00063
    00064
    00065
    00066 /** \addtogroup Functors
    00067 */
    00068 //@{
    00069 /** \brief Export associated information for a functor.
    00070
    00071     The FunctorTraits class contains the following fields:
    00072
    00073     \code
    00074     template <class T>
    00075     struct FunctorTraits
    00076     {
    00077         typedef T type;
    00078
    00079         typedef ... isInitializer;
    00080
    00081         typedef ... isUnaryFunctor;
    00082         typedef ... isBinaryFunctor;
    00083         typedef ... isTernaryFunctor;
    00084
    00085         typedef ... isUnaryAnalyser;
    00086         typedef ... isBinaryAnalyser;
    00087         typedef ... isTernaryAnalyser;
    00088     };
    00089     \endcode
    00090
    00091     Where the dots are either <tt>VigraTrueType</tt> or <tt>VigraFalseType</tt>
    00092     depending on whether the functor supports the respective functionality or not.
    00093     If a functor <tt>f</tt> is a model of these categories, it supports the following
    00094     calls (<tt>v</tt> is a variable such that the result type of the functor
    00095     calls can be converted into <tt>v</tt>'s type, and <tt>a1, a2, a3</tt> are
    00096     variables convertible into the functor's argument types):
    00097
    00098     <DL>
    00099     <DT><b>Initializer</b>
    00100         <DD> <tt>v = f()</tt> (used with initImageWithFunctor())
    00101     <DT><b>UnaryFunctor</b>
    00102         <DD> <tt>v = f(a1)</tt> (used with transformImage())
    00103     <DT><b>BinaryFunctor</b>
    00104         <DD> <tt>v = f(a1, a2)</tt> (used with combineTwoImages())
    00105     <DT><b>TernaryFunctor</b>
    00106         <DD> <tt>v = f(a1, a2, a3)</tt> (used with combineThreeImages())
    00107     <DT><b>UnaryAnalyser</b>
    00108         <DD> <tt>f(a1)</tt> (return type <tt>void</tt>, used with inspectImage())
    00109     <DT><b>BinaryAnalyser</b>
    00110         <DD> <tt>f(a1, a2)</tt> (return type <tt>void</tt>, used with inspectTwoImages())
    00111     <DT><b>TernaryAnalyser</b>
    00112         <DD> <tt>f(a1, a2, a3)</tt> (return type <tt>void</tt>)
    00113     </DL>
    00114
    00115     It should be noted that the functor's argument and result types are not contained
    00116     in the traits class: Since the function calls are often member template functions in
    00117     VIGRA, many functors do not have fixed argument types. Neither are the result
    00118     types fixed in this case because they are computed (via a template meta-program)
    00119     from the argument types.
    00120
    00121     <b>\#include</b> <<a href="functortraits_8hxx-source.html">vigra/functortraits.hxx</a>>
    00122     Namespace: vigra
    00123 */
    00124 template <class T>
    00125 class FunctorTraits
    00126 : public FunctorTraitsBase<T>
    00127 {};
    00128
    00129 #define VIGRA_DEFINE_STL_FUNCTOR(name, unary, binary) \
    00130 template <class T> \
    00131 class FunctorTraits<name<T> > \
    00132 { \
    00133   public: \
    00134     typedef T type; \
    00135      \
    00136     typedef VigraFalseType isInitializer; \
    00137      \
    00138     typedef unary          isUnaryFunctor; \
    00139     typedef binary         isBinaryFunctor; \
    00140     typedef VigraFalseType isTernaryFunctor; \
    00141      \
    00142     typedef VigraFalseType isUnaryAnalyser; \
    00143     typedef VigraFalseType isBinaryAnalyser; \
    00144     typedef VigraFalseType isTernaryAnalyser; \
    00145 };
    00146
    00147 // ???TODO: these should also be specialized for the ptr_fun and mem_fun_ptr wrappers
    00148 VIGRA_DEFINE_STL_FUNCTOR(std::plus, VigraFalseType, VigraTrueType)
    00149 VIGRA_DEFINE_STL_FUNCTOR(std::minus, VigraFalseType, VigraTrueType)
    00150 VIGRA_DEFINE_STL_FUNCTOR(std::multiplies, VigraFalseType, VigraTrueType)
    00151 VIGRA_DEFINE_STL_FUNCTOR(std::divides, VigraFalseType, VigraTrueType)
    00152 VIGRA_DEFINE_STL_FUNCTOR(std::modulus, VigraFalseType, VigraTrueType)
    00153 VIGRA_DEFINE_STL_FUNCTOR(std::equal_to, VigraFalseType, VigraTrueType)
    00154 VIGRA_DEFINE_STL_FUNCTOR(std::not_equal_to, VigraFalseType, VigraTrueType)
    00155 VIGRA_DEFINE_STL_FUNCTOR(std::greater, VigraFalseType, VigraTrueType)
    00156 VIGRA_DEFINE_STL_FUNCTOR(std::less, VigraFalseType, VigraTrueType)
    00157 VIGRA_DEFINE_STL_FUNCTOR(std::greater_equal, VigraFalseType, VigraTrueType)
    00158 VIGRA_DEFINE_STL_FUNCTOR(std::less_equal, VigraFalseType, VigraTrueType)
    00159 VIGRA_DEFINE_STL_FUNCTOR(std::logical_and, VigraFalseType, VigraTrueType)
    00160 VIGRA_DEFINE_STL_FUNCTOR(std::logical_or, VigraFalseType, VigraTrueType)
    00161 VIGRA_DEFINE_STL_FUNCTOR(std::binary_negate, VigraFalseType, VigraTrueType)
    00162
    00163 VIGRA_DEFINE_STL_FUNCTOR(std::negate, VigraTrueType, VigraFalseType)
    00164 VIGRA_DEFINE_STL_FUNCTOR(std::logical_not, VigraTrueType, VigraFalseType)
    00165 VIGRA_DEFINE_STL_FUNCTOR(std::unary_negate, VigraTrueType, VigraFalseType)
    00166 VIGRA_DEFINE_STL_FUNCTOR(std::binder1st, VigraTrueType, VigraFalseType)
    00167 VIGRA_DEFINE_STL_FUNCTOR(std::binder2nd, VigraTrueType, VigraFalseType)
    00168 #undef VIGRA_DEFINE_STL_FUNCTOR
    00169
    00170 template <class R>
    00171 class FunctorTraits<R (*)()>
    00172 {
    00173   public:
    00174     typedef R (*type)();
    00175
    00176     typedef VigraTrueType  isInitializer;
    00177     typedef VigraFalseType 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 T>
    00186 class FunctorTraits<R (*)(T)>
    00187 {
    00188   public:
    00189     typedef R (*type)(T);
    00190
    00191     typedef VigraFalseType isInitializer;
    00192     typedef VigraTrueType  isUnaryFunctor;
    00193     typedef VigraFalseType 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>
    00201 class FunctorTraits<R (*)(T1, T2)>
    00202 {
    00203   public:
    00204     typedef R (*type)(T1, T2);
    00205
    00206     typedef VigraFalseType isInitializer;
    00207     typedef VigraFalseType isUnaryFunctor;
    00208     typedef VigraTrueType  isBinaryFunctor;
    00209     typedef VigraFalseType isTernaryFunctor;
    00210     typedef VigraFalseType isUnaryAnalyser;
    00211     typedef VigraFalseType isBinaryAnalyser;
    00212     typedef VigraFalseType isTernaryAnalyser;
    00213 };
    00214
    00215 template <class R, class T1, class T2, class T3>
    00216 class FunctorTraits<R (*)(T1, T2, T3)>
    00217 {
    00218   public:
    00219     typedef R (*type)(T1, T2, T3);
    00220
    00221     typedef VigraFalseType isInitializer;
    00222     typedef VigraFalseType isUnaryFunctor;
    00223     typedef VigraFalseType isBinaryFunctor;
    00224     typedef VigraTrueType  isTernaryFunctor;
    00225     typedef VigraFalseType isUnaryAnalyser;
    00226     typedef VigraFalseType isBinaryAnalyser;
    00227     typedef VigraFalseType isTernaryAnalyser;
    00228 };
    00229
    00230 //@}
    00231
    00232 } // namespace vigra
    00233
    00234 #endif // VIGRA_FUNCTORTRAITS_HXX

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python VIGRA 1.6.0 (13 Aug 2008)