KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
scoped_file.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Máté Kelemen
11 //
12 
13 
14 #pragma once
15 
16 // STL includes
17 #include <filesystem>
18 #include <fstream>
19 
20 
21 namespace Kratos::Testing {
22 
23 
29 {
30 public:
31  ScopedEntry(const std::filesystem::path& rPath);
32 
33  ScopedEntry(ScopedEntry&& rOther) = default;
34 
35  ScopedEntry(const ScopedEntry& rOther) = delete;
36 
37  ScopedEntry& operator=(ScopedEntry&& rOther) = delete;
38 
39  ScopedEntry& operator=(const ScopedEntry& rOther) = delete;
40 
41  virtual ~ScopedEntry();
42 
43  operator const std::filesystem::path& () const;
44 
45 private:
46  const std::filesystem::path mPath;
47 }; // class ScopedEntry
48 
49 
51 struct ScopedDirectory final : public ScopedEntry
52 {
54 }; // struct ScopedDirectory
55 
56 
58 class ScopedFile final : public ScopedEntry
59 {
60 public:
61  ScopedFile(const std::filesystem::path& rPath);
62 
63  ~ScopedFile() override;
64 
65  template <class T>
66  friend ScopedFile& operator<<(ScopedFile& rFile, const T& rContent)
67  {
68  rFile.mStream << rContent;
69  rFile.mStream.flush();
70  return rFile;
71  }
72 
73 private:
74  std::ofstream mStream;
75 }; // class ScopedFile
76 
77 
79 struct ScopedSymlink final : public ScopedEntry
80 {
81  ScopedSymlink(const std::filesystem::path& rSymlinkPath, const std::filesystem::path& rTargetPath);
82 }; // struct ScopedSymlink
83 
84 
85 } // namespace Kratos::Testing
Definition: scoped_file.h:29
ScopedEntry & operator=(const ScopedEntry &rOther)=delete
virtual ~ScopedEntry()
Definition: scoped_file.cpp:26
ScopedEntry(const ScopedEntry &rOther)=delete
ScopedEntry(ScopedEntry &&rOther)=default
ScopedEntry & operator=(ScopedEntry &&rOther)=delete
ScopedEntry(const std::filesystem::path &rPath)
Definition: scoped_file.cpp:21
Class representing a file that follows RAII.
Definition: scoped_file.h:59
~ScopedFile() override
Definition: scoped_file.cpp:52
ScopedFile(const std::filesystem::path &rPath)
Definition: scoped_file.cpp:45
friend ScopedFile & operator<<(ScopedFile &rFile, const T &rContent)
Definition: scoped_file.h:66
string path
Definition: DEM_run_all_benchmarks_analysis.py:10
Definition: distributed_test_case.cpp:24
Class representing a directory that follows RAII.
Definition: scoped_file.h:52
ScopedDirectory(const std::filesystem::path &rPath)
Definition: scoped_file.cpp:38