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_44EB56F0A33711DEB31B41BB56D89593
7 #define UUID_44EB56F0A33711DEB31B41BB56D89593
8 
9 #include <boost/qvm/inline.hpp>
10 #include <boost/qvm/assert.hpp>
11 #include <boost/qvm/static_assert.hpp>
12 
13 namespace
14 boost
15     {
16     namespace
17     qvm
18         {
19         template <class T,int D>
20         struct
21         vec
22             {
23             T a[D];
24             template <class R>
operator Rboost::qvm::vec25             operator R() const
26                 {
27                 R r;
28                 assign(r,*this);
29                 return r;
30                 }
31             };
32 
33         template <class V>
34         struct vec_traits;
35 
36         template <class T,int Dim>
37         struct
38         vec_traits< vec<T,Dim> >
39             {
40             typedef vec<T,Dim> this_vector;
41             typedef T scalar_type;
42             static int const dim=Dim;
43 
44             template <int I>
45             static
46             BOOST_QVM_INLINE_CRITICAL
47             scalar_type
read_elementboost::qvm::vec_traits48             read_element( this_vector const & x )
49                 {
50                 BOOST_QVM_STATIC_ASSERT(I>=0);
51                 BOOST_QVM_STATIC_ASSERT(I<dim);
52                 return x.a[I];
53                 }
54 
55             template <int I>
56             static
57             BOOST_QVM_INLINE_CRITICAL
58             scalar_type &
write_elementboost::qvm::vec_traits59             write_element( this_vector & x )
60                 {
61                 BOOST_QVM_STATIC_ASSERT(I>=0);
62                 BOOST_QVM_STATIC_ASSERT(I<dim);
63                 return x.a[I];
64                 }
65 
66             static
67             BOOST_QVM_INLINE_CRITICAL
68             scalar_type
read_element_idxboost::qvm::vec_traits69             read_element_idx( int i, this_vector const & x )
70                 {
71                 BOOST_QVM_ASSERT(i>=0);
72                 BOOST_QVM_ASSERT(i<dim);
73                 return x.a[i];
74                 }
75 
76             static
77             BOOST_QVM_INLINE_CRITICAL
78             scalar_type &
write_element_idxboost::qvm::vec_traits79             write_element_idx( int i, this_vector & x )
80                 {
81                 BOOST_QVM_ASSERT(i>=0);
82                 BOOST_QVM_ASSERT(i<dim);
83                 return x.a[i];
84                 }
85             };
86         }
87     }
88 
89 #endif
90