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