more methods for UnformattedRead

This commit is contained in:
Guilhem Lavaux 2010-04-23 09:31:25 +02:00
parent 996a17b509
commit 7adde40f6b
2 changed files with 29 additions and 3 deletions

View File

@ -49,6 +49,25 @@ void UnformattedRead::setCheckpointSize(CheckpointSize cs)
cSize = cs; cSize = cs;
} }
void UnformattedRead::skip(int64_t off)
throw (InvalidUnformattedAccess)
{
if (checkPointAccum == 0 && checkPointRef == 0)
{
// We are not in a checked block
f->seekg(off, ios::cur);
return;
}
if (off < 0)
throw InvalidUnformattedAccess();
if ((checkPointAccum+off) > checkPointRef)
throw InvalidUnformattedAccess();
f->seekg(off, ios::cur);
checkPointAccum += off;
}
void UnformattedRead::beginCheckpoint() void UnformattedRead::beginCheckpoint()
throw (InvalidUnformattedAccess,EndOfFileException) throw (InvalidUnformattedAccess,EndOfFileException)
{ {
@ -65,11 +84,15 @@ void UnformattedRead::beginCheckpoint()
throw EndOfFileException(); throw EndOfFileException();
} }
void UnformattedRead::endCheckpoint() void UnformattedRead::endCheckpoint(bool autodrop)
throw (InvalidUnformattedAccess) throw (InvalidUnformattedAccess)
{ {
if (checkPointRef != checkPointAccum) if (checkPointRef != checkPointAccum)
throw InvalidUnformattedAccess(); {
if (!autodrop || checkPointAccum > checkPointRef)
throw InvalidUnformattedAccess();
f->seekg(checkPointRef-checkPointAccum, ios::cur);
}
int64_t oldCheckPoint = checkPointRef; int64_t oldCheckPoint = checkPointRef;

View File

@ -41,7 +41,7 @@ namespace CosmoTool
void beginCheckpoint() void beginCheckpoint()
throw (InvalidUnformattedAccess,EndOfFileException); throw (InvalidUnformattedAccess,EndOfFileException);
void endCheckpoint() void endCheckpoint(bool autodrop = false)
throw (InvalidUnformattedAccess); throw (InvalidUnformattedAccess);
double readReal64() double readReal64()
@ -53,6 +53,9 @@ namespace CosmoTool
int64_t readInt64() int64_t readInt64()
throw (InvalidUnformattedAccess); throw (InvalidUnformattedAccess);
void skip(int64_t off)
throw (InvalidUnformattedAccess);
protected: protected:
bool swapOrdering; bool swapOrdering;
CheckpointSize cSize; CheckpointSize cSize;