/src/freeimage-svn/FreeImage/trunk/Source/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 IMF_EXPORT 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 | | StdIFStream (const char fileName[]); |
71 | | |
72 | | |
73 | | //--------------------------------------------------------- |
74 | | // A constructor that uses a std::ifstream that has already |
75 | | // been opened by the caller. The StdIFStream's destructor |
76 | | // will not close the std::ifstream. |
77 | | //--------------------------------------------------------- |
78 | | |
79 | | StdIFStream (std::ifstream &is, const char fileName[]); |
80 | | |
81 | | |
82 | | virtual ~StdIFStream (); |
83 | | |
84 | | virtual bool read (char c[/*n*/], int n); |
85 | | virtual Int64 tellg (); |
86 | | virtual void seekg (Int64 pos); |
87 | | virtual void clear (); |
88 | | |
89 | | private: |
90 | | |
91 | | std::ifstream * _is; |
92 | | bool _deleteStream; |
93 | | }; |
94 | | |
95 | | |
96 | | //------------------------------------------- |
97 | | // class StdOFStream -- an implementation of |
98 | | // class OPENEXR_IMF_INTERNAL_NAMESPACE::OStream based on class std::ofstream |
99 | | //------------------------------------------- |
100 | | |
101 | | class IMF_EXPORT StdOFStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::OStream |
102 | | { |
103 | | public: |
104 | | |
105 | | //------------------------------------------------------- |
106 | | // A constructor that opens the file with the given name. |
107 | | // The destructor will close the file. |
108 | | //------------------------------------------------------- |
109 | | |
110 | | StdOFStream (const char fileName[]); |
111 | | |
112 | | |
113 | | //--------------------------------------------------------- |
114 | | // A constructor that uses a std::ofstream that has already |
115 | | // been opened by the caller. The StdOFStream's destructor |
116 | | // will not close the std::ofstream. |
117 | | //--------------------------------------------------------- |
118 | | |
119 | | StdOFStream (std::ofstream &os, const char fileName[]); |
120 | | |
121 | | |
122 | | virtual ~StdOFStream (); |
123 | | |
124 | | virtual void write (const char c[/*n*/], int n); |
125 | | virtual Int64 tellp (); |
126 | | virtual void seekp (Int64 pos); |
127 | | |
128 | | private: |
129 | | |
130 | | std::ofstream * _os; |
131 | | bool _deleteStream; |
132 | | }; |
133 | | |
134 | | |
135 | | //------------------------------------------------ |
136 | | // class StdOSStream -- an implementation of class |
137 | | // OPENEXR_IMF_INTERNAL_NAMESPACE::OStream, based on class std::ostringstream |
138 | | //------------------------------------------------ |
139 | | |
140 | | class IMF_EXPORT StdOSStream: public OPENEXR_IMF_INTERNAL_NAMESPACE::OStream |
141 | | { |
142 | | public: |
143 | | |
144 | | StdOSStream (); |
145 | | |
146 | | virtual void write (const char c[/*n*/], int n); |
147 | | virtual Int64 tellp (); |
148 | | virtual void seekp (Int64 pos); |
149 | | |
150 | 0 | std::string str () const {return _os.str();} |
151 | | |
152 | | private: |
153 | | |
154 | | std::ostringstream _os; |
155 | | }; |
156 | | |
157 | | |
158 | | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT |
159 | | |
160 | | #endif |