2 Copyright 2005-2007 Adobe Systems Incorporated
4 Use, modification and distribution are subject to the Boost Software License,
5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt).
8 See http://opensource.adobe.com/gil for most recent version including documentation.
10 /*************************************************************************************************/
12 #ifndef GIL_DYNAMIC_IO_H
13 #define GIL_DYNAMIC_IO_H
16 /// \brief Generic io functions for dealing with dynamic images
18 /// \author Hailin Jin and Lubomir Bourdev \n
19 /// Adobe Systems Incorporated
20 /// \date 2005-2007 \n Last updated May 30, 2006
22 #include <boost/mpl/at.hpp>
23 #include <boost/mpl/size.hpp>
24 #include "../../gil_config.hpp"
25 #include "io_error.hpp"
26 #include "../dynamic_image/any_image.hpp"
28 namespace boost { namespace gil {
33 struct construct_matched_t {
34 template <typename Images,typename Pred>
35 static bool apply(any_image<Images>& im,Pred pred) {
36 if (pred.template apply<typename mpl::at_c<Images,N-1>::type>()) {
37 typename mpl::at_c<Images,N-1>::type x;
40 } else return construct_matched_t<N-1>::apply(im,pred);
44 struct construct_matched_t<0> {
45 template <typename Images,typename Pred>
46 static bool apply(any_image<Images>&,Pred) {return false;}
49 // A function object that can be passed to apply_operation.
50 // Given a predicate IsSupported taking a view type and returning an MPL boolean,
51 // calls the apply method of OpClass with the view if the given view IsSupported, or throws an exception otherwise
52 template <typename IsSupported, typename OpClass>
53 class dynamic_io_fnobj {
56 template <typename View>
57 void apply(const View& view,mpl::true_ ) {_op->apply(view);}
58 template <typename View>
59 void apply(const View& view,mpl::false_) {io_error("dynamic_io: unsupported view type for the given file format");}
61 dynamic_io_fnobj(OpClass* op) : _op(op) {}
63 typedef void result_type;
65 template <typename View>
66 void operator()(const View& view) {apply(view,typename IsSupported::template apply<View>::type());}
71 /// \brief Within the any_image, constructs an image with the given dimensions
72 /// and a type that satisfies the given predicate
73 template <typename Images,typename Pred>
74 inline bool construct_matched(any_image<Images>& im,Pred pred) {
75 return detail::construct_matched_t<mpl::size<Images>::value>::apply(im,pred);
78 } } // namespace boost::gil