Mantid
Loading...
Searching...
No Matches
ScopedFileHelper.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8//------------------------------------------------------------------------------
9// Includes
10//------------------------------------------------------------------------------
11#include <filesystem>
12#include <fstream>
13#include <string>
14
16
24public:
25 ScopedFile(const std::string &fileContents, const std::string &fileName);
26 ScopedFile(const std::string &fileContents, const std::string &fileName, const std::string &fileDirectory);
27 ScopedFile &operator=(const ScopedFile &other);
28 ScopedFile(const ScopedFile &other);
29 void release() const;
30 const std::string &getFileName() const;
32
33private:
34 void doCreateFile(const std::string &fileContents, const std::filesystem::path &fileNameAndPath);
35
36 mutable std::string m_filename;
37 std::ofstream m_file;
38 // Following methods keeps us from being able to put objects of this type on
39 // the heap.
40 void *operator new(size_t);
41 void operator delete(void *);
42 void *operator new[](size_t);
43 void operator delete[](void *);
44};
45} // namespace ScopedFileHelper
ScopedFile & operator=(const ScopedFile &other)
Assignement.
void release() const
Release the resource from management.
const std::string & getFileName() const
Getter for the filename with path.
void doCreateFile(const std::string &fileContents, const std::filesystem::path &fileNameAndPath)
Common method used by all constructors.