00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef GIL_DYNAMIC_IO_H
00013 #define GIL_DYNAMIC_IO_H
00014
00017
00021
00022 #include <boost/mpl/at.hpp>
00023 #include <boost/mpl/size.hpp>
00024 #include "../../gil_config.hpp"
00025 #include "../dynamic_image/any_image.hpp"
00026
00027 namespace boost { namespace gil {
00028
00029 namespace detail {
00030
00031 template <long N>
00032 struct construct_matched_t {
00033 template <typename Images,typename Pred>
00034 static bool apply(any_image<Images>& im,Pred pred) {
00035 if (pred.template apply<typename mpl::at_c<Images,N-1>::type>()) {
00036 typename mpl::at_c<Images,N-1>::type x;
00037 im.move_in(x);
00038 return true;
00039 } else return construct_matched_t<N-1>::apply(im,pred);
00040 }
00041 };
00042 template <>
00043 struct construct_matched_t<0> {
00044 template <typename Images,typename Pred>
00045 static bool apply(any_image<Images>&,Pred) {return false;}
00046 };
00047
00048
00049
00050
00051 template <typename IsSupported, typename OpClass>
00052 class dynamic_io_fnobj {
00053 OpClass* _op;
00054
00055 template <typename View>
00056 void apply(const View& view,mpl::true_ ) {_op->apply(view);}
00057 template <typename View>
00058 void apply(const View& view,mpl::false_) {io_error("dynamic_io: unsupported view type for the given file format");}
00059 public:
00060 dynamic_io_fnobj(OpClass* op) : _op(op) {}
00061
00062 typedef void result_type;
00063
00064 template <typename View>
00065 void operator()(const View& view) {apply(view,typename IsSupported::template apply<View>::type());}
00066 };
00067
00068 }
00069
00072 template <typename Images,typename Pred>
00073 inline bool construct_matched(any_image<Images>& im,Pred pred) {
00074 return detail::construct_matched_t<mpl::size<Images>::value>::apply(im,pred);
00075 }
00076
00077 } }
00078
00079 #endif