/src/opencv/3rdparty/openexr/IlmImf/ImfStdIO.h
Line | Count | Source (jump to first uncovered line) |
1 | | /////////////////////////////////////////////////////////////////////////// |
2 | | // |
3 | | // Copyright (c) 2004, Industrial Light & Magic, a division of Lucas |
4 | | // Digital Ltd. LLC |
5 | | // |
6 | | // All rights reserved. |
7 | | // |
8 | | // Redistribution and use in source and binary forms, with or without |
9 | | // modification, are permitted provided that the following conditions are |
10 | | // met: |
11 | | // * Redistributions of source code must retain the above copyright |
12 | | // notice, this list of conditions and the following disclaimer. |
13 | | // * Redistributions in binary form must reproduce the above |
14 | | // copyright notice, this list of conditions and the following disclaimer |
15 | | // in the documentation and/or other materials provided with the |
16 | | // distribution. |
17 | | // * Neither the name of Industrial Light & Magic nor the names of |
18 | | // its contributors may be used to endorse or promote products derived |
19 | | // from this software without specific prior written permission. |
20 | | // |
21 | | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
22 | | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
23 | | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
24 | | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
25 | | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
26 | | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
27 | | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
28 | | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
29 | | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
30 | | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
31 | | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 | | // |
33 | | /////////////////////////////////////////////////////////////////////////// |
34 | | |
35 | | |
36 | | #ifndef INCLUDED_IMF_STD_IO_H |
37 | | #define INCLUDED_IMF_STD_IO_H |
38 | | |
39 | | //----------------------------------------------------------------------------- |
40 | | // |
41 | | // Low-level file input and output for OpenEXR |
42 | | // based on C++ standard iostreams. |
43 | | // |
44 | | //----------------------------------------------------------------------------- |
45 | | |
46 | | #include "ImfIO.h" |
47 | | #include "ImfNamespace.h" |
48 | | #include "ImfExport.h" |
49 | | |
50 | | #include <fstream> |
51 | | #include <sstream> |
52 | | |
53 | | |
54 | | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER |
55 | | |
56 | | //------------------------------------------- |
57 | | // class StdIFStream -- an implementation of |
58 | | // class OPENEXR_IMF_INTERNAL_NAMESPACE::IStream based on class std::ifstream |
59 | | //------------------------------------------- |
60 | | |
61 | | class StdIFStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::IStream |
62 | | { |
63 | | public: |
64 | | |
65 | | //------------------------------------------------------- |
66 | | // A constructor that opens the file with the given name. |
67 | | // The destructor will close the file. |
68 | | //------------------------------------------------------- |
69 | | |
70 | | IMF_EXPORT |
71 | | StdIFStream (const char fileName[]); |
72 | | |
73 | | |
74 | | //--------------------------------------------------------- |
75 | | // A constructor that uses a std::ifstream that has already |
76 | | // been opened by the caller. The StdIFStream's destructor |
77 | | // will not close the std::ifstream. |
78 | | //--------------------------------------------------------- |
79 | | |
80 | | IMF_EXPORT |
81 | | StdIFStream (std::ifstream &is, const char fileName[]); |
82 | | |
83 | | |
84 | | IMF_EXPORT |
85 | | virtual ~StdIFStream (); |
86 | | |
87 | | IMF_EXPORT |
88 | | virtual bool read (char c[/*n*/], int n); |
89 | | IMF_EXPORT |
90 | | virtual Int64 tellg (); |
91 | | IMF_EXPORT |
92 | | virtual void seekg (Int64 pos); |
93 | | IMF_EXPORT |
94 | | virtual void clear (); |
95 | | |
96 | | private: |
97 | | |
98 | | std::ifstream * _is; |
99 | | bool _deleteStream; |
100 | | }; |
101 | | |
102 | | |
103 | | //------------------------------------------- |
104 | | // class StdOFStream -- an implementation of |
105 | | // class OPENEXR_IMF_INTERNAL_NAMESPACE::OStream based on class std::ofstream |
106 | | //------------------------------------------- |
107 | | |
108 | | class StdOFStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::OStream |
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 |
118 | | StdOFStream (const char fileName[]); |
119 | | |
120 | | |
121 | | //--------------------------------------------------------- |
122 | | // A constructor that uses a std::ofstream that has already |
123 | | // been opened by the caller. The StdOFStream's destructor |
124 | | // will not close the std::ofstream. |
125 | | //--------------------------------------------------------- |
126 | | |
127 | | IMF_EXPORT |
128 | | StdOFStream (std::ofstream &os, const char fileName[]); |
129 | | |
130 | | |
131 | | IMF_EXPORT |
132 | | virtual ~StdOFStream (); |
133 | | |
134 | | IMF_EXPORT |
135 | | virtual void write (const char c[/*n*/], int n); |
136 | | IMF_EXPORT |
137 | | virtual Int64 tellp (); |
138 | | IMF_EXPORT |
139 | | virtual void seekp (Int64 pos); |
140 | | |
141 | | private: |
142 | | |
143 | | std::ofstream * _os; |
144 | | bool _deleteStream; |
145 | | }; |
146 | | |
147 | | |
148 | | //------------------------------------------------ |
149 | | // class StdOSStream -- an implementation of class |
150 | | // OPENEXR_IMF_INTERNAL_NAMESPACE::OStream, based on class std::ostringstream |
151 | | //------------------------------------------------ |
152 | | |
153 | | class StdOSStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::OStream |
154 | | { |
155 | | public: |
156 | | |
157 | | IMF_EXPORT |
158 | | StdOSStream (); |
159 | | |
160 | | IMF_EXPORT |
161 | | virtual void write (const char c[/*n*/], int n); |
162 | | IMF_EXPORT |
163 | | virtual Int64 tellp (); |
164 | | IMF_EXPORT |
165 | | virtual void seekp (Int64 pos); |
166 | | |
167 | | IMF_EXPORT |
168 | 0 | std::string str () const {return _os.str();} |
169 | | |
170 | | private: |
171 | | |
172 | | std::ostringstream _os; |
173 | | }; |
174 | | |
175 | | |
176 | | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT |
177 | | |
178 | | #endif |