1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/multi_array/iterator.hpp Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,170 @@
1.4 +// Copyright 2002 The Trustees of Indiana University.
1.5 +
1.6 +// Use, modification and distribution is subject to the Boost Software
1.7 +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.8 +// http://www.boost.org/LICENSE_1_0.txt)
1.9 +
1.10 +// Boost.MultiArray Library
1.11 +// Authors: Ronald Garcia
1.12 +// Jeremy Siek
1.13 +// Andrew Lumsdaine
1.14 +// See http://www.boost.org/libs/multi_array for documentation.
1.15 +
1.16 +#ifndef ITERATOR_RG071801_HPP
1.17 +#define ITERATOR_RG071801_HPP
1.18 +
1.19 +//
1.20 +// iterator.hpp - implementation of iterators for the
1.21 +// multi-dimensional array class
1.22 +//
1.23 +
1.24 +#include "boost/multi_array/base.hpp"
1.25 +#include "boost/iterator/iterator_facade.hpp"
1.26 +#include "boost/mpl/aux_/msvc_eti_base.hpp"
1.27 +#include <algorithm>
1.28 +#include <cstddef>
1.29 +#include <iterator>
1.30 +
1.31 +namespace boost {
1.32 +namespace detail {
1.33 +namespace multi_array {
1.34 +
1.35 +/////////////////////////////////////////////////////////////////////////
1.36 +// iterator components
1.37 +/////////////////////////////////////////////////////////////////////////
1.38 +
1.39 +template <class T>
1.40 +struct operator_arrow_proxy
1.41 +{
1.42 + operator_arrow_proxy(T const& px) : value_(px) {}
1.43 + T* operator->() const { return &value_; }
1.44 + // This function is needed for MWCW and BCC, which won't call operator->
1.45 + // again automatically per 13.3.1.2 para 8
1.46 + operator T*() const { return &value_; }
1.47 + mutable T value_;
1.48 +};
1.49 +
1.50 +template <typename T, typename TPtr, typename NumDims, typename Reference>
1.51 +class array_iterator;
1.52 +
1.53 +template <typename T, typename TPtr, typename NumDims, typename Reference>
1.54 +class array_iterator
1.55 + : public
1.56 + iterator_facade<
1.57 + array_iterator<T,TPtr,NumDims,Reference>
1.58 + , typename associated_types<T,NumDims>::value_type
1.59 + , boost::random_access_traversal_tag
1.60 + , Reference
1.61 + >
1.62 + , private
1.63 +#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
1.64 + mpl::aux::msvc_eti_base<typename
1.65 +#endif
1.66 + value_accessor_generator<T,NumDims>::type
1.67 +#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
1.68 + >::type
1.69 +#endif
1.70 +{
1.71 + friend class iterator_core_access;
1.72 + typedef detail::multi_array::associated_types<T,NumDims> access_t;
1.73 +
1.74 + typedef iterator_facade<
1.75 + array_iterator<T,TPtr,NumDims,Reference>
1.76 + , typename detail::multi_array::associated_types<T,NumDims>::value_type
1.77 + , boost::random_access_traversal_tag
1.78 + , Reference
1.79 + > facade_type;
1.80 +
1.81 + typedef typename access_t::index index;
1.82 + typedef typename access_t::size_type size_type;
1.83 +
1.84 +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
1.85 + template <typename, typename, typename, typename>
1.86 + friend class array_iterator;
1.87 +#else
1.88 + public:
1.89 +#endif
1.90 +
1.91 + index idx_;
1.92 + TPtr base_;
1.93 + const size_type* extents_;
1.94 + const index* strides_;
1.95 + const index* index_base_;
1.96 +
1.97 +public:
1.98 + // Typedefs to circumvent ambiguities between parent classes
1.99 + typedef typename facade_type::reference reference;
1.100 + typedef typename facade_type::value_type value_type;
1.101 + typedef typename facade_type::difference_type difference_type;
1.102 +
1.103 + array_iterator() {}
1.104 +
1.105 + array_iterator(index idx, TPtr base, const size_type* extents,
1.106 + const index* strides,
1.107 + const index* index_base) :
1.108 + idx_(idx), base_(base), extents_(extents),
1.109 + strides_(strides), index_base_(index_base) { }
1.110 +
1.111 + template <typename OPtr, typename ORef>
1.112 + array_iterator(
1.113 + const array_iterator<T,OPtr,NumDims,ORef>& rhs
1.114 + , typename boost::enable_if_convertible<OPtr,TPtr>::type* = 0
1.115 + )
1.116 + : idx_(rhs.idx_), base_(rhs.base_), extents_(rhs.extents_),
1.117 + strides_(rhs.strides_), index_base_(rhs.index_base_) { }
1.118 +
1.119 +
1.120 + // RG - we make our own operator->
1.121 + operator_arrow_proxy<reference>
1.122 + operator->() const
1.123 + {
1.124 + return operator_arrow_proxy<reference>(this->dereference());
1.125 + }
1.126 +
1.127 +
1.128 + reference dereference() const
1.129 + {
1.130 + typedef typename value_accessor_generator<T,NumDims>::type accessor;
1.131 + return accessor::access(boost::type<reference>(),
1.132 + idx_,
1.133 + base_,
1.134 + extents_,
1.135 + strides_,
1.136 + index_base_);
1.137 + }
1.138 +
1.139 + void increment() { ++idx_; }
1.140 + void decrement() { --idx_; }
1.141 +
1.142 + template <class IteratorAdaptor>
1.143 + bool equal(IteratorAdaptor& rhs) const {
1.144 + const std::size_t N = NumDims::value;
1.145 + return (idx_ == rhs.idx_) &&
1.146 + (base_ == rhs.base_) &&
1.147 + ( (extents_ == rhs.extents_) ||
1.148 + std::equal(extents_,extents_+N,rhs.extents_) ) &&
1.149 + ( (strides_ == rhs.strides_) ||
1.150 + std::equal(strides_,strides_+N,rhs.strides_) ) &&
1.151 + ( (index_base_ == rhs.index_base_) ||
1.152 + std::equal(index_base_,index_base_+N,rhs.index_base_) );
1.153 + }
1.154 +
1.155 + template <class DifferenceType>
1.156 + void advance(DifferenceType n) {
1.157 + idx_ += n;
1.158 + }
1.159 +
1.160 + template <class IteratorAdaptor>
1.161 + typename facade_type::difference_type
1.162 + distance_to(IteratorAdaptor& rhs) const {
1.163 + return rhs.idx_ - idx_;
1.164 + }
1.165 +
1.166 +
1.167 +};
1.168 +
1.169 +} // namespace multi_array
1.170 +} // namespace detail
1.171 +} // namespace boost
1.172 +
1.173 +#endif // ITERATOR_RG071801_HPP