1.1 --- a/epoc32/include/stdapis/boost/mpl/base.hpp Wed Mar 31 12:27:01 2010 +0100
1.2 +++ b/epoc32/include/stdapis/boost/mpl/base.hpp Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -1,479 +1,35 @@
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 +#ifndef BOOST_MPL_BASE_HPP_INCLUDED
1.9 +#define BOOST_MPL_BASE_HPP_INCLUDED
1.10 +
1.11 +// Copyright Aleksey Gurtovoy 2000-2004
1.12 +//
1.13 +// Distributed under the Boost Software License, Version 1.0.
1.14 +// (See accompanying file LICENSE_1_0.txt or copy at
1.15 // http://www.boost.org/LICENSE_1_0.txt)
1.16 +//
1.17 +// See http://www.boost.org/libs/mpl for documentation.
1.18
1.19 -// Boost.MultiArray Library
1.20 -// Authors: Ronald Garcia
1.21 -// Jeremy Siek
1.22 -// Andrew Lumsdaine
1.23 -// See http://www.boost.org/libs/multi_array for documentation.
1.24 +// $Source: /cvsroot/boost/boost/boost/mpl/base.hpp,v $
1.25 +// $Date: 2004/09/02 15:40:41 $
1.26 +// $Revision: 1.4 $
1.27
1.28 -#ifndef BASE_RG071801_HPP
1.29 -#define BASE_RG071801_HPP
1.30 +#include <boost/mpl/aux_/na_spec.hpp>
1.31 +#include <boost/mpl/aux_/lambda_support.hpp>
1.32
1.33 -//
1.34 -// base.hpp - some implementation base classes for from which
1.35 -// functionality is acquired
1.36 -//
1.37 +namespace boost { namespace mpl {
1.38
1.39 -#include "boost/multi_array/extent_range.hpp"
1.40 -#include "boost/multi_array/extent_gen.hpp"
1.41 -#include "boost/multi_array/index_range.hpp"
1.42 -#include "boost/multi_array/index_gen.hpp"
1.43 -#include "boost/multi_array/storage_order.hpp"
1.44 -#include "boost/multi_array/types.hpp"
1.45 -#include "boost/config.hpp"
1.46 -#include "boost/multi_array/concept_checks.hpp" //for ignore_unused_...
1.47 -#include "boost/mpl/eval_if.hpp"
1.48 -#include "boost/mpl/if.hpp"
1.49 -#include "boost/mpl/size_t.hpp"
1.50 -#include "boost/mpl/aux_/msvc_eti_base.hpp"
1.51 -#include "boost/iterator/reverse_iterator.hpp"
1.52 -#include "boost/static_assert.hpp"
1.53 -#include "boost/type.hpp"
1.54 -#include "boost/assert.hpp"
1.55 -#include <cstddef>
1.56 -#include <memory>
1.57 -
1.58 -namespace boost {
1.59 -
1.60 -/////////////////////////////////////////////////////////////////////////
1.61 -// class declarations
1.62 -/////////////////////////////////////////////////////////////////////////
1.63 -
1.64 -template<typename T, std::size_t NumDims,
1.65 - typename Allocator = std::allocator<T> >
1.66 -class multi_array;
1.67 -
1.68 -// This is a public interface for use by end users!
1.69 -namespace multi_array_types {
1.70 - typedef boost::detail::multi_array::size_type size_type;
1.71 - typedef std::ptrdiff_t difference_type;
1.72 - typedef boost::detail::multi_array::index index;
1.73 - typedef detail::multi_array::index_range<index,size_type> index_range;
1.74 - typedef detail::multi_array::extent_range<index,size_type> extent_range;
1.75 - typedef detail::multi_array::index_gen<0,0> index_gen;
1.76 - typedef detail::multi_array::extent_gen<0> extent_gen;
1.77 -}
1.78 -
1.79 -
1.80 -// boost::extents and boost::indices are now a part of the public
1.81 -// interface. That way users don't necessarily have to create their
1.82 -// own objects. On the other hand, one may not want the overhead of
1.83 -// object creation in small-memory environments. Thus, the objects
1.84 -// can be left undefined by defining BOOST_MULTI_ARRAY_NO_GENERATORS
1.85 -// before loading multi_array.hpp.
1.86 -#if !BOOST_MULTI_ARRAY_NO_GENERATORS
1.87 -namespace {
1.88 - multi_array_types::extent_gen extents;
1.89 - multi_array_types::index_gen indices;
1.90 -}
1.91 -#endif // BOOST_MULTI_ARRAY_NO_GENERATORS
1.92 -
1.93 -namespace detail {
1.94 -namespace multi_array {
1.95 -
1.96 -template <typename T, std::size_t NumDims>
1.97 -class sub_array;
1.98 -
1.99 -template <typename T, std::size_t NumDims, typename TPtr = const T*>
1.100 -class const_sub_array;
1.101 -
1.102 -template <typename T, typename TPtr, typename NumDims, typename Reference>
1.103 -class array_iterator;
1.104 -
1.105 -template <typename T, std::size_t NumDims, typename TPtr = const T*>
1.106 -class const_multi_array_view;
1.107 -
1.108 -template <typename T, std::size_t NumDims>
1.109 -class multi_array_view;
1.110 -
1.111 -/////////////////////////////////////////////////////////////////////////
1.112 -// class interfaces
1.113 -/////////////////////////////////////////////////////////////////////////
1.114 -
1.115 -class multi_array_base {
1.116 -public:
1.117 - typedef multi_array_types::size_type size_type;
1.118 - typedef multi_array_types::difference_type difference_type;
1.119 - typedef multi_array_types::index index;
1.120 - typedef multi_array_types::index_range index_range;
1.121 - typedef multi_array_types::extent_range extent_range;
1.122 - typedef multi_array_types::index_gen index_gen;
1.123 - typedef multi_array_types::extent_gen extent_gen;
1.124 +template<
1.125 + typename BOOST_MPL_AUX_NA_PARAM(T)
1.126 + >
1.127 +struct base
1.128 +{
1.129 + typedef typename T::base type;
1.130 + BOOST_MPL_AUX_LAMBDA_SUPPORT(1,base,(T))
1.131 };
1.132
1.133 -//
1.134 -// value_accessor_n
1.135 -// contains the routines for accessing elements from
1.136 -// N-dimensional views.
1.137 -//
1.138 -template<typename T, std::size_t NumDims>
1.139 -class value_accessor_n : public multi_array_base {
1.140 - typedef multi_array_base super_type;
1.141 -public:
1.142 - typedef typename super_type::index index;
1.143 +BOOST_MPL_AUX_NA_SPEC(1, base)
1.144
1.145 - //
1.146 - // public typedefs used by classes that inherit from this base
1.147 - //
1.148 - typedef T element;
1.149 - typedef boost::multi_array<T,NumDims-1> value_type;
1.150 - typedef sub_array<T,NumDims-1> reference;
1.151 - typedef const_sub_array<T,NumDims-1> const_reference;
1.152 +}}
1.153
1.154 -protected:
1.155 - // used by array operator[] and iterators to get reference types.
1.156 - template <typename Reference, typename TPtr>
1.157 - Reference access(boost::type<Reference>,index idx,TPtr base,
1.158 - const size_type* extents,
1.159 - const index* strides,
1.160 - const index* index_bases) const {
1.161 -
1.162 - BOOST_ASSERT(idx - index_bases[0] >= 0);
1.163 - BOOST_ASSERT(size_type(idx - index_bases[0]) < extents[0]);
1.164 - // return a sub_array<T,NDims-1> proxy object
1.165 - TPtr newbase = base + idx * strides[0];
1.166 - return Reference(newbase,extents+1,strides+1,index_bases+1);
1.167 -
1.168 - }
1.169 -
1.170 - value_accessor_n() { }
1.171 - ~value_accessor_n() { }
1.172 -};
1.173 -
1.174 -
1.175 -
1.176 -//
1.177 -// value_accessor_one
1.178 -// contains the routines for accessing reference elements from
1.179 -// 1-dimensional views.
1.180 -//
1.181 -template<typename T>
1.182 -class value_accessor_one : public multi_array_base {
1.183 - typedef multi_array_base super_type;
1.184 -public:
1.185 - typedef typename super_type::index index;
1.186 - //
1.187 - // public typedefs for use by classes that inherit it.
1.188 - //
1.189 - typedef T element;
1.190 - typedef T value_type;
1.191 - typedef T& reference;
1.192 - typedef T const& const_reference;
1.193 -
1.194 -protected:
1.195 - // used by array operator[] and iterators to get reference types.
1.196 - template <typename Reference, typename TPtr>
1.197 - Reference access(boost::type<Reference>,index idx,TPtr base,
1.198 - const size_type* extents,
1.199 - const index* strides,
1.200 - const index* index_bases) const {
1.201 -
1.202 - ignore_unused_variable_warning(index_bases);
1.203 - ignore_unused_variable_warning(extents);
1.204 - BOOST_ASSERT(idx - index_bases[0] >= 0);
1.205 - BOOST_ASSERT(size_type(idx - index_bases[0]) < extents[0]);
1.206 - return *(base + idx * strides[0]);
1.207 - }
1.208 -
1.209 - value_accessor_one() { }
1.210 - ~value_accessor_one() { }
1.211 -};
1.212 -
1.213 -
1.214 -/////////////////////////////////////////////////////////////////////////
1.215 -// choose value accessor begins
1.216 -//
1.217 -
1.218 -template <typename T, std::size_t NumDims>
1.219 -struct choose_value_accessor_n {
1.220 - typedef value_accessor_n<T,NumDims> type;
1.221 -};
1.222 -
1.223 -template <typename T>
1.224 -struct choose_value_accessor_one {
1.225 - typedef value_accessor_one<T> type;
1.226 -};
1.227 -
1.228 -template <typename T, typename NumDims>
1.229 -struct value_accessor_generator {
1.230 - BOOST_STATIC_CONSTANT(std::size_t, dimensionality = NumDims::value);
1.231 -
1.232 - typedef typename
1.233 - mpl::eval_if_c<(dimensionality == 1),
1.234 - choose_value_accessor_one<T>,
1.235 - choose_value_accessor_n<T,dimensionality>
1.236 - >::type type;
1.237 -};
1.238 -
1.239 -#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
1.240 -
1.241 -struct eti_value_accessor
1.242 -{
1.243 - typedef int index;
1.244 - typedef int size_type;
1.245 - typedef int element;
1.246 - typedef int index_range;
1.247 - typedef int value_type;
1.248 - typedef int reference;
1.249 - typedef int const_reference;
1.250 -};
1.251 -
1.252 -template <>
1.253 -struct value_accessor_generator<int,int>
1.254 -{
1.255 - typedef eti_value_accessor type;
1.256 -};
1.257 -
1.258 -template <class T, class NumDims>
1.259 -struct associated_types
1.260 - : mpl::aux::msvc_eti_base<
1.261 - typename value_accessor_generator<T,NumDims>::type
1.262 - >::type
1.263 -{};
1.264 -
1.265 -template <>
1.266 -struct associated_types<int,int> : eti_value_accessor {};
1.267 -
1.268 -#else
1.269 -
1.270 -template <class T, class NumDims>
1.271 -struct associated_types
1.272 - : value_accessor_generator<T,NumDims>::type
1.273 -{};
1.274 -
1.275 -#endif
1.276 -
1.277 -//
1.278 -// choose value accessor ends
1.279 -/////////////////////////////////////////////////////////////////////////
1.280 -
1.281 -
1.282 -
1.283 -////////////////////////////////////////////////////////////////////////
1.284 -// multi_array_base
1.285 -////////////////////////////////////////////////////////////////////////
1.286 -template <typename T, std::size_t NumDims>
1.287 -class multi_array_impl_base
1.288 - :
1.289 -#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
1.290 - public mpl::aux::msvc_eti_base<
1.291 - typename value_accessor_generator<T,mpl::size_t<NumDims> >::type
1.292 - >::type
1.293 -#else
1.294 - public value_accessor_generator<T,mpl::size_t<NumDims> >::type
1.295 -#endif
1.296 -{
1.297 - typedef associated_types<T,mpl::size_t<NumDims> > types;
1.298 -public:
1.299 - typedef typename types::index index;
1.300 - typedef typename types::size_type size_type;
1.301 - typedef typename types::element element;
1.302 - typedef typename types::index_range index_range;
1.303 - typedef typename types::value_type value_type;
1.304 - typedef typename types::reference reference;
1.305 - typedef typename types::const_reference const_reference;
1.306 -
1.307 - template <std::size_t NDims>
1.308 - struct subarray {
1.309 - typedef boost::detail::multi_array::sub_array<T,NDims> type;
1.310 - };
1.311 -
1.312 - template <std::size_t NDims>
1.313 - struct const_subarray {
1.314 - typedef boost::detail::multi_array::const_sub_array<T,NDims> type;
1.315 - };
1.316 -
1.317 - template <std::size_t NDims>
1.318 - struct array_view {
1.319 - typedef boost::detail::multi_array::multi_array_view<T,NDims> type;
1.320 - };
1.321 -
1.322 - template <std::size_t NDims>
1.323 - struct const_array_view {
1.324 - public:
1.325 - typedef boost::detail::multi_array::const_multi_array_view<T,NDims> type;
1.326 - };
1.327 -
1.328 - //
1.329 - // iterator support
1.330 - //
1.331 - typedef array_iterator<T,T*,mpl::size_t<NumDims>,reference> iterator;
1.332 - typedef array_iterator<T,T const*,mpl::size_t<NumDims>,const_reference> const_iterator;
1.333 -
1.334 - typedef ::boost::reverse_iterator<iterator> reverse_iterator;
1.335 - typedef ::boost::reverse_iterator<const_iterator> const_reverse_iterator;
1.336 -
1.337 - BOOST_STATIC_CONSTANT(std::size_t, dimensionality = NumDims);
1.338 -protected:
1.339 -
1.340 - multi_array_impl_base() { }
1.341 - ~multi_array_impl_base() { }
1.342 -
1.343 - // Used by operator() in our array classes
1.344 - template <typename Reference, typename IndexList, typename TPtr>
1.345 - Reference access_element(boost::type<Reference>,
1.346 - const IndexList& indices,
1.347 - TPtr base,
1.348 - const size_type* extents,
1.349 - const index* strides,
1.350 - const index* index_bases) const {
1.351 -
1.352 - ignore_unused_variable_warning(index_bases);
1.353 - ignore_unused_variable_warning(extents);
1.354 -#if !defined(NDEBUG) && !defined(BOOST_DISABLE_ASSERTS)
1.355 - for (size_type i = 0; i != NumDims; ++i) {
1.356 - BOOST_ASSERT(indices[i] - index_bases[i] >= 0);
1.357 - BOOST_ASSERT(size_type(indices[i] - index_bases[i]) < extents[i]);
1.358 - }
1.359 -#endif
1.360 -
1.361 - index offset = 0;
1.362 - for (size_type n = 0; n != NumDims; ++n)
1.363 - offset += indices[n] * strides[n];
1.364 -
1.365 - return base[offset];
1.366 - }
1.367 -
1.368 - template <typename StrideList, typename ExtentList>
1.369 - void compute_strides(StrideList& stride_list, ExtentList& extent_list,
1.370 - const general_storage_order<NumDims>& storage)
1.371 - {
1.372 - // invariant: stride = the stride for dimension n
1.373 - index stride = 1;
1.374 - for (size_type n = 0; n != NumDims; ++n) {
1.375 - index stride_sign = +1;
1.376 -
1.377 - if (!storage.ascending(storage.ordering(n)))
1.378 - stride_sign = -1;
1.379 -
1.380 - // The stride for this dimension is the product of the
1.381 - // lengths of the ranks minor to it.
1.382 - stride_list[storage.ordering(n)] = stride * stride_sign;
1.383 -
1.384 - stride *= extent_list[storage.ordering(n)];
1.385 - }
1.386 - }
1.387 -
1.388 - // This calculates the offset to the array base pointer due to:
1.389 - // 1. dimensions stored in descending order
1.390 - // 2. non-zero dimension index bases
1.391 - template <typename StrideList, typename ExtentList, typename BaseList>
1.392 - index
1.393 - calculate_origin_offset(const StrideList& stride_list,
1.394 - const ExtentList& extent_list,
1.395 - const general_storage_order<NumDims>& storage,
1.396 - const BaseList& index_base_list)
1.397 - {
1.398 - return
1.399 - calculate_descending_dimension_offset(stride_list,extent_list,
1.400 - storage) +
1.401 - calculate_indexing_offset(stride_list,index_base_list);
1.402 - }
1.403 -
1.404 - // This calculates the offset added to the base pointer that are
1.405 - // caused by descending dimensions
1.406 - template <typename StrideList, typename ExtentList>
1.407 - index
1.408 - calculate_descending_dimension_offset(const StrideList& stride_list,
1.409 - const ExtentList& extent_list,
1.410 - const general_storage_order<NumDims>& storage)
1.411 - {
1.412 - index offset = 0;
1.413 - if (!storage.all_dims_ascending())
1.414 - for (size_type n = 0; n != NumDims; ++n)
1.415 - if (!storage.ascending(n))
1.416 - offset -= (extent_list[n] - 1) * stride_list[n];
1.417 -
1.418 - return offset;
1.419 - }
1.420 -
1.421 - // This is used to reindex array_views, which are no longer
1.422 - // concerned about storage order (specifically, whether dimensions
1.423 - // are ascending or descending) since the viewed array handled it.
1.424 -
1.425 - template <typename StrideList, typename BaseList>
1.426 - index
1.427 - calculate_indexing_offset(const StrideList& stride_list,
1.428 - const BaseList& index_base_list)
1.429 - {
1.430 - index offset = 0;
1.431 - for (size_type n = 0; n != NumDims; ++n)
1.432 - offset -= stride_list[n] * index_base_list[n];
1.433 - return offset;
1.434 - }
1.435 -
1.436 - // Slicing using an index_gen.
1.437 - // Note that populating an index_gen creates a type that encodes
1.438 - // both the number of dimensions in the current Array (NumDims), and
1.439 - // the Number of dimensions for the resulting view. This allows the
1.440 - // compiler to fail if the dimensions aren't completely accounted
1.441 - // for. For reasons unbeknownst to me, a BOOST_STATIC_ASSERT
1.442 - // within the member function template does not work. I should add a
1.443 - // note to the documentation specifying that you get a damn ugly
1.444 - // error message if you screw up in your slicing code.
1.445 - template <typename ArrayRef, int NDims, typename TPtr>
1.446 - ArrayRef
1.447 - generate_array_view(boost::type<ArrayRef>,
1.448 - const boost::detail::multi_array::
1.449 - index_gen<NumDims,NDims>& indices,
1.450 - const size_type* extents,
1.451 - const index* strides,
1.452 - const index* index_bases,
1.453 - TPtr base) const {
1.454 -
1.455 - boost::array<index,NDims> new_strides;
1.456 - boost::array<index,NDims> new_extents;
1.457 -
1.458 - index offset = 0;
1.459 - size_type dim = 0;
1.460 - for (size_type n = 0; n != NumDims; ++n) {
1.461 - const index default_start = index_bases[n];
1.462 - const index default_finish = default_start+extents[n];
1.463 - const index_range& current_range = indices.ranges_[n];
1.464 - index start = current_range.get_start(default_start);
1.465 - index finish = current_range.get_finish(default_finish);
1.466 - index index_factor = current_range.stride();
1.467 - index len = (finish - start + (index_factor - 1)) / index_factor;
1.468 -
1.469 - BOOST_ASSERT(index_bases[n] <= start &&
1.470 - start <= index_bases[n]+index(extents[n]));
1.471 - BOOST_ASSERT(index_bases[n] <= finish &&
1.472 - finish <= index_bases[n]+index(extents[n]));
1.473 - BOOST_ASSERT(index_factor > 0);
1.474 -
1.475 - // the array data pointer is modified to account for non-zero
1.476 - // bases during slicing (see [Garcia] for the math involved)
1.477 - offset += start * strides[n];
1.478 -
1.479 - if (!current_range.is_degenerate()) {
1.480 -
1.481 - // The index_factor for each dimension is included into the
1.482 - // strides for the array_view (see [Garcia] for the math involved).
1.483 - new_strides[dim] = index_factor * strides[n];
1.484 -
1.485 - // calculate new extents
1.486 - new_extents[dim] = len;
1.487 - ++dim;
1.488 - }
1.489 - }
1.490 - BOOST_ASSERT(dim == NDims);
1.491 -
1.492 - return
1.493 - ArrayRef(base+offset,
1.494 - new_extents,
1.495 - new_strides);
1.496 - }
1.497 -
1.498 -
1.499 -};
1.500 -
1.501 -} // namespace multi_array
1.502 -} // namespace detail
1.503 -
1.504 -} // namespace boost
1.505 -
1.506 -#endif // BASE_RG071801_HPP
1.507 +#endif // BOOST_MPL_BASE_HPP_INCLUDED