Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

vector_cast.hh

00001 //=============================================================================
00002 //                                                                            
00003 //                               OpenMesh                                     
00004 //      Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen       
00005 //                           www.openmesh.org                                 
00006 //                                                                            
00007 //-----------------------------------------------------------------------------
00008 //                                                                            
00009 //                                License                                     
00010 //                                                                            
00011 //   This library is free software; you can redistribute it and/or modify it 
00012 //   under the terms of the GNU Library General Public License as published  
00013 //   by the Free Software Foundation, version 2.                             
00014 //                                                                             
00015 //   This library is distributed in the hope that it will be useful, but       
00016 //   WITHOUT ANY WARRANTY; without even the implied warranty of                
00017 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         
00018 //   Library General Public License for more details.                          
00019 //                                                                            
00020 //   You should have received a copy of the GNU Library General Public         
00021 //   License along with this library; if not, write to the Free Software       
00022 //   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 
00023 //                                                                            
00024 //-----------------------------------------------------------------------------
00025 //                                                                            
00026 //   $Revision: 1.1.1.1 $
00027 //   $Date: 2004/09/06 12:35:37 $
00028 //                                                                            
00029 //=============================================================================
00030 
00031 
00032 //=============================================================================
00033 //
00034 //  Helper Functions for binary reading / writing
00035 //
00036 //=============================================================================
00037 
00038 
00039 #ifndef OPENMESH_VECTORCAST_HH
00040 #define OPENMESH_VECTORCAST_HH
00041 
00042 
00043 //== INCLUDES =================================================================
00044 
00045 
00046 #include <OpenMesh/Core/System/config.hh>
00047 #include <OpenMesh/Core/Utils/vector_traits.hh>
00048 #include <OpenMesh/Core/Utils/GenProg.hh>
00049 #include <iostream>
00050 #include <algorithm>
00051 #include <OpenMesh/Core/Math/VectorT.hh>
00052 
00053 
00054 //== NAMESPACES ===============================================================
00055 
00056 
00057 namespace OpenMesh {
00058 
00059 
00060 //=============================================================================
00061 
00062 
00066 
00067 //-----------------------------------------------------------------------------
00068 
00069 
00070 template <typename src_t, typename dst_t>
00071 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<1> )
00072 {
00073   _dst[0] = _src[0];
00074 }
00075 
00076 template <typename src_t, typename dst_t>
00077 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<2> )
00078 {
00079   _dst[0] = _src[0];
00080   _dst[1] = _src[1];
00081 }
00082 
00083 template <typename src_t, typename dst_t>
00084 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<3> )
00085 {
00086   _dst[0] = _src[0];
00087   _dst[1] = _src[1];
00088   _dst[2] = _src[2];
00089 }
00090 
00091 template <typename src_t, typename dst_t>
00092 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<4> )
00093 {
00094   _dst[0] = _src[0];
00095   _dst[1] = _src[1];
00096   _dst[2] = _src[2];
00097   _dst[3] = _src[3];
00098 }
00099 
00100 template <typename src_t, typename dst_t>
00101 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<5> )
00102 {
00103   _dst[0] = _src[0];
00104   _dst[1] = _src[1];
00105   _dst[2] = _src[2];
00106   _dst[3] = _src[3];
00107   _dst[4] = _src[4];
00108 }
00109 
00110 template <typename src_t, typename dst_t>
00111 inline void vector_copy( const src_t &_src, dst_t &_dst, GenProg::Int2Type<6> )
00112 {
00113   _dst[0] = _src[0];
00114   _dst[1] = _src[1];
00115   _dst[2] = _src[2];
00116   _dst[3] = _src[3];
00117   _dst[4] = _src[4];
00118   _dst[5] = _src[5];
00119 }
00120 
00121 
00122 //-----------------------------------------------------------------------------
00123 #ifndef DOXY_IGNORE_THIS
00124 
00125 template <typename dst_t, typename src_t>
00126 struct vector_caster
00127 {
00128   typedef dst_t  return_type;
00129 
00130   inline static return_type cast(const src_t& _src)
00131   {
00132     dst_t dst;
00133     vector_copy(_src, dst, GenProg::Int2Type<vector_traits<dst_t>::size_>());
00134     return dst;
00135   }
00136 };
00137 
00138 #if !defined(OM_CC_MSVC)
00139 template <typename dst_t>
00140 struct vector_caster<dst_t,dst_t>
00141 {
00142   typedef const dst_t&  return_type;
00143 
00144   inline static return_type cast(const dst_t& _src)
00145   {
00146     return _src;
00147   }
00148 };
00149 #endif
00150 
00151 #endif
00152 //-----------------------------------------------------------------------------
00153 
00154 
00156 template <typename dst_t, typename src_t>
00157 inline
00158 typename vector_caster<dst_t, src_t>::return_type
00159 vector_cast(const src_t& _src )
00160 {
00161   return vector_caster<dst_t, src_t>::cast(_src);
00162 }
00163 
00164 
00166 
00167 
00168 //=============================================================================
00169 } // namespace OpenMesh
00170 //=============================================================================
00171 #endif // OPENMESH_MESHREADER_HH defined
00172 //=============================================================================

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .