Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:02

0001 //
0002 // Copyright 2005-2007 Adobe Systems Incorporated
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 #ifndef BOOST_GIL_IO_DETAIL_DYNAMIC_HPP
0009 #define BOOST_GIL_IO_DETAIL_DYNAMIC_HPP
0010 
0011 #include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp>
0012 
0013 #include <boost/gil/detail/mp11.hpp>
0014 #include <boost/gil/io/error.hpp>
0015 
0016 #include <type_traits>
0017 
0018 namespace boost { namespace gil { namespace detail {
0019 
0020 template <long N>
0021 struct construct_matched_t
0022 {
0023     template <typename ...Images, typename Pred>
0024     static bool apply(any_image<Images...>& img, Pred pred)
0025     {
0026         if (pred.template apply<mp11::mp_at_c<any_image<Images...>, N-1>>())
0027         {
0028             using image_t = mp11::mp_at_c<any_image<Images...>, N-1>;
0029             image_t x;
0030             img = std::move(x);
0031             return true;
0032         }
0033         else
0034             return construct_matched_t<N-1>::apply(img, pred);
0035     }
0036 };
0037 template <>
0038 struct construct_matched_t<0>
0039 {
0040     template <typename ...Images, typename Pred>
0041     static bool apply(any_image<Images...>&, Pred) { return false; }
0042 };
0043 
0044 // A function object that can be passed to variant2::visit.
0045 // Given a predicate IsSupported taking a view type and returning an boolean integral coonstant,
0046 // calls the apply method of OpClass with the view if the given view IsSupported, or throws an exception otherwise
0047 template <typename IsSupported, typename OpClass>
0048 class dynamic_io_fnobj
0049 {
0050 private:
0051     OpClass* _op;
0052 
0053     template <typename View>
0054     void apply(View const& view, std::true_type) { _op->apply(view); }
0055 
0056     template <typename View, typename Info>
0057     void apply(View const& view, Info const & info, const std::true_type) { _op->apply(view, info); }
0058 
0059     template <typename View>
0060     void apply(View const& /* view */, std::false_type)
0061     {
0062         io_error("dynamic_io: unsupported view type for the given file format");
0063     }
0064 
0065     template <typename View, typename Info >
0066     void apply(View const& /* view */, Info const& /* info */, const std::false_type)
0067     {
0068         io_error("dynamic_io: unsupported view type for the given file format");
0069     }
0070 
0071 public:
0072     dynamic_io_fnobj(OpClass* op) : _op(op) {}
0073 
0074     using result_type = void;
0075 
0076     template <typename View>
0077     void operator()(View const& view)
0078     {
0079         apply(view, typename IsSupported::template apply<View>::type());
0080     }
0081 
0082     template <typename View, typename Info>
0083     void operator()(View const& view, Info const& info)
0084     {
0085         apply(view, info, typename IsSupported::template apply<View>::type());
0086     }
0087 };
0088 
0089 /// \brief Within the any_image, constructs an image with the given dimensions
0090 ///        and a type that satisfies the given predicate
0091 template <typename ...Images, typename Pred>
0092 inline bool construct_matched(any_image<Images...>& img, Pred pred)
0093 {
0094     constexpr auto size = mp11::mp_size<any_image<Images...>>::value;
0095     return construct_matched_t<size>::apply(img, pred);
0096 }
0097 
0098 } } }  // namespace boost::gil::detail
0099 
0100 #endif