1 ///////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
6 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
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
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.
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.
33 ///////////////////////////////////////////////////////////////////////////
36 #ifndef INCLUDED_IMF_IO_H
37 #define INCLUDED_IMF_IO_H
39 //-----------------------------------------------------------------------------
41 // Low-level file input and output for OpenEXR.
43 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------
51 // class IStream -- an abstract base class for input streams.
52 //-----------------------------------------------------------
65 //-------------------------------------------------
66 // Does this input stream support memory-mapped IO?
68 // Memory-mapped streams can avoid an extra copy;
69 // memory-mapped read operations return a pointer
70 // to an internal buffer instead of copying data
71 // into a buffer supplied by the caller.
72 //-------------------------------------------------
74 virtual bool isMemoryMapped () const;
77 //------------------------------------------------------
78 // Read from the stream:
80 // read(c,n) reads n bytes from the stream, and stores
81 // them in array c. If the stream contains less than n
82 // bytes, or if an I/O error occurs, read(c,n) throws
83 // an exception. If read(c,n) reads the last byte from
84 // the file it returns false, otherwise it returns true.
85 //------------------------------------------------------
87 virtual bool read (char c[/*n*/], int n) = 0;
90 //---------------------------------------------------
91 // Read from a memory-mapped stream:
93 // readMemoryMapped(n) reads n bytes from the stream
94 // and returns a pointer to the first byte. The
95 // returned pointer remains valid until the stream
96 // is closed. If there are less than n byte left to
97 // read in the stream or if the stream is not memory-
98 // mapped, readMemoryMapped(n) throws an exception.
99 //---------------------------------------------------
101 virtual char * readMemoryMapped (int n);
104 //--------------------------------------------------------
105 // Get the current reading position, in bytes from the
106 // beginning of the file. If the next call to read() will
107 // read the first byte in the file, tellg() returns 0.
108 //--------------------------------------------------------
110 virtual Int64 tellg () = 0;
113 //-------------------------------------------
114 // Set the current reading position.
115 // After calling seekg(i), tellg() returns i.
116 //-------------------------------------------
118 virtual void seekg (Int64 pos) = 0;
121 //------------------------------------------------------
122 // Clear error conditions after an operation has failed.
123 //------------------------------------------------------
125 virtual void clear ();
128 //------------------------------------------------------
129 // Get the name of the file associated with this stream.
130 //------------------------------------------------------
132 const char * fileName () const;
136 IStream (const char fileName[]);
140 IStream (const IStream &); // not implemented
141 IStream & operator = (const IStream &); // not implemented
143 std::string _fileName;
147 //-----------------------------------------------------------
148 // class OStream -- an abstract base class for output streams
149 //-----------------------------------------------------------
162 //----------------------------------------------------------
163 // Write to the stream:
165 // write(c,n) takes n bytes from array c, and stores them
166 // in the stream. If an I/O error occurs, write(c,n) throws
168 //----------------------------------------------------------
170 virtual void write (const char c[/*n*/], int n) = 0;
173 //---------------------------------------------------------
174 // Get the current writing position, in bytes from the
175 // beginning of the file. If the next call to write() will
176 // start writing at the beginning of the file, tellp()
178 //---------------------------------------------------------
180 virtual Int64 tellp () = 0;
183 //-------------------------------------------
184 // Set the current writing position.
185 // After calling seekp(i), tellp() returns i.
186 //-------------------------------------------
188 virtual void seekp (Int64 pos) = 0;
191 //------------------------------------------------------
192 // Get the name of the file associated with this stream.
193 //------------------------------------------------------
195 const char * fileName () const;
199 OStream (const char fileName[]);
203 OStream (const OStream &); // not implemented
204 OStream & operator = (const OStream &); // not implemented
206 std::string _fileName;
210 //-----------------------
211 // Helper classes for Xdr
212 //-----------------------
217 writeChars (OStream &os, const char c[/*n*/], int n)
223 readChars (IStream &is, char c[/*n*/], int n)
225 return is.read (c, n);
233 writeChars (char *&op, const char c[/*n*/], int n)
240 readChars (const char *&ip, char c[/*n*/], int n)