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