From b8564e256c067275287792a1678a74cf81d4ae08 Mon Sep 17 00:00:00 2001 From: Samuel Debionne Date: Thu, 18 Mar 2021 10:53:53 +0100 Subject: [PATCH] Fix any_image_view::const_t (#526) Use inherited constructors in any_image as well --- .../gil/extension/dynamic_image/any_image.hpp | 18 +-- .../dynamic_image/any_image_view.hpp | 16 +-- test/extension/dynamic_image/CMakeLists.txt | 1 + test/extension/dynamic_image/Jamfile | 1 + .../dynamic_image/any_image_view.cpp | 128 ++++++++++++++++++ 5 files changed, 136 insertions(+), 28 deletions(-) create mode 100644 test/extension/dynamic_image/any_image_view.cpp diff --git a/include/boost/gil/extension/dynamic_image/any_image.hpp b/include/boost/gil/extension/dynamic_image/any_image.hpp index 701fece697..69b674b1f9 100644 --- a/include/boost/gil/extension/dynamic_image/any_image.hpp +++ b/include/boost/gil/extension/dynamic_image/any_image.hpp @@ -89,29 +89,15 @@ template class any_image : public variant2::variant { using parent_t = variant2::variant; + public: using view_t = mp11::mp_rename, any_image_view>; using const_view_t = mp11::mp_rename, any_image_view>; using x_coord_t = std::ptrdiff_t; using y_coord_t = std::ptrdiff_t; using point_t = point; - - any_image() = default; - any_image(any_image const& img) : parent_t((parent_t const&)img) {} - - template - explicit any_image(Image const& img) : parent_t(img) {} - template - any_image(Image&& img) : parent_t(std::move(img)) {} - - template - explicit any_image(Image& img, bool do_swap) : parent_t(img, do_swap) {} - - template - any_image(any_image const& img) - : parent_t((variant2::variant const&)img) - {} + using parent_t::parent_t; any_image& operator=(any_image const& img) { diff --git a/include/boost/gil/extension/dynamic_image/any_image_view.hpp b/include/boost/gil/extension/dynamic_image/any_image_view.hpp index 901fb6fdbe..5d71b588b0 100644 --- a/include/boost/gil/extension/dynamic_image/any_image_view.hpp +++ b/include/boost/gil/extension/dynamic_image/any_image_view.hpp @@ -1,5 +1,6 @@ // // Copyright 2005-2007 Adobe Systems Incorporated +// Copyright 2020 Samuel Debionne // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at @@ -24,10 +25,10 @@ struct dynamic_xy_step_transposed_type; namespace detail { template -struct get_const_t { using type = typename View::const_t; }; +using get_const_t = typename View::const_t; template -struct views_get_const_t : mp11::mp_transform {}; +using views_get_const_t = mp11::mp_transform; // works for both image_view and image struct any_type_get_num_channels @@ -82,16 +83,7 @@ class any_image_view : public variant2::variant using point_t = point; using size_type = std::size_t; - any_image_view() = default; - any_image_view(any_image_view const& view) : parent_t((parent_t const&)view) {} - - template - explicit any_image_view(View const& view) : parent_t(view) {} - - template - any_image_view(any_image_view const& view) - : parent_t((variant2::variant const&)view) - {} + using parent_t::parent_t; any_image_view& operator=(any_image_view const& view) { diff --git a/test/extension/dynamic_image/CMakeLists.txt b/test/extension/dynamic_image/CMakeLists.txt index d2a37bf10c..0e720b5bab 100644 --- a/test/extension/dynamic_image/CMakeLists.txt +++ b/test/extension/dynamic_image/CMakeLists.txt @@ -8,6 +8,7 @@ message(STATUS "Boost.GIL: Configuring tests in test/extension/dynamic_image") foreach(_name any_image + any_image_view subimage_view) set(_test t_ext_dynamic_image_${_name}) set(_target test_ext_dynamic_image_${_name}) diff --git a/test/extension/dynamic_image/Jamfile b/test/extension/dynamic_image/Jamfile index 8cd2d5184d..63189265e4 100644 --- a/test/extension/dynamic_image/Jamfile +++ b/test/extension/dynamic_image/Jamfile @@ -11,4 +11,5 @@ import testing ; alias headers : [ generate_self_contained_headers extension/dynamic_image ] ; run any_image.cpp ; +run any_image_view.cpp ; run subimage_view.cpp ; diff --git a/test/extension/dynamic_image/any_image_view.cpp b/test/extension/dynamic_image/any_image_view.cpp new file mode 100644 index 0000000000..176e7f25b2 --- /dev/null +++ b/test/extension/dynamic_image/any_image_view.cpp @@ -0,0 +1,128 @@ +// +// Copyright 2020 Samuel Debionne +// +// Distributed under the Boost Software License, Version 1.0 +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// +#include +#include + +#include +#include + +#include + +#include "test_fixture.hpp" +#include "core/image/test_fixture.hpp" + +namespace gil = boost::gil; +namespace fixture = boost::gil::test::fixture; + +void test_any_image_view_nested_types() +{ + BOOST_TEST_TRAIT_SAME(gil::any_image_view::const_t, gil::any_image_view); +} + + +struct test_any_image_view_init_ctor +{ + template + void operator()(Image const&) + { + using image_t = Image; + using view_t = typename Image::view_t; + using any_view_t = gil::any_image_view; + using any_const_view_t = typename any_view_t::const_t; + Image i0(fixture::create_image(4, 4, 128)); + + view_t v0 = gil::view(i0); + any_view_t v1 = v0; + + BOOST_TEST_EQ(v1.dimensions().x, 4); + BOOST_TEST_EQ(v1.dimensions().y, 4); + + any_const_view_t v2 = v0; + + BOOST_TEST_EQ(v2.dimensions().x, 4); + BOOST_TEST_EQ(v2.dimensions().y, 4); + + //any_const_view_t v3 = v1; + } + static void run() + { + boost::mp11::mp_for_each(test_any_image_view_init_ctor{}); + } +}; + +struct test_any_image_view_copy_ctor +{ + template + void operator()(Image const&) + { + using image_t = Image; + using view_t = typename Image::view_t; + using any_view_t = gil::any_image_view; + using any_const_view_t = typename any_view_t::const_t; + Image i0(fixture::create_image(4, 4, 128)); + + view_t v0 = gil::view(i0); + any_view_t v1 = v0; + + BOOST_TEST_EQ(v1.dimensions().x, 4); + BOOST_TEST_EQ(v1.dimensions().y, 4); + + any_const_view_t v2 = v0; + + BOOST_TEST_EQ(v2.dimensions().x, 4); + BOOST_TEST_EQ(v2.dimensions().y, 4); + + //any_const_view_t v3 = v1; + } + static void run() + { + boost::mp11::mp_for_each(test_any_image_view_copy_ctor{}); + } +}; + +struct test_any_image_view_assign_operator +{ + template + void operator()(Image const&) + { + using image_t = Image; + using view_t = typename Image::view_t; + using any_view_t = gil::any_image_view; + using any_const_view_t = typename any_view_t::const_t; + Image i0(fixture::create_image(4, 4, 128)); + + view_t v0 = gil::view(i0); + any_view_t v1; + any_const_view_t v2; + + v1 = v0; + + BOOST_TEST_EQ(v1.dimensions().x, 4); + BOOST_TEST_EQ(v1.dimensions().y, 4); + + v2 = v0; + + BOOST_TEST_EQ(v2.dimensions().x, 4); + BOOST_TEST_EQ(v2.dimensions().y, 4); + + //v2 = v1; + } + static void run() + { + boost::mp11::mp_for_each(test_any_image_view_assign_operator{}); + } +}; + +int main() +{ + test_any_image_view_init_ctor::run(); + test_any_image_view_copy_ctor::run(); + test_any_image_view_assign_operator::run(); + + return ::boost::report_errors(); +}