From 450fc261cb6598471973c01394f099c5b48856f1 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Thu, 12 Sep 2013 18:19:42 +0200 Subject: [PATCH] Implemented OFile::rewind --- src/tools/OFile.cpp | 10 ++++++++++ src/tools/OFile.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/tools/OFile.cpp b/src/tools/OFile.cpp index 5ff9a73a1..effc8fa18 100644 --- a/src/tools/OFile.cpp +++ b/src/tools/OFile.cpp @@ -280,6 +280,16 @@ OFile& OFile::open(const std::string&path){ return *this; } +OFile& OFile::rewind(){ +// we use here "hard" rewind, which means close/reopen +// the reason is that normal rewind does not work when in append mode + plumed_assert(fp); + clearFields(); + fclose(fp); + fp=std::fopen(const_cast<char*>(path.c_str()),"w"); + return *this; +} + } diff --git a/src/tools/OFile.h b/src/tools/OFile.h index fe08c9dce..3c6b76cc0 100644 --- a/src/tools/OFile.h +++ b/src/tools/OFile.h @@ -184,6 +184,8 @@ this method can be used to clean the field list. /// Formatted output with << operator template <class T> friend OFile& operator<<(OFile&,const T &); +/// Rewind a file + OFile&rewind(); }; /// Write using << syntax -- GitLab