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 <fstream> 48 #include <sstream> 49 50 namespace Imf { 51 52 //------------------------------------------- 53 // class StdIFStream -- an implementation of 54 // class IStream based on class std::ifstream 55 //------------------------------------------- 56 57 class StdIFStream: public IStream 58 { 59 public: 60 61 //------------------------------------------------------- 62 // A constructor that opens the file with the given name. 63 // The destructor will close the file. 64 //------------------------------------------------------- 65 66 StdIFStream (const char fileName[]); 67 68 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 //--------------------------------------------------------- 74 75 StdIFStream (std::ifstream &is, const char fileName[]); 76 77 78 virtual ~StdIFStream (); 79 80 virtual bool read (char c[/*n*/], int n); 81 virtual Int64 tellg (); 82 virtual void seekg (Int64 pos); 83 virtual void clear (); 84 85 private: 86 87 std::ifstream * _is; 88 bool _deleteStream; 89 }; 90 91 92 //------------------------------------------- 93 // class StdOFStream -- an implementation of 94 // class OStream based on class std::ofstream 95 //------------------------------------------- 96 97 class StdOFStream: public OStream 98 { 99 public: 100 101 //------------------------------------------------------- 102 // A constructor that opens the file with the given name. 103 // The destructor will close the file. 104 //------------------------------------------------------- 105 106 StdOFStream (const char fileName[]); 107 108 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 //--------------------------------------------------------- 114 115 StdOFStream (std::ofstream &os, const char fileName[]); 116 117 118 virtual ~StdOFStream (); 119 120 virtual void write (const char c[/*n*/], int n); 121 virtual Int64 tellp (); 122 virtual void seekp (Int64 pos); 123 124 private: 125 126 std::ofstream * _os; 127 bool _deleteStream; 128 }; 129 130 131 //------------------------------------------------ 132 // class StdOSStream -- an implementation of class 133 // OStream, based on class std::ostringstream 134 //------------------------------------------------ 135 136 class StdOSStream: public OStream 137 { 138 public: 139 140 StdOSStream (); 141 142 virtual void write (const char c[/*n*/], int n); 143 virtual Int64 tellp (); 144 virtual void seekp (Int64 pos); 145 146 std::string str () const {return _os.str();} 147 148 private: 149 150 std::ostringstream _os; 151 }; 152 153 154 } // namespace Imf 155 156 #endif 157