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 
43  FS_Writer(FS_Writer&&) noexcept;
45 
46  /// Get the amount of memory owned by this FS_Writer
47  int64 getMemoryUsage(bool inclusive) const;
48 
49  /// Closes the stream. After calling this function, the getStream()
50  /// function will always return @c NULL.
51  void close();
52 
53  /// This function retrieves the C++ stream object which you can interact
54  /// with in the normal ways. If this function returns @c NULL, the file
55  /// specified in the constructor could not be created.
56  std::ostream *getStream() const;
57 
58  bool removeFile();
59 
60  // Functions for adding and removing helpers.
61  static void addWriterHelper(FS_WriterHelper *helper);
62  static void removeWriterHelper(FS_WriterHelper *helper);
63 
64  /// Ensure plugins for read helpers are loaded
65  static void ensureHelpersLoaded();
66 
67 private:
68  void createStreamFromDest(const char *dest);
69 
71 };
72 
73 /// This class provides a plug-in method for adding a custom "file-system"
74 /// @see FS_ReaderHelper, FS_InfoHelper
76 {
77 public:
80  virtual ~FS_WriterHelper()
82 
84 
85  /// Return an FS_WriterStream if the helper is able to open the source
86  /// filename.
87  virtual FS_WriterStream *createStream(const char *source) = 0;
88 
89  /// Whether this helper supports the given source path for makeDirectory().
90  ///
91  /// If this helper supports the concept of directories and can create them,
92  /// then this method should share the same implementation as your
93  /// FS_InfoHelper::canHandle() override.
94  ///
95  /// This is required for backwards compatibility for old FS_WriterHelper
96  /// classes that did not understand how to make directories. When this
97  /// returns false and an FS_InfoHelper exists for source, FSmakeDirs() will
98  /// silently succeed to allow FS_WriterHelper::createStream() a chance to
99  /// create source without first creating the necessary directories.
100  /// This is to support cases where source has no concept of a "directory".
101  virtual bool canMakeDirectory(const char *source)
102  { return false; }
103 
104  /// Make a directory and all the parent directories needed.
105  ///
106  /// @param source @n The path to create
107  /// @param mode @n The unix file mode used to create the directory
108  /// @param ignore_umask @n
109  /// By default, the user's umask will be used in conjunction with the
110  /// mode. This parameter will @b force the mode to be the given value.
111  ///
112  /// @note From the HDK, this is used by FSmakeDirs().
113  virtual bool makeDirectory(
114  const char *source,
115  mode_t mode = 0777,
116  bool ignore_umask = false)
117  { return false; }
118 };
119 
121 
122 #endif
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
static void addWriterHelper(FS_WriterHelper *helper)
virtual ~FS_WriterHelper()
Definition: FS_Writer.h:80
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:113
#define FS_API
Definition: FS_API.h:10