Coverage Report

Created: 2023-12-08 06:53

/src/freeimage-svn/FreeImage/trunk/Source/OpenEXR/IlmImf/ImfArray.h
Line
Count
Source (jump to first uncovered 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
37
#ifndef INCLUDED_IMF_ARRAY_H
38
#define INCLUDED_IMF_ARRAY_H
39
40
#include "ImfForward.h"
41
42
//-------------------------------------------------------------------------
43
//
44
// class Array
45
// class Array2D
46
//
47
// "Arrays of T" whose sizes are not known at compile time.
48
// When an array goes out of scope, its elements are automatically
49
// deleted.
50
//
51
// Usage example:
52
//
53
//  struct C
54
//  {
55
//      C ()    {std::cout << "C::C  (" << this << ")\n";};
56
//      virtual ~C () {std::cout << "C::~C (" << this << ")\n";};
57
//  };
58
// 
59
//  int
60
//  main ()
61
//  {
62
//      Array <C> a(3);
63
// 
64
//      C &b = a[1];
65
//      const C &c = a[1];
66
//      C *d = a + 2;
67
//      const C *e = a;
68
// 
69
//      return 0;
70
//  }
71
//
72
//-------------------------------------------------------------------------
73
74
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
75
76
template <class T>
77
class Array
78
{
79
  public:
80
81
    //-----------------------------
82
    // Constructors and destructors
83
    //-----------------------------
84
85
0
     Array ()       {_data = 0; _size = 0;}
Unexecuted instantiation: Imf_2_2::Array<char>::Array()
Unexecuted instantiation: Imf_2_2::Array<unsigned int>::Array()
Unexecuted instantiation: Imf_2_2::Array<bool>::Array()
86
0
     Array (long size)      {_data = new T[size]; _size = size;}
87
0
    ~Array ()       {delete [] _data;}
Unexecuted instantiation: Imf_2_2::Array<char>::~Array()
Unexecuted instantiation: Imf_2_2::Array<unsigned int>::~Array()
Unexecuted instantiation: Imf_2_2::Array<bool>::~Array()
88
89
90
    //-----------------------------
91
    // Access to the array elements
92
    //-----------------------------
93
94
0
    operator T * ()     {return _data;}
Unexecuted instantiation: Imf_2_2::Array<char>::operator char*()
Unexecuted instantiation: Imf_2_2::Array<unsigned int>::operator unsigned int*()
Unexecuted instantiation: Imf_2_2::Array<bool>::operator bool*()
95
0
    operator const T * () const   {return _data;}
96
97
98
    //------------------------------------------------------
99
    // Resize and clear the array (the contents of the array
100
    // are not preserved across the resize operation).
101
    //
102
    // resizeEraseUnsafe() is more memory efficient than
103
    // resizeErase() because it deletes the old memory block
104
    // before allocating a new one, but if allocating the
105
    // new block throws an exception, resizeEraseUnsafe()
106
    // leaves the array in an unusable state.
107
    //
108
    //------------------------------------------------------
109
110
    void resizeErase (long size);
111
    void resizeEraseUnsafe (long size);
112
113
114
    //-------------------------------
115
    // Return the size of this array.
116
    //-------------------------------
117
118
0
    long size() const   {return _size;}
119
120
121
  private:
122
123
    Array (const Array &);    // Copying and assignment
124
    Array & operator = (const Array &); // are not implemented
125
126
    long _size;
127
    T * _data;
128
};
129
130
131
template <class T>
132
class Array2D
133
{
134
  public:
135
136
    //-----------------------------
137
    // Constructors and destructors
138
    //-----------------------------
139
140
     Array2D ();      // empty array, 0 by 0 elements
141
     Array2D (long sizeX, long sizeY);  // sizeX by sizeY elements
142
    ~Array2D ();
143
144
145
    //-----------------------------
146
    // Access to the array elements
147
    //-----------------------------
148
149
    T *   operator [] (long x);
150
    const T * operator [] (long x) const;
151
152
153
    //------------------------------------------------------
154
    // Resize and clear the array (the contents of the array
155
    // are not preserved across the resize operation).
156
    //
157
    // resizeEraseUnsafe() is more memory efficient than
158
    // resizeErase() because it deletes the old memory block
159
    // before allocating a new one, but if allocating the
160
    // new block throws an exception, resizeEraseUnsafe()
161
    // leaves the array in an unusable state.
162
    //
163
    //------------------------------------------------------
164
165
    void resizeErase (long sizeX, long sizeY);
166
    void resizeEraseUnsafe (long sizeX, long sizeY);
167
168
169
    //-------------------------------
170
    // Return the size of this array.
171
    //-------------------------------
172
173
    long height() const  {return _sizeX;}
174
    long width() const   {return _sizeY;}
175
176
177
  private:
178
179
    Array2D (const Array2D &);      // Copying and assignment
180
    Array2D & operator = (const Array2D &); // are not implemented
181
182
    long        _sizeX;
183
    long  _sizeY;
184
    T *   _data;
185
};
186
187
188
//---------------
189
// Implementation
190
//---------------
191
192
template <class T>
193
inline void
194
Array<T>::resizeErase (long size)
195
0
{
196
0
    T *tmp = new T[size];
197
0
    delete [] _data;
198
0
    _size = size;
199
0
    _data = tmp;
200
0
}
Unexecuted instantiation: Imf_2_2::Array<char>::resizeErase(long)
Unexecuted instantiation: Imf_2_2::Array<unsigned int>::resizeErase(long)
Unexecuted instantiation: Imf_2_2::Array<bool>::resizeErase(long)
201
202
203
template <class T>
204
inline void
205
Array<T>::resizeEraseUnsafe (long size)
206
{
207
    delete [] _data;
208
    _data = 0;
209
    _size = 0;
210
    _data = new T[size];
211
    _size = size;
212
}
213
214
215
template <class T>
216
inline
217
Array2D<T>::Array2D ():
218
    _sizeX(0), _sizeY (0), _data (0)
219
0
{
220
    // emtpy
221
0
}
222
223
224
template <class T>
225
inline
226
Array2D<T>::Array2D (long sizeX, long sizeY):
227
    _sizeX (sizeX), _sizeY (sizeY), _data (new T[sizeX * sizeY])
228
0
{
229
    // emtpy
230
0
}
231
232
233
template <class T>
234
inline
235
Array2D<T>::~Array2D ()
236
0
{
237
0
    delete [] _data;
238
0
}
Unexecuted instantiation: Imf_2_2::Array2D<Imf_2_2::Rgba>::~Array2D()
Unexecuted instantiation: Imf_2_2::Array2D<unsigned int>::~Array2D()
239
240
241
template <class T>
242
inline T *  
243
Array2D<T>::operator [] (long x)
244
0
{
245
0
    return _data + x * _sizeY;
246
0
}
Unexecuted instantiation: Imf_2_2::Array2D<Imf_2_2::Rgba>::operator[](long)
Unexecuted instantiation: Imf_2_2::Array2D<unsigned int>::operator[](long)
247
248
249
template <class T>
250
inline const T *
251
Array2D<T>::operator [] (long x) const
252
{
253
    return _data + x * _sizeY;
254
}
255
256
257
template <class T>
258
inline void
259
Array2D<T>::resizeErase (long sizeX, long sizeY)
260
0
{
261
0
    T *tmp = new T[sizeX * sizeY];
262
0
    delete [] _data;
263
0
    _sizeX = sizeX;
264
0
    _sizeY = sizeY;
265
0
    _data = tmp;
266
0
}
267
268
269
template <class T>
270
inline void
271
Array2D<T>::resizeEraseUnsafe (long sizeX, long sizeY)
272
{
273
    delete [] _data;
274
    _data = 0;
275
    _sizeX = 0;
276
    _sizeY = 0;
277
    _data = new T[sizeX * sizeY];
278
    _sizeX = sizeX;
279
    _sizeY = sizeY;
280
}
281
282
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
283
284
285
#endif