00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#ifndef SH_BINARYIO_H
00022
#define SH_BINARYIO_H
00023
00024
#include <cstdio>
00025
#include <string>
00026
00027
#include "common.h"
00028
00033 class BinaryIO {
00034
public:
00035 enum MODE {
READ,
WRITE } ;
00036
00037
BinaryIO (
void) ;
00038
00046
BinaryIO (
const std::string& fn, MODE m) ;
00047
00048
~BinaryIO (
void) ;
00049
00053 const std::string&
getName (
void)
const
00054
{
return Name ; } ;
00055
00059 bool is_open (
void)
const
00060
{
return FileOpen ; } ;
00061
00065 bool is_std (
void)
const
00066
{
return (
getStream() != NULL &&
getName() ==
"") ; } ;
00067
00071 unsigned long getPos (
void)
const
00072
{
return ftell(
getStream()) ; } ;
00073
00077
bool eof (
void) const ;
00078
00084
void open (const std::string& fn, MODE m) ;
00085
00089
void close (
void) ;
00090
00094 BYTE read8 (
void) ;
00095
00099 UWORD16 read16_le (
void) ;
00100
00104 UWORD16 read16_be (
void) ;
00105
00109 UWORD32 read32_le (
void) ;
00110
00114 UWORD32 read32_be (
void) ;
00115
00120 UWORD32 read_le (
unsigned short n) ;
00121
00125 std::string readstring (
unsigned int len) ;
00126
00130
void write8 (BYTE val) ;
00131
00135
void write16_le (UWORD16 val) ;
00136
00140
void write16_be (UWORD16 val) ;
00141
00145
void write32_le (UWORD32 val) ;
00146
00150
void write32_be (UWORD32 val) ;
00151
00157
void write_le (UWORD32 val,
unsigned short n) ;
00158
00159
void writestring (const std::string& s) ;
00160
00164 FILE* getStream (
void)
const
00165
{
return Stream ; } ;
00166
00167
protected:
00168 void setStream (FILE* s)
00169 {
Stream = s ; } ;
00170
00171 void setName (
const std::string& fn)
00172 {
Name = fn ; } ;
00173
00174 MODE getMode (
void)
const
00175
{
return Mode ; } ;
00176
00177 void setMode (MODE m)
00178 {
Mode = m ; } ;
00179
00180
private:
00181 std::string
Name ;
00182 FILE *
Stream ;
00183 bool FileOpen ;
00184 MODE Mode ;
00185
00186
void init (
void) ;
00187
00188 void set_open (
bool o)
00189 {
FileOpen = o ; } ;
00190
00194
void checkForce (
const std::string& fn)
const ;
00195
00200
bool Fileexists (
const std::string& fn)
const ;
00201 } ;
00202
00203
#endif