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