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 <fstream>
12#include <string>
13
15
16#include <Poco/Path.h>
17
25public:
26 ScopedFile(const std::string &fileContents, const std::string &fileName);
27 ScopedFile(const std::string &fileContents, const std::string &fileName, const std::string &fileDirectory);
28 ScopedFile &operator=(const ScopedFile &other);
29 ScopedFile(const ScopedFile &other);
30 void release() const;
31 std::string getFileName() const;
33
34private:
35 void doCreateFile(const std::string &fileContents, const Poco::Path &fileNameAndPath);
36
37 mutable std::string m_filename;
38 std::ofstream m_file;
39 // Following methods keeps us from being able to put objects of this type on
40 // the heap.
41 void *operator new(size_t);
42 void operator delete(void *);
43 void *operator new[](size_t);
44 void operator delete[](void *);
45};
46} // namespace ScopedFileHelper
std::string getFileName() const
Getter for the filename with path.
ScopedFile & operator=(const ScopedFile &other)
Assignement.
void doCreateFile(const std::string &fileContents, const Poco::Path &fileNameAndPath)
Common method used by all constructors.
void release() const
Release the resource from management.
~ScopedFile()
Free up resources.