• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/types.h

Go to the documentation of this file.
00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00021 #ifndef _types_h
00022 #define _types_h
00023 
00024 #if defined(_WIN32) || defined(_WIN64)
00025 #include <spl/cleanwindows.h>
00026 #else
00027 #include <spl/autoconf/config.h>
00028 #endif
00029 
00030 #if HAVE_TYPES_H
00031 #include <types.h>
00032 #endif
00033 #if HAVE_SYS_TYPES_H
00034 #include <sys/types.h>
00035 #endif
00036 #if HAVE_STRING_H
00037 #include <string.h>
00038 #endif
00039 
00228 #if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || defined(_MSC_VER)
00229 #ifndef _WIN32  //< TODO should be able to remove this
00230 #define _WIN32
00231 #endif
00232 #ifndef WIN32   //< TODO should be able to remove this
00233 #define WIN32
00234 #endif
00235 #ifndef _WINDOWS
00236 #define _WINDOWS
00237 #endif
00238 #if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
00239 #define LITTLE_ENDIAN 1
00240 #endif
00241         typedef signed __int64 int64;           //< A signed 64-bit integer.
00242         typedef unsigned __int64 uint64;        //< An unsigned 64-bit integer.  Note: this is signed on platforms that don't support unsigned 64 bits.
00243         typedef signed int int32;                       //< A signed 32-bit integer.
00244         typedef signed short int16;                     //< A signed 16-bit integer.
00245         typedef __int8 int8;                            //< A signed 8-bit integer.
00246         typedef unsigned char byte;                     //< 8 unsigned bits.
00247 
00248         typedef unsigned int uint32;            //< Unsigned 32-bit integer.
00249         typedef unsigned short uint16;          //< Unsigned 16-bit integer.
00250         typedef unsigned __int8 uint8;          //< Unsigned 8-bit integer.
00251 
00252         typedef float float32;                          //< float, should be 32-bits.
00253         typedef double float64;                         //< double, should be 64-bits.
00254 
00255 #elif __GNUC__
00256 #if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
00257 #define LITTLE_ENDIAN 1
00258 #endif
00259         typedef signed long long int64;
00260         typedef unsigned long long uint64;
00261         typedef signed int int32;
00262         typedef signed short int16;
00263         typedef char int8;
00264         typedef unsigned char byte;
00265 
00266         typedef unsigned int uint32;
00267         typedef unsigned short uint16;
00268         typedef unsigned char uint8;
00269 
00270         typedef float float32;
00271         typedef double float64;
00272 
00273         char *itoa( int i, char *buf, const int buflen );
00274 
00275 #elif defined(__TANDEM)
00276 #define _TANDEM         /* I've mixed __ and _ in the code */
00277 
00278 #include <sys/types.h>
00279 #include <wchar.h>
00280 #if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
00281 #define BIG_ENDIAN 1
00282 #endif
00283         typedef signed long long int64;
00284         /*typedef unsigned long long uint64;*/
00285         typedef signed long long uint64;
00286         typedef signed int int32;
00287         typedef signed short int16;
00288         typedef char int8;
00289         typedef unsigned char byte;
00290 
00291         typedef unsigned int uint32;
00292         typedef unsigned short uint16;
00293         typedef unsigned char uint8;
00294 
00295         typedef float float32;
00296         typedef double float64;
00297 
00298         char *itoa( int i, char *buf, const int buflen );
00299         /*int iswspace( char ch );*/
00300         
00301 #else
00302 
00303         #error Unsupported Target
00304 
00305 #endif
00306 
00307 #ifndef __cplusplus
00308 #define false 0
00309 #define true 1
00310 typedef char bool;
00311 #endif
00312 
00313 #define IL_MIN_INT32                            ((int32)0x80000000)
00314 #define IL_MAX_INT32                            ((int32)0x7FFFFFFF)
00315 #define IL_MAX_UINT32                           ((uint32)0xFFFFFFFFL)
00316 #define IL_MIN_INT64                            ((int64)0x8000000000000000LL)
00317 #define IL_MAX_INT64                            ((int64)0x7FFFFFFFFFFFFFFFLL)
00318 #define IL_MAX_UINT64                           ((int64)0x7FFFFFFFFFFFFFFFLL)
00319 
00320 #define READ_BYTE(buf, offset)  ((int32)(((int8 *)(buf))[(offset)]))
00321 #define READ_BYTE_SHIFT(buf,offset,shift) (((uint32)(((uint8 *)(buf))[(offset)])) << (shift))
00322 
00324 inline void ValidateType( int8 i ) {}
00325 inline void ValidateType( int16 i ) {}
00326 inline void ValidateType( int32 i ) {}
00327 inline void ValidateType( int64 i ) {}
00328 inline void ValidateType( float32 i ) {}
00329 inline void ValidateType( float64 i ) {}
00330 inline void ValidateType( byte i ) {}
00331 inline void ValidateType( uint16 i ) {}
00332 inline void ValidateType( uint32 i ) {}
00333 #ifndef __TANDEM
00334 inline void ValidateType( uint64 i ) {}
00335 #endif
00336 
00337 
00339 class IHashable
00340 {
00341 public:
00342         inline IHashable() {}
00343         virtual ~IHashable();
00344         virtual int32 HashCode() const = 0;
00345 };
00346 
00350 class IComparable : public IHashable
00351 {
00352 public:
00353         inline IComparable() {}
00354         virtual ~IComparable();
00355         virtual bool Equals( const IComparable& a ) const = 0;
00356         virtual int Compare( const IComparable& a ) const = 0;
00357 
00360         virtual int32 MajicNumber() const = 0;
00361         virtual int32 HashCode() const = 0;
00362 };
00363 
00364 #define BYTE_MAJIC 0x0112
00365 #define BOOL_MAJIC 0x0113
00366 #define INT16_MAJIC 0x0114
00367 #define FLOAT32_MAJIC 0x0115
00368 
00369 #include <spl/typeof.h>
00370 
00374 #endif