head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.38; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.55; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.01; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.21.57; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# lowlevel.hxx

    00001 // lowlevel.hxx -- routines to handle lowlevel compressed binary IO of
    00002 //                 various datatypes
    00003 //
    00004 // Shamelessly adapted from plib  January 2001
    00005 //
    00006 // Original version Copyright (C) 2000  the plib team
    00007 // Local changes Copyright (C) 2000  Curtis L. Olson  - curt@@flightgear.org
    00008 //
    00009 // This program is free software; you can redistribute it and/or modify
    00010 // it under the terms of the GNU General Public License as published by
    00011 // the Free Software Foundation; either version 2 of the License, or
    00012 // (at your option) any later version.
    00013 //
    00014 // This program is distributed in the hope that it will be useful,
    00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00017 // GNU General Public License for more details.
    00018 //
    00019 // You should have received a copy of the GNU General Public License
    00020 // along with this program; if not, write to the Free Software
    00021 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00022 //
    00023 // $Id: lowlevel.hxx,v 1.8 2001/12/29 00:35:34 curt Exp $
    00024 //
    00025
    00026
    00027 #ifndef _SG_LOWLEVEL_HXX
    00028 #define _SG_LOWLEVEL_HXX
    00029
    00030
    00031 #include <stdio.h>
    00032 #include <zlib.h>
    00033
    00034 #include <plib/sg.h>
    00035
    00036 #ifdef _MSC_VER
    00037 typedef __int64 int64;
    00038 typedef __int64 uint64;
    00039 #else
    00040 typedef long long int64;
    00041 typedef unsigned long long uint64;
    00042 #endif
    00043
    00044 // Note that output is written in little endian form (and converted as
    00045 // necessary for big endian machines)
    00046
    00047 void sgReadChar ( gzFile fd, char *var ) ;
    00048 void sgWriteChar ( gzFile fd, const char var ) ;
    00049 void sgReadFloat ( gzFile fd, float *var ) ;
    00050 void sgWriteFloat ( gzFile fd, const float var ) ;
    00051 void sgReadDouble ( gzFile fd, double *var ) ;
    00052 void sgWriteDouble ( gzFile fd, const double var ) ;
    00053 void sgReadUInt ( gzFile fd, unsigned int *var ) ;
    00054 void sgWriteUInt ( gzFile fd, const unsigned int var ) ;
    00055 void sgReadInt ( gzFile fd, int *var ) ;
    00056 void sgWriteInt ( gzFile fd, const int var ) ;
    00057 void sgReadLong ( gzFile fd, long int *var ) ;
    00058 void sgWriteLong ( gzFile fd, const long int var ) ;
    00059 void sgReadLongLong ( gzFile fd, int64 *var ) ;
    00060 void sgWriteLongLong ( gzFile fd, const int64 var ) ;
    00061 void sgReadUShort ( gzFile fd, unsigned short *var ) ;
    00062 void sgWriteUShort ( gzFile fd, const unsigned short var ) ;
    00063 void sgReadShort ( gzFile fd, short *var ) ;
    00064 void sgWriteShort ( gzFile fd, const short var ) ;
    00065
    00066 void sgReadFloat ( gzFile fd, const unsigned int n, float *var ) ;
    00067 void sgWriteFloat ( gzFile fd, const unsigned int n, const float *var ) ;
    00068 void sgReadDouble ( gzFile fd, const unsigned int n, double *var ) ;
    00069 void sgWriteDouble ( gzFile fd, const unsigned int n, const double *var ) ;
    00070 void sgReadUInt ( gzFile fd, const unsigned int n, unsigned int *var ) ;
    00071 void sgWriteUInt ( gzFile fd, const unsigned int n, const unsigned int *var ) ;
    00072 void sgReadInt ( gzFile fd, const unsigned int n, int *var ) ;
    00073 void sgWriteInt ( gzFile fd, const unsigned int n, const int *var ) ;
    00074 void sgReadUShort ( gzFile fd, const unsigned int n, unsigned short *var ) ;
    00075 void sgWriteUShort ( gzFile fd, const unsigned int n, const unsigned short *var ) ;
    00076 void sgReadShort ( gzFile fd, const unsigned int n, short *var ) ;
    00077 void sgWriteShort ( gzFile fd, const unsigned int n, const short *var ) ;
    00078 void sgReadBytes ( gzFile fd, const unsigned int n, void *var ) ;
    00079 void sgWriteBytes ( gzFile fd, const unsigned int n, const void *var ) ;
    00080
    00081 void sgReadString ( gzFile fd, char **var ) ;
    00082 void sgWriteString ( gzFile fd, const char *var ) ;
    00083
    00084 inline void sgReadVec2  ( gzFile fd, sgVec2 var ) {
    00085     sgReadFloat  ( fd, 2, var ) ;
    00086 }
    00087 inline void sgWriteVec2 ( gzFile fd, const sgVec2 var ) {
    00088     sgWriteFloat ( fd, 2, var ) ;
    00089 }
    00090
    00091 inline void sgReadVec3  ( gzFile fd, sgVec3 var ) {
    00092     sgReadFloat  ( fd, 3, var ) ;
    00093 }
    00094 inline void sgWriteVec3 ( gzFile fd, const sgVec3 var ) {
    00095     sgWriteFloat ( fd, 3, var ) ;
    00096 }
    00097
    00098 inline void sgReaddVec3  ( gzFile fd, sgdVec3 var ) {
    00099     sgReadDouble  ( fd, 3, var ) ;
    00100 }
    00101 inline void sgWritedVec3 ( gzFile fd, const sgdVec3 var ) {
    00102     sgWriteDouble ( fd, 3, var ) ;
    00103 }
    00104
    00105 inline void sgReadVec4  ( gzFile fd, sgVec4 var ) {
    00106     sgReadFloat  ( fd, 4, var ) ;
    00107 }
    00108 inline void sgWriteVec4 ( gzFile fd, const sgVec4 var ) {
    00109     sgWriteFloat ( fd, 4, var ) ;
    00110 }
    00111
    00112 inline void sgReadMat4  ( gzFile fd, sgMat4 var ) {
    00113     sgReadFloat  ( fd, 16, (float *)var ) ;
    00114 }
    00115 inline void sgWriteMat4 ( gzFile fd, const sgMat4 var ) {
    00116     sgWriteFloat ( fd, 16, (float *)var ) ;
    00117 }
    00118
    00119 void sgClearReadError();
    00120 void sgClearWriteError();
    00121 int sgReadError();
    00122 int sgWriteError();
    00123
    00124 inline bool sgIsLittleEndian() {
    00125     static const int sgEndianTest = 1;
    00126     return (*((char *) &sgEndianTest ) != 0);
    00127 }
    00128
    00129 inline bool sgIsBigEndian() {
    00130     static const int sgEndianTest = 1;
    00131     return (*((char *) &sgEndianTest ) == 0);
    00132 }
    00133
    00134 inline void sgEndianSwap(unsigned short *x) {
    00135     *x =
    00136         (( *x >>  8 ) & 0x00FF ) |
    00137         (( *x <<  8 ) & 0xFF00 ) ;
    00138 }
    00139
    00140 inline void sgEndianSwap(unsigned int *x) {
    00141     *x =
    00142         (( *x >> 24 ) & 0x000000FF ) |
    00143         (( *x >>  8 ) & 0x0000FF00 ) |
    00144         (( *x <<  8 ) & 0x00FF0000 ) |
    00145         (( *x << 24 ) & 0xFF000000 ) ;
    00146 }
    00147
    00148 inline void sgEndianSwap(uint64 *x) {
    00149 #ifndef _MSC_VER
    00150     *x =
    00151         (( *x >> 56 ) & 0x00000000000000FFULL ) |
    00152         (( *x >> 40 ) & 0x000000000000FF00ULL ) |
    00153         (( *x >> 24 ) & 0x0000000000FF0000ULL ) |
    00154         (( *x >>  8 ) & 0x00000000FF000000ULL ) |
    00155         (( *x <<  8 ) & 0x000000FF00000000ULL ) |
    00156         (( *x << 24 ) & 0x0000FF0000000000ULL ) |
    00157         (( *x << 40 ) & 0x00FF000000000000ULL ) |
    00158         (( *x << 56 ) & 0xFF00000000000000ULL ) ;
    00159 #else
    00160     *x =
    00161         (( *x >> 56 ) & 0x00000000000000FF ) |
    00162         (( *x >> 40 ) & 0x000000000000FF00 ) |
    00163         (( *x >> 24 ) & 0x0000000000FF0000 ) |
    00164         (( *x >>  8 ) & 0x00000000FF000000 ) |
    00165         (( *x <<  8 ) & 0x000000FF00000000 ) |
    00166         (( *x << 24 ) & 0x0000FF0000000000 ) |
    00167         (( *x << 40 ) & 0x00FF000000000000 ) |
    00168         (( *x << 56 ) & 0xFF00000000000000 ) ;
    00169 #endif
    00170 }
    00171
    00172 #endif // _SG_LOWLEVEL_HXX

@ 1.3 log @Oops, try again. @ text @d181 1 a181 1