Skip to content

Commit

Permalink
any_image_view use inheriting constructors and add constructor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sdebionne committed Mar 2, 2021
1 parent c55d506 commit c2c44b8
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 11 deletions.
12 changes: 2 additions & 10 deletions include/boost/gil/extension/dynamic_image/any_image_view.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -82,16 +83,7 @@ class any_image_view : public variant2::variant<Views...>
using point_t = point<std::ptrdiff_t>;
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 <typename View>
explicit any_image_view(View const& view) : parent_t(view) {}

template <typename ...OtherViews>
any_image_view(any_image_view<OtherViews...> const& view)
: parent_t((variant2::variant<OtherViews...> const&)view)
{}
using parent_t::parent_t;

any_image_view& operator=(any_image_view const& view)
{
Expand Down
103 changes: 102 additions & 1 deletion test/extension/dynamic_image/any_image_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,110 @@
namespace gil = boost::gil;
namespace fixture = boost::gil::test::fixture;

int main()
void test_any_image_view_nested_types()
{
BOOST_TEST_TRAIT_SAME(gil::any_image_view<gil::gray8_view_t>::const_t, gil::any_image_view<gil::gray8c_view_t>);
}


struct test_any_image_view_init_ctor
{
template <typename Image>
void operator()(Image const&)
{
using image_t = Image;
using view_t = typename Image::view_t;
using any_view_t = gil::any_image_view<view_t>;
using any_const_view_t = typename any_view_t::const_t;
Image i0(fixture::create_image<image_t>(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<fixture::image_types>(test_any_image_view_init_ctor{});
}
};

struct test_any_image_view_copy_ctor
{
template <typename Image>
void operator()(Image const&)
{
using image_t = Image;
using view_t = typename Image::view_t;
using any_view_t = gil::any_image_view<view_t>;
using any_const_view_t = typename any_view_t::const_t;
Image i0(fixture::create_image<image_t>(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<fixture::image_types>(test_any_image_view_copy_ctor{});
}
};

struct test_any_image_view_assign_operator
{
template <typename Image>
void operator()(Image const&)
{
using image_t = Image;
using view_t = typename Image::view_t;
using any_view_t = gil::any_image_view<view_t>;
using any_const_view_t = typename any_view_t::const_t;
Image i0(fixture::create_image<image_t>(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<fixture::image_types>(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();
}

0 comments on commit c2c44b8

Please sign in to comment.