dynamic_io.hpp
Go to the documentation of this file.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 "io_error.hpp"
00026 #include "../dynamic_image/any_image.hpp"
00027
00028 namespace boost { namespace gil {
00029
00030 namespace detail {
00031
00032 template <long N>
00033 struct construct_matched_t {
00034 template <typename Images,typename Pred>
00035 static bool apply(any_image<Images>& im,Pred pred) {
00036 if (pred.template apply<typename mpl::at_c<Images,N-1>::type>()) {
00037 typename mpl::at_c<Images,N-1>::type x;
00038 im.move_in(x);
00039 return true;
00040 } else return construct_matched_t<N-1>::apply(im,pred);
00041 }
00042 };
00043 template <>
00044 struct construct_matched_t<0> {
00045 template <typename Images,typename Pred>
00046 static bool apply(any_image<Images>&,Pred) {return false;}
00047 };
00048
00049
00050
00051
00052 template <typename IsSupported, typename OpClass>
00053 class dynamic_io_fnobj {
00054 OpClass* _op;
00055
00056 template <typename View>
00057 void apply(const View& view,mpl::true_ ) {_op->apply(view);}
00058 template <typename View>
00059 void apply(const View& view,mpl::false_) {io_error("dynamic_io: unsupported view type for the given file format");}
00060 public:
00061 dynamic_io_fnobj(OpClass* op) : _op(op) {}
00062
00063 typedef void result_type;
00064
00065 template <typename View>
00066 void operator()(const View& view) {apply(view,typename IsSupported::template apply<View>::type());}
00067 };
00068
00069 }
00070
00073 template <typename Images,typename Pred>
00074 inline bool construct_matched(any_image<Images>& im,Pred pred) {
00075 return detail::construct_matched_t<mpl::size<Images>::value>::apply(im,pred);
00076 }
00077
00078 } }
00079
00080 #endif