Fixed 64-bit issue by truncating the 4 higher order bytes of size_t which is converted to unsigned long on 64 bit machines.
This guarantees compatability between 32 and 64 bit architectures but comes along with some restrictions in usage: - OpenMesh won't be able to store data of type unsigned long (if necessary split data into two uints) - OpenMesh won't be able to store data types whose size exceeds the unsigned integer value range (which is theoretically possible on 64 bit machines). Theoretically... git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@127 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
@@ -98,7 +98,7 @@ SIMPLE_BINARY(bool);
|
||||
//SIMPLE_BINARY(int);
|
||||
|
||||
// Why is this needed? Should not be used as not 32 bit compatible
|
||||
SIMPLE_BINARY(unsigned long);
|
||||
//SIMPLE_BINARY(unsigned long);
|
||||
SIMPLE_BINARY(float);
|
||||
SIMPLE_BINARY(double);
|
||||
SIMPLE_BINARY(long double);
|
||||
@@ -114,6 +114,43 @@ SIMPLE_BINARY(uint64_t);
|
||||
|
||||
#undef SIMPLE_BINARY
|
||||
|
||||
// For unsigned long which is of size 64 bit on 64 bit
|
||||
// architectures: convert into 32 bit unsigned integer value
|
||||
// in order to stay compatible between 32/64 bit architectures.
|
||||
// This allows cross reading BUT forbids storing unsigned longs
|
||||
// as data type since higher order word (4 bytes) will be truncated.
|
||||
// Does not work in case the data type that is to be stored
|
||||
// exceeds the value range of unsigned int in size, which is improbable...
|
||||
|
||||
#define SIMPLE_BINARY( T ) \
|
||||
template <> struct binary< T > { \
|
||||
typedef T value_type; \
|
||||
static const bool is_streamable = true; \
|
||||
static size_t size_of(const value_type&) { return sizeof(value_type); } \
|
||||
static size_t size_of(void) { return sizeof(value_type); } \
|
||||
static size_t store( std::ostream& _os, const value_type& _val, \
|
||||
bool _swap=false) { \
|
||||
value_type tmp = _val; \
|
||||
if (_swap) reverse_byte_order(tmp); \
|
||||
/* Convert unsigned long to unsigned int for compatibility reasons */ \
|
||||
unsigned int t1 = static_cast<unsigned int>(tmp); \
|
||||
_os.write( (const char*)&t1, sizeof(unsigned int) ); \
|
||||
return _os.good() ? sizeof(unsigned int) : 0; \
|
||||
} \
|
||||
\
|
||||
static size_t restore( std::istream& _is, value_type& _val, \
|
||||
bool _swap=false) { \
|
||||
unsigned int t1; \
|
||||
_is.read( (char*)&t1, sizeof(unsigned int) ); \
|
||||
_val = t1; \
|
||||
if (_swap) reverse_byte_order(_val); \
|
||||
return _is.good() ? sizeof(unsigned int) : 0; \
|
||||
} \
|
||||
}
|
||||
|
||||
SIMPLE_BINARY(unsigned long);
|
||||
|
||||
#undef SIMPLE_BINARY
|
||||
|
||||
#define VECTORT_BINARY( T ) \
|
||||
template <> struct binary< T > { \
|
||||
|
||||
Reference in New Issue
Block a user