OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vector_cast.hh
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 736 $ *
38 * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08. Okt 2012) $ *
39 * *
40 \*===========================================================================*/
41
42
43 //=============================================================================
44 //
45 // Helper Functions for binary reading / writing
46 //
47 //=============================================================================
48
49
50 #ifndef OPENMESH_VECTORCAST_HH
51 #define OPENMESH_VECTORCAST_HH
52
53
54 //== INCLUDES =================================================================
55
56
57 #include <OpenMesh/Core/System/config.h>
58 #include <OpenMesh/Core/Utils/vector_traits.hh>
59 #include <OpenMesh/Core/Utils/GenProg.hh>
60 #include <iostream>
61 #include <algorithm>
62 #include <OpenMesh/Core/Geometry/VectorT.hh>
63
64
65 //== NAMESPACES ===============================================================
66
67
68 namespace OpenMesh {
69
70
71 //=============================================================================
72
73
77
78 //-----------------------------------------------------------------------------
79
80
81 template <typename src_t, typename dst_t>
82 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<1> )
83 {
84 _dst[0] = _src[0];
85 }
86
87 template <typename src_t, typename dst_t>
88 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<2> )
89 {
90 _dst[0] = _src[0];
91 _dst[1] = _src[1];
92 }
93
94 template <typename src_t, typename dst_t>
95 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<3> )
96 {
97 _dst[0] = _src[0];
98 _dst[1] = _src[1];
99 _dst[2] = _src[2];
100 }
101
102 template <typename src_t, typename dst_t>
103 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<4> )
104 {
105 _dst[0] = _src[0];
106 _dst[1] = _src[1];
107 _dst[2] = _src[2];
108 _dst[3] = _src[3];
109 }
110
111 template <typename src_t, typename dst_t>
112 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<5> )
113 {
114 _dst[0] = _src[0];
115 _dst[1] = _src[1];
116 _dst[2] = _src[2];
117 _dst[3] = _src[3];
118 _dst[4] = _src[4];
119 }
120
121 template <typename src_t, typename dst_t>
122 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<6> )
123 {
124 _dst[0] = _src[0];
125 _dst[1] = _src[1];
126 _dst[2] = _src[2];
127 _dst[3] = _src[3];
128 _dst[4] = _src[4];
129 _dst[5] = _src[5];
130 }
131
132
133 //-----------------------------------------------------------------------------
134 #ifndef DOXY_IGNORE_THIS
135
136 template <typename dst_t, typename src_t>
137 struct vector_caster
138 {
139 typedef dst_t return_type;
140
141 inline static return_type cast(const src_t& _src)
142 {
143 dst_t dst;
144 vector_copy(_src, dst, GenProg::Int2Type<vector_traits<dst_t>::size_>());
145 return dst;
146 }
147 };
148
149 #if !defined(OM_CC_MSVC)
150 template <typename dst_t>
151 struct vector_caster<dst_t,dst_t>
152 {
153 typedef const dst_t& return_type;
154
155 inline static return_type cast(const dst_t& _src)
156 {
157 return _src;
158 }
159 };
160 #endif
161
162 #endif
163 //-----------------------------------------------------------------------------
164
165
167 template <typename dst_t, typename src_t>
168 inline
169 typename vector_caster<dst_t, src_t>::return_type
170 vector_cast(const src_t& _src )
171 {
172 return vector_caster<dst_t, src_t>::cast(_src);
173 }
174
175
177
178
179 //=============================================================================
180 } // namespace OpenMesh
181 //=============================================================================
182 #endif // OPENMESH_MESHREADER_HH defined
183 //=============================================================================