00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #define OPENMESH_IO_OMFORMAT_CC
00051
00052
00053
00054
00055 #include <OpenMesh/Core/IO/OMFormat.hh>
00056 #include <algorithm>
00057 #include <iomanip>
00058
00059
00060
00061 namespace OpenMesh {
00062 namespace IO {
00063
00064
00065 template< typename T >
00066 size_t
00067 store( std::ostream& _os,
00068 const T& _val,
00069 OMFormat::Chunk::Integer_Size _b,
00070 bool _swap,
00071 t_signed)
00072 {
00073 assert( OMFormat::is_integer( _val ) );
00074
00075 switch( _b )
00076 {
00077 case OMFormat::Chunk::Integer_8:
00078 {
00079 OMFormat::int8 v = static_cast<OMFormat::int8>(_val);
00080 return store( _os, v, _swap );
00081 }
00082 case OMFormat::Chunk::Integer_16:
00083 {
00084 OMFormat::int16 v = static_cast<OMFormat::int16>(_val);
00085 return store( _os, v, _swap );
00086 }
00087 case OMFormat::Chunk::Integer_32:
00088 {
00089 OMFormat::int32 v = static_cast<OMFormat::int32>(_val);
00090 return store( _os, v, _swap );
00091 }
00092 case OMFormat::Chunk::Integer_64:
00093 {
00094 OMFormat::int64 v = static_cast<OMFormat::int64>(_val);
00095 return store( _os, v, _swap );
00096 }
00097 }
00098 return 0;
00099 }
00100
00101
00102
00103 template< typename T >
00104 size_t
00105 store( std::ostream& _os,
00106 const T& _val,
00107 OMFormat::Chunk::Integer_Size _b,
00108 bool _swap,
00109 t_unsigned)
00110 {
00111 assert( OMFormat::is_integer( _val ) );
00112
00113 switch( _b )
00114 {
00115 case OMFormat::Chunk::Integer_8:
00116 {
00117 OMFormat::uint8 v = static_cast<OMFormat::uint8>(_val);
00118 return store( _os, v, _swap );
00119 }
00120 case OMFormat::Chunk::Integer_16:
00121 {
00122 OMFormat::uint16 v = static_cast<OMFormat::uint16>(_val);
00123 return store( _os, v, _swap );
00124 }
00125 case OMFormat::Chunk::Integer_32:
00126 {
00127 OMFormat::uint32 v = static_cast<OMFormat::uint32>(_val);
00128 return store( _os, v, _swap );
00129 }
00130
00131 case OMFormat::Chunk::Integer_64:
00132 {
00133 OMFormat::uint64 v = static_cast<OMFormat::uint64>(_val);
00134 return store( _os, v, _swap );
00135 }
00136 }
00137 return 0;
00138 }
00139
00140
00141
00142 template< typename T >
00143 size_t
00144 restore( std::istream& _is,
00145 T& _val,
00146 OMFormat::Chunk::Integer_Size _b,
00147 bool _swap,
00148 t_signed)
00149 {
00150 assert( OMFormat::is_integer( _val ) );
00151 size_t bytes = 0;
00152
00153 switch( _b )
00154 {
00155 case OMFormat::Chunk::Integer_8:
00156 {
00157 OMFormat::int8 v;
00158 bytes = restore( _is, v, _swap );
00159 _val = static_cast<T>(v);
00160 break;
00161 }
00162 case OMFormat::Chunk::Integer_16:
00163 {
00164 OMFormat::int16 v;
00165 bytes = restore( _is, v, _swap );
00166 _val = static_cast<T>(v);
00167 }
00168 case OMFormat::Chunk::Integer_32:
00169 {
00170 OMFormat::int32 v;
00171 bytes = restore( _is, v, _swap );
00172 _val = static_cast<T>(v);
00173 }
00174 case OMFormat::Chunk::Integer_64:
00175 {
00176 OMFormat::int64 v;
00177 bytes = restore( _is, v, _swap );
00178 _val = static_cast<T>(v);
00179 }
00180 }
00181 return bytes;
00182 }
00183
00184
00185
00186 template< typename T >
00187 size_t
00188 restore( std::istream& _is,
00189 T& _val,
00190 OMFormat::Chunk::Integer_Size _b,
00191 bool _swap,
00192 t_unsigned)
00193 {
00194 assert( OMFormat::is_integer( _val ) );
00195 size_t bytes = 0;
00196
00197 switch( _b )
00198 {
00199 case OMFormat::Chunk::Integer_8:
00200 {
00201 OMFormat::uint8 v;
00202 bytes = restore( _is, v, _swap );
00203 _val = static_cast<T>(v);
00204 break;
00205 }
00206 case OMFormat::Chunk::Integer_16:
00207 {
00208 OMFormat::uint16 v;
00209 bytes = restore( _is, v, _swap );
00210 _val = static_cast<T>(v);
00211 break;
00212 }
00213 case OMFormat::Chunk::Integer_32:
00214 {
00215 OMFormat::uint32 v;
00216 bytes = restore( _is, v, _swap );
00217 _val = static_cast<T>(v);
00218 break;
00219 }
00220
00221 case OMFormat::Chunk::Integer_64:
00222 {
00223 OMFormat::uint64 v;
00224 bytes = restore( _is, v, _swap );
00225 _val = static_cast<T>(v);
00226 break;
00227 }
00228 }
00229 return bytes;
00230 }
00231
00232
00233 }
00234 }
00235