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