]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' |
2 | 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> | |
3 | <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'> | |
4 | <head> | |
5 | <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/> | |
6 | <title>vec_traits</title> | |
7 | <link href='reno.css' type='text/css' rel='stylesheet'/> | |
8 | </head> | |
9 | <body> | |
10 | <div class="body-0"> | |
11 | <div class="body-1"> | |
12 | <div class="body-2"> | |
13 | <div> | |
14 | <h1>QVM: Quaternions, Vectors, Matrices</h1> | |
15 | </div> | |
16 | <!-- Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc. --> | |
17 | <!-- Distributed under the Boost Software License, Version 1.0. (See accompanying --> | |
18 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> | |
19 | <div class="RenoIncludeDIV"><div class="RenoAutoDIV"><h3>vec_traits</h3> | |
20 | </div> | |
21 | <div class="RenoIncludeDIV"><p><span class="RenoEscape">#<!--<wiki>`#</wiki>--></span>include <<span class="RenoLink"><a href="boost_qvm_vec_traits_hpp.html">boost/qvm/vec_traits.hpp</a></span>></p> | |
22 | <pre>namespace | |
23 | boost | |
24 | { | |
25 | namespace | |
26 | <span class="RenoLink"><a href="qvm.html">qvm</a></span> | |
27 | { | |
28 | <span class="RenoIncludeSPAN"> template <class V> | |
29 | struct <span class="RenoLink">vec_traits</span> | |
30 | { | |
31 | /*main template members unspecified*/ | |
32 | }; | |
33 | ||
34 | /* | |
35 | User-defined (possibly partial) specializations: | |
36 | ||
37 | template <> | |
38 | struct <span class="RenoLink">vec_traits</span><V> | |
39 | { | |
40 | <span class="RenoIncludeSPAN"> static int const <span class="RenoLink"><a href="vec_traits_Vector_dim.html">dim</a></span> = /*user-defined*/;</span> | |
41 | <span class="RenoIncludeSPAN"> typedef /*user-defined*/ <span class="RenoLink"><a href="vec_traits_V_scalar_type.html">scalar_type</a></span>;</span> | |
42 | ||
43 | <span class="RenoIncludeSPAN"> template <int I> static inline <span class="RenoLink"><a href="vec_traits_V_scalar_type.html">scalar_type</a></span> <span class="RenoLink"><a href="vec_traits_V_read_element.html">read_element</a></span>( Vector const & v );</span> | |
44 | <span class="RenoIncludeSPAN"> template <int I> static inline <span class="RenoLink"><a href="vec_traits_V_scalar_type.html">scalar_type</a></span> & <span class="RenoLink"><a href="vec_traits_V_write_element.html">write_element</a></span>( Vector & v );</span> | |
45 | ||
46 | <span class="RenoIncludeSPAN"> static inline <span class="RenoLink"><a href="vec_traits_V_scalar_type.html">scalar_type</a></span> <span class="RenoLink"><a href="vec_traits_V_read_element_idx.html">read_element_idx</a></span>( int i, Vector const & v );</span> | |
47 | <span class="RenoIncludeSPAN"> static inline <span class="RenoLink"><a href="vec_traits_V_scalar_type.html">scalar_type</a></span> & <span class="RenoLink"><a href="vec_traits_V_write_element_idx.html">write_element_idx</a></span>( int i, Vector & v );</span> | |
48 | }; | |
49 | */</span> | |
50 | } | |
51 | }</pre> | |
52 | </div><p>The <i><span class="RenoLink">vec_traits</span></i> template must be specialized for (user-defined) vector types in order to enable vector and matrix operations defined in Boost QVM headers for objects of those types.</p> | |
53 | <p><i>Note: vector types are not required to be copyable.</i></p> | |
54 | <p>The main <i><span class="RenoLink">vec_traits</span></i> template members are not specified. Valid specializations are required to define the following members:</p> | |
55 | <div><ul><li> <i><span class="RenoLink"><a href="vec_traits_Vector_dim.html">dim</a></span></i>: the expression <i><span class="RenoLink">vec_traits</span><Vector>::<span class="RenoLink"><a href="vec_traits_Vector_dim.html">dim</a></span></i> must evaluate to a compile-time integer constant greater than 0 that specifies the vector size.</li> | |
56 | <li> <i><span class="RenoLink"><a href="vec_traits_V_scalar_type.html">scalar_type</a></span></i>: the expression <i><span class="RenoLink">vec_traits</span><Vector>::<span class="RenoLink"><a href="vec_traits_V_scalar_type.html">scalar_type</a></span></i> must be a value type which satisfies the <span class="RenoLink"><a href="scalar_requirements.html">scalar requirements</a></span>.</li> | |
57 | </ul></div> | |
58 | <p>In addition, valid specializations of the <i><span class="RenoLink">vec_traits</span></i> template may define the following access functions as static members, where <i>v</i> is an object of type <i>Vector</i>, <i>I</i> is a compile-time integer constant, and <i>i</i> is a variable of type <i>int</i>:</p> | |
59 | <div><ul><li> <i><span class="RenoLink"><a href="vec_traits_V_read_element.html">read_element</a></span></i>: the expression <i><span class="RenoLink">vec_traits</span><Vector>::<span class="RenoLink"><a href="vec_traits_V_read_element.html">read_element</a></span><I>(v)</i> returns either a copy of or a const reference to the <i>I</i>-th element of <i>v</i>.</li> | |
60 | <li> <i><span class="RenoLink"><a href="vec_traits_V_write_element.html">write_element</a></span></i>: the expression <i><span class="RenoLink">vec_traits</span><Vector>::<span class="RenoLink"><a href="vec_traits_V_write_element.html">write_element</a></span><I>(v)</i> returns mutable reference to the <i>I</i>-th element of <i>v</i>.</li> | |
61 | <li> <i><span class="RenoLink"><a href="vec_traits_V_read_element_idx.html">read_element_idx</a></span></i>: the expression <i><span class="RenoLink">vec_traits</span><Vector>::<span class="RenoLink"><a href="vec_traits_V_read_element_idx.html">read_element_idx</a></span>(i,v)</i> returns either a copy of or a const reference to the <i>i</i>-th element of <i>v</i>.</li> | |
62 | <li> <i><span class="RenoLink"><a href="vec_traits_V_write_element_idx.html">write_element_idx</a></span></i>: the expression <i><span class="RenoLink">vec_traits</span><Vector>::<span class="RenoLink"><a href="vec_traits_V_write_element_idx.html">write_element_idx</a></span>(i,v)</i> returns mutable reference to the <i>i</i>-th element of <i>v</i>.</li> | |
63 | </ul></div> | |
64 | <p>It is illegal to call any of the above functions unless <i><span class="RenoLink"><a href="is_vec.html">is_vec</a></span><Vector>::value</i> is <i>true</i>. Even then, vector types are allowed to define only a subset of the access functions. The general requirements are:</p> | |
65 | <div><ul><li> At least one of <i><span class="RenoLink"><a href="vec_traits_V_read_element.html">read_element</a></span></i> or <i><span class="RenoLink"><a href="vec_traits_V_write_element.html">write_element</a></span></i> must be defined;</li> | |
66 | <li> If <i><span class="RenoLink"><a href="vec_traits_V_read_element_idx.html">read_element_idx</a></span></i> is defined, <i><span class="RenoLink"><a href="vec_traits_V_read_element.html">read_element</a></span></i> must also be defined;</li> | |
67 | <li> If <i><span class="RenoLink"><a href="vec_traits_V_write_element_idx.html">write_element_idx</a></span></i> is defined, <i><span class="RenoLink"><a href="vec_traits_V_write_element.html">write_element</a></span></i> must also be defined.</li> | |
68 | </ul></div> | |
69 | <p>Below is an example of a user-defined 3D vector type, and its corresponding specialization of the <i><span class="RenoLink">vec_traits</span></i> template:</p> | |
70 | <div class="RenoIncludeDIV"><pre>#include <<span class="RenoLink"><a href="boost_qvm_vec_traits_hpp.html">boost/qvm/vec_traits.hpp</a></span>> | |
71 | ||
72 | struct float3 { float a[3]; }; | |
73 | ||
74 | namespace boost | |
75 | { | |
76 | namespace <span class="RenoLink"><a href="qvm.html">qvm</a></span> | |
77 | { | |
78 | template <> | |
79 | struct <span class="RenoLink">vec_traits</span><float3> | |
80 | { | |
81 | static int const <span class="RenoLink"><a href="vec_traits_Vector_dim.html">dim</a></span>=3; | |
82 | typedef float <span class="RenoLink"><a href="vec_traits_V_scalar_type.html">scalar_type</a></span>; | |
83 | ||
84 | template <int I> static inline <span class="RenoLink"><a href="vec_traits_V_scalar_type.html">scalar_type</a></span> & <span class="RenoLink"><a href="vec_traits_V_write_element.html">write_element</a></span>( float3 & v ) { return v.a[I]; } | |
85 | template <int I> static inline <span class="RenoLink"><a href="vec_traits_V_scalar_type.html">scalar_type</a></span> <span class="RenoLink"><a href="vec_traits_V_read_element.html">read_element</a></span>( float3 const & v ) { return v.a[I]; } | |
86 | ||
87 | static inline <span class="RenoLink"><a href="vec_traits_V_scalar_type.html">scalar_type</a></span> & <span class="RenoLink"><a href="vec_traits_V_write_element_idx.html">write_element_idx</a></span>( int i, float3 & v ) { return v.a[i]; } //optional | |
88 | static inline <span class="RenoLink"><a href="vec_traits_V_scalar_type.html">scalar_type</a></span> <span class="RenoLink"><a href="vec_traits_V_read_element_idx.html">read_element_idx</a></span>( int i, float3 const & v ) { return v.a[i]; } //optional | |
89 | }; | |
90 | } | |
91 | }</pre> | |
92 | </div></div><div class="RenoAutoDIV"><div class="RenoHR"><hr/></div> | |
93 | See also: <span class="RenoPageList"><a href="assign_vec_vec_.html">assign(vec,vec)</a> | <a href="boost_qvm_vec_traits_hpp.html">boost/qvm/vec_traits.hpp</a> | <a href="boost_qvm_vec_traits_array_hpp.html">boost/qvm/vec_traits_array.hpp</a> | <a href="cmp_vec_vec_.html">cmp(vec,vec)</a> | <a href="convert_to_vec_.html">convert_to(vec)</a> | <a href="cross.html">cross</a> | <a href="deduce_vec.html">deduce_vec</a> | <a href="deduce_vec2.html">deduce_vec2</a> | <a href="dot_vec_vec_.html">dot(vec,vec)</a> | <a href="is_vec.html">is_vec</a> | <a href="mag_vec_.html">mag(vec)</a> | <a href="mag_sqr_vec_.html">mag_sqr(vec)</a> | <a href="normalize_vec_.html">normalize(vec)</a> | <a href="operator_not_eq_vec_vec_.html">operator!=(vec,vec)</a> | <a href="operator_times_mat_vec_.html">operator*(mat,vec)</a> | <a href="operator_times_quat_vec_.html">operator*(quat,vec)</a> | <a href="operator_times_vec_mat_.html">operator*(vec,mat)</a> | <a href="operator_plus_vec_vec_.html">operator+(vec,vec)</a> | <a href="operator_add_vec_vec_.html">operator+=(vec,vec)</a> | <a href="operator_minus_vec_vec_.html">operator-(vec,vec)</a> | <a href="operator_sub_eq_vec_vec_.html">operator-=(vec,vec)</a> | <a href="operator_eq_vec_vec_.html">operator==(vec,vec)</a> | <a href="rot_mat.html">rot_mat</a> | <a href="rot_quat.html">rot_quat</a> | <a href="rotate_mat_vec_scalar_.html">rotate(mat,vec,scalar)</a> | <a href="rotate_quat_vec_scalar_.html">rotate(quat,vec,scalar)</a> | <a href="SFINAE_enable_if.html">SFINAE/enable_if</a> | <a href="scalar.html">scalar</a> | <a href="set_rot_mat_vec_scalar_.html">set_rot(mat,vec,scalar)</a> | <a href="set_rot_quat_vec_scalar_.html">set_rot(quat,vec,scalar)</a> | <a href="set_zero_vec_.html">set_zero(vec)</a> | <a href="transform_point.html">transform_point</a> | <a href="transform_vector.html">transform_vector</a> | <a href="view_proxy.html">View Proxy</a> | <a href="vec.html">vec</a> | <a href="vec_index_read.html">vec_index_read</a> | <a href="vec_index_write.html">vec_index_write</a> | <a href="vec_traits_V_read_element.html">vec_traits<V>::read_element</a> | <a href="vec_traits_V_read_element_idx.html">vec_traits<V>::read_element_idx</a> | <a href="vec_traits_V_scalar_type.html">vec_traits<V>::scalar_type</a> | <a href="vec_traits_V_write_element.html">vec_traits<V>::write_element</a> | <a href="vec_traits_V_write_element_idx.html">vec_traits<V>::write_element_idx</a> | <a href="vec_traits_Vector_dim.html">vec_traits<Vector>::dim</a></span> | |
94 | </div> | |
95 | <!-- Copyright (c) 2008-2016 Emil Dotchevski and Reverge Studios, Inc. --> | |
96 | <!-- Distributed under the Boost Software License, Version 1.0. (See accompanying --> | |
97 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> | |
98 | <div id="footer"> | |
99 | <p> | |
100 | <a class="logo" href="http://jigsaw.w3.org/css-validator/check/referer"><img class="logo_pic" src="valid-css.png" alt="Valid CSS" height="31" width="88"/></a> | |
101 | <a class="logo" href="http://validator.w3.org/check?uri=referer"><img class="logo_pic" src="valid-xhtml.png" alt="Valid XHTML 1.0" height="31" width="88"/></a> | |
102 | <small>Copyright (c) 2008-2016 by Emil Dotchevski and Reverge Studios, Inc.<br/> | |
103 | Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License, Version 1.0</a>.</small> | |
104 | </p> | |
105 | </div> | |
106 | </div> | |
107 | </div> | |
108 | </div> | |
109 | </body> | |
110 | </html> |