8 #include "boost/mpl/assert.hpp" 9 #include "boost/mpl/equal.hpp" 10 #include "boost/mpl/int.hpp" 11 #include "boost/mpl/placeholders.hpp" 12 #include "boost/mpl/transform.hpp" 13 #include "boost/mpl/vector.hpp" 50 template <
template <
typename >
class TImage >
61 template <
template <
typename >
class TImage,
typename T >
67 TImage<T> &
image() {
return m_im; }
92 template <
template <
typename>
class TImage,
class TImage0 >
100 #define TIL_DYNIM_BLOCKS(funcall) \ 101 TIL_DYNIM_BLOCKS_BEGIN \ 102 TIL_DYNIM_BLOCK(funcall, uchar) \ 103 TIL_DYNIM_BLOCK(funcall, char) \ 104 TIL_DYNIM_BLOCK(funcall, ushort) \ 105 TIL_DYNIM_BLOCK(funcall, short) \ 106 TIL_DYNIM_BLOCK(funcall, int) \ 107 TIL_DYNIM_BLOCK(funcall, float) \ 108 TIL_DYNIM_BLOCK(funcall, double) \ 109 TIL_DYNIM_BLOCKS_END \ 111 #define TIL_DYNIM_BLOCKS_BEGIN if(0) {} 112 #define TIL_DYNIM_BLOCKS_END else { throw std::runtime_error("Unknown dynamic image type"); } 113 #define TIL_DYNIM_BLOCK(funcall, type) \ 114 else if (DynImage_typed<TImage, type > *pim = dynamic_cast<DynImage_typed<TImage, type >*>(&dynim)) \ 116 typedef type PixelType; \ 130 template <
typename Functor,
typename TReturn =
void >
131 class Dyn :
public Functor
135 Dyn(
const Functor &functor) : Functor(functor) {}
139 template <
template <
typename >
class TImage >
147 template <
typename TReturn,
typename Functor >
154 template <
typename Functor >
176 template <
typename T >
187 typedef boost::mpl::vector<
197 typedef boost::mpl::vector<
208 typedef boost::mpl::transform<StandardNumericTypes, ImageC<boost::mpl::_1> >::type
toto;
259 template <
class TMPLContainer >
264 typedef typename boost::mpl::begin<TMPLContainer>
begin;
265 typedef typename boost::mpl::end<TMPLContainer>
end;
273 template <
template <
typename>
class TFunctor >
276 Self::template execute<Self::begin, TFunctor>();
282 template <
class TFunctor >
283 static void execute(
const TFunctor &functor = TFunctor())
285 Self::template execute<Self::begin, TFunctor>(functor);
290 template <
class TMPLIterator,
template <
typename >
class TFunctor >
291 static void execute()
294 if (boost::is_same<
typename TMPLIterator::type,
typename boost::mpl::end<TMPLContainer>::type>::value)
return;
297 TFunctor<typename TMPLIterator::type> functor;
301 execute<typename boost::mpl::next<TMPLIterator>::type, TFunctor>(functor);
303 template <
class TMPLIterator,
class TFunctor >
304 static void execute(
const TFunctor &functor)
307 if (boost::is_same<typename TMPLIterator::type, typename Self::end::type>::value)
return;
310 functor.template operator()<
typename TMPLIterator::type>();
313 execute<typename boost::mpl::next<TMPLIterator>::type, TFunctor>(functor);
317 template <
typename TFunctor,
typename T >
322 template <
typename V >
325 if (V
object = dynamic_cast<V>(m_object))
340 template <
class TTypeCollection,
class TFunctor >
341 void dyn(
const TFunctor & functor)
363 template <
typename T >
A concrete instance of a generic object, containing a real object of type T.
static void execute(const TFunctor &functor=TFunctor())
Execute a functor.
DynImage_typed(TImage< T > &im)
boost::mpl::begin< TMPLContainer > begin
Belongs to package Box Do not include directly, include til/Box.h instead.
General macros, definitions and functions.
Child class of dynamic image base class, implementing a specific type.
boost::mpl::end< TMPLContainer > end
Loop< TMPLContainer > Self
static void execute()
Execute a templated functor.
boost::mpl::vector< unsigned char, char, unsigned short, short, int, float, double > StandardNumericTypes
#define TIL_DYNIM_BLOCKS(funcall)
Macro for code to do dynamic type resolution.
Base class for dynamic type images.
DynImage< TImage > * dynImageFactory(TImage0 &im)
boost::mpl::transform< StandardNumericTypes, ImageC< boost::mpl::_1 > >::type toto
Dyn< Functor, TReturn > dyn(const Functor &functor)
Conveniance function to create dynamic functor wrapper with return type.
BOOST_MPL_ASSERT((boost::mpl::equal< imeu, toto >))
Functor wrapper for dynamic type images.
Dyn(const Functor &functor)
Image class using contiguous memory.
TReturn operator()(DynImage< TImage > *dynim)
boost::mpl::vector< ImageC< unsigned char >, ImageC< char >, ImageC< unsigned short >, ImageC< short >, ImageC< int >, ImageC< float >, ImageC< double > > imeu