Modules | Alphabetical List | Class List | Directories | File List | GIL Home Page # any_image_view.hpp Go to the documentation of this file.
    00001 /*
    00002     Copyright 2005-2007 Adobe Systems Incorporated
    00003
    00004     Use, modification and distribution are subject to the Boost Software License,
    00005     Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    00006     http://www.boost.org/LICENSE_1_0.txt).
    00007
    00008     See http://opensource.adobe.com/gil for most recent version including documentation.
    00009 */
    00010
    00011 /*************************************************************************************************/
    00012
    00013 #ifndef GIL_DYNAMICIMAGE_ANY_IMAGEVIEW_HPP
    00014 #define GIL_DYNAMICIMAGE_ANY_IMAGEVIEW_HPP
    00015
    00024
    00025 #include "variant.hpp"
    00026 #include "../../image_view.hpp"
    00027 #include "../../image.hpp"
    00028
    00029 namespace boost { namespace gil {
    00030
    00031 namespace detail {
    00032     template <typename View> struct get_const_t { typedef typename View::const_t type; };
    00033     template <typename Views> struct views_get_const_t : public mpl::transform<Views, get_const_t<mpl::_1> > {};
    00034 }
    00035 template <typename View> struct dynamic_xy_step_type;
    00036 template <typename View> struct dynamic_xy_step_transposed_type;
    00037
    00038 namespace detail {
    00039     struct any_type_get_num_channels {   // works for both image_view and image
    00040         typedef int result_type;
    00041         template <typename T> result_type operator()(const T& v) const { return num_channels<T>::value; }
    00042     };
    00043     struct any_type_get_dimensions {    // works for both image_view and image
    00044         typedef point2<std::ptrdiff_t> result_type;
    00045         template <typename T> result_type operator()(const T& v) const { return v.dimensions(); }
    00046     };
    00047 }
    00048
    00063 template <typename ImageViewTypes>
    00064 class any_image_view : public variant<ImageViewTypes> {
    00065     typedef variant<ImageViewTypes> parent_t;
    00066 public:
    00067     typedef any_image_view<typename detail::views_get_const_t<ImageViewTypes>::type> const_t;
    00068     typedef std::ptrdiff_t x_coord_t;
    00069     typedef std::ptrdiff_t y_coord_t;
    00070     typedef point2<std::ptrdiff_t> point_t;
    00071
    00072     any_image_view()                                                          : parent_t() {}
    00073     template <typename T> explicit any_image_view(const T& obj)               : parent_t(obj) {}
    00074     any_image_view(const any_image_view& v)                                   : parent_t((const parent_t&)v)    {}
    00075
    00076     template <typename T> any_image_view& operator=(const T& obj)             { parent_t::operator=(obj); return *this; }
    00077     any_image_view&                       operator=(const any_image_view& v)  { parent_t::operator=((const parent_t&)v); return *this;}
    00078
    00079     std::size_t num_channels()  const { return apply_operation(*this, detail::any_type_get_num_channels()); }
    00080     point_t     dimensions()    const { return apply_operation(*this, detail::any_type_get_dimensions()); }
    00081     x_coord_t   width()         const { return dimensions().x; }
    00082     y_coord_t   height()        const { return dimensions().y; }
    00083 };
    00084
    00086 //  HasDynamicXStepTypeConcept
    00088
    00089 template <typename IVTypes>
    00090 struct dynamic_x_step_type<any_image_view<IVTypes> > {
    00091     typedef any_image_view<typename mpl::transform<IVTypes, dynamic_x_step_type<mpl::_1> >::type> type;
    00092 };
    00093
    00095 //  HasDynamicYStepTypeConcept
    00097
    00098 template <typename IVTypes>
    00099 struct dynamic_y_step_type<any_image_view<IVTypes> > {
    00100     typedef any_image_view<typename mpl::transform<IVTypes, dynamic_y_step_type<mpl::_1> >::type> type;
    00101 };
    00102
    00103 template <typename IVTypes>
    00104 struct dynamic_xy_step_type<any_image_view<IVTypes> > {
    00105     typedef any_image_view<typename mpl::transform<IVTypes, dynamic_xy_step_type<mpl::_1> >::type> type;
    00106 };
    00107
    00108 template <typename IVTypes>
    00109 struct dynamic_xy_step_transposed_type<any_image_view<IVTypes> > {
    00110     typedef any_image_view<typename mpl::transform<IVTypes, dynamic_xy_step_transposed_type<mpl::_1> >::type> type;
    00111 };
    00112
    00113 } }  // namespace boost::gil
    00114
    00115 #endif