From b35d6a982df8de0d3c10ee03eb8ce70d3613ef33 Mon Sep 17 00:00:00 2001 From: Robin Davies Date: Tue, 3 Sep 2024 02:06:53 -0400 Subject: [PATCH] ofstream_synced close --- PiPedalCommon/src/include/ofstream_synced.hpp | 2 ++ PiPedalCommon/src/ofstream_synced.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/PiPedalCommon/src/include/ofstream_synced.hpp b/PiPedalCommon/src/include/ofstream_synced.hpp index b04af94..fa7264f 100644 --- a/PiPedalCommon/src/include/ofstream_synced.hpp +++ b/PiPedalCommon/src/include/ofstream_synced.hpp @@ -10,6 +10,7 @@ namespace pipedal class ofstream_synced : public std::ofstream { public: + using super = std::ofstream; ofstream_synced() {} explicit ofstream_synced(const std::string &filename, ios_base::openmode mode = ios_base::out) @@ -20,6 +21,7 @@ namespace pipedal : std::ofstream(filename, mode) { } + void close(); ~ofstream_synced(); }; diff --git a/PiPedalCommon/src/ofstream_synced.cpp b/PiPedalCommon/src/ofstream_synced.cpp index 8d305d2..7caa3dd 100644 --- a/PiPedalCommon/src/ofstream_synced.cpp +++ b/PiPedalCommon/src/ofstream_synced.cpp @@ -8,12 +8,14 @@ void pipedal::FileSystemSync() { ::sync(); } - -ofstream_synced::~ofstream_synced() -{ +void ofstream_synced::close() { if (is_open()) { - close(); + super::close(); ::sync(); } +} +ofstream_synced::~ofstream_synced() +{ + ofstream_synced::close(); } \ No newline at end of file