59#include <OpenMesh/Core/IO/BinaryHelper.hh>
68#ifndef DOXY_IGNORE_THIS
76 union u1 {
short int s;
unsigned char c[2]; } sc;
77 fread(
reinterpret_cast<char*
>(sc.c), 1, 2, _in);
78 if (_swap) std::swap(sc.c[0], sc.c[1]);
88 union u2 {
int i;
unsigned char c[4]; } ic;
89 fread(
reinterpret_cast<char*
>(ic.c), 1, 4, _in);
91 std::swap(ic.c[0], ic.c[3]);
92 std::swap(ic.c[1], ic.c[2]);
103 union u3 {
float f;
unsigned char c[4]; } fc;
104 fread(
reinterpret_cast<char*
>(fc.c), 1, 4, _in);
106 std::swap(fc.c[0], fc.c[3]);
107 std::swap(fc.c[1], fc.c[2]);
118 union u4 {
double d;
unsigned char c[8]; } dc;
119 fread(
reinterpret_cast<char*
>(dc.c), 1, 8, _in);
121 std::swap(dc.c[0], dc.c[7]);
122 std::swap(dc.c[1], dc.c[6]);
123 std::swap(dc.c[2], dc.c[5]);
124 std::swap(dc.c[3], dc.c[4]);
131short int read_short(std::istream& _in,
bool _swap)
133 union u1 {
short int s;
unsigned char c[2]; } sc;
134 _in.read(
reinterpret_cast<char*
>(sc.c), 2);
135 if (_swap) std::swap(sc.c[0], sc.c[1]);
143int read_int(std::istream& _in,
bool _swap)
145 union u2 {
int i;
unsigned char c[4]; } ic;
146 _in.read(
reinterpret_cast<char*
>(ic.c), 4);
148 std::swap(ic.c[0], ic.c[3]);
149 std::swap(ic.c[1], ic.c[2]);
158float read_float(std::istream& _in,
bool _swap)
160 union u3 {
float f;
unsigned char c[4]; } fc;
161 _in.read(
reinterpret_cast<char*
>(fc.c), 4);
163 std::swap(fc.c[0], fc.c[3]);
164 std::swap(fc.c[1], fc.c[2]);
175 union u4 {
double d;
unsigned char c[8]; } dc;
176 _in.read(
reinterpret_cast<char*
>(dc.c), 8);
178 std::swap(dc.c[0], dc.c[7]);
179 std::swap(dc.c[1], dc.c[6]);
180 std::swap(dc.c[2], dc.c[5]);
181 std::swap(dc.c[3], dc.c[4]);
190void write_short(
short int _i, FILE* _out,
bool _swap)
192 union u1 {
short int s;
unsigned char c[2]; } sc;
194 if (_swap) std::swap(sc.c[0], sc.c[1]);
195 fwrite(
reinterpret_cast<char*
>(sc.c), 1, 2, _out);
202void write_int(
int _i, FILE* _out,
bool _swap)
204 union u2 {
int i;
unsigned char c[4]; } ic;
207 std::swap(ic.c[0], ic.c[3]);
208 std::swap(ic.c[1], ic.c[2]);
210 fwrite(
reinterpret_cast<char*
>(ic.c), 1, 4, _out);
219 union u3 {
float f;
unsigned char c[4]; } fc;
222 std::swap(fc.c[0], fc.c[3]);
223 std::swap(fc.c[1], fc.c[2]);
225 fwrite(
reinterpret_cast<char*
>(fc.c), 1, 4, _out);
234 union u4 {
double d;
unsigned char c[8]; } dc;
237 std::swap(dc.c[0], dc.c[7]);
238 std::swap(dc.c[1], dc.c[6]);
239 std::swap(dc.c[2], dc.c[5]);
240 std::swap(dc.c[3], dc.c[4]);
242 fwrite(
reinterpret_cast<char*
>(dc.c), 1, 8, _out);
249void write_short(
short int _i, std::ostream& _out,
bool _swap)
251 union u1 {
short int s;
unsigned char c[2]; } sc;
253 if (_swap) std::swap(sc.c[0], sc.c[1]);
254 _out.write(
reinterpret_cast<char*
>(sc.c), 2);
261void write_int(
int _i, std::ostream& _out,
bool _swap)
263 union u2 {
int i;
unsigned char c[4]; } ic;
266 std::swap(ic.c[0], ic.c[3]);
267 std::swap(ic.c[1], ic.c[2]);
269 _out.write(
reinterpret_cast<char*
>(ic.c), 4);
276void write_float(
float _f, std::ostream& _out,
bool _swap)
278 union u3 {
float f;
unsigned char c[4]; } fc;
281 std::swap(fc.c[0], fc.c[3]);
282 std::swap(fc.c[1], fc.c[2]);
284 _out.write(
reinterpret_cast<char*
>(fc.c), 4);
291void write_double(
double _d, std::ostream& _out,
bool _swap)
293 union u4 {
double d;
unsigned char c[8]; } dc;
296 std::swap(dc.c[0], dc.c[7]);
297 std::swap(dc.c[1], dc.c[6]);
298 std::swap(dc.c[2], dc.c[5]);
299 std::swap(dc.c[3], dc.c[4]);
301 _out.write(
reinterpret_cast<char*
>(dc.c), 8);
short int read_short(FILE *_in, bool _swap=false)
float read_float(FILE *_in, bool _swap=false)
void write_int(int _i, FILE *_out, bool _swap=false)
void write_double(double _d, FILE *_out, bool _swap=false)
void write_short(short int _i, FILE *_out, bool _swap=false)
int read_int(FILE *_in, bool _swap=false)
double read_double(FILE *_in, bool _swap=false)
void write_float(float _f, FILE *_out, bool _swap=false)