HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FS_WriterStream.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_WriterStream.h ( FS Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __FS_WriterStream__
13 #define __FS_WriterStream__
14 
15 #include "FS_API.h"
16 #include <UT/UT_NonCopyable.h>
17 #include <UT/UT_StringHolder.h>
18 #include <UT/UT_UniquePtr.h>
19 #include <SYS/SYS_Inline.h>
20 #include <SYS/SYS_Types.h>
21 #include <iosfwd>
22 
23 // This class is essentially a holder for an ostream object. However, it
24 // can be overridden with a custom implementation if some cleanup code needs
25 // to be run for a particular FS_Writer implementation.
26 // This class also knows how to write to index file section (see FS_IndexFile),
27 // if the file name contains the section name separator, '?', by creating a
28 // temporary file (myTempFile) for the section, and then embedding that section
29 // in the final index file in destroy() method.
30 
32 {
33 public:
34  /// Default constructor, sets myStream to NULL.
36  /// Convenience constructor for files on disk. Basically just calls init().
37  FS_WriterStream(const char *file);
38  /// Destructor. Calls destroy() virtual, but since this is a destructor,
39  /// any overriding destroy() methods in derived classes won't be called
40  /// and should be explicitly invoked in derived class's destructor.
41  virtual ~FS_WriterStream();
42 
44 
45  /// Get the amount of memory owned by this FS_WriterStream
46  virtual int64 getMemoryUsage(bool inclusive) const;
47 
48  /// Obtains the output stream.
50  std::ostream *getStream() const { return myStream.get(); }
51 
52  /// Deletes the file, if possible.
53  bool removeFile();
54 
55 protected:
56  /// Sets myFile member to file argument and creates myStream output stream.
57  /// If file refers to a section in an index file (ie, using standard
58  /// convention, the file name contains the '?' section separator character),
59  /// then it creates a temporery file
60  /// (whose path is stored in myTempFile) and a stream for that temporary
61  /// file (represented by myStream), where the section data is being written
62  /// out. In destroy(), the temp file is embedded into the final destination
63  /// index file and then removed.
64  virtual bool init(const char *file);
65 
66  /// Destroys the output stream and removes file.
67  /// If the stream refers to a section in an index file, the data is flushed
68  /// out and the new section is embedded in the index file.
69  virtual bool destroy(bool removefile);
70 
71 protected:
72  /// File path for the output stream. It can be an empty string if
73  /// stream does not refer to a file.
75 
76  /// Path to the temporary file, if the original file path refers to a
77  /// section in an index file. This temp file holds new data written to that
78  /// section.
80 
81  /// The stream object used for writing out data. This class creates
82  /// default stream for disk files, but derived classes can override init()
83  /// and destroy() to create custom output streams.
85 #ifdef WIN32
86  /// This is a write buffer for Windows, because it doesn't seem to use a
87  /// large enough one by default.
88  UT_UniquePtr<char[]> myTempBuf;
89 #endif
90 };
91 
92 #endif
93 
SYS_FORCE_INLINE std::ostream * getStream() const
Obtains the output stream.
UT_UniquePtr< std::ostream > myStream
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
UT_StringHolder myTempFile
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
long long int64
Definition: SYS_Types.h:116
UT_StringHolder myFile
#define FS_API
Definition: FS_API.h:10