1 ///////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2004, 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_STD_IO_H
37 #define INCLUDED_IMF_STD_IO_H
39 //-----------------------------------------------------------------------------
41 // Low-level file input and output for OpenEXR
42 // based on C++ standard iostreams.
44 //-----------------------------------------------------------------------------
52 //-------------------------------------------
53 // class StdIFStream -- an implementation of
54 // class IStream based on class std::ifstream
55 //-------------------------------------------
57 class StdIFStream: public IStream
61 //-------------------------------------------------------
62 // A constructor that opens the file with the given name.
63 // The destructor will close the file.
64 //-------------------------------------------------------
66 StdIFStream (const char fileName[]);
69 //---------------------------------------------------------
70 // A constructor that uses a std::ifstream that has already
71 // been opened by the caller. The StdIFStream's destructor
72 // will not close the std::ifstream.
73 //---------------------------------------------------------
75 StdIFStream (std::ifstream &is, const char fileName[]);
78 virtual ~StdIFStream ();
80 virtual bool read (char c[/*n*/], int n);
81 virtual Int64 tellg ();
82 virtual void seekg (Int64 pos);
83 virtual void clear ();
92 //-------------------------------------------
93 // class StdOFStream -- an implementation of
94 // class OStream based on class std::ofstream
95 //-------------------------------------------
97 class StdOFStream: public OStream
101 //-------------------------------------------------------
102 // A constructor that opens the file with the given name.
103 // The destructor will close the file.
104 //-------------------------------------------------------
106 StdOFStream (const char fileName[]);
109 //---------------------------------------------------------
110 // A constructor that uses a std::ofstream that has already
111 // been opened by the caller. The StdOFStream's destructor
112 // will not close the std::ofstream.
113 //---------------------------------------------------------
115 StdOFStream (std::ofstream &os, const char fileName[]);
118 virtual ~StdOFStream ();
120 virtual void write (const char c[/*n*/], int n);
121 virtual Int64 tellp ();
122 virtual void seekp (Int64 pos);
131 //------------------------------------------------
132 // class StdOSStream -- an implementation of class
133 // OStream, based on class std::ostringstream
134 //------------------------------------------------
136 class StdOSStream: public OStream
142 virtual void write (const char c[/*n*/], int n);
143 virtual Int64 tellp ();
144 virtual void seekp (Int64 pos);
146 std::string str () const {return _os.str();}
150 std::ostringstream _os;