1 /*****************************************************************************
\r
2 ** FILE IDENTIFICATION
\r
4 ** Name: fnetorderstream.h
\r
5 ** Purpose: Network-order file stream header
\r
6 ** Programmer: Kevin Rosenberg
\r
7 ** Date Started: Sep 2000
\r
9 ** This is part of the CTSim program
\r
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
\r
12 ** $Id: fnetorderstream.h,v 1.6 2000/12/16 06:12:47 kevin Exp $
\r
14 ** This program is free software; you can redistribute it and/or modify
\r
15 ** it under the terms of the GNU General Public License (version 2) as
\r
16 ** published by the Free Software Foundation.
\r
18 ** This program is distributed in the hope that it will be useful,
\r
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 ** GNU General Public License for more details.
\r
23 ** You should have received a copy of the GNU General Public License
\r
24 ** along with this program; if not, write to the Free Software
\r
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
26 ******************************************************************************/
\r
41 inline bool NativeBigEndian (void)
43 #ifdef WORDS_BIGENDIAN
51 SwapBytes2 (void* buffer)
53 unsigned char* p = static_cast<unsigned char*>(buffer);
54 unsigned char temp = p[0];
59 // 0<->3 1<->2 = 0123 -> 3210
61 SwapBytes4 (void* buffer)
63 unsigned char* p = static_cast<unsigned char*>(buffer);
64 unsigned char temp = p[0];
72 // 0<->7 1<->6 2<->5 3<->4 = 01234567 -> 76543210
74 SwapBytes8 (void* buffer)
76 unsigned char* p = static_cast<unsigned char*>(buffer);
77 unsigned char temp = p[0];
92 void ConvertNetworkOrder (void* buffer, size_t bytes);
93 void ConvertReverseNetworkOrder (void* buffer, size_t bytes);
96 class fnetorderstream : public fstream {
98 fnetorderstream (const char* filename, int mode)
99 : fstream (filename, mode) {}
101 ~fnetorderstream (void)
104 virtual void writeInt16 (kuint16 n);
105 virtual void writeInt32 (kuint32 n);
106 virtual void writeFloat32 (kfloat32 n);
107 virtual void writeFloat64 (kfloat64 n);
109 virtual void readInt16 (kuint16& n);
110 virtual void readInt32 (kuint32& n);
111 virtual void readFloat32 (kfloat32& n);
112 virtual void readFloat64 (kfloat64& n);
116 class frnetorderstream : public fnetorderstream {
118 frnetorderstream (const char* filename, int mode)
119 : fnetorderstream (filename, mode) {}
121 virtual void writeInt16 (kuint16 n);
122 virtual void writeInt32 (kuint32 n);
123 virtual void writeFloat32 (kfloat32 n);
124 virtual void writeFloat64 (kfloat64 n);
126 virtual void readInt16 (kuint16& n);
127 virtual void readInt32 (kuint32& n);
128 virtual void readFloat32 (kfloat32& n);
129 virtual void readFloat64 (kfloat64& n);