Generic Image Library: dynamic_io.hpp Source File

Modules | Alphabetical List | Class List | Directories | File List | GIL Home Page # 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 "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 // A function object that can be passed to apply_operation.
    00050 // Given a predicate IsSupported taking a view type and returning an MPL boolean,
    00051 // calls the apply method of OpClass with the view if the given view IsSupported, or throws an exception otherwise
    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 } // namespace detail
    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 } }  // namespace boost::gil
    00079
    00080 #endif