MSVC++ doesn't have long long, but does have __int64.

This commit is contained in:
curt 2001-05-15 15:52:10 +00:00
parent 00ccafb90d
commit 2d21e59b54
3 changed files with 36 additions and 18 deletions

View File

@ -79,7 +79,7 @@ void sgReadDouble ( gzFile fd, double *var )
read_error = true ;
}
if ( sgIsBigEndian() ) {
sgEndianSwap( (unsigned long long*)var);
sgEndianSwap( (uint64*)var);
}
}
@ -87,7 +87,7 @@ void sgReadDouble ( gzFile fd, double *var )
void sgWriteDouble ( gzFile fd, const double var )
{
if ( sgIsBigEndian() ) {
sgEndianSwap( (unsigned long long*)&var);
sgEndianSwap( (uint64*)&var);
}
if ( gzwrite ( fd, (void *)(&var), sizeof(double) ) != sizeof(double) ) {
write_error = true ;
@ -165,24 +165,24 @@ void sgWriteLong ( gzFile fd, const long int var )
}
void sgReadLongLong ( gzFile fd, long long int *var )
void sgReadLongLong ( gzFile fd, int64 *var )
{
if ( gzread ( fd, var, sizeof(long long int) ) != sizeof(long long int) ) {
if ( gzread ( fd, var, sizeof(int64) ) != sizeof(int64) ) {
read_error = true ;
}
if ( sgIsBigEndian() ) {
sgEndianSwap( (unsigned long long int*)var);
sgEndianSwap( (uint64*)var);
}
}
void sgWriteLongLong ( gzFile fd, const long long int var )
void sgWriteLongLong ( gzFile fd, const int64 var )
{
if ( sgIsBigEndian() ) {
sgEndianSwap( (unsigned long long*)&var);
sgEndianSwap( (uint64*)&var);
}
if ( gzwrite ( fd, (void *)(&var), sizeof(long long int) )
!= sizeof(long long int) )
if ( gzwrite ( fd, (void *)(&var), sizeof(int64) )
!= sizeof(int64) )
{
write_error = true ;
}
@ -273,7 +273,7 @@ void sgReadDouble ( gzFile fd, const unsigned int n, double *var )
}
if ( sgIsBigEndian() ) {
for ( unsigned int i = 0; i < n; ++i ) {
sgEndianSwap( (unsigned long long*)var++);
sgEndianSwap( (uint64*)var++);
}
}
}
@ -286,7 +286,7 @@ void sgWriteDouble ( gzFile fd, const unsigned int n, const double *var )
double *ptr = swab;
memcpy( swab, var, sizeof(double) * n );
for ( unsigned int i = 0; i < n; ++i ) {
sgEndianSwap( (unsigned long long*)ptr++);
sgEndianSwap( (uint64*)ptr++);
}
var = swab;
}

View File

@ -38,6 +38,13 @@
#include <plib/sg.h>
#ifdef _MSC_VER
typedef __int64 int64;
typedef __int64 uint64;
#else
typedef long long int64;
typedef unsigned long long uint64;
#endif
// Note that output is written in little endian form (and converted as
// necessary for big endian machines)
@ -54,8 +61,8 @@ void sgReadInt ( gzFile fd, int *var ) ;
void sgWriteInt ( gzFile fd, const int var ) ;
void sgReadLong ( gzFile fd, long int *var ) ;
void sgWriteLong ( gzFile fd, const long int var ) ;
void sgReadLongLong ( gzFile fd, long long int *var ) ;
void sgWriteLongLong ( gzFile fd, const long long int var ) ;
void sgReadLongLong ( gzFile fd, int64 *var ) ;
void sgWriteLongLong ( gzFile fd, const int64 var ) ;
void sgReadUShort ( gzFile fd, unsigned short *var ) ;
void sgWriteUShort ( gzFile fd, const unsigned short var ) ;
void sgReadShort ( gzFile fd, short *var ) ;
@ -143,7 +150,8 @@ inline void sgEndianSwap(unsigned int *x) {
(( *x << 24 ) & 0xFF000000 ) ;
}
inline void sgEndianSwap(unsigned long long *x) {
inline void sgEndianSwap(uint64 *x) {
#ifndef _MSC_VER
*x =
(( *x >> 56 ) & 0x00000000000000FFULL ) |
(( *x >> 40 ) & 0x000000000000FF00ULL ) |
@ -153,7 +161,17 @@ inline void sgEndianSwap(unsigned long long *x) {
(( *x << 24 ) & 0x0000FF0000000000ULL ) |
(( *x << 40 ) & 0x00FF000000000000ULL ) |
(( *x << 56 ) & 0xFF00000000000000ULL ) ;
#else
*x =
(( *x >> 56 ) & 0x00000000000000FF ) |
(( *x >> 40 ) & 0x000000000000FF00 ) |
(( *x >> 24 ) & 0x0000000000FF0000 ) |
(( *x >> 8 ) & 0x00000000FF000000 ) |
(( *x << 8 ) & 0x000000FF00000000 ) |
(( *x << 24 ) & 0x0000FF0000000000 ) |
(( *x << 40 ) & 0x00FF000000000000 ) |
(( *x << 56 ) & 0xFF00000000000000 ) ;
#endif
}
#endif // _SG_LOWLEVEL_HXX

View File

@ -255,9 +255,9 @@ bool SGBinObject::read_bin( const string& file ) {
double *dptr = (double *)ptr;
if ( sgIsBigEndian() ) {
sgEndianSwap( (unsigned long long *)&(dptr[0]) );
sgEndianSwap( (unsigned long long *)&(dptr[1]) );
sgEndianSwap( (unsigned long long *)&(dptr[2]) );
sgEndianSwap( (uint64 *)&(dptr[0]) );
sgEndianSwap( (uint64 *)&(dptr[1]) );
sgEndianSwap( (uint64 *)&(dptr[2]) );
}
gbs_center = Point3D( dptr[0], dptr[1], dptr[2] );
// cout << "Center = " << gbs_center << endl;