@@ -870,8 +870,6 @@ class CDataStream
870
870
typedef CSerializeData vector_type;
871
871
vector_type vch;
872
872
unsigned int nReadPos;
873
- short state;
874
- short exceptmask;
875
873
public:
876
874
int nType;
877
875
int nVersion;
@@ -923,8 +921,6 @@ class CDataStream
923
921
nReadPos = 0 ;
924
922
nType = nTypeIn;
925
923
nVersion = nVersionIn;
926
- state = 0 ;
927
- exceptmask = std::ios::badbit | std::ios::failbit;
928
924
}
929
925
930
926
CDataStream& operator +=(const CDataStream& b)
@@ -1047,19 +1043,7 @@ class CDataStream
1047
1043
//
1048
1044
// Stream subset
1049
1045
//
1050
- void setstate (short bits, const char * psz)
1051
- {
1052
- state |= bits;
1053
- if (state & exceptmask)
1054
- throw std::ios_base::failure (psz);
1055
- }
1056
-
1057
1046
bool eof () const { return size () == 0 ; }
1058
- bool fail () const { return state & (std::ios::badbit | std::ios::failbit); }
1059
- bool good () const { return !eof () && (state == 0 ); }
1060
- void clear (short n) { state = n; } // name conflict with vector clear()
1061
- short exceptions () { return exceptmask; }
1062
- short exceptions (short mask) { short prev = exceptmask; exceptmask = mask; setstate (0 , " CDataStream" ); return prev; }
1063
1047
CDataStream* rdbuf () { return this ; }
1064
1048
int in_avail () { return size (); }
1065
1049
@@ -1079,9 +1063,7 @@ class CDataStream
1079
1063
{
1080
1064
if (nReadPosNext > vch.size ())
1081
1065
{
1082
- setstate (std::ios::failbit, " CDataStream::read() : end of data" );
1083
- memset (pch, 0 , nSize);
1084
- nSize = vch.size () - nReadPos;
1066
+ throw std::ios_base::failure (" CDataStream::read() : end of data" );
1085
1067
}
1086
1068
memcpy (pch, &vch[nReadPos], nSize);
1087
1069
nReadPos = 0 ;
@@ -1101,7 +1083,7 @@ class CDataStream
1101
1083
if (nReadPosNext >= vch.size ())
1102
1084
{
1103
1085
if (nReadPosNext > vch.size ())
1104
- setstate ( std::ios::failbit, " CDataStream::ignore() : end of data" );
1086
+ throw std::ios_base::failure ( " CDataStream::ignore() : end of data" );
1105
1087
nReadPos = 0 ;
1106
1088
vch.clear ();
1107
1089
return (*this );
@@ -1174,8 +1156,6 @@ class CAutoFile
1174
1156
{
1175
1157
protected:
1176
1158
FILE* file;
1177
- short state;
1178
- short exceptmask;
1179
1159
public:
1180
1160
int nType;
1181
1161
int nVersion;
@@ -1185,8 +1165,6 @@ class CAutoFile
1185
1165
file = filenew;
1186
1166
nType = nTypeIn;
1187
1167
nVersion = nVersionIn;
1188
- state = 0 ;
1189
- exceptmask = std::ios::badbit | std::ios::failbit;
1190
1168
}
1191
1169
1192
1170
~CAutoFile ()
@@ -1213,19 +1191,6 @@ class CAutoFile
1213
1191
//
1214
1192
// Stream subset
1215
1193
//
1216
- void setstate (short bits, const char * psz)
1217
- {
1218
- state |= bits;
1219
- if (state & exceptmask)
1220
- throw std::ios_base::failure (psz);
1221
- }
1222
-
1223
- bool fail () const { return state & (std::ios::badbit | std::ios::failbit); }
1224
- bool good () const { return state == 0 ; }
1225
- void clear (short n = 0 ) { state = n; }
1226
- short exceptions () { return exceptmask; }
1227
- short exceptions (short mask) { short prev = exceptmask; exceptmask = mask; setstate (0 , " CAutoFile" ); return prev; }
1228
-
1229
1194
void SetType (int n) { nType = n; }
1230
1195
int GetType () { return nType; }
1231
1196
void SetVersion (int n) { nVersion = n; }
@@ -1238,7 +1203,7 @@ class CAutoFile
1238
1203
if (!file)
1239
1204
throw std::ios_base::failure (" CAutoFile::read : file handle is NULL" );
1240
1205
if (fread (pch, 1 , nSize, file) != nSize)
1241
- setstate ( std::ios::failbit, feof (file) ? " CAutoFile::read : end of file" : " CAutoFile::read : fread failed" );
1206
+ throw std::ios_base::failure ( feof (file) ? " CAutoFile::read : end of file" : " CAutoFile::read : fread failed" );
1242
1207
return (*this );
1243
1208
}
1244
1209
@@ -1247,7 +1212,7 @@ class CAutoFile
1247
1212
if (!file)
1248
1213
throw std::ios_base::failure (" CAutoFile::write : file handle is NULL" );
1249
1214
if (fwrite (pch, 1 , nSize, file) != nSize)
1250
- setstate ( std::ios::failbit, " CAutoFile::write : write failed" );
1215
+ throw std::ios_base::failure ( " CAutoFile::write : write failed" );
1251
1216
return (*this );
1252
1217
}
1253
1218
@@ -1292,16 +1257,7 @@ class CBufferedFile
1292
1257
uint64_t nRewind; // how many bytes we guarantee to rewind
1293
1258
std::vector<char > vchBuf; // the buffer
1294
1259
1295
- short state;
1296
- short exceptmask;
1297
-
1298
1260
protected:
1299
- void setstate (short bits, const char *psz) {
1300
- state |= bits;
1301
- if (state & exceptmask)
1302
- throw std::ios_base::failure (psz);
1303
- }
1304
-
1305
1261
// read data from the source to fill the buffer
1306
1262
bool Fill () {
1307
1263
unsigned int pos = nSrcPos % vchBuf.size ();
@@ -1313,8 +1269,7 @@ class CBufferedFile
1313
1269
return false ;
1314
1270
size_t read = fread ((void *)&vchBuf[pos], 1 , readNow, src);
1315
1271
if (read == 0 ) {
1316
- setstate (std::ios_base::failbit, feof (src) ? " CBufferedFile::Fill : end of file" : " CBufferedFile::Fill : fread failed" );
1317
- return false ;
1272
+ throw std::ios_base::failure (feof (src) ? " CBufferedFile::Fill : end of file" : " CBufferedFile::Fill : fread failed" );
1318
1273
} else {
1319
1274
nSrcPos += read;
1320
1275
return true ;
@@ -1327,12 +1282,7 @@ class CBufferedFile
1327
1282
1328
1283
CBufferedFile (FILE *fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn) :
1329
1284
src (fileIn), nSrcPos(0 ), nReadPos(0 ), nReadLimit((uint64_t )(-1 )), nRewind(nRewindIn), vchBuf(nBufSize, 0 ),
1330
- state (0 ), exceptmask(std::ios_base::badbit | std::ios_base::failbit), nType(nTypeIn), nVersion(nVersionIn) {
1331
- }
1332
-
1333
- // check whether no error occurred
1334
- bool good () const {
1335
- return state == 0 ;
1285
+ nType (nTypeIn), nVersion(nVersionIn) {
1336
1286
}
1337
1287
1338
1288
// check whether we're at the end of the source file
@@ -1391,7 +1341,6 @@ class CBufferedFile
1391
1341
nLongPos = ftell (src);
1392
1342
nSrcPos = nLongPos;
1393
1343
nReadPos = nLongPos;
1394
- state = 0 ;
1395
1344
return true ;
1396
1345
}
1397
1346
0 commit comments