/*===========================================================================*/
/*= =*/
/*= Int 64 =*/
/*= =*/
/*---------------------------------------------------------------------------*/
/*= =*/
/*= This type is aimed at providing an uniformised way of handling 64 bits =*/
/*= integers =*/
/*= =*/
/*---------------------------------------------------------------------------*/
/*= =*/
/*= File : int64.h =*/
/*= Copyright (c) May 1999, Luc Hermitte =*/
/*= =*/
/*===========================================================================*/
/*===============================[ Avoid Re-inclusion ]======================*/
#ifndef __INT64_H__
#define __INT64_H__
/*===============================[ Definitions ]=============================*/
// If we use Ms Visual C++ on PC...
// Take care that, it could be different on Alpha, ...
/**@name Definition of a 64 bits integer type.
*/
//@{
/*-------------------------------[ Using MsVC++ ]----------------------------*/
/**@name Using Microsoft Visual C++
*/
//@{
#ifdef _MSC_VER
//#pragma message( "----------------------------------------------" )
//#pragma message( "## Using the MsVC++ 64 bits integers : __int64" )
//#pragma message( "----------------------------------------------" )
#include <iostream.h>
/// We use the {\em \_\_int64} type from Ms Visual C++
typedef __int64 Integer64;
/// The unsigned version
typedef unsigned __int64 UInteger64;
/// The ostream operator for Integer64
ostream & operator<<( ostream &os, const Integer64 & i64 );
/// The ostream operator for UInteger64
ostream & operator<<( ostream &os, const UInteger64 & i64 );
/// The istream operator for Integer64
istream & operator>>( istream &is, Integer64 & i64 );
/// The istream operator for UInteger64
istream & operator>>( istream &is, UInteger64 & i64 );
//@}
/*-------------------------------[ Using GNU g++ ]---------------------------*/
/**@name Using GNU g++
*
* Stream operators are already provided.
*/
//@{
#elif __GNUC__
//#warning Using the g++ 64 bits integers : long long
/// We use the {\em long long} type from g++
typedef long long Integer64;
/// The unsigned version
typedef unsigned long long UInteger64;
//@}
/**@name Other compilers
*/
//@{
#else // No 64 bits int defined
#warning This compiler does not seems to have a predifined 64 bits integer
#include "DLong.h"
/// We define an empty 64 bits int type.
typedef DLong Integer64;
/// The unsigned version
typedef UDLong UInteger64;
#endif
//@}
//@}
/*===============================[ Inlines 4 MsVC++ ]========================*/
#ifdef _MSC_VER
#include <TCHAR.H>
#include <stdlib.h>
inline istream & operator>>( istream &is, Integer64 & i64 )
{
TCHAR ch[21]; // 21 is the max length for a 64 bits ints
is >> ch;
i64 = _ttoi64(ch);
// You may have to correct the file TCHAR.H, line 480 : "atoi64" becomes
// "_atoi64"
return is;
}
inline istream & operator>>( istream &is, UInteger64 & i64 )
{
TCHAR ch[21]; // 21 is the max length for a 64 bits ints
is >> ch;
i64 = _ttoi64(ch);
// You may have to correct the file TCHAR.H, line 480 : "atoi64" becomes
// "_atoi64"
return is;
}
inline int radix( ostream & os )
{
if ( ( os.flags() & ios::basefield ) == ios::hex )
return 16;
else if ( ( os.flags() & ios::basefield ) == ios::dec )
return 10;
else if ( ( os.flags() & ios::basefield ) == ios::oct )
return 8;
else return 10;
}
inline ostream & operator<<( ostream & os, const Integer64 & i64 )
{
TCHAR ch[21];
_i64tot( i64, ch, radix(os) );
os << ch;
return os;
}
inline ostream & operator<<( ostream & os, const UInteger64 & i64 )
{
TCHAR ch[20];
_ui64tot( i64, ch, radix(os) );
os << ch;
return os;
}
#endif
/*===============================[ Avoid Re-inclusion ]======================*/
#endif
Colorization made by code2html.