|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r61899 - trunk/boost/gil/extension/dynamic_image
From: lbourdev_at_[hidden]
Date: 2010-05-10 21:07:02
Author: lbourdev
Date: 2010-05-10 21:07:00 EDT (Mon, 10 May 2010)
New Revision: 61899
URL: http://svn.boost.org/trac/boost/changeset/61899
Log:
GIL: Added support for copying between variants of different types
Text files modified:
trunk/boost/gil/extension/dynamic_image/any_image.hpp | 6 ++++--
trunk/boost/gil/extension/dynamic_image/any_image_view.hpp | 6 ++++--
trunk/boost/gil/extension/dynamic_image/variant.hpp | 20 +++++++++++++++++---
3 files changed, 25 insertions(+), 7 deletions(-)
Modified: trunk/boost/gil/extension/dynamic_image/any_image.hpp
==============================================================================
--- trunk/boost/gil/extension/dynamic_image/any_image.hpp (original)
+++ trunk/boost/gil/extension/dynamic_image/any_image.hpp 2010-05-10 21:07:00 EDT (Mon, 10 May 2010)
@@ -84,9 +84,11 @@
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 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 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;}
void recreate(const point_t& dims, unsigned alignment=1) { apply_operation(*this,detail::recreate_image_fnobj(dims,alignment)); }
void recreate(x_coord_t width, y_coord_t height, unsigned alignment=1) { recreate(point2<std::ptrdiff_t>(width,height),alignment); }
Modified: trunk/boost/gil/extension/dynamic_image/any_image_view.hpp
==============================================================================
--- trunk/boost/gil/extension/dynamic_image/any_image_view.hpp (original)
+++ trunk/boost/gil/extension/dynamic_image/any_image_view.hpp 2010-05-10 21:07:00 EDT (Mon, 10 May 2010)
@@ -72,9 +72,11 @@
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 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 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;}
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()); }
Modified: trunk/boost/gil/extension/dynamic_image/variant.hpp
==============================================================================
--- trunk/boost/gil/extension/dynamic_image/variant.hpp (original)
+++ trunk/boost/gil/extension/dynamic_image/variant.hpp 2010-05-10 21:07:00 EDT (Mon, 10 May 2010)
@@ -29,7 +29,8 @@
#include <algorithm>
#include <typeinfo>
#include <boost/bind.hpp>
-
+#include <boost/utility/enable_if.hpp>
+#include <boost/mpl/bool.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/sizeof.hpp>
@@ -48,6 +49,7 @@
};
template <typename T, typename Bits> void copy_construct_in_place(const T& t, Bits& bits);
template <typename Bits> struct copy_construct_in_place_fn;
+ template <typename Types> struct type_to_index_fn;
}
/**
\brief Represents a concrete instance of a run-time specified type from a set of types
@@ -98,7 +100,12 @@
virtual ~variant() { apply_operation(*this, detail::destructor_op()); }
// Throws std::bad_cast if T is not in Types
- template <typename T> explicit variant(const T& obj){ _index=type_id<T>(); if (_index==NUM_TYPES) throw std::bad_cast(); detail::copy_construct_in_place(obj, _bits); }
+ template <typename T> explicit variant(const T& obj){ _index=type_id<T>(); if (_index==NUM_TYPES) throw std::bad_cast(); detail::copy_construct_in_place(obj, _bits); }
+
+ template <typename Types2> explicit variant(const variant<Types2>& obj) : _index(apply_operation(obj,detail::type_to_index_fn<Types>())) {
+ if (_index==NUM_TYPES) throw std::bad_cast();
+ apply_operation(obj, detail::copy_construct_in_place_fn<base_t>(_bits));
+ }
// When doSwap is true, swaps obj with the contents of the variant. obj will contain default-constructed instance after the call
template <typename T> explicit variant(T& obj, bool do_swap);
@@ -125,7 +132,7 @@
private:
template <typename T> static std::size_t type_id() { return detail::type_to_index<Types,T>::value; }
- template <typename Cs> friend void swap(variant<Cs>& x, variant<Cs>& y);
+ template <typename Cs> friend void swap(variant<Cs>& x, variant<Cs>& y);
template <typename Types2, typename UnaryOp> friend typename UnaryOp::result_type apply_operation(variant<Types2>& var, UnaryOp op);
template <typename Types2, typename UnaryOp> friend typename UnaryOp::result_type apply_operation(const variant<Types2>& var, UnaryOp op);
template <typename Types1, typename Types2, typename BinaryOp> friend typename BinaryOp::result_type apply_operation(const variant<Types1>& arg1, const variant<Types2>& arg2, BinaryOp op);
@@ -161,6 +168,13 @@
return x==*gil_reinterpret_cast_c<const T*>(&_dst);
}
};
+
+ template <typename Types>
+ struct type_to_index_fn {
+ typedef std::size_t result_type;
+
+ template <typename T> result_type operator()(const T&) const { return detail::type_to_index<Types,T>::value; }
+ };
}
// When doSwap is true, swaps obj with the contents of the variant. obj will contain default-constructed instance after the call
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk