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