64 #include <OpenMesh/Core/IO/BinaryHelper.hh> 73 #ifndef DOXY_IGNORE_THIS 81 union u1 {
short int s;
unsigned char c[2]; } sc;
82 fread((
char*)sc.c, 1, 2, _in);
83 if (_swap) std::swap(sc.c[0], sc.c[1]);
93 union u2 {
int i;
unsigned char c[4]; } ic;
94 fread((
char*)ic.c, 1, 4, _in);
96 std::swap(ic.c[0], ic.c[3]);
97 std::swap(ic.c[1], ic.c[2]);
108 union u3 {
float f;
unsigned char c[4]; } fc;
109 fread((
char*)fc.c, 1, 4, _in);
111 std::swap(fc.c[0], fc.c[3]);
112 std::swap(fc.c[1], fc.c[2]);
123 union u4 {
double d;
unsigned char c[8]; } dc;
124 fread((
char*)dc.c, 1, 8, _in);
126 std::swap(dc.c[0], dc.c[7]);
127 std::swap(dc.c[1], dc.c[6]);
128 std::swap(dc.c[2], dc.c[5]);
129 std::swap(dc.c[3], dc.c[4]);
136 short int read_short(std::istream& _in,
bool _swap)
138 union u1 {
short int s;
unsigned char c[2]; } sc;
139 _in.read((
char*)sc.c, 2);
140 if (_swap) std::swap(sc.c[0], sc.c[1]);
148 int read_int(std::istream& _in,
bool _swap)
150 union u2 {
int i;
unsigned char c[4]; } ic;
151 _in.read((
char*)ic.c, 4);
153 std::swap(ic.c[0], ic.c[3]);
154 std::swap(ic.c[1], ic.c[2]);
163 float read_float(std::istream& _in,
bool _swap)
165 union u3 {
float f;
unsigned char c[4]; } fc;
166 _in.read((
char*)fc.c, 4);
168 std::swap(fc.c[0], fc.c[3]);
169 std::swap(fc.c[1], fc.c[2]);
180 union u4 {
double d;
unsigned char c[8]; } dc;
181 _in.read((
char*)dc.c, 8);
183 std::swap(dc.c[0], dc.c[7]);
184 std::swap(dc.c[1], dc.c[6]);
185 std::swap(dc.c[2], dc.c[5]);
186 std::swap(dc.c[3], dc.c[4]);
195 void write_short(
short int _i, FILE* _out,
bool _swap)
197 union u1 {
short int s;
unsigned char c[2]; } sc;
199 if (_swap) std::swap(sc.c[0], sc.c[1]);
200 fwrite((
char*)sc.c, 1, 2, _out);
207 void write_int(
int _i, FILE* _out,
bool _swap)
209 union u2 {
int i;
unsigned char c[4]; } ic;
212 std::swap(ic.c[0], ic.c[3]);
213 std::swap(ic.c[1], ic.c[2]);
215 fwrite((
char*)ic.c, 1, 4, _out);
224 union u3 {
float f;
unsigned char c[4]; } fc;
227 std::swap(fc.c[0], fc.c[3]);
228 std::swap(fc.c[1], fc.c[2]);
230 fwrite((
char*)fc.c, 1, 4, _out);
239 union u4 {
double d;
unsigned char c[8]; } dc;
242 std::swap(dc.c[0], dc.c[7]);
243 std::swap(dc.c[1], dc.c[6]);
244 std::swap(dc.c[2], dc.c[5]);
245 std::swap(dc.c[3], dc.c[4]);
247 fwrite((
char*)dc.c, 1, 8, _out);
254 void write_short(
short int _i, std::ostream& _out,
bool _swap)
256 union u1 {
short int s;
unsigned char c[2]; } sc;
258 if (_swap) std::swap(sc.c[0], sc.c[1]);
259 _out.write((
char*)sc.c, 2);
266 void write_int(
int _i, std::ostream& _out,
bool _swap)
268 union u2 {
int i;
unsigned char c[4]; } ic;
271 std::swap(ic.c[0], ic.c[3]);
272 std::swap(ic.c[1], ic.c[2]);
274 _out.write((
char*)ic.c, 4);
281 void write_float(
float _f, std::ostream& _out,
bool _swap)
283 union u3 {
float f;
unsigned char c[4]; } fc;
286 std::swap(fc.c[0], fc.c[3]);
287 std::swap(fc.c[1], fc.c[2]);
289 _out.write((
char*)fc.c, 4);
296 void write_double(
double _d, std::ostream& _out,
bool _swap)
298 union u4 {
double d;
unsigned char c[8]; } dc;
301 std::swap(dc.c[0], dc.c[7]);
302 std::swap(dc.c[1], dc.c[6]);
303 std::swap(dc.c[2], dc.c[5]);
304 std::swap(dc.c[3], dc.c[4]);
306 _out.write((
char*)dc.c, 8);
short int read_short(FILE *_in, bool _swap=false)
void write_int(int _i, FILE *_out, bool _swap=false)
void write_float(float _f, FILE *_out, bool _swap=false)
double read_double(FILE *_in, bool _swap=false)
void write_double(double _d, FILE *_out, bool _swap=false)
float read_float(FILE *_in, bool _swap=false)
int read_int(FILE *_in, bool _swap=false)
void write_short(short int _i, FILE *_out, bool _swap=false)