OpenVDB  9.0.1
TempFile.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 
4 /// @file TempFile.h
5 
6 #ifndef OPENVDB_IO_TEMPFILE_HAS_BEEN_INCLUDED
7 #define OPENVDB_IO_TEMPFILE_HAS_BEEN_INCLUDED
8 
9 #include <openvdb/version.h>
10 #include <memory>
11 #include <ostream>
12 
13 
14 namespace openvdb {
16 namespace OPENVDB_VERSION_NAME {
17 namespace io {
18 
19 /// Output stream to a unique temporary file
20 class OPENVDB_API TempFile: public std::ostream
21 {
22 public:
23  /// @brief Create and open a unique file.
24  /// @details On UNIX systems, the file is created in the directory specified by
25  /// the environment variable @c OPENVDB_TEMP_DIR, if that variable is defined,
26  /// or else in the directory specified by @c TMPDIR, if that variable is defined.
27  /// Otherwise (and on non-UNIX systems), the file is created in the system default
28  /// temporary directory.
29  TempFile();
30  ~TempFile();
31 
32  /// Return the path to the temporary file.
33  const std::string& filename() const;
34 
35  /// Return @c true if the file is open for writing.
36  bool is_open() const;
37 
38  /// Close the file.
39  void close();
40 
41 private:
42  struct TempFileImpl;
43  std::unique_ptr<TempFileImpl> mImpl;
44 };
45 
46 } // namespace io
47 } // namespace OPENVDB_VERSION_NAME
48 } // namespace openvdb
49 
50 #endif // OPENVDB_IO_TEMPFILE_HAS_BEEN_INCLUDED
#define OPENVDB_API
Definition: Platform.h:254
Definition: Exceptions.h:13
Output stream to a unique temporary file.
Definition: TempFile.h:20
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202