Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Boost.Variant instead of GIL's own variant implementation. #231

Merged
merged 4 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ before_build:
- git submodule --quiet update --init libs/preprocessor
- git submodule --quiet update --init libs/test
- git submodule --quiet update --init libs/type_traits
- git submodule --quiet update --init libs/variant
mloskot marked this conversation as resolved.
Show resolved Hide resolved
## Transitive (of GIL tests too)
- git submodule --quiet update --init libs/atomic
- git submodule --quiet update --init libs/bind
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ install:
- git submodule --quiet update --init libs/preprocessor
- git submodule --quiet update --init libs/test
- git submodule --quiet update --init libs/type_traits
- git submodule --quiet update --init libs/variant
## Transitive (of GIL tests too)
- git submodule --quiet update --init libs/atomic
- git submodule --quiet update --init libs/bind
Expand Down
9 changes: 5 additions & 4 deletions include/boost/gil/extension/dynamic_image/any_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_HPP

#include <boost/gil/extension/dynamic_image/any_image_view.hpp>
#include <boost/gil/extension/dynamic_image/apply_operation.hpp>

#include <boost/gil/image.hpp>

Expand Down Expand Up @@ -63,8 +64,8 @@ namespace detail {
/// In particular, its \p view and \p const_view methods return \p any_image_view, which does not fully model ImageViewConcept. See \p any_image_view for more.
////////////////////////////////////////////////////////////////////////////////////////
template <typename ImageTypes>
class any_image : public variant<ImageTypes> {
using parent_t = variant<ImageTypes>;
class any_image : public make_variant_over<ImageTypes>::type {
using parent_t = typename make_variant_over<ImageTypes>::type;
public:
using const_view_t = any_image_view<typename detail::images_get_const_views_t<ImageTypes>::type>;
using view_t = any_image_view<typename detail::images_get_views_t<ImageTypes>::type>;
Expand All @@ -76,11 +77,11 @@ class any_image : public variant<ImageTypes> {
template <typename T> explicit any_image(const T& obj) : parent_t(obj) {}
template <typename T> explicit any_image(T& obj, bool do_swap) : parent_t(obj,do_swap) {}
any_image(const any_image& v) : parent_t((const parent_t&)v) {}
template <typename Types> any_image(const any_image<Types>& v) : parent_t((const variant<Types>&)v) {}
template <typename Types> any_image(const any_image<Types>& v) : parent_t((const typename make_variant_over<Types>::type&)v) {}

template <typename T> any_image& operator=(const T& obj) { parent_t::operator=(obj); return *this; }
any_image& operator=(const any_image& v) { parent_t::operator=((const parent_t&)v); return *this;}
template <typename Types> any_image& operator=(const any_image<Types>& v) { parent_t::operator=((const variant<Types>&)v); return *this;}
template <typename Types> any_image& operator=(const any_image<Types>& v) { parent_t::operator=((const typename make_variant_over<Types>::type&)v); return *this;}

void recreate(const point_t& dims, unsigned alignment=1)
{
Expand Down
10 changes: 5 additions & 5 deletions include/boost/gil/extension/dynamic_image/any_image_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP
#define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_ANY_IMAGE_VIEW_HPP

#include <boost/gil/extension/dynamic_image/variant.hpp>
#include <boost/variant.hpp>

#include <boost/gil/image.hpp>
#include <boost/gil/image_view.hpp>
Expand Down Expand Up @@ -57,8 +57,8 @@ namespace detail {
/// To perform an algorithm on any_image_view, put the algorithm in a function object and invoke it by calling \p apply_operation(runtime_view, algorithm_fn);
////////////////////////////////////////////////////////////////////////////////////////
template <typename ImageViewTypes>
class any_image_view : public variant<ImageViewTypes> {
using parent_t = variant<ImageViewTypes>;
class any_image_view : public make_variant_over<ImageViewTypes>::type {
mloskot marked this conversation as resolved.
Show resolved Hide resolved
using parent_t = typename make_variant_over<ImageViewTypes>::type;
public:
using const_t = any_image_view<typename detail::views_get_const_t<ImageViewTypes>::type>;
using x_coord_t = std::ptrdiff_t;
Expand All @@ -68,11 +68,11 @@ class any_image_view : public variant<ImageViewTypes> {
any_image_view() : parent_t() {}
template <typename T> explicit any_image_view(const T& obj) : parent_t(obj) {}
any_image_view(const any_image_view& v) : parent_t((const parent_t&)v) {}
template <typename Types> any_image_view(const any_image_view<Types>& v) : parent_t((const variant<Types>&)v) {}
template <typename Types> any_image_view(const any_image_view<Types>& v) : parent_t((const typename make_variant_over<Types>::type&)v) {}

template <typename T> any_image_view& operator=(const T& obj) { parent_t::operator=(obj); return *this; }
any_image_view& operator=(const any_image_view& v) { parent_t::operator=((const parent_t&)v); return *this;}
template <typename Types> any_image_view& operator=(const any_image_view<Types>& v) { parent_t::operator=((const variant<Types>&)v); return *this;}
template <typename Types> any_image_view& operator=(const any_image_view<Types>& v) { parent_t::operator=((const typename make_variant_over<Types>::type&)v); return *this;}

std::size_t num_channels() const { return apply_operation(*this, detail::any_type_get_num_channels()); }
point_t dimensions() const { return apply_operation(*this, detail::any_type_get_dimensions()); }
Expand Down
17 changes: 11 additions & 6 deletions include/boost/gil/extension/dynamic_image/apply_operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
#ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_APPLY_OPERATION_HPP
#define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_APPLY_OPERATION_HPP

#include <boost/gil/extension/dynamic_image/apply_operation_base.hpp>
#include <boost/gil/extension/dynamic_image/variant.hpp>
#include <boost/variant/apply_visitor.hpp>

#ifdef BOOST_GIL_DOXYGEN_ONLY
#undef BOOST_GIL_REDUCE_CODE_BLOAT
Expand All @@ -30,19 +29,23 @@ namespace boost { namespace gil {
template <typename Types, typename UnaryOp>
BOOST_FORCEINLINE
auto apply_operation(variant<Types>& arg, UnaryOp op)
#if defined(BOOST_NO_CXX14_DECLTYPE_AUTO) || defined(BOOST_NO_CXX11_DECLTYPE_N3276)
mloskot marked this conversation as resolved.
Show resolved Hide resolved
-> typename UnaryOp::result_type
#endif
{
return apply_operation_base<Types>(arg._bits, arg._index ,op);
return apply_visitor(op, arg);
}

/// \ingroup Variant
/// \brief Invokes a generic constant operation (represented as a unary function object) on a variant
template <typename Types, typename UnaryOp>
BOOST_FORCEINLINE
auto apply_operation(variant<Types> const& arg, UnaryOp op)
#if defined(BOOST_NO_CXX14_DECLTYPE_AUTO) || defined(BOOST_NO_CXX11_DECLTYPE_N3276)
-> typename UnaryOp::result_type
#endif
{
return apply_operation_basec<Types>(arg._bits, arg._index ,op);
return apply_visitor(op, arg);
}

/// \ingroup Variant
Expand All @@ -53,10 +56,12 @@ auto apply_operation(
variant<Types1> const& arg1,
variant<Types2> const& arg2,
BinaryOp op)
#if defined(BOOST_NO_CXX14_DECLTYPE_AUTO) || defined(BOOST_NO_CXX11_DECLTYPE_N3276)
-> typename BinaryOp::result_type
#endif
{
return apply_operation_base<Types1, Types2>(
arg1._bits, arg1._index, arg2._bits, arg2._index, op);
return apply_visitor(
op, arg1, arg2);
}

}} // namespace boost::gil
Expand Down
175 changes: 0 additions & 175 deletions include/boost/gil/extension/dynamic_image/apply_operation_base.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <boost/gil/extension/dynamic_image/algorithm.hpp>
#include <boost/gil/extension/dynamic_image/any_image.hpp>
#include <boost/gil/extension/dynamic_image/apply_operation.hpp>
#include <boost/gil/extension/dynamic_image/variant.hpp>
#include <boost/gil/extension/dynamic_image/image_view_factory.hpp>
#include <boost/gil.hpp> // FIXME: Include what you use!

Expand Down
Loading