PBRT
/home/felix/UBC/projects/AdaptiveLightfieldSampling/pbrt_v2/src/3rdparty/openexr-1.7.0/ImfStdIO.h
00001 
00002 //
00003 // Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
00004 // Digital Ltd. LLC
00005 // 
00006 // All rights reserved.
00007 // 
00008 // Redistribution and use in source and binary forms, with or without
00009 // modification, are permitted provided that the following conditions are
00010 // met:
00011 // *       Redistributions of source code must retain the above copyright
00012 // notice, this list of conditions and the following disclaimer.
00013 // *       Redistributions in binary form must reproduce the above
00014 // copyright notice, this list of conditions and the following disclaimer
00015 // in the documentation and/or other materials provided with the
00016 // distribution.
00017 // *       Neither the name of Industrial Light & Magic nor the names of
00018 // its contributors may be used to endorse or promote products derived
00019 // from this software without specific prior written permission. 
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00024 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00025 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00026 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00027 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00028 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00029 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00030 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032 //
00034 
00035 
00036 #ifndef INCLUDED_IMF_STD_IO_H
00037 #define INCLUDED_IMF_STD_IO_H
00038 
00039 //-----------------------------------------------------------------------------
00040 //
00041 //      Low-level file input and output for OpenEXR
00042 //      based on C++ standard iostreams.
00043 //
00044 //-----------------------------------------------------------------------------
00045 
00046 #include <ImfIO.h>
00047 #include <fstream>
00048 #include <sstream>
00049 
00050 namespace Imf {
00051 
00052 //-------------------------------------------
00053 // class StdIFStream -- an implementation of
00054 // class IStream based on class std::ifstream
00055 //-------------------------------------------
00056 
00057 class StdIFStream: public IStream
00058 {
00059   public:
00060 
00061     //-------------------------------------------------------
00062     // A constructor that opens the file with the given name.
00063     // The destructor will close the file.
00064     //-------------------------------------------------------
00065 
00066     StdIFStream (const char fileName[]);
00067 
00068     
00069     //---------------------------------------------------------
00070     // A constructor that uses a std::ifstream that has already
00071     // been opened by the caller.  The StdIFStream's destructor
00072     // will not close the std::ifstream.
00073     //---------------------------------------------------------
00074 
00075     StdIFStream (std::ifstream &is, const char fileName[]);
00076 
00077 
00078     virtual ~StdIFStream ();
00079 
00080     virtual bool        read (char c[/*n*/], int n);
00081     virtual Int64       tellg ();
00082     virtual void        seekg (Int64 pos);
00083     virtual void        clear ();
00084 
00085   private:
00086 
00087     std::ifstream *     _is;
00088     bool                _deleteStream;
00089 };
00090 
00091 
00092 //-------------------------------------------
00093 // class StdOFStream -- an implementation of
00094 // class OStream based on class std::ofstream
00095 //-------------------------------------------
00096 
00097 class StdOFStream: public OStream
00098 {
00099   public:
00100 
00101     //-------------------------------------------------------
00102     // A constructor that opens the file with the given name.
00103     // The destructor will close the file.
00104     //-------------------------------------------------------
00105 
00106     StdOFStream (const char fileName[]);
00107     
00108 
00109     //---------------------------------------------------------
00110     // A constructor that uses a std::ofstream that has already
00111     // been opened by the caller.  The StdOFStream's destructor
00112     // will not close the std::ofstream.
00113     //---------------------------------------------------------
00114 
00115     StdOFStream (std::ofstream &os, const char fileName[]);
00116 
00117 
00118     virtual ~StdOFStream ();
00119 
00120     virtual void        write (const char c[/*n*/], int n);
00121     virtual Int64       tellp ();
00122     virtual void        seekp (Int64 pos);
00123 
00124   private:
00125 
00126     std::ofstream *     _os;
00127     bool                _deleteStream;
00128 };
00129 
00130 
00131 //------------------------------------------------
00132 // class StdOSStream -- an implementation of class
00133 // OStream, based on class std::ostringstream
00134 //------------------------------------------------
00135 
00136 class StdOSStream: public OStream
00137 {
00138   public:
00139 
00140     StdOSStream ();
00141 
00142     virtual void        write (const char c[/*n*/], int n);
00143     virtual Int64       tellp ();
00144     virtual void        seekp (Int64 pos);
00145 
00146     std::string         str () const {return _os.str();}
00147 
00148   private:
00149 
00150     std::ostringstream  _os;
00151 };
00152 
00153 
00154 } // namespace Imf
00155 
00156 #endif