-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrpc_string.cpp
More file actions
128 lines (103 loc) · 4.92 KB
/
rpc_string.cpp
File metadata and controls
128 lines (103 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
Copyright 2020 Michael Beckh
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/// @file
#include "m3c/rpc_string.h"
#include "m3c/Log.h"
#include "m3c/exception.h"
#include "m3c.events.h"
#include <memory>
#include <type_traits>
namespace m3c {
template <AnyOf<char, wchar_t> T>
basic_rpc_string<T>::basic_rpc_string(basic_rpc_string&& str) noexcept
: m_ptr(str.release()) {
// empty
}
template <AnyOf<char, wchar_t> T>
basic_rpc_string<T>::~basic_rpc_string() noexcept {
const RPC_STATUS status = destroy();
if (status != RPC_S_OK) {
[[unlikely]];
// destructor SHOULD NOT throw
Log::Error(evt::MemoryLeak_R, rpc_status(status));
}
}
template <AnyOf<char, wchar_t> T>
basic_rpc_string<T>& basic_rpc_string<T>::operator=(basic_rpc_string<T>&& p) noexcept {
const RPC_STATUS status = destroy();
if (status != RPC_S_OK) {
[[unlikely]];
// move operator SHOULD NOT throw
Log::Error(evt::MemoryLeak_R, rpc_status(status));
}
m_ptr = p.release();
return *this;
}
template <AnyOf<char, wchar_t> T>
basic_rpc_string<T>& basic_rpc_string<T>::operator=(std::nullptr_t) {
const RPC_STATUS status = destroy();
if (status != RPC_S_OK) {
[[unlikely]];
throw rpc_error(status) + evt::MemoryLeak_R;
}
m_ptr = nullptr;
return *this;
}
template <AnyOf<char, wchar_t> T>
_Ret_notnull_ typename basic_rpc_string<T>::rpc_str_type* basic_rpc_string<T>::operator&() {
const RPC_STATUS status = destroy();
if (status != RPC_S_OK) {
[[unlikely]];
throw rpc_error(status) + evt::MemoryLeak_R;
}
return std::addressof(m_ptr);
}
template <>
RPC_STATUS basic_rpc_string<char>::destroy() noexcept {
return RpcStringFreeA(&m_ptr);
}
template <>
RPC_STATUS basic_rpc_string<wchar_t>::destroy() noexcept {
return RpcStringFreeW(&m_ptr);
}
template class basic_rpc_string<char>;
template class basic_rpc_string<wchar_t>;
template bool operator==(const basic_rpc_string<char>& str, const basic_rpc_string<char>& oth) noexcept;
template bool operator==(const basic_rpc_string<char>& str, typename basic_rpc_string<char>::rpc_str_type p) noexcept;
template bool operator==(typename basic_rpc_string<char>::rpc_str_type p, const basic_rpc_string<char>& str) noexcept;
template bool operator==(const basic_rpc_string<char>& str, std::nullptr_t) noexcept;
template bool operator==(std::nullptr_t, const basic_rpc_string<char>& str) noexcept;
template bool operator==(const basic_rpc_string<wchar_t>& str, const basic_rpc_string<wchar_t>& oth) noexcept;
template bool operator==(const basic_rpc_string<wchar_t>& str, typename basic_rpc_string<wchar_t>::rpc_str_type p) noexcept;
template bool operator==(typename basic_rpc_string<wchar_t>::rpc_str_type p, const basic_rpc_string<wchar_t>& str) noexcept;
template bool operator==(const basic_rpc_string<wchar_t>& str, std::nullptr_t) noexcept;
template bool operator==(std::nullptr_t, const basic_rpc_string<wchar_t>& str) noexcept;
template bool operator!=(const basic_rpc_string<char>& str, const basic_rpc_string<char>& oth) noexcept;
template bool operator!=(const basic_rpc_string<char>& str, typename basic_rpc_string<char>::rpc_str_type p) noexcept;
template bool operator!=(typename basic_rpc_string<char>::rpc_str_type p, const basic_rpc_string<char>& str) noexcept;
template bool operator!=(const basic_rpc_string<char>& str, std::nullptr_t) noexcept;
template bool operator!=(std::nullptr_t, const basic_rpc_string<char>& str) noexcept;
template bool operator!=(const basic_rpc_string<wchar_t>& str, const basic_rpc_string<wchar_t>& oth) noexcept;
template bool operator!=(const basic_rpc_string<wchar_t>& str, typename basic_rpc_string<wchar_t>::rpc_str_type p) noexcept;
template bool operator!=(typename basic_rpc_string<wchar_t>::rpc_str_type p, const basic_rpc_string<wchar_t>& str) noexcept;
template bool operator!=(const basic_rpc_string<wchar_t>& str, std::nullptr_t) noexcept;
template bool operator!=(std::nullptr_t, const basic_rpc_string<wchar_t>& str) noexcept;
template void swap(basic_rpc_string<char>& str, basic_rpc_string<char>& oth) noexcept;
template void swap(basic_rpc_string<wchar_t>& str, basic_rpc_string<wchar_t>& oth) noexcept;
} // namespace m3c
template struct std::hash<m3c::basic_rpc_string<char>>;
template struct std::hash<m3c::basic_rpc_string<wchar_t>>;
template struct fmt::formatter<m3c::basic_rpc_string<char>, char>;
template struct fmt::formatter<m3c::basic_rpc_string<char>, wchar_t>;
template struct fmt::formatter<m3c::basic_rpc_string<wchar_t>, char>;
template struct fmt::formatter<m3c::basic_rpc_string<wchar_t>, wchar_t>;