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 
25 
26 //-------------------------------------------
27 // class StdIFStream -- an implementation of
28 // class OPENEXR_IMF_INTERNAL_NAMESPACE::IStream based on class std::ifstream
29 //-------------------------------------------
30 
33 {
34 public:
35  //-------------------------------------------------------
36  // A constructor that opens the file with the given name.
37  // The destructor will close the file.
38  //-------------------------------------------------------
39 
40  IMF_EXPORT StdIFStream (const char fileName[]);
41 
42  //---------------------------------------------------------
43  // A constructor that uses a std::ifstream that has already
44  // been opened by the caller. The StdIFStream's destructor
45  // will not close the std::ifstream.
46  //---------------------------------------------------------
47 
48  IMF_EXPORT StdIFStream (std::ifstream& is, const char fileName[]);
49 
50  IMF_EXPORT virtual ~StdIFStream ();
51  StdIFStream (const StdIFStream&) = delete;
52  StdIFStream (StdIFStream&&) = delete;
53  StdIFStream& operator= (const StdIFStream&) = delete;
54  StdIFStream& operator= (StdIFStream&&) = delete;
55 
56  IMF_EXPORT virtual bool read (char c[/*n*/], int n);
57  IMF_EXPORT virtual uint64_t tellg ();
58  IMF_EXPORT virtual void seekg (uint64_t pos);
59  IMF_EXPORT virtual void clear ();
60 
61 private:
62  std::ifstream* _is;
63  bool _deleteStream;
64 };
65 
66 //------------------------------------------------
67 // class StdISStream -- an implementation of class
68 // OPENEXR_IMF_INTERNAL_NAMESPACE::IStream, based on class std::istringstream
69 //------------------------------------------------
70 
73 {
74 public:
76  IMF_EXPORT ~StdISStream ();
77  StdISStream (const StdISStream&) = delete;
78  StdISStream (StdISStream&&) = delete;
79  StdISStream& operator= (const StdISStream&) = delete;
80  StdISStream& operator= (StdISStream&&) = delete;
81 
82  IMF_EXPORT virtual bool read (char c[/*n*/], int n);
83  IMF_EXPORT virtual uint64_t tellg ();
84  IMF_EXPORT virtual void seekg (uint64_t pos);
85  IMF_EXPORT virtual void clear ();
86 
87  IMF_EXPORT std::string str () const;
88 
89  IMF_EXPORT void str (const std::string& s);
90 
91 private:
92  std::istringstream _is;
93 };
94 
95 //-------------------------------------------
96 // class StdOFStream -- an implementation of
97 // class OPENEXR_IMF_INTERNAL_NAMESPACE::OStream based on class std::ofstream
98 //-------------------------------------------
99 
102 {
103 public:
104  //-------------------------------------------------------
105  // A constructor that opens the file with the given name.
106  // The destructor will close the file.
107  //-------------------------------------------------------
108 
109  IMF_EXPORT StdOFStream (const char fileName[]);
110 
111  //---------------------------------------------------------
112  // A constructor that uses a std::ofstream that has already
113  // been opened by the caller. The StdOFStream's destructor
114  // will not close the std::ofstream.
115  //---------------------------------------------------------
116 
117  IMF_EXPORT StdOFStream (std::ofstream& os, const char fileName[]);
118 
119  IMF_EXPORT virtual ~StdOFStream ();
120  StdOFStream (const StdOFStream&) = delete;
121  StdOFStream (StdOFStream&&) = delete;
122  StdOFStream& operator= (const StdOFStream&) = delete;
123  StdOFStream& operator= (StdOFStream&&) = delete;
124 
125  IMF_EXPORT virtual void write (const char c[/*n*/], int n);
126  IMF_EXPORT virtual uint64_t tellp ();
127  IMF_EXPORT virtual void seekp (uint64_t pos);
128 
129 private:
130  std::ofstream* _os;
131  bool _deleteStream;
132 };
133 
134 //------------------------------------------------
135 // class StdOSStream -- an implementation of class
136 // OPENEXR_IMF_INTERNAL_NAMESPACE::OStream, based on class std::ostringstream
137 //------------------------------------------------
138 
141 {
142 public:
144  IMF_EXPORT ~StdOSStream ();
145  StdOSStream (const StdOSStream&) = delete;
146  StdOSStream (StdOSStream&&) = delete;
147  StdOSStream& operator= (const StdOSStream&) = delete;
148  StdOSStream& operator= (StdOSStream&&) = delete;
149 
150  IMF_EXPORT virtual void write (const char c[/*n*/], int n);
151  IMF_EXPORT virtual uint64_t tellp ();
152  IMF_EXPORT virtual void seekp (uint64_t pos);
153 
154  IMF_EXPORT std::string str () const;
155 
156 private:
157  std::ostringstream _os;
158 };
159 
161 
162 #endif
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:83
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
GLdouble n
Definition: glcorearb.h:2008
#define IMF_EXPORT
Definition: ImfExport.h:54
class IMF_EXPORT_TYPE OStream
Definition: ImfForward.h:86
LeafData & operator=(const LeafData &)=delete
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:80
#define IMF_EXPORT_TYPE
Definition: ImfExport.h:57
class IMF_EXPORT_TYPE IStream
Definition: ImfForward.h:87