Coverage Report

Created: 2025-07-16 07:53

/usr/local/include/OpenEXR/ImfArray.h
Line
Count
Source (jump to first uncovered line)
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
    {
54
        _data = 0;
55
        _size = 0;
56
    }
57
    Array (long size)
58
    {
59
        _data = new T[size];
60
        _size = size;
61
    }
62
    ~Array () { delete[] _data; }
63
64
    //-----------------------------
65
    // Access to the array elements
66
    //-----------------------------
67
68
    operator T* () { return _data; }
69
    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
    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
0
    long height () const { return _sizeX; }
140
0
    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
{
161
    T* tmp = new T[size];
162
    delete[] _data;
163
    _size = size;
164
    _data = tmp;
165
}
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
4.80k
inline Array2D<T>::Array2D () : _sizeX (0), _sizeY (0), _data (0)
180
4.80k
{
181
    // empty
182
4.80k
}
Imf_3_3::Array2D<Imf_3_3::Rgba>::Array2D()
Line
Count
Source
179
4.80k
inline Array2D<T>::Array2D () : _sizeX (0), _sizeY (0), _data (0)
180
4.80k
{
181
    // empty
182
4.80k
}
Unexecuted instantiation: Imf_3_3::Array2D<Imf_3_3::PreviewRgba>::Array2D()
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
4.80k
{
193
4.80k
    delete[] _data;
194
4.80k
}
Imf_3_3::Array2D<Imf_3_3::Rgba>::~Array2D()
Line
Count
Source
192
4.80k
{
193
4.80k
    delete[] _data;
194
4.80k
}
Unexecuted instantiation: Imf_3_3::Array2D<Imf_3_3::PreviewRgba>::~Array2D()
195
196
template <class T>
197
inline T*
198
Array2D<T>::operator[] (long x)
199
990M
{
200
990M
    return _data + x * _sizeY;
201
990M
}
Imf_3_3::Array2D<Imf_3_3::Rgba>::operator[](long)
Line
Count
Source
199
990M
{
200
990M
    return _data + x * _sizeY;
201
990M
}
Unexecuted instantiation: Imf_3_3::Array2D<Imf_3_3::PreviewRgba>::operator[](long)
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
4.80k
{
214
4.80k
    T* tmp = new T[sizeX * sizeY];
215
4.80k
    delete[] _data;
216
4.80k
    _sizeX = sizeX;
217
4.80k
    _sizeY = sizeY;
218
4.80k
    _data  = tmp;
219
4.80k
}
Imf_3_3::Array2D<Imf_3_3::Rgba>::resizeErase(long, long)
Line
Count
Source
213
4.80k
{
214
4.80k
    T* tmp = new T[sizeX * sizeY];
215
4.80k
    delete[] _data;
216
4.80k
    _sizeX = sizeX;
217
4.80k
    _sizeY = sizeY;
218
4.80k
    _data  = tmp;
219
4.80k
}
Unexecuted instantiation: Imf_3_3::Array2D<Imf_3_3::PreviewRgba>::resizeErase(long, long)
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