source: NonGTP/OpenEXR/include/IlmImf/ImfIO.h @ 855

Revision 855, 6.3 KB checked in by igarcia, 19 years ago (diff)
Line 
1///////////////////////////////////////////////////////////////////////////
2//
3// Copyright (c) 2002, 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_IO_H
37#define INCLUDED_IMF_IO_H
38
39//-----------------------------------------------------------------------------
40//
41//      Low-level file input and output for OpenEXR.
42//
43//-----------------------------------------------------------------------------
44
45#include <ImfInt64.h>
46#include <string>
47
48namespace Imf {
49
50//-----------------------------------------------------------
51// class IStream -- an abstract base class for input streams.
52//-----------------------------------------------------------
53
54class IStream
55{
56  public:
57
58    //-----------
59    // Destructor
60    //-----------
61
62    virtual ~IStream ();
63
64    //------------------------------------------------------
65    // Read from the stream:
66    //
67    // read(c,n) reads n bytes from the stream, and stores
68    // them in array c.  If the stream contains less than n
69    // bytes, or if an I/O error occurs, read(c,n) throws
70    // an exception.  If read(c,n) reads the last byte from
71    // the file it returns false, otherwise it returns true.
72    //------------------------------------------------------
73
74    virtual bool        read (char c[/*n*/], int n) = 0;
75
76
77    //--------------------------------------------------------
78    // Get the current reading position, in bytes from the
79    // beginning of the file.  If the next call to read() will
80    // read the first byte in the file, tellg() returns 0.
81    //--------------------------------------------------------
82
83    virtual Int64       tellg () = 0;
84
85
86    //-------------------------------------------
87    // Set the current reading position.
88    // After calling seekg(i), tellg() returns i.
89    //-------------------------------------------
90
91    virtual void        seekg (Int64 pos) = 0;
92
93
94    //------------------------------------------------------
95    // Clear error conditions after an operation has failed.
96    //------------------------------------------------------
97
98    virtual void        clear ();
99
100
101    //------------------------------------------------------
102    // Get the name of the file associated with this stream.
103    //------------------------------------------------------
104
105    const char *        fileName () const;
106
107  protected:
108
109    IStream (const char fileName[]);
110
111  private:
112
113    IStream (const IStream &);                  // not implemented
114    IStream & operator = (const IStream &);     // not implemented
115
116    std::string         _fileName;
117};
118
119
120//-----------------------------------------------------------
121// class OStream -- an abstract base class for output streams
122//-----------------------------------------------------------
123
124class OStream
125{
126  public:
127
128    //-----------
129    // Destructor
130    //-----------
131
132    virtual ~OStream ();
133
134
135    //----------------------------------------------------------
136    // Write to the stream:
137    //
138    // write(c,n) takes n bytes from array c, and stores them
139    // in the stream.  If an I/O error occurs, write(c,n) throws
140    // an exception.
141    //----------------------------------------------------------
142
143    virtual void        write (const char c[/*n*/], int n) = 0;
144
145
146    //---------------------------------------------------------
147    // Get the current writing position, in bytes from the
148    // beginning of the file.  If the next call to write() will
149    // start writing at the beginning of the file, tellp()
150    // returns 0.
151    //---------------------------------------------------------
152
153    virtual Int64       tellp () = 0;
154
155
156    //-------------------------------------------
157    // Set the current writing position.
158    // After calling seekp(i), tellp() returns i.
159    //-------------------------------------------
160
161    virtual void        seekp (Int64 pos) = 0;
162
163
164    //------------------------------------------------------
165    // Get the name of the file associated with this stream.
166    //------------------------------------------------------
167
168    const char *        fileName () const;
169
170  protected:
171
172    OStream (const char fileName[]);
173
174  private:
175
176    OStream (const OStream &);                  // not implemented
177    OStream & operator = (const OStream &);     // not implemented
178
179    std::string         _fileName;
180};
181
182
183//-----------------------
184// Helper classes for Xdr
185//-----------------------
186
187struct StreamIO
188{
189    static void
190    writeChars (OStream &os, const char c[/*n*/], int n)
191    {
192        os.write (c, n);
193    }
194
195    static bool
196    readChars (IStream &is, char c[/*n*/], int n)
197    {
198        return is.read (c, n);
199    }
200};
201
202
203struct CharPtrIO
204{
205    static void
206    writeChars (char *&op, const char c[/*n*/], int n)
207    {
208        while (n--)
209            *op++ = *c++;
210    }
211
212    static bool
213    readChars (const char *&ip, char c[/*n*/], int n)
214    {
215        while (n--)
216            *c++ = *ip++;
217
218        return true;
219    }
220};
221
222
223} // namespace Imf
224
225#endif
Note: See TracBrowser for help on using the repository browser.