dynamic_io.hpp

Go to the documentation of this file.
00001 /*
00002     Copyright 2005-2007 Adobe Systems Incorporated
00003    
00004     Use, modification and distribution are subject to the Boost Software License,
00005     Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
00006     http://www.boost.org/LICENSE_1_0.txt).
00007 
00008     See http://opensource.adobe.com/gil for most recent version including documentation.
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 // A function object that can be passed to apply_operation.
00049 // Given a predicate IsSupported taking a view type and returning an MPL boolean,
00050 // calls the apply method of OpClass with the view if the given view IsSupported, or throws an exception otherwise
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 } // namespace detail
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 } }  // namespace boost::gil
00078 
00079 #endif

Generated on Thu Nov 8 21:53:16 2007 for Generic Image Library by  doxygen 1.4.4