HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FS_Writer.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: FS_Writer.h ( FS Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __FS_Writer__
13 #define __FS_Writer__
14 
15 #include "FS_API.h"
16 
17 #include <SYS/SYS_Types.h>
18 #include <UT/UT_NonCopyable.h>
19 #include <UT/UT_UniquePtr.h>
20 
21 #include <iosfwd>
22 #include <sys/types.h>
23 
24 #if _WIN32
25 using mode_t = int;
26 #endif
27 
28 class FS_WriterHelper;
29 class FS_WriterStream;
30 
31 template <typename T> class UT_Array;
32 
33 /// Class for writing files
34 class FS_API FS_Writer final
35 {
36 public:
37  /// Use this constructor to create a new writer. The specified file is
38  /// created immediately.
39  FS_Writer(const char *dest);
40 
41  ~FS_Writer();
42 
44 
45  FS_Writer(FS_Writer&&) noexcept;
46 
47  /// Get the amount of memory owned by this FS_Writer
48  virtual int64 getMemoryUsage(bool inclusive) const;
49 
50  /// Closes the stream. After calling this function, the getStream()
51  /// function will always return @c NULL.
52  void close();
53 
54  /// This function retrieves the C++ stream object which you can interact
55  /// with in the normal ways. If this function returns @c NULL, the file
56  /// specified in the constructor could not be created.
57  std::ostream *getStream() const;
58 
59  bool removeFile();
60 
61  // Functions for adding and removing helpers.
62  static void addWriterHelper(FS_WriterHelper *helper);
63  static void removeWriterHelper(FS_WriterHelper *helper);
64 
65 private:
66  void createStreamFromDest(const char *dest);
67 
69 };
70 
71 /// This class provides a plug-in method for adding a custom "file-system"
72 /// @see FS_ReaderHelper, FS_InfoHelper
74 {
75 public:
78  virtual ~FS_WriterHelper()
80 
82 
83  /// Return an FS_WriterStream if the helper is able to open the source
84  /// filename.
85  virtual FS_WriterStream *createStream(const char *source) = 0;
86 
87  /// Whether this helper supports the given source path for makeDirectory().
88  ///
89  /// If this helper supports the concept of directories and can create them,
90  /// then this method should share the same implementation as your
91  /// FS_InfoHelper::canHandle() override.
92  ///
93  /// This is required for backwards compatibility for old FS_WriterHelper
94  /// classes that did not understand how to make directories. When this
95  /// returns false and an FS_InfoHelper exists for source, FSmakeDirs() will
96  /// silently succeed to allow FS_WriterHelper::createStream() a chance to
97  /// create source without first creating the necessary directories.
98  /// This is to support cases where source has no concept of a "directory".
99  virtual bool canMakeDirectory(const char *source)
100  { return false; }
101 
102  /// Make a directory and all the parent directories needed.
103  ///
104  /// @param source @n The path to create
105  /// @param mode @n The unix file mode used to create the directory
106  /// @param ignore_umask @n
107  /// By default, the user's umask will be used in conjunction with the
108  /// mode. This parameter will @b force the mode to be the given value.
109  ///
110  /// @note From the HDK, this is used by FSmakeDirs().
111  virtual bool makeDirectory(
112  const char *source,
113  mode_t mode = 0777,
114  bool ignore_umask = false)
115  { return false; }
116 };
117 
119 
120 #endif
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
static void addWriterHelper(FS_WriterHelper *helper)
virtual ~FS_WriterHelper()
Definition: FS_Writer.h:78
void close() override
static void removeWriterHelper(FS_WriterHelper *helper)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
Class for writing files.
Definition: FS_Writer.h:34
long long int64
Definition: SYS_Types.h:116
FS_API UT_Array< FS_WriterHelper * > & FSgetWriterHelpers()
GLenum mode
Definition: glcorearb.h:99
virtual bool makeDirectory(const char *source, mode_t mode=0777, bool ignore_umask=false)
Definition: FS_Writer.h:111
#define FS_API
Definition: FS_API.h:10