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