Coverage Report

Created: 2026-01-25 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openexr/src/lib/OpenEXR/ImfArray.h
Line
Count
Source
1
//
2
// SPDX-License-Identifier: BSD-3-Clause
3
// Copyright (c) Contributors to the OpenEXR Project.
4
//
5
6
#ifndef INCLUDED_IMF_ARRAY_H
7
#define INCLUDED_IMF_ARRAY_H
8
9
#include "ImfForward.h"
10
11
//-------------------------------------------------------------------------
12
//
13
// class Array
14
// class Array2D
15
//
16
// "Arrays of T" whose sizes are not known at compile time.
17
// When an array goes out of scope, its elements are automatically
18
// deleted.
19
//
20
// Usage example:
21
//
22
//  struct C
23
//  {
24
//      C ()    {std::cout << "C::C  (" << this << ")\n";};
25
//      virtual ~C () {std::cout << "C::~C (" << this << ")\n";};
26
//  };
27
//
28
//  int
29
//  main ()
30
//  {
31
//      Array <C> a(3);
32
//
33
//      C &b = a[1];
34
//      const C &c = a[1];
35
//      C *d = a + 2;
36
//      const C *e = a;
37
//
38
//      return 0;
39
//  }
40
//
41
//-------------------------------------------------------------------------
42
43
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
44
45
template <class T> class IMF_EXPORT_TEMPLATE_TYPE Array
46
{
47
public:
48
    //-----------------------------
49
    // Constructors and destructors
50
    //-----------------------------
51
52
    Array ()
53
171k
    {
54
171k
        _data = 0;
55
171k
        _size = 0;
56
171k
    }
Imf_4_0::Array<unsigned int>::Array()
Line
Count
Source
53
19.7k
    {
54
19.7k
        _data = 0;
55
19.7k
        _size = 0;
56
19.7k
    }
Imf_4_0::Array<void*>::Array()
Line
Count
Source
53
43.7k
    {
54
43.7k
        _data = 0;
55
43.7k
        _size = 0;
56
43.7k
    }
Imf_4_0::Array<char>::Array()
Line
Count
Source
53
107k
    {
54
107k
        _data = 0;
55
107k
        _size = 0;
56
107k
    }
Unexecuted instantiation: Imf_4_0::Array<unsigned char>::Array()
57
    Array (long size)
58
147k
    {
59
147k
        _data = new T[size];
60
147k
        _size = size;
61
147k
    }
Imf_4_0::Array<Imf_4_0::Array<void*> >::Array(long)
Line
Count
Source
58
19.7k
    {
59
19.7k
        _data = new T[size];
60
19.7k
        _size = size;
61
19.7k
    }
Imf_4_0::Array<Imf_4_0::Array2D<float*> >::Array(long)
Line
Count
Source
58
14.8k
    {
59
14.8k
        _data = new T[size];
60
14.8k
        _size = size;
61
14.8k
    }
Unexecuted instantiation: Imf_4_0::Array<Imf_4_0::Rgba>::Array(long)
Imf_4_0::Array<char>::Array(long)
Line
Count
Source
58
107k
    {
59
107k
        _data = new T[size];
60
107k
        _size = size;
61
107k
    }
Imf_4_0::Array<unsigned char>::Array(long)
Line
Count
Source
58
5.66k
    {
59
5.66k
        _data = new T[size];
60
5.66k
        _size = size;
61
5.66k
    }
62
319k
    ~Array () { delete[] _data; }
Imf_4_0::Array<void*>::~Array()
Line
Count
Source
62
43.7k
    ~Array () { delete[] _data; }
Imf_4_0::Array<Imf_4_0::Array<void*> >::~Array()
Line
Count
Source
62
19.7k
    ~Array () { delete[] _data; }
Imf_4_0::Array<unsigned int>::~Array()
Line
Count
Source
62
19.7k
    ~Array () { delete[] _data; }
Imf_4_0::Array<Imf_4_0::Array2D<float*> >::~Array()
Line
Count
Source
62
14.8k
    ~Array () { delete[] _data; }
Unexecuted instantiation: Imf_4_0::Array<Imf_4_0::Rgba>::~Array()
Imf_4_0::Array<char>::~Array()
Line
Count
Source
62
215k
    ~Array () { delete[] _data; }
Imf_4_0::Array<unsigned char>::~Array()
Line
Count
Source
62
5.66k
    ~Array () { delete[] _data; }
63
64
    //-----------------------------
65
    // Access to the array elements
66
    //-----------------------------
67
68
611k
    operator T* () { return _data; }
Imf_4_0::Array<Imf_4_0::Array<void*> >::operator Imf_4_0::Array<void*>*()
Line
Count
Source
68
106k
    operator T* () { return _data; }
Imf_4_0::Array<unsigned int>::operator unsigned int*()
Line
Count
Source
68
120k
    operator T* () { return _data; }
Imf_4_0::Array<void*>::operator void**()
Line
Count
Source
68
62.6k
    operator T* () { return _data; }
Imf_4_0::Array<Imf_4_0::Array2D<float*> >::operator Imf_4_0::Array2D<float*>*()
Line
Count
Source
68
101k
    operator T* () { return _data; }
Unexecuted instantiation: Imf_4_0::Array<Imf_4_0::Rgba>::operator Imf_4_0::Rgba*()
Imf_4_0::Array<char>::operator char*()
Line
Count
Source
68
215k
    operator T* () { return _data; }
Imf_4_0::Array<unsigned char>::operator unsigned char*()
Line
Count
Source
68
5.66k
    operator T* () { return _data; }
69
110k
    operator const T* () const { return _data; }
Imf_4_0::Array<char>::operator char const*() const
Line
Count
Source
69
107k
    operator const T* () const { return _data; }
Imf_4_0::Array<unsigned char>::operator unsigned char const*() const
Line
Count
Source
69
2.83k
    operator const T* () const { return _data; }
70
71
    //------------------------------------------------------
72
    // Resize and clear the array (the contents of the array
73
    // are not preserved across the resize operation).
74
    //
75
    // resizeEraseUnsafe() is more memory efficient than
76
    // resizeErase() because it deletes the old memory block
77
    // before allocating a new one, but if allocating the
78
    // new block throws an exception, resizeEraseUnsafe()
79
    // leaves the array in an unusable state.
80
    //
81
    //------------------------------------------------------
82
83
    void resizeErase (long size);
84
    void resizeEraseUnsafe (long size);
85
86
    //-------------------------------
87
    // Return the size of this array.
88
    //-------------------------------
89
90
5.66k
    long size () const { return _size; }
91
92
private:
93
    Array (const Array&)            = delete;
94
    Array& operator= (const Array&) = delete;
95
    Array (Array&&)                 = delete;
96
    Array& operator= (Array&&)      = delete;
97
98
    long _size;
99
    T*   _data;
100
};
101
102
template <class T> class IMF_EXPORT_TEMPLATE_TYPE Array2D
103
{
104
public:
105
    //-----------------------------
106
    // Constructors and destructors
107
    //-----------------------------
108
109
    Array2D ();                       // empty array, 0 by 0 elements
110
    Array2D (long sizeX, long sizeY); // sizeX by sizeY elements
111
    ~Array2D ();
112
113
    //-----------------------------
114
    // Access to the array elements
115
    //-----------------------------
116
117
    T*       operator[] (long x);
118
    const T* operator[] (long x) const;
119
120
    //------------------------------------------------------
121
    // Resize and clear the array (the contents of the array
122
    // are not preserved across the resize operation).
123
    //
124
    // resizeEraseUnsafe() is more memory efficient than
125
    // resizeErase() because it deletes the old memory block
126
    // before allocating a new one, but if allocating the
127
    // new block throws an exception, resizeEraseUnsafe()
128
    // leaves the array in an unusable state.
129
    //
130
    //------------------------------------------------------
131
132
    void resizeErase (long sizeX, long sizeY);
133
    void resizeEraseUnsafe (long sizeX, long sizeY);
134
135
    //-------------------------------
136
    // Return the size of this array.
137
    //-------------------------------
138
139
    long height () const { return _sizeX; }
140
    long width () const { return _sizeY; }
141
142
private:
143
    Array2D (const Array2D&)            = delete;
144
    Array2D& operator= (const Array2D&) = delete;
145
    Array2D (Array2D&&)                 = delete;
146
    Array2D& operator= (Array2D&&)      = delete;
147
148
    long _sizeX;
149
    long _sizeY;
150
    T*   _data;
151
};
152
153
//---------------
154
// Implementation
155
//---------------
156
157
template <class T>
158
inline void
159
Array<T>::resizeErase (long size)
160
279k
{
161
279k
    T* tmp = new T[size];
162
279k
    delete[] _data;
163
279k
    _size = size;
164
279k
    _data = tmp;
165
279k
}
Imf_4_0::Array<unsigned int>::resizeErase(long)
Line
Count
Source
160
19.7k
{
161
19.7k
    T* tmp = new T[size];
162
19.7k
    delete[] _data;
163
19.7k
    _size = size;
164
19.7k
    _data = tmp;
165
19.7k
}
Imf_4_0::Array<void*>::resizeErase(long)
Line
Count
Source
160
43.7k
{
161
43.7k
    T* tmp = new T[size];
162
43.7k
    delete[] _data;
163
43.7k
    _size = size;
164
43.7k
    _data = tmp;
165
43.7k
}
Imf_4_0::Array<char>::resizeErase(long)
Line
Count
Source
160
215k
{
161
215k
    T* tmp = new T[size];
162
215k
    delete[] _data;
163
215k
    _size = size;
164
215k
    _data = tmp;
165
215k
}
Unexecuted instantiation: Imf_4_0::Array<unsigned char>::resizeErase(long)
166
167
template <class T>
168
inline void
169
Array<T>::resizeEraseUnsafe (long size)
170
{
171
    delete[] _data;
172
    _data = 0;
173
    _size = 0;
174
    _data = new T[size];
175
    _size = size;
176
}
177
178
template <class T>
179
45.7k
inline Array2D<T>::Array2D () : _sizeX (0), _sizeY (0), _data (0)
180
45.7k
{
181
    // empty
182
45.7k
}
Imf_4_0::Array2D<unsigned int>::Array2D()
Line
Count
Source
179
14.8k
inline Array2D<T>::Array2D () : _sizeX (0), _sizeY (0), _data (0)
180
14.8k
{
181
    // empty
182
14.8k
}
Imf_4_0::Array2D<float*>::Array2D()
Line
Count
Source
179
30.8k
inline Array2D<T>::Array2D () : _sizeX (0), _sizeY (0), _data (0)
180
30.8k
{
181
    // empty
182
30.8k
}
183
184
template <class T>
185
inline Array2D<T>::Array2D (long sizeX, long sizeY)
186
    : _sizeX (sizeX), _sizeY (sizeY), _data (new T[sizeX * sizeY])
187
{
188
    // empty
189
}
190
191
template <class T> inline Array2D<T>::~Array2D ()
192
45.7k
{
193
45.7k
    delete[] _data;
194
45.7k
}
Imf_4_0::Array2D<float*>::~Array2D()
Line
Count
Source
192
30.8k
{
193
30.8k
    delete[] _data;
194
30.8k
}
Imf_4_0::Array2D<unsigned int>::~Array2D()
Line
Count
Source
192
14.8k
{
193
14.8k
    delete[] _data;
194
14.8k
}
195
196
template <class T>
197
inline T*
198
Array2D<T>::operator[] (long x)
199
9.85M
{
200
9.85M
    return _data + x * _sizeY;
201
9.85M
}
Imf_4_0::Array2D<unsigned int>::operator[](long)
Line
Count
Source
199
9.78M
{
200
9.78M
    return _data + x * _sizeY;
201
9.78M
}
Imf_4_0::Array2D<float*>::operator[](long)
Line
Count
Source
199
70.4k
{
200
70.4k
    return _data + x * _sizeY;
201
70.4k
}
202
203
template <class T>
204
inline const T*
205
Array2D<T>::operator[] (long x) const
206
{
207
    return _data + x * _sizeY;
208
}
209
210
template <class T>
211
inline void
212
Array2D<T>::resizeErase (long sizeX, long sizeY)
213
45.7k
{
214
45.7k
    T* tmp = new T[sizeX * sizeY];
215
45.7k
    delete[] _data;
216
45.7k
    _sizeX = sizeX;
217
45.7k
    _sizeY = sizeY;
218
45.7k
    _data  = tmp;
219
45.7k
}
Imf_4_0::Array2D<unsigned int>::resizeErase(long, long)
Line
Count
Source
213
14.8k
{
214
14.8k
    T* tmp = new T[sizeX * sizeY];
215
14.8k
    delete[] _data;
216
14.8k
    _sizeX = sizeX;
217
14.8k
    _sizeY = sizeY;
218
14.8k
    _data  = tmp;
219
14.8k
}
Imf_4_0::Array2D<float*>::resizeErase(long, long)
Line
Count
Source
213
30.8k
{
214
30.8k
    T* tmp = new T[sizeX * sizeY];
215
30.8k
    delete[] _data;
216
30.8k
    _sizeX = sizeX;
217
30.8k
    _sizeY = sizeY;
218
30.8k
    _data  = tmp;
219
30.8k
}
220
221
template <class T>
222
inline void
223
Array2D<T>::resizeEraseUnsafe (long sizeX, long sizeY)
224
{
225
    delete[] _data;
226
    _data  = 0;
227
    _sizeX = 0;
228
    _sizeY = 0;
229
    _data  = new T[sizeX * sizeY];
230
    _sizeX = sizeX;
231
    _sizeY = sizeY;
232
}
233
234
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
235
236
#endif