From 7adde40f6b6de110ced7486bbb652d4872f45be5 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Fri, 23 Apr 2010 09:31:25 +0200 Subject: [PATCH] more methods for UnformattedRead --- src/fortran.cpp | 27 +++++++++++++++++++++++++-- src/fortran.hpp | 5 ++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/fortran.cpp b/src/fortran.cpp index 4ca7254..0664c51 100644 --- a/src/fortran.cpp +++ b/src/fortran.cpp @@ -49,6 +49,25 @@ void UnformattedRead::setCheckpointSize(CheckpointSize 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() throw (InvalidUnformattedAccess,EndOfFileException) { @@ -65,11 +84,15 @@ void UnformattedRead::beginCheckpoint() throw EndOfFileException(); } -void UnformattedRead::endCheckpoint() +void UnformattedRead::endCheckpoint(bool autodrop) throw (InvalidUnformattedAccess) { if (checkPointRef != checkPointAccum) - throw InvalidUnformattedAccess(); + { + if (!autodrop || checkPointAccum > checkPointRef) + throw InvalidUnformattedAccess(); + f->seekg(checkPointRef-checkPointAccum, ios::cur); + } int64_t oldCheckPoint = checkPointRef; diff --git a/src/fortran.hpp b/src/fortran.hpp index 6c5a52e..1ddffda 100644 --- a/src/fortran.hpp +++ b/src/fortran.hpp @@ -41,7 +41,7 @@ namespace CosmoTool void beginCheckpoint() throw (InvalidUnformattedAccess,EndOfFileException); - void endCheckpoint() + void endCheckpoint(bool autodrop = false) throw (InvalidUnformattedAccess); double readReal64() @@ -53,6 +53,9 @@ namespace CosmoTool int64_t readInt64() throw (InvalidUnformattedAccess); + void skip(int64_t off) + throw (InvalidUnformattedAccess); + protected: bool swapOrdering; CheckpointSize cSize;