HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfStdIO.h
Go to the documentation of this file.
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright (c) Contributors to the OpenEXR Project.
4 //
5 
6 #ifndef INCLUDED_IMF_STD_IO_H
7 #define INCLUDED_IMF_STD_IO_H
8 
9 //-----------------------------------------------------------------------------
10 //
11 // Low-level file input and output for OpenEXR
12 // based on C++ standard iostreams.
13 //
14 //-----------------------------------------------------------------------------
15 
16 #include "ImfExport.h"
17 #include "ImfNamespace.h"
18 
19 #include "ImfIO.h"
20 
21 #include <fstream>
22 #include <sstream>
23 
24 
26 
27 //-------------------------------------------
28 // class StdIFStream -- an implementation of
29 // class OPENEXR_IMF_INTERNAL_NAMESPACE::IStream based on class std::ifstream
30 //-------------------------------------------
31 
33 {
34  public:
35 
36  //-------------------------------------------------------
37  // A constructor that opens the file with the given name.
38  // The destructor will close the file.
39  //-------------------------------------------------------
40 
41  IMF_EXPORT StdIFStream (const char fileName[]);
42 
43 
44  //---------------------------------------------------------
45  // A constructor that uses a std::ifstream that has already
46  // been opened by the caller. The StdIFStream's destructor
47  // will not close the std::ifstream.
48  //---------------------------------------------------------
49 
50  IMF_EXPORT StdIFStream (std::ifstream &is, const char fileName[]);
51 
52 
53  IMF_EXPORT virtual ~StdIFStream ();
54  StdIFStream (const StdIFStream &) = delete;
55  StdIFStream (StdIFStream &&) = delete;
56  StdIFStream &operator=(const StdIFStream &) = delete;
57  StdIFStream &operator=(StdIFStream &&) = delete;
58 
59  IMF_EXPORT virtual bool read (char c[/*n*/], int n);
60  IMF_EXPORT virtual uint64_t tellg ();
61  IMF_EXPORT virtual void seekg (uint64_t pos);
62  IMF_EXPORT virtual void clear ();
63 
64  private:
65 
66  std::ifstream * _is;
67  bool _deleteStream;
68 };
69 
70 
71 //------------------------------------------------
72 // class StdISStream -- an implementation of class
73 // OPENEXR_IMF_INTERNAL_NAMESPACE::IStream, based on class std::istringstream
74 //------------------------------------------------
75 
77 {
78  public:
79 
81  IMF_EXPORT ~StdISStream ();
82  StdISStream (const StdISStream &) = delete;
83  StdISStream (StdISStream &&) = delete;
84  StdISStream &operator=(const StdISStream &) = delete;
85  StdISStream &operator=(StdISStream &&) = delete;
86 
87  IMF_EXPORT virtual bool read (char c[/*n*/], int n);
88  IMF_EXPORT virtual uint64_t tellg ();
89  IMF_EXPORT virtual void seekg (uint64_t pos);
90  IMF_EXPORT virtual void clear ();
91 
92  IMF_EXPORT std::string str () const;
93 
94  IMF_EXPORT void str (const std::string &s);
95 
96  private:
97 
98  std::istringstream _is;
99 };
100 
101 
102 
103 //-------------------------------------------
104 // class StdOFStream -- an implementation of
105 // class OPENEXR_IMF_INTERNAL_NAMESPACE::OStream based on class std::ofstream
106 //-------------------------------------------
107 
109 {
110  public:
111 
112  //-------------------------------------------------------
113  // A constructor that opens the file with the given name.
114  // The destructor will close the file.
115  //-------------------------------------------------------
116 
117  IMF_EXPORT StdOFStream (const char fileName[]);
118 
119 
120  //---------------------------------------------------------
121  // A constructor that uses a std::ofstream that has already
122  // been opened by the caller. The StdOFStream's destructor
123  // will not close the std::ofstream.
124  //---------------------------------------------------------
125 
126  IMF_EXPORT StdOFStream (std::ofstream &os, const char fileName[]);
127 
128 
129  IMF_EXPORT virtual ~StdOFStream ();
130  StdOFStream (const StdOFStream &) = delete;
131  StdOFStream (StdOFStream &&) = delete;
132  StdOFStream &operator=(const StdOFStream &) = delete;
133  StdOFStream &operator=(StdOFStream &&) = delete;
134 
135  IMF_EXPORT virtual void write (const char c[/*n*/], int n);
136  IMF_EXPORT virtual uint64_t tellp ();
137  IMF_EXPORT virtual void seekp (uint64_t pos);
138 
139  private:
140 
141  std::ofstream * _os;
142  bool _deleteStream;
143 };
144 
145 
146 //------------------------------------------------
147 // class StdOSStream -- an implementation of class
148 // OPENEXR_IMF_INTERNAL_NAMESPACE::OStream, based on class std::ostringstream
149 //------------------------------------------------
150 
152 {
153  public:
154 
156  IMF_EXPORT ~StdOSStream ();
157  StdOSStream (const StdOSStream &) = delete;
158  StdOSStream (StdOSStream &&) = delete;
159  StdOSStream &operator=(const StdOSStream &) = delete;
160  StdOSStream &operator=(StdOSStream &&) = delete;
161 
162  IMF_EXPORT virtual void write (const char c[/*n*/], int n);
163  IMF_EXPORT virtual uint64_t tellp ();
164  IMF_EXPORT virtual void seekp (uint64_t pos);
165 
166  IMF_EXPORT std::string str () const;
167 
168  private:
169 
170  std::ostringstream _os;
171 };
172 
173 
175 
176 #endif
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:80
OIIO_NAMESPACE_BEGIN typedef std::ifstream ifstream
Definition: filesystem.h:57
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
std::ofstream ofstream
Definition: filesystem.h:58
GLdouble s
Definition: glad.h:3009
void read(T &in, bool &v)
Definition: ImfXdr.h:502
GLdouble n
Definition: glcorearb.h:2008
#define IMF_EXPORT
Definition: ImfExport.h:54
class IMF_EXPORT_TYPE OStream
Definition: ImfForward.h:88
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:79
void write(T &out, bool v)
Definition: ImfXdr.h:287
#define IMF_EXPORT_TYPE
Definition: ImfExport.h:57
class IMF_EXPORT_TYPE IStream
Definition: ImfForward.h:89