1 // lowlevel.hxx -- routines to handle lowlevel compressed binary IO of
4 // Shamelessly adapted from plib January 2001
6 // Original version Copyright (C) 2000 the plib team
7 // Local changes Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #ifndef _SG_LOWLEVEL_HXX
28 #define _SG_LOWLEVEL_HXX
33 #include <simgear/compiler.h>
34 #include <simgear/misc/stdint.hxx>
36 #include <simgear/math/SGMath.hxx>
38 // Note that output is written in little endian form (and converted as
39 // necessary for big endian machines)
41 void sgReadChar ( gzFile fd, char *var ) ;
42 void sgWriteChar ( gzFile fd, const char var ) ;
43 void sgReadFloat ( gzFile fd, float *var ) ;
44 void sgWriteFloat ( gzFile fd, const float var ) ;
45 void sgReadDouble ( gzFile fd, double *var ) ;
46 void sgWriteDouble ( gzFile fd, const double var ) ;
47 void sgReadUInt ( gzFile fd, unsigned int *var ) ;
48 void sgWriteUInt ( gzFile fd, const unsigned int var ) ;
49 void sgReadInt ( gzFile fd, int *var ) ;
50 void sgWriteInt ( gzFile fd, const int var ) ;
51 void sgReadLong ( gzFile fd, int32_t *var ) ;
52 void sgWriteLong ( gzFile fd, const int32_t var ) ;
53 void sgReadLongLong ( gzFile fd, int64_t *var ) ;
54 void sgWriteLongLong ( gzFile fd, const int64_t var ) ;
55 void sgReadUShort ( gzFile fd, unsigned short *var ) ;
56 void sgWriteUShort ( gzFile fd, const unsigned short var ) ;
57 void sgReadShort ( gzFile fd, short *var ) ;
58 void sgWriteShort ( gzFile fd, const short var ) ;
60 void sgReadFloat ( gzFile fd, const unsigned int n, float *var ) ;
61 void sgWriteFloat ( gzFile fd, const unsigned int n, const float *var ) ;
62 void sgReadDouble ( gzFile fd, const unsigned int n, double *var ) ;
63 void sgWriteDouble ( gzFile fd, const unsigned int n, const double *var ) ;
64 void sgReadUInt ( gzFile fd, const unsigned int n, unsigned int *var ) ;
65 void sgWriteUInt ( gzFile fd, const unsigned int n, const unsigned int *var ) ;
66 void sgReadInt ( gzFile fd, const unsigned int n, int *var ) ;
67 void sgWriteInt ( gzFile fd, const unsigned int n, const int *var ) ;
68 void sgReadUShort ( gzFile fd, const unsigned int n, unsigned short *var ) ;
69 void sgWriteUShort ( gzFile fd, const unsigned int n, const unsigned short *var ) ;
70 void sgReadShort ( gzFile fd, const unsigned int n, short *var ) ;
71 void sgWriteShort ( gzFile fd, const unsigned int n, const short *var ) ;
72 void sgReadBytes ( gzFile fd, const unsigned int n, void *var ) ;
73 void sgWriteBytes ( gzFile fd, const unsigned int n, const void *var ) ;
75 void sgReadString ( gzFile fd, char **var ) ;
76 void sgWriteString ( gzFile fd, const char *var ) ;
78 inline void sgReadVec2 ( gzFile fd, SGVec2f& var ) {
79 sgReadFloat ( fd, 2, var.data() ) ;
81 inline void sgWriteVec2 ( gzFile fd, const SGVec2f& var ) {
82 sgWriteFloat ( fd, 2, var.data() ) ;
85 inline void sgReadVec3 ( gzFile fd, SGVec3f& var ) {
86 sgReadFloat ( fd, 3, var.data() ) ;
88 inline void sgWriteVec3 ( gzFile fd, const SGVec3f& var ) {
89 sgWriteFloat ( fd, 3, var.data() ) ;
92 inline void sgReaddVec3 ( gzFile fd, SGVec3d& var ) {
93 sgReadDouble ( fd, 3, var.data() ) ;
95 inline void sgWritedVec3 ( gzFile fd, const SGVec3d& var ) {
96 sgWriteDouble ( fd, 3, var.data() ) ;
99 inline void sgReadVec4 ( gzFile fd, SGVec4f& var ) {
100 sgReadFloat ( fd, 4, var.data() ) ;
102 inline void sgWriteVec4 ( gzFile fd, const SGVec4f& var ) {
103 sgWriteFloat ( fd, 4, var.data() ) ;
106 inline void sgReadMat4 ( gzFile fd, SGMatrixf& var ) {
107 sgReadFloat ( fd, 16, (float *)var.data() ) ;
109 inline void sgWriteMat4 ( gzFile fd, const SGMatrixf& var ) {
110 sgWriteFloat ( fd, 16, (float *)var.data() ) ;
113 inline void sgReadGeod ( gzFile fd, SGGeod& var ) {
115 sgReadDouble ( fd, 3, data );
116 var = SGGeod::fromDegM( data[0], data[1], data[2] );
118 inline void sgWriteGeod ( gzFile fd, const SGGeod& var ) {
119 sgWriteDouble( fd, var.getLongitudeDeg() );
120 sgWriteDouble( fd, var.getLatitudeDeg() );
121 sgWriteDouble( fd, var.getElevationM() );
124 void sgClearReadError();
125 void sgClearWriteError();
129 #endif // _SG_LOWLEVEL_HXX