Debian Codegraph @

src/atlas/array/native/NativeArrayView.cc

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #include <initializer_list>
12 #include <ostream>
13
14 #include "atlas/array/ArrayView.h"
15 #include "atlas/array/helpers/ArrayAssigner.h"
16 #include "atlas/array/helpers/ArrayCopier.h"
17 #include "atlas/array/helpers/ArrayWriter.h"
18
19 //------------------------------------------------------------------------------------------------------
20
21 namespace atlas {
22 namespace array {
23
24 //------------------------------------------------------------------------------------------------------
25
26 #undef ENABLE_IF_NON_CONST
27 #define ENABLE_IF_NON_CONST \
28 template <bool EnableBool, typename std::enable_if<(!std::is_const<Value>::value && EnableBool), int>::type*>
29
30
31 template <typename Value, int Rank>
32 ENABLE_IF_NON_CONST void ArrayView<Value, Rank>::assign(const value_type& value) {
33 helpers::array_assigner<Value, Rank>::apply(*this, value);
34 }
35
36 //------------------------------------------------------------------------------------------------------
37
38 template <typename Value, int Rank>
39 ENABLE_IF_NON_CONST void ArrayView<Value, Rank>::assign(const std::initializer_list<value_type>& list) {
40 helpers::array_assigner<Value, Rank>::apply(*this, list);
41 }
42
43 //------------------------------------------------------------------------------------------------------
44
45
46 template <typename Value, int Rank>
47 ENABLE_IF_NON_CONST void ArrayView<Value, Rank>::assign(const ArrayView& other) {
48 helpers::array_copier<Value, Rank>::apply(other, *this);
49 }
50
51 //------------------------------------------------------------------------------------------------------
52
53 template <typename Value, int Rank>
54 ENABLE_IF_NON_CONST void ArrayView<Value, Rank>::assign(const LocalView<Value, Rank>& other) {
55 helpers::array_copier<Value, Rank>::apply(other, *this);
56 }
57
58 //------------------------------------------------------------------------------------------------------
59
60 template <typename Value, int Rank>
61 void ArrayView<Value, Rank>::dump(std::ostream& os) const {
62 os << "size: " << size() << " , values: ";
63 os << "[ ";
64 helpers::array_writer::apply(*this, os);
65 os << " ]";
66 }
67
68 //------------------------------------------------------------------------------------------------------
69
70 } // namespace array
71 } // namespace atlas
72
73 //-----------------------------------------------------------------------
74 // Explicit instantiation
75 namespace atlas {
76 namespace array {
77 #define EXPLICIT_TEMPLATE_INSTANTIATION(Rank) \
78 template class ArrayView<int, Rank>; \
79 template class ArrayView<const int, Rank>; \
80 template class ArrayView<long, Rank>; \
81 template class ArrayView<const long, Rank>; \
82 template class ArrayView<unsigned int, Rank>; \
83 template class ArrayView<const unsigned int, Rank>; \
84 template class ArrayView<long unsigned, Rank>; \
85 template class ArrayView<const long unsigned, Rank>; \
86 template class ArrayView<float, Rank>; \
87 template class ArrayView<const float, Rank>; \
88 template class ArrayView<double, Rank>; \
89 template class ArrayView<const double, Rank>; \
90 template void ArrayView<int, Rank>::assign<true, nullptr>(int const&); \
91 template void ArrayView<long, Rank>::assign<true, nullptr>(long const&); \
92 template void ArrayView<float, Rank>::assign<true, nullptr>(float const&); \
93 template void ArrayView<double, Rank>::assign<true, nullptr>(double const&); \
94 template void ArrayView<int, Rank>::assign<true, nullptr>(std::initializer_list<int> const&); \
95 template void ArrayView<long, Rank>::assign<true, nullptr>(std::initializer_list<long> const&); \
96 template void ArrayView<float, Rank>::assign<true, nullptr>(std::initializer_list<float> const&); \
97 template void ArrayView<double, Rank>::assign<true, nullptr>(std::initializer_list<double> const&); \
98 template void ArrayView<int, Rank>::assign<true, nullptr>(ArrayView<int, Rank> const&); \
99 template void ArrayView<long, Rank>::assign<true, nullptr>(ArrayView<long, Rank> const&); \
100 template void ArrayView<float, Rank>::assign<true, nullptr>(ArrayView<float, Rank> const&); \
101 template void ArrayView<double, Rank>::assign<true, nullptr>(ArrayView<double, Rank> const&); \
102 template void ArrayView<int, Rank>::assign<true, nullptr>(LocalView<int, Rank> const&); \
103 template void ArrayView<long, Rank>::assign<true, nullptr>(LocalView<long, Rank> const&); \
104 template void ArrayView<float, Rank>::assign<true, nullptr>(LocalView<float, Rank> const&); \
105 template void ArrayView<double, Rank>::assign<true, nullptr>(LocalView<double, Rank> const&);
106
107 // For each NDims in [1..9]
108 EXPLICIT_TEMPLATE_INSTANTIATION(1)
109 EXPLICIT_TEMPLATE_INSTANTIATION(2)
110 EXPLICIT_TEMPLATE_INSTANTIATION(3)
111 EXPLICIT_TEMPLATE_INSTANTIATION(4)
112 EXPLICIT_TEMPLATE_INSTANTIATION(5)
113 EXPLICIT_TEMPLATE_INSTANTIATION(6)
114 EXPLICIT_TEMPLATE_INSTANTIATION(7)
115 EXPLICIT_TEMPLATE_INSTANTIATION(8)
116 EXPLICIT_TEMPLATE_INSTANTIATION(9)
117
118 #undef EXPLICIT_TEMPLATE_INSTANTIATION
119
120 } // namespace array
121 } // namespace atlas