LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
ArrayTraits.h
Go to the documentation of this file.
1 // -*- c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008, 2009, 2010, 2011 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 #ifndef NDARRAY_ArrayTraits_h_INCLUDED
24 #define NDARRAY_ArrayTraits_h_INCLUDED
25 
32 #include "ndarray_fwd.h"
34 #include "ndarray/detail/Core.h"
35 #include <boost/mpl/int.hpp>
36 #include <boost/mpl/bool.hpp>
37 
38 namespace ndarray {
39 namespace detail {
40 
41 template <int N, typename T2, int C2, typename T1, int C1>
42 struct Convertible : public boost::mpl::bool_<
43  (((C2>=C1 && C1>=0) || (C2<=C1 && C1<=0) || (N == 1 && C2 == -C1))
44  && boost::is_convertible<T2*,T1*>::value)
45 > {};
46 
47 } // namespace detail
48 
49 
55 template <typename T, int N, int C>
56 struct ArrayTraits {
57  typedef T Element;
58  typedef boost::mpl::int_<N> ND;
59  typedef boost::mpl::int_<C> RMC;
61  typedef ArrayRef<T,N-1,(N==C)?(N-1):((C>0)?C:0)> Reference;
62  typedef Array<T,N-1,(N==C)?(N-1):((C>0)?C:0)> Value;
64  typedef typename Core::ConstPtr CorePtr;
65 
66  static Reference makeReference(Element * data, CorePtr const & core) {
67  return Reference(data, core);
68  }
69  static Iterator makeIterator(Element * data, CorePtr const & core, int stride) {
70  return Iterator(Reference(data, core), stride);
71  }
72  static void fill(Iterator iter, Iterator const & end, Element value) {
73  // We can't use std::fill here because NestedIterator is not formally an STL ForwardIterator;
74  // it has random access traversal, but it does not dereference to an addressable type (see
75  // http://www.boost.org/doc/libs/1_55_0/libs/iterator/doc/new-iter-concepts.html#motivation)
76  // Most C++ standard libraries have a fill implementation that will accept NestedIterator
77  // anyway, but Clang's libc++ is more strictly compliant and does not.
78  for (; iter != end; ++iter) {
79  *iter = value;
80  }
81  }
82 };
83 
84 template <typename T>
85 struct ArrayTraits<T,1,0> {
86  typedef T Element;
87  typedef boost::mpl::int_<1> ND;
88  typedef boost::mpl::int_<0> RMC;
90  typedef Element & Reference;
91  typedef Element Value;
93  typedef typename Core::ConstPtr CorePtr;
94 
95  static Reference makeReference(Element * data, CorePtr const & core) {
96  return *data;
97  }
98  static Iterator makeIterator(Element * data, CorePtr const & core, int stride) {
99  return Iterator(data, stride);
100  }
101  static void fill(Iterator iter, Iterator const & end, Element value) {
102  std::fill(iter, end, value);
103  }
104 };
105 
106 template <typename T>
107 struct ArrayTraits<T,1,1> {
108  typedef T Element;
109  typedef boost::mpl::int_<1> ND;
110  typedef boost::mpl::int_<1> RMC;
111  typedef Element * Iterator;
112  typedef Element & Reference;
113  typedef Element Value;
115  typedef typename Core::ConstPtr CorePtr;
116 
117  static Reference makeReference(Element * data, CorePtr const & core) {
118  return *data;
119  }
120  static Iterator makeIterator(Element * data, CorePtr const & core, int stride) {
121  return data;
122  }
123  static void fill(Iterator iter, Iterator const & end, Element value) {
124  std::fill(iter, end, value);
125  }
126 };
127 
128 template <typename T>
129 struct ArrayTraits<T,1,-1> {
130  typedef T Element;
131  typedef boost::mpl::int_<1> ND;
132  typedef boost::mpl::int_<-1> RMC;
133  typedef Element * Iterator;
134  typedef Element & Reference;
135  typedef Element Value;
137  typedef typename Core::ConstPtr CorePtr;
138 
139  static Reference makeReference(Element * data, CorePtr const & core) {
140  return *data;
141  }
142  static Iterator makeIterator(Element * data, CorePtr const & core, int stride) {
143  return data;
144  }
145  static void fill(Iterator iter, Iterator const & end, Element value) {
146  std::fill(iter, end, value);
147  }
148 };
149 
150 template <typename T, int N, int C>
151 struct ExpressionTraits< Array<T,N,C> > : public ArrayTraits<T,N,C> {
153  typedef boost::mpl::false_ IsScalar;
154 };
155 
156 template <typename T, int N, int C>
157 struct ExpressionTraits< ArrayRef<T,N,C> > : public ArrayTraits<T,N,C> {
159  typedef boost::mpl::false_ IsScalar;
160 };
161 
162 } // namespace ndarray
163 
164 #endif // !NDARRAY_ArrayTraits_h_INCLUDED
int iter
A proxy class for Array with deep assignment operators.
Definition: ArrayRef.h:46
static Reference makeReference(Element *data, CorePtr const &core)
Definition: ArrayTraits.h:117
boost::mpl::int_< 1 > RMC
Definition: ArrayTraits.h:110
Dimension-specialized traits shared by Array and ArrayRef.
Definition: ArrayTraits.h:56
boost::mpl::int_< 1 > ND
Definition: ArrayTraits.h:131
boost::mpl::int_< C > RMC
Definition: ArrayTraits.h:59
Traits for Expression.
boost::intrusive_ptr< Core const > ConstPtr
const intrusive_ptr to Core
Definition: Core.h:64
Forward declarations and default template parameters for ndarray.
boost::mpl::int_<-1 > RMC
Definition: ArrayTraits.h:132
static Reference makeReference(Element *data, CorePtr const &core)
Definition: ArrayTraits.h:66
static void fill(Iterator iter, Iterator const &end, Element value)
Definition: ArrayTraits.h:101
detail::Core< N > Core
Definition: ArrayTraits.h:63
boost::mpl::int_< 1 > ND
Definition: ArrayTraits.h:109
static Iterator makeIterator(Element *data, CorePtr const &core, int stride)
Definition: ArrayTraits.h:98
static void fill(Iterator iter, Iterator const &end, Element value)
Definition: ArrayTraits.h:72
detail::StridedIterator< Element > Iterator
Definition: ArrayTraits.h:89
static Iterator makeIterator(Element *data, CorePtr const &core, int stride)
Definition: ArrayTraits.h:142
boost::mpl::int_< N > ND
Definition: ArrayTraits.h:58
Traits for expressions.
boost::mpl::int_< 0 > RMC
Definition: ArrayTraits.h:88
static Reference makeReference(Element *data, CorePtr const &core)
Definition: ArrayTraits.h:139
static void fill(Iterator iter, Iterator const &end, Element value)
Definition: ArrayTraits.h:145
boost::mpl::int_< 1 > ND
Definition: ArrayTraits.h:87
static Iterator makeIterator(Element *data, CorePtr const &core, int stride)
Definition: ArrayTraits.h:69
A multidimensional strided array.
Definition: Array.h:47
ArrayRef< T, N-1,(N==C)?(N-1):((C >0)?C:0)> Reference
Definition: ArrayTraits.h:61
Array< T, N-1,(N==C)?(N-1):((C >0)?C:0)> Value
Definition: ArrayTraits.h:62
Definitions for Core.
static Reference makeReference(Element *data, CorePtr const &core)
Definition: ArrayTraits.h:95
static Iterator makeIterator(Element *data, CorePtr const &core, int stride)
Definition: ArrayTraits.h:120
detail::NestedIterator< T, N, C > Iterator
Definition: ArrayTraits.h:60
Core::ConstPtr CorePtr
Definition: ArrayTraits.h:64
static void fill(Iterator iter, Iterator const &end, Element value)
Definition: ArrayTraits.h:123