Blender
V4.3
intern
libmv
libmv
base
scoped_ptr.h
Go to the documentation of this file.
1
// Copyright (c) 2009 libmv authors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to
5
// deal in the Software without restriction, including without limitation the
6
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
// sell copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
// IN THE SOFTWARE.
20
21
#ifndef LIBMV_BASE_SCOPED_PTR_H
22
#define LIBMV_BASE_SCOPED_PTR_H
23
24
#include <cassert>
25
#include <cstddef>
26
27
namespace
libmv
{
28
33
template
<
typename
T>
34
class
scoped_ptr
{
35
public
:
36
scoped_ptr
(T* resource) : resource_(resource) {}
37
~scoped_ptr
() {
reset
(0); }
38
39
T*
get
()
const
{
return
resource_; }
40
T*
operator->
()
const
{
return
resource_; }
41
T&
operator*
()
const
{
return
*resource_; }
42
43
void
reset
(T* new_resource) {
44
if
(
sizeof
(T)) {
45
delete
resource_;
46
}
47
resource_ = new_resource;
48
}
49
50
T*
release
() {
51
T* released_resource = resource_;
52
resource_ = 0;
53
return
released_resource;
54
}
55
56
private
:
57
// No copying allowed.
58
T* resource_;
59
};
60
61
// Same as scoped_ptr but caller must allocate the data
62
// with new[] and the destructor will free the memory
63
// using delete[].
64
template
<
typename
T>
65
class
scoped_array
{
66
public
:
67
scoped_array
(T* array) : array_(array) {}
68
~scoped_array
() {
reset
(
NULL
); }
69
70
T*
get
()
const
{
return
array_; }
71
72
T&
operator[]
(std::ptrdiff_t i)
const
{
73
assert(i >= 0);
74
assert(array_ !=
NULL
);
75
return
array_[i];
76
}
77
78
void
reset
(T* new_array) {
79
if
(
sizeof
(T)) {
80
delete
[] array_;
81
}
82
array_ = new_array;
83
}
84
85
T*
release
() {
86
T* released_array = array_;
87
array_ =
NULL
;
88
return
released_array;
89
}
90
91
private
:
92
T* array_;
93
94
// Forbid comparison of different scoped_array types.
95
template
<
typename
T2>
96
bool
operator==(
scoped_array<T2>
const
& p2)
const
;
97
template
<
typename
T2>
98
bool
operator!=(
scoped_array<T2>
const
& p2)
const
;
99
100
// Disallow evil constructors
101
scoped_array
(
const
scoped_array
&);
102
void
operator=(
const
scoped_array
&);
103
};
104
105
}
// namespace libmv
106
107
#endif
// LIBMV_BASE_SCOPED_PTR_H
reset
void reset()
clear internal cached data and reset random seed
Definition
btTetrahedronShape.h:40
libmv::scoped_array
Definition
scoped_ptr.h:65
libmv::scoped_array::operator[]
T & operator[](std::ptrdiff_t i) const
Definition
scoped_ptr.h:72
libmv::scoped_array::reset
void reset(T *new_array)
Definition
scoped_ptr.h:78
libmv::scoped_array::release
T * release()
Definition
scoped_ptr.h:85
libmv::scoped_array::~scoped_array
~scoped_array()
Definition
scoped_ptr.h:68
libmv::scoped_array::get
T * get() const
Definition
scoped_ptr.h:70
libmv::scoped_array::scoped_array
scoped_array(T *array)
Definition
scoped_ptr.h:67
libmv::scoped_ptr
Definition
scoped_ptr.h:34
libmv::scoped_ptr::operator*
T & operator*() const
Definition
scoped_ptr.h:41
libmv::scoped_ptr::reset
void reset(T *new_resource)
Definition
scoped_ptr.h:43
libmv::scoped_ptr::release
T * release()
Definition
scoped_ptr.h:50
libmv::scoped_ptr::scoped_ptr
scoped_ptr(T *resource)
Definition
scoped_ptr.h:36
libmv::scoped_ptr::~scoped_ptr
~scoped_ptr()
Definition
scoped_ptr.h:37
libmv::scoped_ptr::get
T * get() const
Definition
scoped_ptr.h:39
libmv::scoped_ptr::operator->
T * operator->() const
Definition
scoped_ptr.h:40
NULL
#define NULL
Definition
device/metal/compat.h:315
libmv
Definition
libmv/autotrack/autotrack.h:30
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0