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