blob: fdec5deec8cc32ec4857f6a49e5e7a56412107c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
//
// Copyright 1997 by Craig Stuart Sapp, All Rights Reserved.
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Fri May 9 22:30:32 PDT 1997
// Last Modified: Sun Dec 14 05:26:16 GMT-0800 1997
// Filename: ...sig/maint/code/base/FileIO/FileIO.h
// Web Address: http://sig.sapp.org/include/sigBase/FileIO.h
// Documentation: http://sig.sapp.org/doc/classes/FileIO
// Syntax: C++
//
// Description: Derived from the fstream class, this class has
// functions which allow writing binary files in
// both little and big endian formats. Useful for
// writing files such as soundfiles and MIDI files
// which require numbers to be stored in a particular
// endian format.
//
#ifndef _FILEIO_H_INCLUDED
#define _FILEIO_H_INCLUDED
#include <fstream>
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned long ulong;
typedef unsigned int uint;
// templates would be nice to use here, but they don't seem
// to work intuitively...
class FileIO : public std::fstream {
public:
FileIO (void);
FileIO (const char* filename, std::ios::openmode state);
~FileIO ();
void readBigEndian (char& aNumber);
void readBigEndian (uchar& aNumber);
void readBigEndian (short& aNumber);
void readBigEndian (ushort& aNumber);
void readBigEndian (long& aNumber);
void readBigEndian (ulong& aNumber);
void readBigEndian (int& aNumber);
void readBigEndian (uint& aNumber);
void readBigEndian (float& aNumber);
void readBigEndian (double& aNumber);
void readLittleEndian (char& aNumber);
void readLittleEndian (uchar& aNumber);
void readLittleEndian (short& aNumber);
void readLittleEndian (ushort& aNumber);
void readLittleEndian (long& aNumber);
void readLittleEndian (ulong& aNumber);
void readLittleEndian (int& aNumber);
void readLittleEndian (uint& aNumber);
void readLittleEndian (float& aNumber);
void readLittleEndian (double& aNumber);
void readMachineEndian (char& aNumber);
void readMachineEndian (uchar& aNumber);
void readMachineEndian (short& aNumber);
void readMachineEndian (ushort& aNumber);
void readMachineEndian (long& aNumber);
void readMachineEndian (ulong& aNumber);
void readMachineEndian (int& aNumber);
void readMachineEndian (uint& aNumber);
void readMachineEndian (float& aNumber);
void readMachineEndian (double& aNumber);
void readNotMachineEndian (char& aNumber);
void readNotMachineEndian (uchar& aNumber);
void readNotMachineEndian (short& aNumber);
void readNotMachineEndian (ushort& aNumber);
void readNotMachineEndian (long& aNumber);
void readNotMachineEndian (ulong& aNumber);
void readNotMachineEndian (int& aNumber);
void readNotMachineEndian (uint& aNumber);
void readNotMachineEndian (float& aNumber);
void readNotMachineEndian (double& aNumber);
void writeBigEndian (char aNumber);
void writeBigEndian (uchar aNumber);
void writeBigEndian (short aNumber);
void writeBigEndian (ushort aNumber);
void writeBigEndian (long aNumber);
void writeBigEndian (ulong aNumber);
void writeBigEndian (int aNumber);
void writeBigEndian (uint aNumber);
void writeBigEndian (float aNumber);
void writeBigEndian (double aNumber);
void writeLittleEndian (char aNumber);
void writeLittleEndian (uchar aNumber);
void writeLittleEndian (short aNumber);
void writeLittleEndian (ushort aNumber);
void writeLittleEndian (long aNumber);
void writeLittleEndian (ulong aNumber);
void writeLittleEndian (int aNumber);
void writeLittleEndian (uint aNumber);
void writeLittleEndian (float aNumber);
void writeLittleEndian (double aNumber);
void writeMachineEndian (char aNumber);
void writeMachineEndian (uchar aNumber);
void writeMachineEndian (short aNumber);
void writeMachineEndian (ushort aNumber);
void writeMachineEndian (long aNumber);
void writeMachineEndian (ulong aNumber);
void writeMachineEndian (int aNumber);
void writeMachineEndian (uint aNumber);
void writeMachineEndian (float aNumber);
void writeMachineEndian (double aNumber);
void writeNotMachineEndian (char aNumber);
void writeNotMachineEndian (uchar aNumber);
void writeNotMachineEndian (short aNumber);
void writeNotMachineEndian (ushort aNumber);
void writeNotMachineEndian (long aNumber);
void writeNotMachineEndian (ulong aNumber);
void writeNotMachineEndian (int aNumber);
void writeNotMachineEndian (uint aNumber);
void writeNotMachineEndian (float aNumber);
void writeNotMachineEndian (double aNumber);
protected:
char flipBytes (char aNumber);
uchar flipBytes (uchar aNumber);
short flipBytes (short aNumber);
ushort flipBytes (ushort aNumber);
long flipBytes (long aNumber);
ulong flipBytes (ulong aNumber);
int flipBytes (int aNumber);
uint flipBytes (uint aNumber);
float flipBytes (float aNumber);
double flipBytes (double aNumber);
};
#endif /* _FILEIO_H_INCLUDED */
// md5sum: 0a146ebe5c6bd0850be973f612827d20 - FileIO.h =css= 20030102
|