catboost 1.25.1 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEPLOYMENT.md +22 -15
- package/README.md +37 -27
- package/binding.gyp +5 -7
- package/build_scripts/bootstrap.js +2 -1
- package/build_scripts/out/build.js +46 -68
- package/build_scripts/out/build_model.js +1 -1
- package/build_scripts/out/{build_ya.js → build_native.js} +1 -1
- package/build_scripts/out/ci.js +5 -5
- package/build_scripts/out/config.js +32 -18
- package/build_scripts/out/install.js +5 -3
- package/build_scripts/out/package_prepublish.js +1 -1
- package/build_scripts/out/packaging.js +1 -19
- package/build_scripts/out/run_tests.js +1 -1
- package/build_scripts/out/test.js +8 -3
- package/config.json +18 -11
- package/inc/catboost/libs/model_interface/c_api.h +349 -3
- package/lib/catboost.d.ts +65 -21
- package/package.json +4 -4
- package/src/api_helpers.cpp +100 -24
- package/src/api_helpers.h +8 -7
- package/src/api_module.cpp +1 -2
- package/src/model.cpp +483 -83
- package/src/model.h +24 -9
- package/inc/contrib/libs/cxxsupp/system_stl/include/stlfwd +0 -14
- package/inc/util/charset/recode_result.h +0 -9
- package/inc/util/charset/unicode_table.h +0 -123
- package/inc/util/charset/unidata.h +0 -421
- package/inc/util/charset/utf8.h +0 -384
- package/inc/util/charset/wide.h +0 -843
- package/inc/util/charset/wide_specific.h +0 -22
- package/inc/util/datetime/base.h +0 -669
- package/inc/util/datetime/constants.h +0 -7
- package/inc/util/datetime/cputimer.h +0 -124
- package/inc/util/datetime/parser.h +0 -292
- package/inc/util/datetime/systime.h +0 -47
- package/inc/util/datetime/uptime.h +0 -8
- package/inc/util/digest/city.h +0 -88
- package/inc/util/digest/fnv.h +0 -73
- package/inc/util/digest/multi.h +0 -14
- package/inc/util/digest/murmur.h +0 -57
- package/inc/util/digest/numeric.h +0 -86
- package/inc/util/digest/sequence.h +0 -48
- package/inc/util/draft/date.h +0 -129
- package/inc/util/draft/datetime.h +0 -184
- package/inc/util/draft/enum.h +0 -136
- package/inc/util/draft/holder_vector.h +0 -102
- package/inc/util/draft/ip.h +0 -131
- package/inc/util/draft/matrix.h +0 -108
- package/inc/util/draft/memory.h +0 -40
- package/inc/util/folder/dirent_win.h +0 -46
- package/inc/util/folder/dirut.h +0 -121
- package/inc/util/folder/filelist.h +0 -81
- package/inc/util/folder/fts.h +0 -108
- package/inc/util/folder/iterator.h +0 -109
- package/inc/util/folder/lstat_win.h +0 -20
- package/inc/util/folder/path.h +0 -225
- package/inc/util/folder/pathsplit.h +0 -113
- package/inc/util/folder/tempdir.h +0 -42
- package/inc/util/generic/adaptor.h +0 -134
- package/inc/util/generic/algorithm.h +0 -765
- package/inc/util/generic/array_ref.h +0 -282
- package/inc/util/generic/array_size.h +0 -24
- package/inc/util/generic/benchmark/vector_count_ctor/f.h +0 -9
- package/inc/util/generic/bitmap.h +0 -1115
- package/inc/util/generic/bitops.h +0 -459
- package/inc/util/generic/bt_exception.h +0 -24
- package/inc/util/generic/buffer.h +0 -232
- package/inc/util/generic/cast.h +0 -176
- package/inc/util/generic/deque.h +0 -24
- package/inc/util/generic/explicit_type.h +0 -42
- package/inc/util/generic/fastqueue.h +0 -55
- package/inc/util/generic/flags.h +0 -244
- package/inc/util/generic/function.h +0 -103
- package/inc/util/generic/fwd.h +0 -171
- package/inc/util/generic/guid.h +0 -61
- package/inc/util/generic/hash.h +0 -2032
- package/inc/util/generic/hash_primes.h +0 -140
- package/inc/util/generic/hash_set.h +0 -490
- package/inc/util/generic/hide_ptr.h +0 -3
- package/inc/util/generic/intrlist.h +0 -876
- package/inc/util/generic/is_in.h +0 -53
- package/inc/util/generic/iterator.h +0 -137
- package/inc/util/generic/iterator_range.h +0 -105
- package/inc/util/generic/lazy_value.h +0 -66
- package/inc/util/generic/list.h +0 -22
- package/inc/util/generic/map.h +0 -44
- package/inc/util/generic/mapfindptr.h +0 -60
- package/inc/util/generic/maybe.h +0 -713
- package/inc/util/generic/maybe_traits.h +0 -164
- package/inc/util/generic/mem_copy.h +0 -55
- package/inc/util/generic/noncopyable.h +0 -38
- package/inc/util/generic/object_counter.h +0 -53
- package/inc/util/generic/ptr.h +0 -1113
- package/inc/util/generic/queue.h +0 -57
- package/inc/util/generic/refcount.h +0 -162
- package/inc/util/generic/reserve.h +0 -11
- package/inc/util/generic/scope.h +0 -65
- package/inc/util/generic/serialized_enum.h +0 -406
- package/inc/util/generic/set.h +0 -42
- package/inc/util/generic/singleton.h +0 -136
- package/inc/util/generic/size_literals.h +0 -65
- package/inc/util/generic/stack.h +0 -18
- package/inc/util/generic/store_policy.h +0 -120
- package/inc/util/generic/strbase.h +0 -612
- package/inc/util/generic/strbuf.h +0 -552
- package/inc/util/generic/strfcpy.h +0 -17
- package/inc/util/generic/string.h +0 -1572
- package/inc/util/generic/string_hash.h +0 -21
- package/inc/util/generic/string_ut.h +0 -1175
- package/inc/util/generic/type_name.h +0 -34
- package/inc/util/generic/typelist.h +0 -114
- package/inc/util/generic/typetraits.h +0 -325
- package/inc/util/generic/utility.h +0 -132
- package/inc/util/generic/va_args.h +0 -400
- package/inc/util/generic/variant.h +0 -631
- package/inc/util/generic/variant_traits.h +0 -171
- package/inc/util/generic/vector.h +0 -119
- package/inc/util/generic/xrange.h +0 -258
- package/inc/util/generic/yexception.h +0 -212
- package/inc/util/generic/yexception_ut.h +0 -14
- package/inc/util/generic/ylimits.h +0 -92
- package/inc/util/generic/ymath.h +0 -206
- package/inc/util/memory/addstorage.h +0 -93
- package/inc/util/memory/alloc.h +0 -27
- package/inc/util/memory/blob.h +0 -296
- package/inc/util/memory/mmapalloc.h +0 -8
- package/inc/util/memory/pool.h +0 -432
- package/inc/util/memory/segmented_string_pool.h +0 -194
- package/inc/util/memory/segpool_alloc.h +0 -118
- package/inc/util/memory/smallobj.h +0 -141
- package/inc/util/memory/tempbuf.h +0 -111
- package/inc/util/network/address.h +0 -136
- package/inc/util/network/endpoint.h +0 -61
- package/inc/util/network/hostip.h +0 -16
- package/inc/util/network/init.h +0 -60
- package/inc/util/network/interface.h +0 -17
- package/inc/util/network/iovec.h +0 -65
- package/inc/util/network/ip.h +0 -116
- package/inc/util/network/nonblock.h +0 -8
- package/inc/util/network/pair.h +0 -9
- package/inc/util/network/poller.h +0 -58
- package/inc/util/network/pollerimpl.h +0 -707
- package/inc/util/network/sock.h +0 -608
- package/inc/util/network/socket.h +0 -421
- package/inc/util/random/common_ops.h +0 -130
- package/inc/util/random/easy.h +0 -47
- package/inc/util/random/entropy.h +0 -21
- package/inc/util/random/fast.h +0 -101
- package/inc/util/random/init_atfork.h +0 -3
- package/inc/util/random/lcg_engine.h +0 -66
- package/inc/util/random/mersenne.h +0 -46
- package/inc/util/random/mersenne32.h +0 -50
- package/inc/util/random/mersenne64.h +0 -50
- package/inc/util/random/normal.h +0 -38
- package/inc/util/random/random.h +0 -30
- package/inc/util/random/shuffle.h +0 -39
- package/inc/util/str_stl.h +0 -266
- package/inc/util/stream/aligned.h +0 -99
- package/inc/util/stream/buffer.h +0 -119
- package/inc/util/stream/buffered.h +0 -225
- package/inc/util/stream/debug.h +0 -53
- package/inc/util/stream/direct_io.h +0 -43
- package/inc/util/stream/file.h +0 -108
- package/inc/util/stream/format.h +0 -444
- package/inc/util/stream/fwd.h +0 -100
- package/inc/util/stream/hex.h +0 -8
- package/inc/util/stream/holder.h +0 -44
- package/inc/util/stream/input.h +0 -273
- package/inc/util/stream/labeled.h +0 -19
- package/inc/util/stream/length.h +0 -100
- package/inc/util/stream/mem.h +0 -255
- package/inc/util/stream/multi.h +0 -32
- package/inc/util/stream/null.h +0 -61
- package/inc/util/stream/output.h +0 -304
- package/inc/util/stream/pipe.h +0 -112
- package/inc/util/stream/printf.h +0 -25
- package/inc/util/stream/str.h +0 -207
- package/inc/util/stream/tee.h +0 -28
- package/inc/util/stream/tempbuf.h +0 -21
- package/inc/util/stream/tokenizer.h +0 -214
- package/inc/util/stream/trace.h +0 -60
- package/inc/util/stream/walk.h +0 -35
- package/inc/util/stream/zerocopy.h +0 -91
- package/inc/util/stream/zerocopy_output.h +0 -57
- package/inc/util/stream/zlib.h +0 -173
- package/inc/util/string/ascii.h +0 -236
- package/inc/util/string/builder.h +0 -39
- package/inc/util/string/cast.h +0 -347
- package/inc/util/string/cstriter.h +0 -14
- package/inc/util/string/escape.h +0 -70
- package/inc/util/string/hex.h +0 -59
- package/inc/util/string/join.h +0 -194
- package/inc/util/string/printf.h +0 -13
- package/inc/util/string/reverse.h +0 -16
- package/inc/util/string/split.h +0 -1080
- package/inc/util/string/strip.h +0 -257
- package/inc/util/string/strspn.h +0 -65
- package/inc/util/string/subst.h +0 -56
- package/inc/util/string/type.h +0 -50
- package/inc/util/string/util.h +0 -195
- package/inc/util/string/vector.h +0 -132
- package/inc/util/system/align.h +0 -50
- package/inc/util/system/atexit.h +0 -22
- package/inc/util/system/atomic.h +0 -51
- package/inc/util/system/atomic_gcc.h +0 -90
- package/inc/util/system/atomic_ops.h +0 -189
- package/inc/util/system/atomic_win.h +0 -114
- package/inc/util/system/backtrace.h +0 -39
- package/inc/util/system/byteorder.h +0 -186
- package/inc/util/system/compat.h +0 -84
- package/inc/util/system/compiler.h +0 -620
- package/inc/util/system/condvar.h +0 -71
- package/inc/util/system/context.h +0 -181
- package/inc/util/system/context_aarch64.h +0 -8
- package/inc/util/system/context_i686.h +0 -9
- package/inc/util/system/context_x86.h +0 -12
- package/inc/util/system/context_x86_64.h +0 -7
- package/inc/util/system/cpu_id.h +0 -159
- package/inc/util/system/daemon.h +0 -28
- package/inc/util/system/datetime.h +0 -98
- package/inc/util/system/defaults.h +0 -149
- package/inc/util/system/demangle.h +0 -5
- package/inc/util/system/demangle_impl.h +0 -23
- package/inc/util/system/direct_io.h +0 -71
- package/inc/util/system/dynlib.h +0 -119
- package/inc/util/system/env.h +0 -32
- package/inc/util/system/error.h +0 -95
- package/inc/util/system/event.h +0 -122
- package/inc/util/system/execpath.h +0 -17
- package/inc/util/system/fasttime.h +0 -6
- package/inc/util/system/fhandle.h +0 -27
- package/inc/util/system/file.h +0 -210
- package/inc/util/system/file_lock.h +0 -34
- package/inc/util/system/filemap.h +0 -383
- package/inc/util/system/flock.h +0 -35
- package/inc/util/system/fs.h +0 -156
- package/inc/util/system/fs_win.h +0 -29
- package/inc/util/system/fstat.h +0 -46
- package/inc/util/system/getpid.h +0 -12
- package/inc/util/system/guard.h +0 -179
- package/inc/util/system/hi_lo.h +0 -139
- package/inc/util/system/hostname.h +0 -10
- package/inc/util/system/hp_timer.h +0 -36
- package/inc/util/system/info.h +0 -12
- package/inc/util/system/interrupt_signals.h +0 -22
- package/inc/util/system/madvise.h +0 -30
- package/inc/util/system/maxlen.h +0 -32
- package/inc/util/system/mem_info.h +0 -18
- package/inc/util/system/mincore.h +0 -38
- package/inc/util/system/mktemp.h +0 -11
- package/inc/util/system/mlock.h +0 -43
- package/inc/util/system/mutex.h +0 -67
- package/inc/util/system/nice.h +0 -3
- package/inc/util/system/pipe.h +0 -90
- package/inc/util/system/platform.h +0 -246
- package/inc/util/system/progname.h +0 -13
- package/inc/util/system/protect.h +0 -25
- package/inc/util/system/rusage.h +0 -26
- package/inc/util/system/rwlock.h +0 -78
- package/inc/util/system/sanitizers.h +0 -122
- package/inc/util/system/sem.h +0 -41
- package/inc/util/system/shellcommand.h +0 -472
- package/inc/util/system/shmat.h +0 -32
- package/inc/util/system/sigset.h +0 -78
- package/inc/util/system/spin_wait.h +0 -10
- package/inc/util/system/spinlock.h +0 -121
- package/inc/util/system/src_location.h +0 -25
- package/inc/util/system/src_root.h +0 -68
- package/inc/util/system/sys_alloc.h +0 -43
- package/inc/util/system/sysstat.h +0 -52
- package/inc/util/system/tempfile.h +0 -34
- package/inc/util/system/thread.h +0 -167
- package/inc/util/system/tls.h +0 -307
- package/inc/util/system/types.h +0 -119
- package/inc/util/system/unaligned_mem.h +0 -67
- package/inc/util/system/user.h +0 -5
- package/inc/util/system/utime.h +0 -6
- package/inc/util/system/valgrind.h +0 -48
- package/inc/util/system/winint.h +0 -43
- package/inc/util/system/yassert.h +0 -121
- package/inc/util/system/yield.h +0 -4
- package/inc/util/thread/factory.h +0 -65
- package/inc/util/thread/fwd.h +0 -30
- package/inc/util/thread/lfqueue.h +0 -406
- package/inc/util/thread/lfstack.h +0 -188
- package/inc/util/thread/pool.h +0 -388
- package/inc/util/thread/singleton.h +0 -42
- package/inc/util/ysafeptr.h +0 -427
- package/inc/util/ysaveload.h +0 -700
package/inc/util/generic/ptr.h
DELETED
|
@@ -1,1113 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include "fwd.h"
|
|
4
|
-
#include "utility.h"
|
|
5
|
-
#include "intrlist.h"
|
|
6
|
-
#include "refcount.h"
|
|
7
|
-
#include "typetraits.h"
|
|
8
|
-
#include "singleton.h"
|
|
9
|
-
|
|
10
|
-
#include <utility>
|
|
11
|
-
|
|
12
|
-
#include <util/system/yassert.h>
|
|
13
|
-
#include <util/system/defaults.h>
|
|
14
|
-
|
|
15
|
-
template <class T>
|
|
16
|
-
inline void AssertTypeComplete() {
|
|
17
|
-
// If compiler triggers this error from destructor of your class with
|
|
18
|
-
// smart pointer, then may be you should move the destructor definition
|
|
19
|
-
// to the .cpp file, where type T have full definition.
|
|
20
|
-
//
|
|
21
|
-
// 'delete' called on pointer to incomplete type is
|
|
22
|
-
// undefined behavior (missing destructor call/corrupted memory manager).
|
|
23
|
-
// 'sizeof' is used to trigger compile-time error.
|
|
24
|
-
static_assert(sizeof(T) != 0, "Type must be complete");
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
template <class T>
|
|
28
|
-
inline void CheckedDelete(T* t) {
|
|
29
|
-
AssertTypeComplete<T>();
|
|
30
|
-
|
|
31
|
-
delete t;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
template <class T>
|
|
35
|
-
inline void CheckedArrayDelete(T* t) {
|
|
36
|
-
AssertTypeComplete<T>();
|
|
37
|
-
|
|
38
|
-
delete[] t;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
class TNoAction {
|
|
42
|
-
public:
|
|
43
|
-
template <class T>
|
|
44
|
-
static inline void Destroy(T*) noexcept {
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
class TDelete {
|
|
49
|
-
public:
|
|
50
|
-
template <class T>
|
|
51
|
-
static inline void Destroy(T* t) noexcept {
|
|
52
|
-
CheckedDelete(t);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/*
|
|
56
|
-
* special handling for nullptr - call nothing
|
|
57
|
-
*/
|
|
58
|
-
static inline void Destroy(std::nullptr_t) noexcept {
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/*
|
|
62
|
-
* special handling for void* - call ::operator delete()
|
|
63
|
-
*/
|
|
64
|
-
static void Destroy(void* t) noexcept;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
class TDeleteArray {
|
|
68
|
-
public:
|
|
69
|
-
template <class T>
|
|
70
|
-
static inline void Destroy(T* t) noexcept {
|
|
71
|
-
CheckedArrayDelete(t);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
class TDestructor {
|
|
76
|
-
public:
|
|
77
|
-
template <class T>
|
|
78
|
-
static inline void Destroy(T* t) noexcept {
|
|
79
|
-
(void)t;
|
|
80
|
-
t->~T();
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
class TFree {
|
|
85
|
-
public:
|
|
86
|
-
template <class T>
|
|
87
|
-
static inline void Destroy(T* t) noexcept {
|
|
88
|
-
DoDestroy((void*)t);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private:
|
|
92
|
-
/*
|
|
93
|
-
* we do not want dependancy on cstdlib here...
|
|
94
|
-
*/
|
|
95
|
-
static void DoDestroy(void* t) noexcept;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
template <class D>
|
|
99
|
-
struct TDestroyFunctor {
|
|
100
|
-
template <class T>
|
|
101
|
-
inline void operator()(T* t) const noexcept {
|
|
102
|
-
D::Destroy(t);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
template <class Base, class T>
|
|
107
|
-
class TPointerCommon {
|
|
108
|
-
public:
|
|
109
|
-
using TValueType = T;
|
|
110
|
-
|
|
111
|
-
inline T* operator->() const noexcept {
|
|
112
|
-
T* ptr = AsT();
|
|
113
|
-
Y_ASSERT(ptr);
|
|
114
|
-
return ptr;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
#ifndef __cpp_impl_three_way_comparison
|
|
118
|
-
template <class C>
|
|
119
|
-
inline bool operator==(const C& p) const noexcept {
|
|
120
|
-
return (p == AsT());
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
template <class C>
|
|
124
|
-
inline bool operator!=(const C& p) const noexcept {
|
|
125
|
-
return (p != AsT());
|
|
126
|
-
}
|
|
127
|
-
#endif
|
|
128
|
-
|
|
129
|
-
inline explicit operator bool() const noexcept {
|
|
130
|
-
return nullptr != AsT();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
protected:
|
|
134
|
-
inline T* AsT() const noexcept {
|
|
135
|
-
return (static_cast<const Base*>(this))->Get();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
static inline T* DoRelease(T*& t) noexcept {
|
|
139
|
-
T* ret = t;
|
|
140
|
-
t = nullptr;
|
|
141
|
-
return ret;
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
template <class Base, class T>
|
|
146
|
-
class TPointerBase: public TPointerCommon<Base, T> {
|
|
147
|
-
public:
|
|
148
|
-
inline T& operator*() const noexcept {
|
|
149
|
-
Y_ASSERT(this->AsT());
|
|
150
|
-
|
|
151
|
-
return *(this->AsT());
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
inline T& operator[](size_t n) const noexcept {
|
|
155
|
-
Y_ASSERT(this->AsT());
|
|
156
|
-
|
|
157
|
-
return (this->AsT())[n];
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
/*
|
|
162
|
-
* void*-like pointers does not have operator*
|
|
163
|
-
*/
|
|
164
|
-
template <class Base>
|
|
165
|
-
class TPointerBase<Base, void>: public TPointerCommon<Base, void> {
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
template <class T, class D>
|
|
169
|
-
class TAutoPtr: public TPointerBase<TAutoPtr<T, D>, T> {
|
|
170
|
-
public:
|
|
171
|
-
inline TAutoPtr(T* t = nullptr) noexcept
|
|
172
|
-
: T_(t)
|
|
173
|
-
{
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
inline TAutoPtr(const TAutoPtr& t) noexcept
|
|
177
|
-
: T_(t.Release())
|
|
178
|
-
{
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
inline ~TAutoPtr() {
|
|
182
|
-
DoDestroy();
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
inline TAutoPtr& operator=(const TAutoPtr& t) noexcept {
|
|
186
|
-
if (this != &t) {
|
|
187
|
-
Reset(t.Release());
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return *this;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
inline T* Release() const noexcept Y_WARN_UNUSED_RESULT {
|
|
194
|
-
return this->DoRelease(T_);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
inline void Reset(T* t) noexcept {
|
|
198
|
-
if (T_ != t) {
|
|
199
|
-
DoDestroy();
|
|
200
|
-
T_ = t;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
inline void Reset() noexcept {
|
|
205
|
-
Destroy();
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
inline void Destroy() noexcept {
|
|
209
|
-
Reset(nullptr);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
inline void Swap(TAutoPtr& r) noexcept {
|
|
213
|
-
DoSwap(T_, r.T_);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
inline T* Get() const noexcept {
|
|
217
|
-
return T_;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
#ifdef __cpp_impl_three_way_comparison
|
|
221
|
-
template <class Other>
|
|
222
|
-
inline bool operator==(const Other& p) const noexcept {
|
|
223
|
-
return (p == Get());
|
|
224
|
-
}
|
|
225
|
-
#endif
|
|
226
|
-
private:
|
|
227
|
-
inline void DoDestroy() noexcept {
|
|
228
|
-
if (T_) {
|
|
229
|
-
D::Destroy(T_);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
private:
|
|
234
|
-
mutable T* T_;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
template <class T, class D>
|
|
238
|
-
class THolder: public TPointerBase<THolder<T, D>, T> {
|
|
239
|
-
public:
|
|
240
|
-
constexpr THolder() noexcept
|
|
241
|
-
: T_(nullptr)
|
|
242
|
-
{
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
constexpr THolder(std::nullptr_t) noexcept
|
|
246
|
-
: T_(nullptr)
|
|
247
|
-
{
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
inline THolder(T* t) noexcept
|
|
251
|
-
: T_(t)
|
|
252
|
-
{
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
inline THolder(TAutoPtr<T, D> t) noexcept
|
|
256
|
-
: T_(t.Release())
|
|
257
|
-
{
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
template <class U>
|
|
261
|
-
inline THolder(TAutoPtr<U, D> t) noexcept
|
|
262
|
-
: T_(t.Release())
|
|
263
|
-
{
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
inline THolder(THolder&& that) noexcept
|
|
267
|
-
: T_(that.Release())
|
|
268
|
-
{
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
template <class U>
|
|
272
|
-
inline THolder(THolder<U, D>&& that) noexcept
|
|
273
|
-
: T_(that.Release())
|
|
274
|
-
{
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
THolder(const THolder&) = delete;
|
|
278
|
-
THolder& operator=(const THolder&) = delete;
|
|
279
|
-
|
|
280
|
-
inline ~THolder() {
|
|
281
|
-
DoDestroy();
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
inline void Destroy() noexcept {
|
|
285
|
-
Reset(nullptr);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
inline T* Release() noexcept Y_WARN_UNUSED_RESULT {
|
|
289
|
-
return this->DoRelease(T_);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
inline void Reset(T* t) noexcept {
|
|
293
|
-
if (T_ != t) {
|
|
294
|
-
DoDestroy();
|
|
295
|
-
T_ = t;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
inline void Reset(TAutoPtr<T, D> t) noexcept {
|
|
300
|
-
Reset(t.Release());
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
inline void Reset() noexcept {
|
|
304
|
-
Destroy();
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
inline void Swap(THolder& r) noexcept {
|
|
308
|
-
DoSwap(T_, r.T_);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
inline T* Get() const noexcept {
|
|
312
|
-
return T_;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
inline operator TAutoPtr<T, D>() noexcept {
|
|
316
|
-
return Release();
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
THolder& operator=(std::nullptr_t) noexcept {
|
|
320
|
-
this->Reset(nullptr);
|
|
321
|
-
return *this;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
THolder& operator=(THolder&& that) noexcept {
|
|
325
|
-
this->Reset(that.Release());
|
|
326
|
-
return *this;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
template <class U>
|
|
330
|
-
THolder& operator=(THolder<U, D>&& that) noexcept {
|
|
331
|
-
this->Reset(that.Release());
|
|
332
|
-
return *this;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
#ifdef __cpp_impl_three_way_comparison
|
|
336
|
-
template <class Other>
|
|
337
|
-
inline bool operator==(const Other& p) const noexcept {
|
|
338
|
-
return (p == Get());
|
|
339
|
-
}
|
|
340
|
-
#endif
|
|
341
|
-
private:
|
|
342
|
-
inline void DoDestroy() noexcept {
|
|
343
|
-
if (T_) {
|
|
344
|
-
D::Destroy(T_);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
private:
|
|
349
|
-
T* T_;
|
|
350
|
-
};
|
|
351
|
-
|
|
352
|
-
template <typename T, typename... Args>
|
|
353
|
-
THolder<T> MakeHolder(Args&&... args) {
|
|
354
|
-
return new T(std::forward<Args>(args)...);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/*
|
|
358
|
-
* usage:
|
|
359
|
-
* class T: public TRefCounted<T>
|
|
360
|
-
* and we get methods Ref() && UnRef() with
|
|
361
|
-
* proper destruction of last UnRef()
|
|
362
|
-
*/
|
|
363
|
-
template <class T, class C, class D>
|
|
364
|
-
class TRefCounted {
|
|
365
|
-
public:
|
|
366
|
-
inline TRefCounted(long initval = 0) noexcept
|
|
367
|
-
: Counter_(initval)
|
|
368
|
-
{
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
inline ~TRefCounted() = default;
|
|
372
|
-
|
|
373
|
-
inline void Ref(TAtomicBase d) noexcept {
|
|
374
|
-
auto resultCount = Counter_.Add(d);
|
|
375
|
-
Y_ASSERT(resultCount >= d);
|
|
376
|
-
(void)resultCount;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
inline void Ref() noexcept {
|
|
380
|
-
auto resultCount = Counter_.Inc();
|
|
381
|
-
Y_ASSERT(resultCount != 0);
|
|
382
|
-
(void)resultCount;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
inline void UnRef(TAtomicBase d) noexcept {
|
|
386
|
-
auto resultCount = Counter_.Sub(d);
|
|
387
|
-
Y_ASSERT(resultCount >= 0);
|
|
388
|
-
if (resultCount == 0) {
|
|
389
|
-
D::Destroy(static_cast<T*>(this));
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
inline void UnRef() noexcept {
|
|
394
|
-
UnRef(1);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
inline TAtomicBase RefCount() const noexcept {
|
|
398
|
-
return Counter_.Val();
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
inline void DecRef() noexcept {
|
|
402
|
-
auto resultCount = Counter_.Dec();
|
|
403
|
-
Y_ASSERT(resultCount >= 0);
|
|
404
|
-
(void)resultCount;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
TRefCounted(const TRefCounted&)
|
|
408
|
-
: Counter_(0)
|
|
409
|
-
{
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
void operator=(const TRefCounted&) {
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
private:
|
|
416
|
-
C Counter_;
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* Atomically reference-counted base with a virtual destructor.
|
|
421
|
-
*
|
|
422
|
-
* @note Plays well with inheritance, should be used for refcounted base classes.
|
|
423
|
-
*/
|
|
424
|
-
struct TThrRefBase: public TRefCounted<TThrRefBase, TAtomicCounter> {
|
|
425
|
-
virtual ~TThrRefBase();
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Atomically reference-counted base.
|
|
430
|
-
*
|
|
431
|
-
* Deletes refcounted object as type T.
|
|
432
|
-
*
|
|
433
|
-
* @warning Additional care should be taken with regard to inheritance. If used
|
|
434
|
-
* as a base class, @p T should either declare a virtual destructor, or be
|
|
435
|
-
* derived from @p TThrRefBase instead. Otherwise, only destructor of class @p T
|
|
436
|
-
* would be called, potentially slicing the object and creating memory leaks.
|
|
437
|
-
*
|
|
438
|
-
* @note To avoid accidental inheritance when it is not originally intended,
|
|
439
|
-
* class @p T should be marked as final.
|
|
440
|
-
*/
|
|
441
|
-
template <class T, class D = TDelete>
|
|
442
|
-
using TAtomicRefCount = TRefCounted<T, TAtomicCounter, D>;
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* Non-atomically reference-counted base.
|
|
446
|
-
*
|
|
447
|
-
* @warning Not thread-safe. Use with great care. If in doubt, use @p ThrRefBase
|
|
448
|
-
* or @p TAtomicRefCount instead.
|
|
449
|
-
*/
|
|
450
|
-
template <class T, class D = TDelete>
|
|
451
|
-
using TSimpleRefCount = TRefCounted<T, TSimpleCounter, D>;
|
|
452
|
-
|
|
453
|
-
template <class T>
|
|
454
|
-
class TDefaultIntrusivePtrOps {
|
|
455
|
-
public:
|
|
456
|
-
static inline void Ref(T* t) noexcept {
|
|
457
|
-
Y_ASSERT(t);
|
|
458
|
-
|
|
459
|
-
t->Ref();
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
static inline void UnRef(T* t) noexcept {
|
|
463
|
-
Y_ASSERT(t);
|
|
464
|
-
|
|
465
|
-
t->UnRef();
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
static inline void DecRef(T* t) noexcept {
|
|
469
|
-
Y_ASSERT(t);
|
|
470
|
-
|
|
471
|
-
t->DecRef();
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
static inline long RefCount(const T* t) noexcept {
|
|
475
|
-
Y_ASSERT(t);
|
|
476
|
-
|
|
477
|
-
return t->RefCount();
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
|
|
481
|
-
template <class T, class Ops>
|
|
482
|
-
class TIntrusivePtr: public TPointerBase<TIntrusivePtr<T, Ops>, T> {
|
|
483
|
-
friend class TIntrusiveConstPtr<T, Ops>;
|
|
484
|
-
public:
|
|
485
|
-
inline TIntrusivePtr(T* t = nullptr) noexcept
|
|
486
|
-
: T_(t)
|
|
487
|
-
{
|
|
488
|
-
Ops();
|
|
489
|
-
Ref();
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
inline ~TIntrusivePtr() {
|
|
493
|
-
UnRef();
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
inline TIntrusivePtr(const TIntrusivePtr& p) noexcept
|
|
497
|
-
: T_(p.T_)
|
|
498
|
-
{
|
|
499
|
-
Ref();
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
// NOTE:
|
|
503
|
-
// without std::enable_if_t compiler sometimes tries to use this constructor inappropriately
|
|
504
|
-
// e.g.
|
|
505
|
-
// struct A {};
|
|
506
|
-
// struct B {};
|
|
507
|
-
// void Func(TIntrusivePtr<A>);
|
|
508
|
-
// void Func(TIntrusivePtr<B>);
|
|
509
|
-
// ...
|
|
510
|
-
// Func(TIntrusivePtr<A>(new A)); // <--- compiler can't decide which version of Func to use
|
|
511
|
-
template <class U>
|
|
512
|
-
inline TIntrusivePtr(const TIntrusivePtr<U>& p, std::enable_if_t<std::is_convertible<U*, T*>::value>* = nullptr) noexcept
|
|
513
|
-
: T_(p.Get())
|
|
514
|
-
{
|
|
515
|
-
Ref();
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
inline TIntrusivePtr(TIntrusivePtr&& p) noexcept
|
|
519
|
-
: T_(nullptr)
|
|
520
|
-
{
|
|
521
|
-
Swap(p);
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
inline TIntrusivePtr& operator=(TIntrusivePtr p) noexcept {
|
|
525
|
-
p.Swap(*this);
|
|
526
|
-
|
|
527
|
-
return *this;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// Effectively replace both:
|
|
531
|
-
// Reset(const TIntrusivePtr&)
|
|
532
|
-
// Reset(TIntrusivePtr&&)
|
|
533
|
-
inline void Reset(TIntrusivePtr t) noexcept {
|
|
534
|
-
Swap(t);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
inline void Reset() noexcept {
|
|
538
|
-
Drop();
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
inline T* Get() const noexcept {
|
|
542
|
-
return T_;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
inline void Swap(TIntrusivePtr& r) noexcept {
|
|
546
|
-
DoSwap(T_, r.T_);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
inline void Drop() noexcept {
|
|
550
|
-
TIntrusivePtr(nullptr).Swap(*this);
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
inline T* Release() const noexcept Y_WARN_UNUSED_RESULT {
|
|
554
|
-
T* res = T_;
|
|
555
|
-
if (T_) {
|
|
556
|
-
Ops::DecRef(T_);
|
|
557
|
-
T_ = nullptr;
|
|
558
|
-
}
|
|
559
|
-
return res;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
inline long RefCount() const noexcept {
|
|
563
|
-
return T_ ? Ops::RefCount(T_) : 0;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
#ifdef __cpp_impl_three_way_comparison
|
|
567
|
-
template <class Other>
|
|
568
|
-
inline bool operator==(const Other& p) const noexcept {
|
|
569
|
-
return (p == Get());
|
|
570
|
-
}
|
|
571
|
-
#endif
|
|
572
|
-
private:
|
|
573
|
-
inline void Ref() noexcept {
|
|
574
|
-
if (T_) {
|
|
575
|
-
Ops::Ref(T_);
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
inline void UnRef() noexcept {
|
|
580
|
-
if (T_) {
|
|
581
|
-
Ops::UnRef(T_);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
private:
|
|
586
|
-
mutable T* T_;
|
|
587
|
-
};
|
|
588
|
-
|
|
589
|
-
template <class T, class Ops>
|
|
590
|
-
struct THash<TIntrusivePtr<T, Ops>> : THash<const T*> {
|
|
591
|
-
using THash<const T*>::operator();
|
|
592
|
-
inline size_t operator()(const TIntrusivePtr<T, Ops>& ptr) const {
|
|
593
|
-
return THash<const T*>::operator()(ptr.Get());
|
|
594
|
-
}
|
|
595
|
-
};
|
|
596
|
-
|
|
597
|
-
// Behaves like TIntrusivePtr but returns const T* to prevent user from accidentally modifying the referenced object.
|
|
598
|
-
template <class T, class Ops>
|
|
599
|
-
class TIntrusiveConstPtr: public TPointerBase<TIntrusiveConstPtr<T, Ops>, const T> {
|
|
600
|
-
public:
|
|
601
|
-
inline TIntrusiveConstPtr(T* t = nullptr) noexcept // we need a non-const pointer to Ref(), UnRef() and eventually delete it.
|
|
602
|
-
: T_(t)
|
|
603
|
-
{
|
|
604
|
-
Ops();
|
|
605
|
-
Ref();
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
inline ~TIntrusiveConstPtr() {
|
|
609
|
-
UnRef();
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
inline TIntrusiveConstPtr(const TIntrusiveConstPtr& p) noexcept
|
|
613
|
-
: T_(p.T_)
|
|
614
|
-
{
|
|
615
|
-
Ref();
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
inline TIntrusiveConstPtr(TIntrusiveConstPtr&& p) noexcept
|
|
619
|
-
: T_(nullptr)
|
|
620
|
-
{
|
|
621
|
-
Swap(p);
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
inline TIntrusiveConstPtr(TIntrusivePtr<T, Ops> p) noexcept
|
|
625
|
-
: T_(nullptr)
|
|
626
|
-
{
|
|
627
|
-
DoSwap(T_, p.T_);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
template <class U>
|
|
631
|
-
inline TIntrusiveConstPtr(const TIntrusiveConstPtr<U>& p, std::enable_if_t<std::is_convertible<U*, T*>::value>* = nullptr) noexcept
|
|
632
|
-
: T_(p.T_)
|
|
633
|
-
{
|
|
634
|
-
Ref();
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
inline TIntrusiveConstPtr& operator=(TIntrusiveConstPtr p) noexcept {
|
|
638
|
-
p.Swap(*this);
|
|
639
|
-
|
|
640
|
-
return *this;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
// Effectively replace both:
|
|
644
|
-
// Reset(const TIntrusiveConstPtr&)
|
|
645
|
-
// Reset(TIntrusiveConstPtr&&)
|
|
646
|
-
inline void Reset(TIntrusiveConstPtr t) noexcept {
|
|
647
|
-
Swap(t);
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
inline void Reset() noexcept {
|
|
651
|
-
Drop();
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
inline const T* Get() const noexcept {
|
|
655
|
-
return T_;
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
inline void Swap(TIntrusiveConstPtr& r) noexcept {
|
|
659
|
-
DoSwap(T_, r.T_);
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
inline void Drop() noexcept {
|
|
663
|
-
TIntrusiveConstPtr(nullptr).Swap(*this);
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
inline long RefCount() const noexcept {
|
|
667
|
-
return T_ ? Ops::RefCount(T_) : 0;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
#ifdef __cpp_impl_three_way_comparison
|
|
671
|
-
template <class Other>
|
|
672
|
-
inline bool operator==(const Other& p) const noexcept {
|
|
673
|
-
return (p == Get());
|
|
674
|
-
}
|
|
675
|
-
#endif
|
|
676
|
-
private:
|
|
677
|
-
inline void Ref() noexcept {
|
|
678
|
-
if (T_ != nullptr) {
|
|
679
|
-
Ops::Ref(T_);
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
inline void UnRef() noexcept {
|
|
684
|
-
if (T_ != nullptr) {
|
|
685
|
-
Ops::UnRef(T_);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
private:
|
|
690
|
-
T* T_;
|
|
691
|
-
|
|
692
|
-
template <class U, class O>
|
|
693
|
-
friend class TIntrusiveConstPtr;
|
|
694
|
-
};
|
|
695
|
-
|
|
696
|
-
template <class T, class Ops>
|
|
697
|
-
struct THash<TIntrusiveConstPtr<T, Ops>> : THash<const T*> {
|
|
698
|
-
using THash<const T*>::operator();
|
|
699
|
-
inline size_t operator()(const TIntrusiveConstPtr<T, Ops>& ptr) const {
|
|
700
|
-
return THash<const T*>::operator()(ptr.Get());
|
|
701
|
-
}
|
|
702
|
-
};
|
|
703
|
-
|
|
704
|
-
template <class T, class Ops>
|
|
705
|
-
class TSimpleIntrusiveOps {
|
|
706
|
-
using TFunc = void (*)(T*)
|
|
707
|
-
#if __cplusplus >= 201703
|
|
708
|
-
noexcept
|
|
709
|
-
#endif
|
|
710
|
-
;
|
|
711
|
-
|
|
712
|
-
static void DoRef(T* t) noexcept {
|
|
713
|
-
Ops::Ref(t);
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
static void DoUnRef(T* t) noexcept {
|
|
717
|
-
Ops::UnRef(t);
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
public:
|
|
721
|
-
inline TSimpleIntrusiveOps() noexcept {
|
|
722
|
-
InitStaticOps();
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
inline ~TSimpleIntrusiveOps() = default;
|
|
726
|
-
|
|
727
|
-
static inline void Ref(T* t) noexcept {
|
|
728
|
-
Ref_(t);
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
static inline void UnRef(T* t) noexcept {
|
|
732
|
-
UnRef_(t);
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
private:
|
|
736
|
-
static inline void InitStaticOps() noexcept {
|
|
737
|
-
struct TInit {
|
|
738
|
-
inline TInit() noexcept {
|
|
739
|
-
Ref_ = DoRef;
|
|
740
|
-
UnRef_ = DoUnRef;
|
|
741
|
-
}
|
|
742
|
-
};
|
|
743
|
-
|
|
744
|
-
Singleton<TInit>();
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
private:
|
|
748
|
-
static TFunc Ref_;
|
|
749
|
-
static TFunc UnRef_;
|
|
750
|
-
};
|
|
751
|
-
|
|
752
|
-
template <class T, class Ops>
|
|
753
|
-
typename TSimpleIntrusiveOps<T, Ops>::TFunc TSimpleIntrusiveOps<T, Ops>::Ref_ = nullptr;
|
|
754
|
-
|
|
755
|
-
template <class T, class Ops>
|
|
756
|
-
typename TSimpleIntrusiveOps<T, Ops>::TFunc TSimpleIntrusiveOps<T, Ops>::UnRef_ = nullptr;
|
|
757
|
-
|
|
758
|
-
template <typename T, class Ops = TDefaultIntrusivePtrOps<T>, typename... Args>
|
|
759
|
-
TIntrusivePtr<T, Ops> MakeIntrusive(Args&&... args) {
|
|
760
|
-
return new T{std::forward<Args>(args)...};
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
template <typename T, class Ops = TDefaultIntrusivePtrOps<T>, typename... Args>
|
|
764
|
-
TIntrusiveConstPtr<T, Ops> MakeIntrusiveConst(Args&&... args) {
|
|
765
|
-
return new T{std::forward<Args>(args)...};
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
template <class T, class C, class D>
|
|
769
|
-
class TSharedPtr: public TPointerBase<TSharedPtr<T, C, D>, T> {
|
|
770
|
-
template <class TT, class CC, class DD>
|
|
771
|
-
friend class TSharedPtr;
|
|
772
|
-
|
|
773
|
-
public:
|
|
774
|
-
inline TSharedPtr() noexcept
|
|
775
|
-
: T_(nullptr)
|
|
776
|
-
, C_(nullptr)
|
|
777
|
-
{
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
inline TSharedPtr(T* t) {
|
|
781
|
-
THolder<T, D> h(t);
|
|
782
|
-
|
|
783
|
-
Init(h);
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
inline TSharedPtr(TAutoPtr<T, D> t) {
|
|
787
|
-
Init(t);
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
inline TSharedPtr(T* t, C* c) noexcept
|
|
791
|
-
: T_(t)
|
|
792
|
-
, C_(c)
|
|
793
|
-
{
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
template <class TT>
|
|
797
|
-
inline TSharedPtr(THolder<TT>&& t) {
|
|
798
|
-
Init(t);
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
inline ~TSharedPtr() {
|
|
802
|
-
UnRef();
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
inline TSharedPtr(const TSharedPtr& t) noexcept
|
|
806
|
-
: T_(t.T_)
|
|
807
|
-
, C_(t.C_)
|
|
808
|
-
{
|
|
809
|
-
Ref();
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
inline TSharedPtr(TSharedPtr&& t) noexcept
|
|
813
|
-
: T_(nullptr)
|
|
814
|
-
, C_(nullptr)
|
|
815
|
-
{
|
|
816
|
-
Swap(t);
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
template <class TT>
|
|
820
|
-
inline TSharedPtr(const TSharedPtr<TT, C, D>& t) noexcept
|
|
821
|
-
: T_(t.T_)
|
|
822
|
-
, C_(t.C_)
|
|
823
|
-
{
|
|
824
|
-
Ref();
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
inline TSharedPtr& operator=(TSharedPtr t) noexcept {
|
|
828
|
-
t.Swap(*this);
|
|
829
|
-
|
|
830
|
-
return *this;
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
// Effectively replace both:
|
|
834
|
-
// Reset(const TSharedPtr& t)
|
|
835
|
-
// Reset(TSharedPtr&& t)
|
|
836
|
-
inline void Reset(TSharedPtr t) noexcept {
|
|
837
|
-
Swap(t);
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
inline void Reset() noexcept {
|
|
841
|
-
Drop();
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
inline void Drop() noexcept {
|
|
845
|
-
TSharedPtr().Swap(*this);
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
inline T* Get() const noexcept {
|
|
849
|
-
return T_;
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
inline C* ReferenceCounter() const noexcept {
|
|
853
|
-
return C_;
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
inline void Swap(TSharedPtr& r) noexcept {
|
|
857
|
-
DoSwap(T_, r.T_);
|
|
858
|
-
DoSwap(C_, r.C_);
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
inline long RefCount() const noexcept {
|
|
862
|
-
return C_ ? C_->Val() : 0;
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
#ifdef __cpp_impl_three_way_comparison
|
|
866
|
-
template <class Other>
|
|
867
|
-
inline bool operator==(const Other& p) const noexcept {
|
|
868
|
-
return (p == Get());
|
|
869
|
-
}
|
|
870
|
-
#endif
|
|
871
|
-
private:
|
|
872
|
-
template <class X>
|
|
873
|
-
inline void Init(X& t) {
|
|
874
|
-
C_ = !!t ? new C(1) : nullptr;
|
|
875
|
-
T_ = t.Release();
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
inline void Ref() noexcept {
|
|
879
|
-
if (C_) {
|
|
880
|
-
C_->Inc();
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
inline void UnRef() noexcept {
|
|
885
|
-
if (C_ && !C_->Dec()) {
|
|
886
|
-
DoDestroy();
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
inline void DoDestroy() noexcept {
|
|
891
|
-
if (T_) {
|
|
892
|
-
D::Destroy(T_);
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
delete C_;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
private:
|
|
899
|
-
T* T_;
|
|
900
|
-
C* C_;
|
|
901
|
-
};
|
|
902
|
-
|
|
903
|
-
template <class T, class C, class D>
|
|
904
|
-
struct THash<TSharedPtr<T, C, D>> : THash<const T*> {
|
|
905
|
-
using THash<const T*>::operator();
|
|
906
|
-
inline size_t operator()(const TSharedPtr<T, C, D>& ptr) const {
|
|
907
|
-
return THash<const T*>::operator()(ptr.Get());
|
|
908
|
-
}
|
|
909
|
-
};
|
|
910
|
-
|
|
911
|
-
template <class T, class D = TDelete>
|
|
912
|
-
using TAtomicSharedPtr = TSharedPtr<T, TAtomicCounter, D>;
|
|
913
|
-
|
|
914
|
-
// use with great care. if in doubt, use TAtomicSharedPtr instead
|
|
915
|
-
template <class T, class D = TDelete>
|
|
916
|
-
using TSimpleSharedPtr = TSharedPtr<T, TSimpleCounter, D>;
|
|
917
|
-
|
|
918
|
-
template <typename T, typename C, typename... Args>
|
|
919
|
-
TSharedPtr<T, C> MakeShared(Args&&... args) {
|
|
920
|
-
return new T{std::forward<Args>(args)...};
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
template <typename T, typename... Args>
|
|
924
|
-
inline TAtomicSharedPtr<T> MakeAtomicShared(Args&&... args) {
|
|
925
|
-
return MakeShared<T, TAtomicCounter>(std::forward<Args>(args)...);
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
template <typename T, typename... Args>
|
|
929
|
-
inline TSimpleSharedPtr<T> MakeSimpleShared(Args&&... args) {
|
|
930
|
-
return MakeShared<T, TSimpleCounter>(std::forward<Args>(args)...);
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
class TCopyClone {
|
|
934
|
-
public:
|
|
935
|
-
template <class T>
|
|
936
|
-
static inline T* Copy(T* t) {
|
|
937
|
-
if (t)
|
|
938
|
-
return t->Clone();
|
|
939
|
-
return nullptr;
|
|
940
|
-
}
|
|
941
|
-
};
|
|
942
|
-
|
|
943
|
-
class TCopyNew {
|
|
944
|
-
public:
|
|
945
|
-
template <class T>
|
|
946
|
-
static inline T* Copy(T* t) {
|
|
947
|
-
if (t)
|
|
948
|
-
return new T(*t);
|
|
949
|
-
return nullptr;
|
|
950
|
-
}
|
|
951
|
-
};
|
|
952
|
-
|
|
953
|
-
template <class T, class C, class D>
|
|
954
|
-
class TCopyPtr: public TPointerBase<TCopyPtr<T, C, D>, T> {
|
|
955
|
-
public:
|
|
956
|
-
inline TCopyPtr(T* t = nullptr) noexcept
|
|
957
|
-
: T_(t)
|
|
958
|
-
{
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
inline TCopyPtr(const TCopyPtr& t)
|
|
962
|
-
: T_(C::Copy(t.Get()))
|
|
963
|
-
{
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
inline TCopyPtr(TCopyPtr&& t) noexcept
|
|
967
|
-
: T_(nullptr)
|
|
968
|
-
{
|
|
969
|
-
Swap(t);
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
inline ~TCopyPtr() {
|
|
973
|
-
DoDestroy();
|
|
974
|
-
}
|
|
975
|
-
|
|
976
|
-
inline TCopyPtr& operator=(TCopyPtr t) {
|
|
977
|
-
t.Swap(*this);
|
|
978
|
-
|
|
979
|
-
return *this;
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
inline T* Release() noexcept Y_WARN_UNUSED_RESULT {
|
|
983
|
-
return DoRelease(T_);
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
inline void Reset(T* t) noexcept {
|
|
987
|
-
if (T_ != t) {
|
|
988
|
-
DoDestroy();
|
|
989
|
-
T_ = t;
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
inline void Reset() noexcept {
|
|
994
|
-
Destroy();
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
inline void Destroy() noexcept {
|
|
998
|
-
Reset(nullptr);
|
|
999
|
-
}
|
|
1000
|
-
|
|
1001
|
-
inline void Swap(TCopyPtr& r) noexcept {
|
|
1002
|
-
DoSwap(T_, r.T_);
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
inline T* Get() const noexcept {
|
|
1006
|
-
return T_;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
#ifdef __cpp_impl_three_way_comparison
|
|
1010
|
-
template <class Other>
|
|
1011
|
-
inline bool operator==(const Other& p) const noexcept {
|
|
1012
|
-
return (p == Get());
|
|
1013
|
-
}
|
|
1014
|
-
#endif
|
|
1015
|
-
private:
|
|
1016
|
-
inline void DoDestroy() noexcept {
|
|
1017
|
-
if (T_)
|
|
1018
|
-
D::Destroy(T_);
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
private:
|
|
1022
|
-
T* T_;
|
|
1023
|
-
};
|
|
1024
|
-
|
|
1025
|
-
// Copy-on-write pointer
|
|
1026
|
-
template <class TPtr, class TCopy>
|
|
1027
|
-
class TCowPtr: public TPointerBase<TCowPtr<TPtr, TCopy>, const typename TPtr::TValueType> {
|
|
1028
|
-
using T = typename TPtr::TValueType;
|
|
1029
|
-
|
|
1030
|
-
public:
|
|
1031
|
-
inline TCowPtr() = default;
|
|
1032
|
-
|
|
1033
|
-
inline TCowPtr(const TPtr& p)
|
|
1034
|
-
: T_(p)
|
|
1035
|
-
{
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
inline TCowPtr(T* p)
|
|
1039
|
-
: T_(p)
|
|
1040
|
-
{
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
inline const T* Get() const noexcept {
|
|
1044
|
-
return Const();
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
inline const T* Const() const noexcept {
|
|
1048
|
-
return T_.Get();
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
inline T* Mutable() {
|
|
1052
|
-
Unshare();
|
|
1053
|
-
|
|
1054
|
-
return T_.Get();
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
inline bool Shared() const noexcept {
|
|
1058
|
-
return T_.RefCount() > 1;
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
|
-
inline void Swap(TCowPtr& r) noexcept {
|
|
1062
|
-
T_.Swap(r.T_);
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
inline void Reset(TCowPtr p) {
|
|
1066
|
-
p.Swap(*this);
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
inline void Reset() {
|
|
1070
|
-
T_.Reset();
|
|
1071
|
-
}
|
|
1072
|
-
|
|
1073
|
-
#ifdef __cpp_impl_three_way_comparison
|
|
1074
|
-
template <class Other>
|
|
1075
|
-
inline bool operator==(const Other& p) const noexcept {
|
|
1076
|
-
return (p == Get());
|
|
1077
|
-
}
|
|
1078
|
-
#endif
|
|
1079
|
-
private:
|
|
1080
|
-
inline void Unshare() {
|
|
1081
|
-
if (Shared()) {
|
|
1082
|
-
Reset(TCopy::Copy(T_.Get()));
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
private:
|
|
1087
|
-
TPtr T_;
|
|
1088
|
-
};
|
|
1089
|
-
|
|
1090
|
-
// saves .Get() on argument passing. Intended usage: Func(TPtrArg<X> p); ... TIntrusivePtr<X> p2; Func(p2);
|
|
1091
|
-
template <class T>
|
|
1092
|
-
class TPtrArg {
|
|
1093
|
-
T* Ptr;
|
|
1094
|
-
|
|
1095
|
-
public:
|
|
1096
|
-
TPtrArg(T* p)
|
|
1097
|
-
: Ptr(p)
|
|
1098
|
-
{
|
|
1099
|
-
}
|
|
1100
|
-
TPtrArg(const TIntrusivePtr<T>& p)
|
|
1101
|
-
: Ptr(p.Get())
|
|
1102
|
-
{
|
|
1103
|
-
}
|
|
1104
|
-
operator T*() const {
|
|
1105
|
-
return Ptr;
|
|
1106
|
-
}
|
|
1107
|
-
T* operator->() const {
|
|
1108
|
-
return Ptr;
|
|
1109
|
-
}
|
|
1110
|
-
T* Get() const {
|
|
1111
|
-
return Ptr;
|
|
1112
|
-
}
|
|
1113
|
-
};
|