1 /*****************************************************************************
4 ** Name: fnetorderstream.h
5 ** Purpose: Network-order file stream header
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: Sep 2000
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: fnetorderstream.h,v 1.7 2001/01/02 16:02:12 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
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);