HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_TempFileManager.h
Go to the documentation of this file.
1 /*
2 * PROPRIETARY INFORMATION. This software is proprietary to
3 * Side Effects Software Inc., and is not to be reproduced,
4 * transmitted, or disclosed in any way without written permission.
5 *
6 * NAME: UT_TempFileManager.h (UT Library, C++)
7 *
8 * COMMENTS:
9 *
10 */
11 
12 #ifndef __UT_TempFileManager__
13 #define __UT_TempFileManager__
14 
15 #include "UT_API.h"
16 #include "UT_StringArray.h"
17 #include "UT_StringHolder.h"
18 
19 #include <stdio.h>
20 
21 class UT_TempFileManager;
22 class UT_OFStream;
23 
25 {
26 public:
29 
30  // Create a temp file that will be deleted when the process exits
31  // and return the file ptr to it.
32  UT_API static FILE
34  const char *prefix = nullptr);
35 
36  // Create a temp file that will be deleted when the process exits
37  // and return a stream pointer to it. The caller assumes all ownership.
38  UT_API static UT_OFStream
40  const char *prefix = nullptr);
41 
42  // Delete a temp file that was previously created.
43  UT_API static void removeTempFile(const char *filename);
44 
45  // Get a temporary filename of a file that will be deleted when the
46  // process exits.
47  UT_API static UT_StringHolder
48  getTempFilename(const char *prefix = nullptr);
49 
50  // Get an array of all managed temp files.
52 
53  // Add a temp filename to the list of files to delete of exit.
54  UT_API static bool addTempFile(const UT_StringHolder &filename);
55 
56 private:
57  UT_API static UT_TempFileManager *getInstance()
58  {
59  if (!theInstance)
60  theInstance = new UT_TempFileManager();
61  return theInstance;
62  }
63 
64  UT_StringArray myTempFilenames;
65  static UT_TempFileManager *theInstance;
66 };
67 
68 #endif
GT_API const UT_StringHolder filename
static UT_API bool addTempFile(const UT_StringHolder &filename)
#define UT_API
Definition: UT_API.h:14
static UT_API UT_StringHolder getTempFilename(const char *prefix=nullptr)
static UT_API FILE * createTempFile(UT_StringHolder &filename, const char *prefix=nullptr)
static UT_API void removeTempFile(const char *filename)
static UT_API const UT_StringArray & getAllTempFilenames()
static UT_API UT_OFStream * createTempFileStream(UT_StringHolder &filename, const char *prefix=nullptr)
Portable replacement for std::ofstream.
Definition: UT_OFStream.h:26