]> git.lyx.org Git - lyx.git/blobdiff - boost/boost/multi_array/multi_array_ref.hpp
* src/MenuBackend.[Ch]: the specialMenu is now a real menu, not a
[lyx.git] / boost / boost / multi_array / multi_array_ref.hpp
index f166d6157a71ca4ac54bacb98d091e15d7475bfd..41b962a8ebe0b87fb7f81821f10b2664fb9aa7ab 100644 (file)
@@ -25,6 +25,7 @@
 #include "boost/multi_array/subarray.hpp"
 #include "boost/multi_array/view.hpp"
 #include "boost/multi_array/algorithm.hpp"
+#include "boost/type_traits/is_integral.hpp"
 #include "boost/array.hpp"
 #include "boost/concept_check.hpp"
 #include "boost/functional.hpp"
@@ -71,14 +72,12 @@ public:
   // make const_multi_array_ref a friend of itself
   template <typename,std::size_t,typename>
   friend class const_multi_array_ref;
-
-//  template <typename From, typename To>  // needed for enable_if_convertible tests
-//  friend class boost::detail::is_convertible_basic_impl;
 #endif
 
+  // This ensures that const_multi_array_ref types with different TPtr 
+  // types can convert to each other
   template <typename OPtr>
-  const_multi_array_ref(const const_multi_array_ref<T,NumDims,
-                        OPtr>& other)
+  const_multi_array_ref(const const_multi_array_ref<T,NumDims,OPtr>& other)
     : base_(other.base_), storage_(other.storage_),
       extent_list_(other.extent_list_),
       stride_list_(other.stride_list_),
@@ -139,10 +138,17 @@ public:
   }
 
   template <class BaseList>
-  void reindex(const BaseList& values) {
+#ifdef BOOST_NO_SFINAE
+  void
+#else
+  typename
+  disable_if<typename boost::is_integral<BaseList>::type,void >::type
+#endif // BOOST_NO_SFINAE
+  reindex(const BaseList& values) {
     boost::function_requires<
       detail::multi_array::CollectionConcept<BaseList> >();
-    boost::copy_n(values.begin(),num_dimensions(),index_base_list_.begin());
+    boost::detail::multi_array::
+      copy_n(values.begin(),num_dimensions(),index_base_list_.begin());
     origin_offset_ =
       this->calculate_origin_offset(stride_list_,extent_list_,
                               storage_,index_base_list_);
@@ -207,8 +213,8 @@ public:
     boost::function_requires<
       detail::multi_array::CollectionConcept<IndexList> >();
     return super_type::access_element(boost::type<const element&>(),
-                                      origin(),
-                                      indices,strides());
+                                      indices,origin(),
+                                      shape(),strides(),index_bases());
   }
 
   // Only allow const element access
@@ -244,7 +250,7 @@ public:
   }
 
   const_iterator end() const {
-    return const_iterator(*index_bases()+*shape(),origin(),
+    return const_iterator(*index_bases()+(index)*shape(),origin(),
                           shape(),strides(),index_bases());
   }
 
@@ -303,44 +309,46 @@ public:
     return !(*this < rhs);
   }
 
-protected:
-  // This is only supplied to support multi_array's default constructor
-  explicit const_multi_array_ref(TPtr base) :
-    base_(base), storage_(c_storage_order()) {
-    index_base_list_.assign(0);
-    boost::array<size_type,NumDims> filler;
-    filler.assign(0);
-    init_multi_array_ref(filler.begin());
-  }
-
 
-// This ensures that const_multi_array_ref types with different TPtr 
-// types can convert to each other
 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
 protected:
 #else
 public:
 #endif
+
+  typedef boost::array<size_type,NumDims> size_list;
+  typedef boost::array<index,NumDims> index_list;
+
   // This is used by multi_array, which is a subclass of this
   void set_base_ptr(TPtr new_base) { base_ = new_base; }
 
-  template <typename OPtr>
-  const_multi_array_ref(
-      const detail::multi_array::const_sub_array<T,NumDims,OPtr>& rhs
-  )
-    : base_(0), // playing it "safe"; so we learn of errors
-      storage_(c_storage_order()),
-      origin_offset_(0), directional_offset_(0),
-      num_elements_(rhs.num_elements())
-  {
-    using boost::copy_n;
-    copy_n(rhs.shape(),rhs.num_dimensions(),extent_list_.begin());
-    copy_n(rhs.strides(),rhs.num_dimensions(),stride_list_.begin());
-    copy_n(rhs.index_bases(),rhs.num_dimensions(),index_base_list_.begin());
-  }
 
-  typedef boost::array<size_type,NumDims> size_list;
-  typedef boost::array<index,NumDims> index_list;
+  // This constructor supports multi_array's default constructor
+  // and constructors from multi_array_ref, subarray, and array_view
+  explicit
+  const_multi_array_ref(TPtr base,
+                        const storage_order_type& so,
+                        const index * index_bases,
+                        const size_type* extents) :
+    base_(base), storage_(so), origin_offset_(0), directional_offset_(0)
+ {
+   // If index_bases or extents is null, then initialize the corresponding
+   // private data to zeroed lists.
+   if(index_bases) {
+     boost::detail::multi_array::
+       copy_n(index_bases,NumDims,index_base_list_.begin());
+   } else {
+     std::fill_n(index_base_list_.begin(),NumDims,0);
+   }
+   if(extents) {
+     init_multi_array_ref(extents);
+   } else {
+     boost::array<index,NumDims> extent_list;
+     extent_list.assign(0);
+     init_multi_array_ref(extent_list.begin());
+   }
+ }
+
 
   TPtr base_;
   storage_order_type storage_;
@@ -376,18 +384,23 @@ private:
   }
 
 
+#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
+protected:
+#else
+public:
+#endif
+  // RG - move me!
   template <class InputIterator>
   void init_multi_array_ref(InputIterator extents_iter) {
     boost::function_requires<InputIteratorConcept<InputIterator> >();
 
-    boost::copy_n(extents_iter,num_dimensions(),extent_list_.begin());
+    boost::detail::multi_array::
+      copy_n(extents_iter,num_dimensions(),extent_list_.begin());
 
     // Calculate the array size
     num_elements_ = std::accumulate(extent_list_.begin(),extent_list_.end(),
-                            1,std::multiplies<index>());
-#if 0
-    assert(num_elements_ != 0);
-#endif
+                            size_type(1),std::multiplies<size_type>());
+
     this->compute_strides(stride_list_,extent_list_,storage_);
 
     origin_offset_ =
@@ -418,7 +431,9 @@ public:
   typedef typename super_type::index index;
   typedef typename super_type::extent_range extent_range;
 
-
+  typedef typename super_type::storage_order_type storage_order_type;
+  typedef typename super_type::index_list index_list;
+  typedef typename super_type::size_list size_list;
 
   template <std::size_t NDims>
   struct const_array_view {
@@ -459,10 +474,6 @@ public:
                            const general_storage_order<NumDims>& so) :
     super_type(base,ranges,so) { }
 
-  template <typename OPtr>
-  multi_array_ref(const detail::multi_array::
-                  const_sub_array<T,NumDims,OPtr>& rhs)
-    : super_type(rhs) {} 
 
   // Assignment from other ConstMultiArray types.
   template <typename ConstMultiArray>
@@ -499,11 +510,12 @@ public:
 
   template <class IndexList>
   element& operator()(const IndexList& indices) {
-  boost::function_requires<
-    detail::multi_array::CollectionConcept<IndexList> >();
-  return super_type::access_element(boost::type<element&>(),
-                                      origin(),
-                                      indices,this->strides());
+    boost::function_requires<
+      detail::multi_array::CollectionConcept<IndexList> >();
+    return super_type::access_element(boost::type<element&>(),
+                                      indices,origin(),
+                                      this->shape(),this->strides(),
+                                      this->index_bases());
   }
 
 
@@ -541,12 +553,12 @@ public:
   }
 
   iterator end() {
-    return iterator(*this->index_bases()+*this->shape(),origin(),
+    return iterator(*this->index_bases()+(index)*this->shape(),origin(),
                     this->shape(),this->strides(),
                     this->index_bases());
   }
 
-  // RG - rbegin() and rend() written naively to thwart MSVC ICE.
+  // rbegin() and rend() written naively to thwart MSVC ICE.
   reverse_iterator rbegin() {
     reverse_iterator ri(end());
     return ri;
@@ -608,10 +620,11 @@ public:
 
 protected:
   // This is only supplied to support multi_array's default constructor
-  explicit multi_array_ref(T* base) :
-    super_type(base) {
-  }
-
+  explicit multi_array_ref(T* base,
+                           const storage_order_type& so,
+                           const index* index_bases,
+                           const size_type* extents) :
+    super_type(base,so,index_bases,extents) { }
 
 };