| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------- |
|
2
|
|
|
|
|
|
|
| Copyright (c) 2013-2017, Nucleic Development Team. |
|
3
|
|
|
|
|
|
|
| |
|
4
|
|
|
|
|
|
|
| Distributed under the terms of the Modified BSD License. |
|
5
|
|
|
|
|
|
|
| |
|
6
|
|
|
|
|
|
|
| The full license is in the file LICENSE, distributed with this software. |
|
7
|
|
|
|
|
|
|
|----------------------------------------------------------------------------*/ |
|
8
|
|
|
|
|
|
|
#pragma once |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
namespace kiwi |
|
11
|
|
|
|
|
|
|
{ |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
class SharedData |
|
14
|
|
|
|
|
|
|
{ |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
public: |
|
17
|
6817
|
|
|
|
|
|
SharedData() : m_refcount(0) {} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
SharedData(const SharedData &other) = delete; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
SharedData(SharedData&& other) = delete; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
int m_refcount; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
SharedData &operator=(const SharedData &other) = delete; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
SharedData &operator=(SharedData&& other) = delete; |
|
28
|
|
|
|
|
|
|
}; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
template <typename T> |
|
31
|
|
|
|
|
|
|
class SharedDataPtr |
|
32
|
|
|
|
|
|
|
{ |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
public: |
|
35
|
|
|
|
|
|
|
using Type = T; |
|
36
|
|
|
|
|
|
|
|
|
37
|
1438
|
|
|
|
|
|
SharedDataPtr() : m_data(nullptr) {} |
|
38
|
|
|
|
|
|
|
|
|
39
|
6817
|
|
|
|
|
|
explicit SharedDataPtr(T *data) : m_data(data) |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
6817
|
|
|
|
|
|
incref(m_data); |
|
42
|
6817
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
73294
|
|
|
|
|
|
~SharedDataPtr() |
|
45
|
|
|
|
|
|
|
{ |
|
46
|
73294
|
|
|
|
|
|
decref(m_data); |
|
47
|
73294
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
T *data() |
|
50
|
|
|
|
|
|
|
{ |
|
51
|
|
|
|
|
|
|
return m_data; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
const T *data() const |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
|
|
|
|
|
|
return m_data; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
operator T *() |
|
60
|
|
|
|
|
|
|
{ |
|
61
|
|
|
|
|
|
|
return m_data; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
operator const T *() const |
|
65
|
|
|
|
|
|
|
{ |
|
66
|
|
|
|
|
|
|
return m_data; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
16433
|
|
|
|
|
|
T *operator->() |
|
70
|
|
|
|
|
|
|
{ |
|
71
|
16433
|
|
|
|
|
|
return m_data; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
14866
|
|
|
|
|
|
const T *operator->() const |
|
75
|
|
|
|
|
|
|
{ |
|
76
|
14866
|
|
|
|
|
|
return m_data; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
T &operator*() |
|
80
|
|
|
|
|
|
|
{ |
|
81
|
|
|
|
|
|
|
return *m_data; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
const T &operator*() const |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
|
|
|
|
|
|
return *m_data; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
bool operator!() const |
|
90
|
|
|
|
|
|
|
{ |
|
91
|
0
|
|
|
|
|
|
return !m_data; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
157642
|
|
|
|
|
|
bool operator<(const SharedDataPtr<T> &other) const |
|
95
|
|
|
|
|
|
|
{ |
|
96
|
157642
|
|
|
|
|
|
return m_data < other.m_data; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
|
bool operator==(const SharedDataPtr<T> &other) const |
|
100
|
|
|
|
|
|
|
{ |
|
101
|
2
|
|
|
|
|
|
return m_data == other.m_data; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
bool operator!=(const SharedDataPtr<T> &other) const |
|
105
|
|
|
|
|
|
|
{ |
|
106
|
|
|
|
|
|
|
return m_data != other.m_data; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
50582
|
|
|
|
|
|
SharedDataPtr(const SharedDataPtr<T> &other) : m_data(other.m_data) |
|
110
|
|
|
|
|
|
|
{ |
|
111
|
50582
|
|
|
|
|
|
incref(m_data); |
|
112
|
50582
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
28267
|
|
|
|
|
|
SharedDataPtr(SharedDataPtr&& other) noexcept : m_data(other.m_data) |
|
115
|
|
|
|
|
|
|
{ |
|
116
|
28267
|
|
|
|
|
|
other.m_data = nullptr; |
|
117
|
28267
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
1438
|
|
|
|
|
|
SharedDataPtr<T> &operator=(const SharedDataPtr<T> &other) |
|
120
|
|
|
|
|
|
|
{ |
|
121
|
1438
|
0
|
|
|
|
|
if (m_data != other.m_data) |
|
|
|
50
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
{ |
|
123
|
1438
|
|
|
|
|
|
T *temp = m_data; |
|
124
|
1438
|
|
|
|
|
|
m_data = other.m_data; |
|
125
|
1438
|
|
|
|
|
|
incref(m_data); |
|
126
|
1438
|
|
|
|
|
|
decref(temp); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
1438
|
|
|
|
|
|
return *this; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
213186
|
|
|
|
|
|
SharedDataPtr<T>& operator=(SharedDataPtr<T>&& other) noexcept |
|
132
|
|
|
|
|
|
|
{ |
|
133
|
213186
|
50
|
|
|
|
|
if (m_data != other.m_data) |
|
|
|
100
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
{ |
|
135
|
213007
|
|
|
|
|
|
decref(m_data); |
|
136
|
|
|
|
|
|
|
|
|
137
|
213007
|
|
|
|
|
|
m_data = other.m_data; |
|
138
|
213007
|
|
|
|
|
|
other.m_data = nullptr; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
213186
|
|
|
|
|
|
return *this; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
SharedDataPtr<T> &operator=(T *other) |
|
144
|
|
|
|
|
|
|
{ |
|
145
|
|
|
|
|
|
|
if (m_data != other) |
|
146
|
|
|
|
|
|
|
{ |
|
147
|
|
|
|
|
|
|
T *temp = m_data; |
|
148
|
|
|
|
|
|
|
m_data = other; |
|
149
|
|
|
|
|
|
|
incref(m_data); |
|
150
|
|
|
|
|
|
|
decref(temp); |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
return *this; |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
private: |
|
156
|
58837
|
|
|
|
|
|
static void incref(T *data) |
|
157
|
|
|
|
|
|
|
{ |
|
158
|
58837
|
100
|
|
|
|
|
if (data) |
|
|
|
50
|
|
|
|
|
|
|
159
|
58118
|
|
|
|
|
|
++data->m_refcount; |
|
160
|
58837
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
287739
|
|
|
|
|
|
static void decref(T *data) |
|
163
|
|
|
|
|
|
|
{ |
|
164
|
287739
|
100
|
|
|
|
|
if (data && --data->m_refcount == 0) |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
165
|
719
|
50
|
|
|
|
|
delete data; |
|
|
|
0
|
|
|
|
|
|
|
166
|
287739
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
T *m_data; |
|
169
|
|
|
|
|
|
|
}; |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
} // namespace kiwi |