]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/gil/planar_pixel_reference.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / gil / planar_pixel_reference.hpp
index 2d71842992df2ff3d5106861f43078cdc7ff9c4f..7dce352124582ae385a7105f56586e6e3c0de831 100644 (file)
-/*
-    Copyright 2005-2007 Adobe Systems Incorporated
-   
-    Use, modification and distribution are subject to 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).
-
-    See http://stlab.adobe.com/gil for most recent version including documentation.
-*/
-
-/*************************************************************************************************/
-
-#ifndef GIL_PLANAR_REF_H
-#define GIL_PLANAR_REF_H
-
-////////////////////////////////////////////////////////////////////////////////////////
-/// \file               
-/// \brief planar pixel reference class
-/// \author Lubomir Bourdev and Hailin Jin \n
-///         Adobe Systems Incorporated
-/// \date   2005-2007 \n Last updated on September 28, 2006
-///
-////////////////////////////////////////////////////////////////////////////////////////
-
-#include <boost/mpl/range_c.hpp>
-#include "gil_config.hpp"
-#include "gil_concept.hpp"
-#include "color_base.hpp"
-#include "channel.hpp"
-#include "pixel.hpp"
-#include "planar_pixel_iterator.hpp"
+//
+// Copyright 2005-2007 Adobe Systems Incorporated
+//
+// 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
+//
+#ifndef BOOST_GIL_PLANAR_PIXEL_REFERENCE_HPP
+#define BOOST_GIL_PLANAR_PIXEL_REFERENCE_HPP
+
+#include <boost/gil/channel.hpp>
+#include <boost/gil/color_base.hpp>
+#include <boost/gil/concepts.hpp>
+#include <boost/gil/pixel.hpp>
+#include <boost/gil/planar_pixel_iterator.hpp>
+#include <boost/gil/detail/mp11.hpp>
+
+#include <type_traits>
 
 namespace boost { namespace gil {
 
-/// \defgroup ColorBaseModelPlanarRef planar_pixel_reference 
+/// \defgroup ColorBaseModelPlanarRef planar_pixel_reference
 /// \ingroup ColorBaseModel
 /// \brief A homogeneous color base whose element is a channel reference. Models HomogeneousColorBaseConcept, HomogeneousPixelConcept.
 /// This class is used as a reference proxy to a planar pixel.
 
-/// \defgroup PixelModelPlanarRef planar_pixel_reference 
+/// \defgroup PixelModelPlanarRef planar_pixel_reference
 /// \ingroup PixelModel
 /// \brief A reference proxy to a planar pixel. Models HomogeneousColorBaseConcept, HomogeneousPixelConcept.
 
-
 /// \ingroup PixelModelPlanarRef ColorBaseModelPlanarRef PixelBasedModel
-/// \brief A reference proxy to a planar pixel. Models: HomogeneousColorBaseConcept, HomogeneousPixelConcept
+/// \brief A reference proxy to a planar pixel.
 ///
 /// A reference to a planar pixel is a proxy class containing references to each of the corresponding channels.
-/// 
-template <typename ChannelReference, typename ColorSpace>        // ChannelReference is a channel reference (const or mutable)
-struct planar_pixel_reference 
-   : public detail::homogeneous_color_base<ChannelReference,layout<ColorSpace>,mpl::size<ColorSpace>::value> {
-    typedef detail::homogeneous_color_base<ChannelReference,layout<ColorSpace>,mpl::size<ColorSpace>::value> parent_t;
+/// Models: HomogeneousColorBaseConcept, HomogeneousPixelConcept
+///
+/// \tparam ChannelReference A channel reference, either const or mutable
+/// \tparam ColorSpace
+template <typename ChannelReference, typename ColorSpace>
+struct planar_pixel_reference : detail::homogeneous_color_base
+    <
+        ChannelReference,
+        layout<ColorSpace>,
+        mp11::mp_size<ColorSpace>::value
+    >
+{
+    using parent_t =detail::homogeneous_color_base
+        <
+            ChannelReference,
+            layout<ColorSpace>,
+            mp11::mp_size<ColorSpace>::value
+        >;
+
 private:
     // These three are only defined for homogeneous pixels
-    typedef typename channel_traits<ChannelReference>::value_type      channel_t;
-    typedef typename channel_traits<ChannelReference>::const_reference channel_const_reference;
-public:
-    BOOST_STATIC_CONSTANT(bool, is_mutable = channel_traits<ChannelReference>::is_mutable);
-    typedef pixel<channel_t,layout<ColorSpace> >                       value_type;
-    typedef planar_pixel_reference                                     reference;
-    typedef planar_pixel_reference<channel_const_reference,ColorSpace> const_reference;
-
-    planar_pixel_reference(ChannelReference v0, ChannelReference v1) : parent_t(v0,v1) {}
-    planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2) : parent_t(v0,v1,v2) {}
-    planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3) : parent_t(v0,v1,v2,v3) {}
-    planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4) : parent_t(v0,v1,v2,v3,v4) {}
-    planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4, ChannelReference v5) : parent_t(v0,v1,v2,v3,v4,v5) {}
+    using channel_t = typename channel_traits<ChannelReference>::value_type;
+    using channel_const_reference = typename channel_traits<ChannelReference>::const_reference;
 
-    template <typename P>                         planar_pixel_reference(const P& p)        : parent_t(p) { check_compatible<P>();}
+public:
+    static constexpr bool is_mutable = channel_traits<ChannelReference>::is_mutable;
+    using value_type = pixel<channel_t,layout<ColorSpace>>;
+    using reference = planar_pixel_reference<ChannelReference, ColorSpace>;
+    using const_reference = planar_pixel_reference<channel_const_reference,ColorSpace>;
+
+    planar_pixel_reference(ChannelReference v0, ChannelReference v1)
+        : parent_t(v0, v1)
+    {}
+
+    planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2)
+        : parent_t(v0, v1, v2)
+    {}
+
+    planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3)
+        : parent_t(v0, v1, v2, v3)
+    {}
+
+    planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4)
+        : parent_t(v0, v1, v2, v3, v4)
+    {}
+
+    planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4, ChannelReference v5)
+        : parent_t(v0, v1, v2, v3, v4, v5)
+    {}
+
+    planar_pixel_reference(planar_pixel_reference const& p) : parent_t(p) {}
+
+    // TODO: What is the purpose of returning via const reference?
+    auto operator=(planar_pixel_reference const& p) const -> planar_pixel_reference const&
+    {
+        static_copy(p, *this);
+        return *this;
+    }
+
+    template <typename Pixel>
+    planar_pixel_reference(Pixel const& p) : parent_t(p)
+    {
+         check_compatible<Pixel>();
+    }
+
+    // TODO: What is the purpose of returning via const reference?
+    template <typename Pixel>
+    auto operator=(Pixel const& p) const -> planar_pixel_reference const&
+    {
+        check_compatible<Pixel>();
+        static_copy(p, *this);
+        return *this;
+    }
 
     // PERFORMANCE_CHECK: Is this constructor necessary?
-    template <typename ChannelV, typename Mapping>           
-    planar_pixel_reference(pixel<ChannelV,layout<ColorSpace,Mapping> >& p)   : parent_t(p) { check_compatible<pixel<ChannelV,layout<ColorSpace,Mapping> > >();}
+    template <typename ChannelV, typename Mapping>
+    planar_pixel_reference(pixel<ChannelV, layout<ColorSpace, Mapping>>& p)
+       : parent_t(p)
+    {
+        check_compatible<pixel<ChannelV, layout<ColorSpace, Mapping>>>();
+    }
 
     // Construct at offset from a given location
-    template <typename ChannelPtr> planar_pixel_reference(const planar_pixel_iterator<ChannelPtr,ColorSpace>& p, std::ptrdiff_t diff) : parent_t(p,diff) {}
-
-    const planar_pixel_reference&                             operator=(const planar_pixel_reference& p)  const { static_copy(p,*this); return *this; }
-    template <typename P> const planar_pixel_reference&       operator=(const P& p)           const { check_compatible<P>(); static_copy(p,*this); return *this; }
+    template <typename ChannelPtr>
+    planar_pixel_reference(planar_pixel_iterator<ChannelPtr, ColorSpace> const& p, std::ptrdiff_t diff)
+        : parent_t(p, diff)
+    {}
 
 // This overload is necessary for a compiler implementing Core Issue 574
 // to prevent generation of an implicit copy assignment operator (the reason
@@ -91,35 +132,56 @@ public:
     template <typename P> const planar_pixel_reference& operator=(const P& p) { check_compatible<P>(); static_copy(p,*this); return *this; }
 #endif
 
-    template <typename P> bool                    operator==(const P& p)    const { check_compatible<P>(); return static_equal(*this,p); }
-    template <typename P> bool                    operator!=(const P& p)    const { return !(*this==p); }
+    template <typename Pixel>
+    bool operator==(Pixel const& p) const
+    {
+        check_compatible<Pixel>();
+        return static_equal(*this, p);
+    }
 
-    ChannelReference                              operator[](std::size_t i) const { return this->at_c_dynamic(i); }
+    template <typename Pixel>
+    bool operator!=(Pixel const &p) const { return !(*this == p); }
+
+    auto operator[](std::size_t i) const -> ChannelReference { return this->at_c_dynamic(i); }
+    auto operator->() const -> planar_pixel_reference const* { return this; }
 
-    const planar_pixel_reference*     operator->()              const { return this; }
 private:
-    template <typename Pixel> static void check_compatible() { gil_function_requires<PixelsCompatibleConcept<Pixel,planar_pixel_reference> >(); }
+    template <typename Pixel>
+    static void check_compatible()
+    {
+        gil_function_requires<PixelsCompatibleConcept<Pixel, planar_pixel_reference>>();
+    }
 };
 
 /////////////////////////////
 //  ColorBasedConcept
 /////////////////////////////
 
-template <typename ChannelReference, typename ColorSpace, int K>  
-struct kth_element_type<planar_pixel_reference<ChannelReference,ColorSpace>, K> {
-    typedef ChannelReference type;
+template <typename ChannelReference, typename ColorSpace, int K>
+struct kth_element_type<planar_pixel_reference<ChannelReference, ColorSpace>, K>
+{
+    using type = ChannelReference;
 };
 
-template <typename ChannelReference, typename ColorSpace, int K>  
-struct kth_element_reference_type<planar_pixel_reference<ChannelReference,ColorSpace>, K> {
-    typedef ChannelReference type;
+template <typename ChannelReference, typename ColorSpace, int K>
+struct kth_element_reference_type
+    <
+        planar_pixel_reference<ChannelReference, ColorSpace>,
+        K
+    >
+{
+    using type = ChannelReference;
 };
 
-template <typename ChannelReference, typename ColorSpace, int K>  
-struct kth_element_const_reference_type<planar_pixel_reference<ChannelReference,ColorSpace>, K> 
-    : public add_reference<typename add_const<ChannelReference>::type> 
+template <typename ChannelReference, typename ColorSpace, int K>
+struct kth_element_const_reference_type
+    <
+        planar_pixel_reference<ChannelReference, ColorSpace>,
+        K
+    >
+    : std::add_lvalue_reference<typename std::add_const<ChannelReference>::type>
 {
-//    typedef typename channel_traits<ChannelReference>::const_reference type;
+    //    using type = typename channel_traits<ChannelReference>::const_reference;
 };
 
 /////////////////////////////
@@ -128,8 +190,10 @@ struct kth_element_const_reference_type<planar_pixel_reference<ChannelReference,
 
 /// \brief Metafunction predicate that flags planar_pixel_reference as a model of PixelConcept. Required by PixelConcept
 /// \ingroup PixelModelPlanarRef
-template <typename ChannelReference, typename ColorSpace>  
-struct is_pixel< planar_pixel_reference<ChannelReference,ColorSpace> > : public mpl::true_{};
+template <typename ChannelReference, typename ColorSpace>
+struct is_pixel< planar_pixel_reference<ChannelReference, ColorSpace>>
+    : std::true_type
+{};
 
 /////////////////////////////
 //  HomogeneousPixelBasedConcept
@@ -137,35 +201,37 @@ struct is_pixel< planar_pixel_reference<ChannelReference,ColorSpace> > : public
 
 /// \brief Specifies the color space type of a planar pixel reference. Required by PixelBasedConcept
 /// \ingroup PixelModelPlanarRef
-template <typename ChannelReference, typename ColorSpace>  
+template <typename ChannelReference, typename ColorSpace>
 struct color_space_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
-    typedef ColorSpace type;
-}; 
+    using type = ColorSpace;
+};
 
 /// \brief Specifies the color space type of a planar pixel reference. Required by PixelBasedConcept
 /// \ingroup PixelModelPlanarRef
-template <typename ChannelReference, typename ColorSpace>  
+template <typename ChannelReference, typename ColorSpace>
 struct channel_mapping_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
-    typedef typename layout<ColorSpace>::channel_mapping_t type;
-}; 
+    using type = typename layout<ColorSpace>::channel_mapping_t;
+};
 
 /// \brief Specifies that planar_pixel_reference represents a planar construct. Required by PixelBasedConcept
 /// \ingroup PixelModelPlanarRef
-template <typename ChannelReference, typename ColorSpace>  
-struct is_planar<planar_pixel_reference<ChannelReference,ColorSpace> > : mpl::true_ {};
+template <typename ChannelReference, typename ColorSpace>
+struct is_planar<planar_pixel_reference<ChannelReference, ColorSpace>>
+    : std::true_type
+{};
 
 /// \brief Specifies the color space type of a planar pixel reference. Required by HomogeneousPixelBasedConcept
 /// \ingroup PixelModelPlanarRef
-template <typename ChannelReference, typename ColorSpace>  
+template <typename ChannelReference, typename ColorSpace>
 struct channel_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
-    typedef typename channel_traits<ChannelReference>::value_type type;
-}; 
+    using type = typename channel_traits<ChannelReference>::value_type;
+};
 
-} }  // namespace boost::gil
+}}  // namespace boost::gil
 
 namespace std {
 // We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified.
-// swap with 'left bias': 
+// swap with 'left bias':
 // - swap between proxy and anything
 // - swap between value type and proxy
 // - swap between proxy and proxy
@@ -174,25 +240,24 @@ namespace std {
 /// \brief  swap for planar_pixel_reference
 /// \ingroup PixelModelPlanarRef
 template <typename CR, typename CS, typename R> inline
-void swap(const boost::gil::planar_pixel_reference<CR,CS> x, R& y) { 
-    boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y); 
+void swap(const boost::gil::planar_pixel_reference<CR,CS> x, R& y) {
+    boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
 }
 
-
 /// \brief  swap for planar_pixel_reference
 /// \ingroup PixelModelPlanarRef
 template <typename CR, typename CS> inline
-void swap(typename boost::gil::planar_pixel_reference<CR,CS>::value_type& x, const boost::gil::planar_pixel_reference<CR,CS> y) { 
-    boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y); 
+void swap(typename boost::gil::planar_pixel_reference<CR,CS>::value_type& x, const boost::gil::planar_pixel_reference<CR,CS> y) {
+    boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
 }
 
-
 /// \brief  swap for planar_pixel_reference
 /// \ingroup PixelModelPlanarRef
 template <typename CR, typename CS> inline
-void swap(const boost::gil::planar_pixel_reference<CR,CS> x, const boost::gil::planar_pixel_reference<CR,CS> y) { 
-    boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y); 
+void swap(const boost::gil::planar_pixel_reference<CR,CS> x, const boost::gil::planar_pixel_reference<CR,CS> y) {
+    boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
 }
+
 }   // namespace std
 
 #endif