Coverage Report

Created: 2021-08-22 09:07

/src/skia/third_party/externals/dng_sdk/source/dng_auto_ptr.h
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************/
2
// Copyright 2006 Adobe Systems Incorporated
3
// All Rights Reserved.
4
//
5
// NOTICE:  Adobe permits you to use, modify, and distribute this file in
6
// accordance with the terms of the Adobe license agreement accompanying it.
7
/*****************************************************************************/
8
9
/* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_auto_ptr.h#2 $ */ 
10
/* $DateTime: 2012/07/11 10:36:56 $ */
11
/* $Change: 838485 $ */
12
/* $Author: tknoll $ */
13
14
/** \file
15
 * Class to implement std::auto_ptr like functionality even on platforms which do not
16
 * have a full Standard C++ library.
17
 */
18
19
/*****************************************************************************/
20
21
#ifndef __dng_auto_ptr__
22
#define __dng_auto_ptr__
23
24
#include "dng_memory.h"
25
26
#include <memory>
27
#include <stddef.h>
28
#include <stdlib.h>
29
30
/*****************************************************************************/
31
32
// The following template has similar functionality to the STL auto_ptr, without
33
// requiring all the weight of STL.
34
35
/*****************************************************************************/
36
37
/// \brief A class intended to be used in stack scope to hold a pointer from new. The
38
/// held pointer will be deleted automatically if the scope is left without calling
39
/// Release on the AutoPtr first.
40
41
template<class T>
42
class AutoPtr
43
  {
44
  
45
  private:
46
  
47
    T *p_;
48
    
49
  public:
50
51
    /// Construct an AutoPtr with no referent.
52
53
240k
    AutoPtr () : p_ (0) { }
AutoPtr<dng_exif>::AutoPtr()
Line
Count
Source
53
7.07k
    AutoPtr () : p_ (0) { }
AutoPtr<dng_shared>::AutoPtr()
Line
Count
Source
53
7.07k
    AutoPtr () : p_ (0) { }
AutoPtr<dng_ifd>::AutoPtr()
Line
Count
Source
53
226k
    AutoPtr () : p_ (0) { }
Unexecuted instantiation: AutoPtr<dng_memory_block>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_linearization_info>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_mosaic_info>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_image>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_jpeg_image>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_hue_sat_map>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_1d_table>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_spline_solver>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_bad_pixel_list>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_gain_map>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_metadata>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_tiff_directory>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_basic_tag_set>::AutoPtr()
Unexecuted instantiation: AutoPtr<profile_tag_set>::AutoPtr()
Unexecuted instantiation: AutoPtr<color_tag_set>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_linearize_plane>::AutoPtr()
Unexecuted instantiation: AutoPtr<dng_preview>::AutoPtr()
54
  
55
    /// Construct an AutoPtr which owns the argument pointer.
56
    /// \param p pointer which constructed AutoPtr takes ownership of. p will be
57
    /// deleted on destruction or Reset unless Release is called first.
58
59
0
    explicit AutoPtr (T *p) :  p_( p ) { }
Unexecuted instantiation: AutoPtr<dng_memory_block>::AutoPtr(dng_memory_block*)
Unexecuted instantiation: AutoPtr<dng_warp_params>::AutoPtr(dng_warp_params*)
Unexecuted instantiation: AutoPtr<dng_image>::AutoPtr(dng_image*)
Unexecuted instantiation: AutoPtr<dng_exif>::AutoPtr(dng_exif*)
Unexecuted instantiation: AutoPtr<dng_negative>::AutoPtr(dng_negative*)
Unexecuted instantiation: AutoPtr<dng_camera_profile>::AutoPtr(dng_camera_profile*)
Unexecuted instantiation: AutoPtr<dng_opcode>::AutoPtr(dng_opcode*)
Unexecuted instantiation: AutoPtr<dng_jpeg_image>::AutoPtr(dng_jpeg_image*)
Unexecuted instantiation: AutoPtr<dng_color_spec>::AutoPtr(dng_color_spec*)
Unexecuted instantiation: AutoPtr<dng_simple_image>::AutoPtr(dng_simple_image*)
Unexecuted instantiation: AutoPtr<dng_gain_map>::AutoPtr(dng_gain_map*)
Unexecuted instantiation: AutoPtr<dng_hue_sat_map>::AutoPtr(dng_hue_sat_map*)
Unexecuted instantiation: AutoPtr<dng_metadata>::AutoPtr(dng_metadata*)
Unexecuted instantiation: AutoPtr<dng_bilinear_interpolator>::AutoPtr(dng_bilinear_interpolator*)
60
61
    /// Reset is called on destruction.
62
63
    ~AutoPtr ();
64
65
    /// Call Reset with a pointer from new. Uses T's default constructor.
66
67
    void Alloc ();
68
69
    /// Return the owned pointer of this AutoPtr, NULL if none. No change in
70
    /// ownership or other effects occur.
71
72
68.2k
    T *Get () const { return p_; }
Unexecuted instantiation: AutoPtr<dng_memory_block>::Get() const
AutoPtr<dng_exif>::Get() const
Line
Count
Source
72
24.0k
    T *Get () const { return p_; }
Unexecuted instantiation: AutoPtr<dng_linearization_info>::Get() const
Unexecuted instantiation: AutoPtr<dng_mosaic_info>::Get() const
Unexecuted instantiation: AutoPtr<dng_image>::Get() const
AutoPtr<dng_shared>::Get() const
Line
Count
Source
72
24.0k
    T *Get () const { return p_; }
AutoPtr<dng_ifd>::Get() const
Line
Count
Source
72
20.0k
    T *Get () const { return p_; }
Unexecuted instantiation: AutoPtr<dng_negative>::Get() const
Unexecuted instantiation: AutoPtr<dng_camera_profile>::Get() const
Unexecuted instantiation: AutoPtr<dng_jpeg_image>::Get() const
Unexecuted instantiation: AutoPtr<dng_hue_sat_map>::Get() const
Unexecuted instantiation: AutoPtr<dng_1d_table>::Get() const
Unexecuted instantiation: AutoPtr<dng_spline_solver>::Get() const
Unexecuted instantiation: AutoPtr<dng_metadata>::Get() const
Unexecuted instantiation: AutoPtr<dng_preview>::Get() const
73
74
    /// Return the owned pointer of this AutoPtr, NULL if none. The AutoPtr gives
75
    /// up ownership and takes NULL as its value.
76
77
    T *Release ();
78
79
    /// If a pointer is owned, it is deleted. Ownership is taken of passed in
80
    /// pointer.
81
    /// \param p pointer which constructed AutoPtr takes ownership of. p will be
82
    /// deleted on destruction or Reset unless Release is called first.
83
84
    void Reset (T *p);
85
86
    /// If a pointer is owned, it is deleted and the AutoPtr takes NULL as its
87
    /// value.
88
89
    void Reset ();
90
91
    /// Allows members of the owned pointer to be accessed directly. It is an
92
    /// error to call this if the AutoPtr has NULL as its value.
93
94
98.0k
    T *operator-> () const { return p_; }
Unexecuted instantiation: AutoPtr<dng_memory_block>::operator->() const
AutoPtr<dng_exif>::operator->() const
Line
Count
Source
94
3.72k
    T *operator-> () const { return p_; }
AutoPtr<dng_shared>::operator->() const
Line
Count
Source
94
32.2k
    T *operator-> () const { return p_; }
AutoPtr<dng_ifd>::operator->() const
Line
Count
Source
94
62.0k
    T *operator-> () const { return p_; }
Unexecuted instantiation: AutoPtr<dng_warp_params>::operator->() const
Unexecuted instantiation: AutoPtr<dng_image>::operator->() const
Unexecuted instantiation: AutoPtr<dng_negative>::operator->() const
Unexecuted instantiation: AutoPtr<dng_camera_profile>::operator->() const
Unexecuted instantiation: AutoPtr<dng_jpeg_image>::operator->() const
Unexecuted instantiation: AutoPtr<dng_opcode>::operator->() const
Unexecuted instantiation: AutoPtr<dng_color_spec>::operator->() const
Unexecuted instantiation: AutoPtr<dng_simple_image>::operator->() const
Unexecuted instantiation: AutoPtr<dng_bad_pixel_list>::operator->() const
Unexecuted instantiation: AutoPtr<dng_1d_table>::operator->() const
Unexecuted instantiation: AutoPtr<dng_gain_map>::operator->() const
Unexecuted instantiation: AutoPtr<dng_hue_sat_map>::operator->() const
Unexecuted instantiation: AutoPtr<dng_metadata>::operator->() const
Unexecuted instantiation: AutoPtr<dng_tiff_directory>::operator->() const
Unexecuted instantiation: AutoPtr<dng_linearize_plane>::operator->() const
Unexecuted instantiation: AutoPtr<dng_bilinear_interpolator>::operator->() const
95
96
    /// Returns a reference to the object that the owned pointer points to. It is
97
    /// an error to call this if the AutoPtr has NULL as its value.
98
99
0
    T &operator* () const { return *p_; }
Unexecuted instantiation: AutoPtr<dng_image>::operator*() const
Unexecuted instantiation: AutoPtr<dng_preview>::operator*() const
Unexecuted instantiation: AutoPtr<dng_gain_map>::operator*() const
Unexecuted instantiation: AutoPtr<dng_metadata>::operator*() const
Unexecuted instantiation: AutoPtr<dng_tiff_directory>::operator*() const
Unexecuted instantiation: AutoPtr<dng_ifd>::operator*() const
Unexecuted instantiation: AutoPtr<dng_basic_tag_set>::operator*() const
100
    
101
    /// Swap with another auto ptr.
102
    
103
    friend inline void Swap (AutoPtr< T > &x, AutoPtr< T > &y)
104
      {
105
      T* temp = x.p_;
106
      x.p_ = y.p_;
107
      y.p_ = temp;
108
      }
109
    
110
  private:
111
  
112
    // Hidden copy constructor and assignment operator. I don't think the STL
113
    // "feature" of grabbing ownership of the pointer is a good idea.
114
  
115
    AutoPtr (AutoPtr<T> &rhs);
116
117
    AutoPtr<T> & operator= (AutoPtr<T> &rhs);
118
    
119
  };
120
121
/*****************************************************************************/
122
123
template<class T>
124
AutoPtr<T>::~AutoPtr ()
125
240k
  {
126
  
127
240k
  delete p_;
128
240k
  p_ = 0;
129
  
130
240k
  }
AutoPtr<dng_ifd>::~AutoPtr()
Line
Count
Source
125
226k
  {
126
  
127
226k
  delete p_;
128
226k
  p_ = 0;
129
  
130
226k
  }
AutoPtr<dng_exif>::~AutoPtr()
Line
Count
Source
125
7.07k
  {
126
  
127
7.07k
  delete p_;
128
7.07k
  p_ = 0;
129
  
130
7.07k
  }
AutoPtr<dng_shared>::~AutoPtr()
Line
Count
Source
125
7.07k
  {
126
  
127
7.07k
  delete p_;
128
7.07k
  p_ = 0;
129
  
130
7.07k
  }
Unexecuted instantiation: AutoPtr<dng_memory_block>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_warp_params>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_image>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_linearization_info>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_mosaic_info>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_jpeg_image>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_negative>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_camera_profile>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_opcode>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_spline_solver>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_hue_sat_map>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_1d_table>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_color_spec>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_simple_image>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_bad_pixel_list>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_gain_map>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_metadata>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_tiff_directory>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_basic_tag_set>::~AutoPtr()
Unexecuted instantiation: AutoPtr<profile_tag_set>::~AutoPtr()
Unexecuted instantiation: AutoPtr<color_tag_set>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_linearize_plane>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_bilinear_interpolator>::~AutoPtr()
Unexecuted instantiation: AutoPtr<dng_preview>::~AutoPtr()
131
132
/*****************************************************************************/
133
134
template<class T>
135
T *AutoPtr<T>::Release ()
136
0
  {
137
0
  T *result = p_;
138
0
  p_ = 0;
139
0
  return result;
140
0
  }
Unexecuted instantiation: AutoPtr<dng_memory_block>::Release()
Unexecuted instantiation: AutoPtr<dng_warp_params>::Release()
Unexecuted instantiation: AutoPtr<dng_image>::Release()
Unexecuted instantiation: AutoPtr<dng_negative>::Release()
Unexecuted instantiation: AutoPtr<dng_camera_profile>::Release()
Unexecuted instantiation: AutoPtr<dng_exif>::Release()
Unexecuted instantiation: AutoPtr<dng_jpeg_image>::Release()
Unexecuted instantiation: AutoPtr<dng_opcode>::Release()
Unexecuted instantiation: AutoPtr<dng_simple_image>::Release()
Unexecuted instantiation: AutoPtr<dng_bad_pixel_list>::Release()
Unexecuted instantiation: AutoPtr<dng_gain_map>::Release()
Unexecuted instantiation: AutoPtr<dng_hue_sat_map>::Release()
Unexecuted instantiation: AutoPtr<dng_preview>::Release()
141
142
/*****************************************************************************/
143
144
template<class T>
145
void AutoPtr<T>::Reset (T *p)
146
34.2k
  {
147
  
148
34.2k
  if (p_ != p)
149
34.2k
    {
150
34.2k
    if (p_ != 0)
151
0
      delete p_;
152
34.2k
    p_ = p;
153
34.2k
    }
154
  
155
34.2k
  }
Unexecuted instantiation: AutoPtr<dng_memory_block>::Reset(dng_memory_block*)
AutoPtr<dng_exif>::Reset(dng_exif*)
Line
Count
Source
146
7.07k
  {
147
  
148
7.07k
  if (p_ != p)
149
7.07k
    {
150
7.07k
    if (p_ != 0)
151
0
      delete p_;
152
7.07k
    p_ = p;
153
7.07k
    }
154
  
155
7.07k
  }
AutoPtr<dng_shared>::Reset(dng_shared*)
Line
Count
Source
146
7.07k
  {
147
  
148
7.07k
  if (p_ != p)
149
7.07k
    {
150
7.07k
    if (p_ != 0)
151
0
      delete p_;
152
7.07k
    p_ = p;
153
7.07k
    }
154
  
155
7.07k
  }
AutoPtr<dng_ifd>::Reset(dng_ifd*)
Line
Count
Source
146
20.0k
  {
147
  
148
20.0k
  if (p_ != p)
149
20.0k
    {
150
20.0k
    if (p_ != 0)
151
0
      delete p_;
152
20.0k
    p_ = p;
153
20.0k
    }
154
  
155
20.0k
  }
Unexecuted instantiation: AutoPtr<dng_image>::Reset(dng_image*)
Unexecuted instantiation: AutoPtr<dng_jpeg_image>::Reset(dng_jpeg_image*)
Unexecuted instantiation: AutoPtr<dng_linearization_info>::Reset(dng_linearization_info*)
Unexecuted instantiation: AutoPtr<dng_mosaic_info>::Reset(dng_mosaic_info*)
Unexecuted instantiation: AutoPtr<dng_hue_sat_map>::Reset(dng_hue_sat_map*)
Unexecuted instantiation: AutoPtr<dng_spline_solver>::Reset(dng_spline_solver*)
Unexecuted instantiation: AutoPtr<dng_bad_pixel_list>::Reset(dng_bad_pixel_list*)
Unexecuted instantiation: AutoPtr<dng_1d_table>::Reset(dng_1d_table*)
Unexecuted instantiation: AutoPtr<dng_gain_map>::Reset(dng_gain_map*)
Unexecuted instantiation: AutoPtr<dng_metadata>::Reset(dng_metadata*)
Unexecuted instantiation: AutoPtr<dng_tiff_directory>::Reset(dng_tiff_directory*)
Unexecuted instantiation: AutoPtr<dng_basic_tag_set>::Reset(dng_basic_tag_set*)
Unexecuted instantiation: AutoPtr<profile_tag_set>::Reset(profile_tag_set*)
Unexecuted instantiation: AutoPtr<color_tag_set>::Reset(color_tag_set*)
Unexecuted instantiation: AutoPtr<dng_linearize_plane>::Reset(dng_linearize_plane*)
Unexecuted instantiation: AutoPtr<dng_preview>::Reset(dng_preview*)
156
157
/*****************************************************************************/
158
159
template<class T>
160
void AutoPtr<T>::Reset ()
161
0
  {
162
  
163
0
  if (p_ != 0)
164
0
    {
165
0
    delete p_;
166
0
    p_ = 0;
167
0
    }
168
  
169
0
  }
Unexecuted instantiation: AutoPtr<dng_memory_block>::Reset()
Unexecuted instantiation: AutoPtr<dng_linearization_info>::Reset()
Unexecuted instantiation: AutoPtr<dng_mosaic_info>::Reset()
Unexecuted instantiation: AutoPtr<dng_jpeg_image>::Reset()
Unexecuted instantiation: AutoPtr<dng_image>::Reset()
Unexecuted instantiation: AutoPtr<dng_1d_table>::Reset()
170
171
/*****************************************************************************/
172
173
template<class T>
174
void AutoPtr<T>::Alloc ()
175
  {
176
  this->Reset (new T);
177
  }
178
179
/*****************************************************************************/
180
181
/// \brief A class that provides a variable-length array that automatically
182
/// deletes the underlying memory on scope exit.
183
///
184
/// T is not required to be movable. The class is implemented using
185
/// dng_std_vector but purposely does not use any member functions that require
186
/// T to be movable.
187
188
template<typename T>
189
class AutoArray
190
  {
191
192
  public:
193
    /// Construct an AutoArray that refers to a null pointer.
194
195
0
    AutoArray () { }
Unexecuted instantiation: AutoArray<dng_fingerprint>::AutoArray()
Unexecuted instantiation: AutoArray<AutoPtr<dng_memory_block> >::AutoArray()
196
    
197
    /// Construct an AutoArray containing 'count' elements, which are
198
    /// default-constructed. If an out-of-memory condition occurs, a
199
    /// dng_exception with error code dng_error_memory is thrown.
200
201
    explicit AutoArray (size_t count)
202
      : vector_(new dng_std_vector<T>(count))
203
0
      {
204
0
      }
205
206
    /// Changes the size of the AutoArray to 'count' elements. The new
207
    /// elements are default-constructed. The previously existing elements
208
    /// of the array are destroyed. If an out-of-memory condition occurs, a
209
    /// dng_exception with error code dng_error_memory is thrown.
210
211
    void Reset (size_t count)
212
0
      {
213
0
      vector_.reset(new dng_std_vector<T>(count));
214
0
      }
Unexecuted instantiation: AutoArray<dng_fingerprint>::Reset(unsigned long)
Unexecuted instantiation: AutoArray<AutoPtr<dng_memory_block> >::Reset(unsigned long)
215
216
    /// Allows indexing into the AutoArray. The index 'i' must be
217
    /// non-negative and smaller than size of the array (the value that was
218
    /// passed to the constructor or to Reset()).
219
220
    T &operator[] (ptrdiff_t i)
221
0
      {
222
0
      return (*vector_) [i];
223
0
      }
Unexecuted instantiation: AutoArray<dng_fingerprint>::operator[](long)
Unexecuted instantiation: AutoArray<AutoPtr<dng_memory_block> >::operator[](long)
224
    const T &operator[] (ptrdiff_t i) const
225
0
      {
226
0
      return (*vector_) [i];
227
0
      }
228
229
    /// Return a pointer to the beginning of the array.
230
231
    T *Get ()
232
0
      {
233
0
      if (vector_)
234
0
        return vector_->data();
235
0
      else
236
0
        return nullptr;
237
0
      }
238
    const T *Get () const
239
      {
240
      if (vector_)
241
        return vector_->data();
242
      else
243
        return nullptr;
244
      }
245
246
  private:
247
248
    // Hidden copy constructor and assignment operator.
249
250
    AutoArray (const AutoArray &);
251
252
    const AutoArray & operator= (const AutoArray &);
253
254
  private:
255
256
    std::unique_ptr<dng_std_vector<T> > vector_;
257
258
  };
259
260
/*****************************************************************************/
261
262
#endif
263
264
/*****************************************************************************/