]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | #ifndef BOOST_QVM_VEC_TRAITS_ARRAY_HPP_INCLUDED |
2 | #define BOOST_QVM_VEC_TRAITS_ARRAY_HPP_INCLUDED | |
92f5a8d4 | 3 | |
1e59de90 | 4 | // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc. |
92f5a8d4 | 5 | |
1e59de90 TL |
6 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
7 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
92f5a8d4 TL |
8 | |
9 | #include <boost/qvm/inline.hpp> | |
10 | #include <boost/qvm/deduce_vec.hpp> | |
11 | #include <boost/qvm/detail/remove_const.hpp> | |
12 | #include <boost/qvm/assert.hpp> | |
13 | ||
1e59de90 TL |
14 | namespace boost { namespace qvm { |
15 | ||
16 | template <class T,int M,int N> | |
17 | struct | |
18 | vec_traits<T[M][N]> | |
19 | { | |
20 | static int const dim=0; | |
21 | typedef void scalar_type; | |
22 | }; | |
23 | ||
24 | template <class T,int Dim> | |
25 | struct | |
26 | vec_traits<T[Dim]> | |
92f5a8d4 | 27 | { |
1e59de90 TL |
28 | typedef T this_vector[Dim]; |
29 | typedef typename qvm_detail::remove_const<T>::type scalar_type; | |
30 | static int const dim=Dim; | |
31 | ||
32 | template <int I> | |
33 | static | |
34 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL | |
35 | scalar_type | |
36 | read_element( this_vector const & x ) | |
37 | { | |
38 | BOOST_QVM_STATIC_ASSERT(I>=0); | |
39 | BOOST_QVM_STATIC_ASSERT(I<Dim); | |
40 | return x[I]; | |
41 | } | |
42 | ||
43 | template <int I> | |
44 | static | |
45 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL | |
46 | scalar_type & | |
47 | write_element( this_vector & x ) | |
48 | { | |
49 | BOOST_QVM_STATIC_ASSERT(I>=0); | |
50 | BOOST_QVM_STATIC_ASSERT(I<Dim); | |
51 | return x[I]; | |
52 | } | |
53 | ||
54 | static | |
55 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL | |
56 | scalar_type | |
57 | read_element_idx( int i, this_vector const & x ) | |
58 | { | |
59 | BOOST_QVM_ASSERT(i>=0); | |
60 | BOOST_QVM_ASSERT(i<Dim); | |
61 | return x[i]; | |
62 | } | |
63 | ||
64 | static | |
65 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL | |
66 | scalar_type & | |
67 | write_element_idx( int i, this_vector & x ) | |
92f5a8d4 | 68 | { |
1e59de90 TL |
69 | BOOST_QVM_ASSERT(i>=0); |
70 | BOOST_QVM_ASSERT(i<Dim); | |
71 | return x[i]; | |
92f5a8d4 | 72 | } |
1e59de90 TL |
73 | }; |
74 | ||
75 | template <class T,int Dim,int D> | |
76 | struct | |
77 | deduce_vec<T[Dim],D> | |
78 | { | |
79 | typedef vec<T,D> type; | |
80 | }; | |
81 | ||
82 | template <class T,int Dim,int D> | |
83 | struct | |
84 | deduce_vec<T const[Dim],D> | |
85 | { | |
86 | typedef vec<T,D> type; | |
87 | }; | |
88 | ||
89 | template <class T1,class T2,int Dim,int D> | |
90 | struct | |
91 | deduce_vec2<T1[Dim],T2[Dim],D> | |
92 | { | |
93 | typedef vec<typename deduce_scalar<T1,T2>::type,D> type; | |
94 | }; | |
95 | ||
96 | template <int Dim,class T> | |
97 | T (&ptr_vref( T * ptr ))[Dim] | |
98 | { | |
99 | return *reinterpret_cast<T (*)[Dim]>(ptr); | |
92f5a8d4 TL |
100 | } |
101 | ||
1e59de90 TL |
102 | } } |
103 | ||
92f5a8d4 | 104 | #endif |