2 // Copyright 2005-2007 Adobe Systems Incorporated
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 #ifndef BOOST_GIL_IO_DYNAMIC_IO_NEW_HPP
9 #define BOOST_GIL_IO_DYNAMIC_IO_NEW_HPP
11 #include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp>
13 #include <boost/gil/detail/mp11.hpp>
14 #include <boost/gil/io/error.hpp>
16 #include <type_traits>
18 namespace boost { namespace gil {
23 struct construct_matched_t
25 template <typename ...Images,typename Pred>
26 static bool apply(any_image<Images...>& img, Pred pred)
28 if (pred.template apply<mp11::mp_at_c<any_image<Images...>, N-1>>())
30 using image_t = mp11::mp_at_c<any_image<Images...>, N-1>;
36 return construct_matched_t<N-1>::apply(img, pred);
40 struct construct_matched_t<0>
42 template <typename ...Images,typename Pred>
43 static bool apply(any_image<Images...>&,Pred) { return false; }
46 // A function object that can be passed to apply_operation.
47 // Given a predicate IsSupported taking a view type and returning an boolean integral coonstant,
48 // calls the apply method of OpClass with the view if the given view IsSupported, or throws an exception otherwise
49 template <typename IsSupported, typename OpClass>
50 class dynamic_io_fnobj
55 template <typename View>
56 void apply(View const& view, std::true_type) { _op->apply(view); }
58 template <typename View, typename Info>
59 void apply(View const& view, Info const & info, const std::true_type) { _op->apply(view, info); }
61 template <typename View>
62 void apply(View const& /* view */, std::false_type)
64 io_error("dynamic_io: unsupported view type for the given file format");
67 template <typename View, typename Info >
68 void apply(View const& /* view */, Info const& /* info */, const std::false_type)
70 io_error("dynamic_io: unsupported view type for the given file format");
74 dynamic_io_fnobj(OpClass* op) : _op(op) {}
76 using result_type = void;
78 template <typename View>
79 void operator()(View const& view)
81 apply(view, typename IsSupported::template apply<View>::type());
84 template< typename View, typename Info >
85 void operator()(View const& view, Info const& info)
87 apply(view, info, typename IsSupported::template apply<View>::type());
93 /// \brief Within the any_image, constructs an image with the given dimensions
94 /// and a type that satisfies the given predicate
95 template <typename ...Images,typename Pred>
96 inline bool construct_matched(any_image<Images...>& img, Pred pred)
98 constexpr auto size = mp11::mp_size<any_image<Images...>>::value;
99 return detail::construct_matched_t<size>::apply(img, pred);
102 } } // namespace boost::gil