]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | //Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc. |
2 | ||
3 | //Distributed under the Boost Software License, Version 1.0. (See accompanying | |
4 | //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | #ifndef UUID_7FF8E2E00E5411E2AB79F7FE6188709B | |
7 | #define UUID_7FF8E2E00E5411E2AB79F7FE6188709B | |
8 | ||
9 | #include <boost/qvm/vec_traits.hpp> | |
10 | #include <boost/qvm/inline.hpp> | |
11 | #include <boost/qvm/assert.hpp> | |
12 | #include <boost/qvm/enable_if.hpp> | |
13 | #include <boost/qvm/error.hpp> | |
14 | #include <boost/exception/info.hpp> | |
15 | ||
16 | namespace | |
17 | boost | |
18 | { | |
19 | namespace | |
20 | qvm | |
21 | { | |
22 | //////////////////////////////////////////////// | |
23 | ||
24 | namespace | |
25 | qvm_detail | |
26 | { | |
27 | template <int D> | |
28 | struct | |
29 | vec_index_read_defined | |
30 | { | |
31 | static bool const value=false; | |
32 | }; | |
33 | ||
34 | template <int I,int N> | |
35 | struct | |
36 | vector_r | |
37 | { | |
38 | template <class A> | |
39 | static | |
40 | BOOST_QVM_INLINE_CRITICAL | |
41 | typename vec_traits<A>::scalar_type | |
42 | read_element_idx( A const & a, int i ) | |
43 | { | |
44 | return I==i? | |
45 | vec_traits<A>::template read_element<I>(a) : | |
46 | vector_r<I+1,N>::read_element_idx(a,i); | |
47 | } | |
48 | }; | |
49 | ||
50 | template <int N> | |
51 | struct | |
52 | vector_r<N,N> | |
53 | { | |
54 | template <class A> | |
55 | static | |
56 | BOOST_QVM_INLINE_TRIVIAL | |
57 | typename vec_traits<A>::scalar_type | |
58 | read_element_idx( A const & a, int ) | |
59 | { | |
60 | BOOST_QVM_ASSERT(0); | |
61 | return vec_traits<A>::template read_element<0>(a); | |
62 | } | |
63 | }; | |
64 | } | |
65 | ||
66 | template <class A> | |
67 | BOOST_QVM_INLINE_TRIVIAL | |
68 | typename boost::enable_if_c< | |
69 | is_vec<A>::value && | |
70 | !qvm_detail::vec_index_read_defined<vec_traits<A>::dim>::value, | |
71 | typename vec_traits<A>::scalar_type>::type | |
72 | vec_index_read( A const & a, int i ) | |
73 | { | |
74 | return qvm_detail::vector_r<0,vec_traits<A>::dim>::read_element_idx(a,i); | |
75 | } | |
76 | ||
77 | //////////////////////////////////////////////// | |
78 | ||
79 | namespace | |
80 | qvm_detail | |
81 | { | |
82 | template <int D> | |
83 | struct | |
84 | vec_index_write_defined | |
85 | { | |
86 | static bool const value=false; | |
87 | }; | |
88 | ||
89 | template <int I,int N> | |
90 | struct | |
91 | vector_w | |
92 | { | |
93 | template <class A> | |
94 | static | |
95 | BOOST_QVM_INLINE_CRITICAL | |
96 | typename vec_traits<A>::scalar_type & | |
97 | write_element_idx( A & a, int i ) | |
98 | { | |
99 | return I==i? | |
100 | vec_traits<A>::template write_element<I>(a) : | |
101 | vector_w<I+1,N>::write_element_idx(a,i); | |
102 | } | |
103 | }; | |
104 | ||
105 | template <int N> | |
106 | struct | |
107 | vector_w<N,N> | |
108 | { | |
109 | template <class A> | |
110 | static | |
111 | BOOST_QVM_INLINE_TRIVIAL | |
112 | typename vec_traits<A>::scalar_type & | |
113 | write_element_idx( A & a, int ) | |
114 | { | |
115 | BOOST_QVM_ASSERT(0); | |
116 | return vec_traits<A>::template write_element<0>(a); | |
117 | } | |
118 | }; | |
119 | } | |
120 | ||
121 | template <class A> | |
122 | BOOST_QVM_INLINE_TRIVIAL | |
123 | typename boost::enable_if_c< | |
124 | is_vec<A>::value && | |
125 | !qvm_detail::vec_index_write_defined<vec_traits<A>::dim>::value, | |
126 | typename vec_traits<A>::scalar_type &>::type | |
127 | vec_index_write( A & a, int i ) | |
128 | { | |
129 | return qvm_detail::vector_w<0,vec_traits<A>::dim>::write_element_idx(a,i); | |
130 | } | |
131 | ||
132 | //////////////////////////////////////////////// | |
133 | ||
134 | namespace | |
135 | sfinae | |
136 | { | |
137 | using ::boost::qvm::vec_index_read; | |
138 | using ::boost::qvm::vec_index_write; | |
139 | } | |
140 | ||
141 | //////////////////////////////////////////////// | |
142 | } | |
143 | } | |
144 | ||
145 | #endif |