File indexing completed on 2026-10-09 08:30:26
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "WrappedFileHandle.hpp"
0010
0011 #include <cstdio>
0012 #include <utility>
0013
0014 namespace ActsPlugins::detail {
0015
0016
0017 WrappedFileHandle::WrappedFileHandle(const std::filesystem::path& outf)
0018 : m_path(outf) {
0019 if (!outf.empty()) {
0020 m_handle = std::fopen(outf.c_str(), "w");
0021 }
0022 }
0023
0024 WrappedFileHandle::~WrappedFileHandle() {
0025 if (m_handle != nullptr) {
0026 std::fclose(m_handle);
0027 }
0028 }
0029
0030 WrappedFileHandle::WrappedFileHandle(WrappedFileHandle&& other) noexcept
0031 : m_handle(std::exchange(other.m_handle, nullptr)),
0032 m_path(std::move(other.m_path)) {}
0033
0034 WrappedFileHandle& WrappedFileHandle::operator=(
0035 WrappedFileHandle&& other) noexcept {
0036 if (this != &other) {
0037 if (m_handle != nullptr) {
0038 std::fclose(m_handle);
0039 }
0040 m_handle = std::exchange(other.m_handle, nullptr);
0041 m_path = std::move(other.m_path);
0042 }
0043
0044 return *this;
0045 }
0046 FILE* WrappedFileHandle::operator()() const {
0047 return m_handle;
0048 }
0049 bool WrappedFileHandle::isRedirected() const {
0050 return m_handle != nullptr;
0051 }
0052 const std::filesystem::path& WrappedFileHandle::path() const {
0053 return m_path;
0054 }
0055
0056 }