Skip to content

Commit 17ee243

Browse files
Merge branch 'active' into gpg_signing_with_ssh_key
2 parents d9d3b8d + 6663fa2 commit 17ee243

File tree

3 files changed

+62
-25
lines changed

3 files changed

+62
-25
lines changed

windows/devices/util/DeviceEnumerator.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ DeviceEnumerator::GetDeviceInterfaceClassInstanceNames(const GUID& deviceInterfa
5858

5959
/* static */
6060
std::vector<std::string>
61-
DeviceEnumerator::GetDeviceInterfaceClassInstanceNames(const std::string& deviceInterfaceClassString) noexcept
61+
DeviceEnumerator::GetDeviceInterfaceClassInstanceNames(std::string_view deviceInterfaceClassString) noexcept
6262
{
63-
auto deviceClassInterfaceGuid = notstd::GuidFromString(deviceInterfaceClassString);
63+
auto deviceClassInterfaceGuid = notstd::GuidFromStringView(deviceInterfaceClassString);
6464
if (!deviceClassInterfaceGuid.has_value()) {
6565
return {};
6666
}

windows/devices/util/include/windows/devices/DeviceEnumerator.hxx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
#ifndef WINDOWS_DEVICE_ENUMERATOR
33
#define WINDOWS_DEVICE_ENUMERATOR
44

5-
#include <string>
5+
#include <string_view>
66
#include <vector>
77

88
// NB: This must come before any other Windows include
99
#include <windows.h>
1010

1111
#include <guiddef.h>
1212

13-
namespace windows
14-
{
15-
namespace devices
13+
namespace windows::devices
1614
{
1715
/**
1816
* @brief Enumerates the names of device interface instances belonging to a
@@ -23,7 +21,7 @@ struct DeviceEnumerator
2321
/**
2422
* @brief Get a list of device paths for instances of the specified device
2523
* interface class.
26-
*
24+
*
2725
* @param deviceInterfaceClassGuid The GUID of the device class to enumerate.
2826
* @return std::vector<std::string> A list of device paths.
2927
*/
@@ -33,14 +31,13 @@ struct DeviceEnumerator
3331
/**
3432
* @brief Get a list of device paths for instances of the specified device
3533
* interface class.
36-
*
37-
* @param deviceInterfaceClassString
38-
* @return std::vector<std::string>
34+
*
35+
* @param deviceInterfaceClassString
36+
* @return std::vector<std::string>
3937
*/
4038
static std::vector<std::string>
41-
GetDeviceInterfaceClassInstanceNames(const std::string& deviceInterfaceClassString) noexcept;
39+
GetDeviceInterfaceClassInstanceNames(std::string_view deviceInterfaceClassString) noexcept;
4240
};
43-
} // namespace devices
44-
} // namespace windows
41+
} // namespace windows::devices
4542

46-
#endif // WINDOWS_DEVICE_ENUMERATOR
43+
#endif // WINDOWS_DEVICE_ENUMERATOR

windows/shared/notstd/guid.hxx

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <iterator>
55
#include <optional>
66
#include <string>
7+
#include <string_view>
78
#include <utility>
89

910
#include <rpc.h>
@@ -77,29 +78,29 @@ GuidToString(const GUID& guid)
7778
}
7879

7980
/**
80-
* @brief Parses a string for a GUID and returns it, if valid.
81+
* @brief Parses a string (_view) for a GUID and returns it, if valid.
8182
*
82-
* @tparam TString The type of input string to parse.
83-
* @param input The string to parse.
83+
* @tparam TStringView The type of input string view to parse.
84+
* @param input The string view to parse.
8485
* @return std::optional<GUID> An optional containing a GUID if the input was valid, std::nullopt otherwise.
8586
*/
86-
template <typename TString>
87+
template <typename TStringView>
8788
inline std::optional<GUID>
88-
GuidFromString(const TString& input) noexcept;
89+
GuidFromStringView(TStringView input) noexcept;
8990

9091
/**
91-
* @brief Specialization for parsing a GUID from std::string.
92+
* @brief Specialization for parsing a GUID from std::string_view.
9293
*
9394
* @tparam TString std::string
9495
* @param input
9596
* @return std::optional<GUID>
9697
*/
9798
template <>
9899
inline std::optional<GUID>
99-
GuidFromString(const std::string& input) noexcept
100+
GuidFromStringView(std::string_view input) noexcept
100101
{
101102
GUID guid{};
102-
auto result = UuidFromStringA(reinterpret_cast<RPC_CSTR>(const_cast<std::string::value_type*>(std::data(input))), &guid);
103+
auto result = UuidFromStringA(reinterpret_cast<RPC_CSTR>(const_cast<std::string_view::value_type*>(std::data(input))), &guid);
103104
if (result != NOERROR) {
104105
return std::nullopt;
105106
}
@@ -108,24 +109,63 @@ GuidFromString(const std::string& input) noexcept
108109
}
109110

110111
/**
111-
* @brief Specialization for parsing a GUID from std::wstring.
112+
* @brief Specialization for parsing a GUID from std::wstring_view.
112113
*
113114
* @tparam TString std::wstring
114115
* @param input
115116
* @return std::optional<GUID>
116117
*/
117118
template <>
118119
inline std::optional<GUID>
119-
GuidFromString(const std::wstring& input) noexcept
120+
GuidFromStringView(std::wstring_view input) noexcept
120121
{
121122
GUID guid{};
122-
auto result = UuidFromStringW(reinterpret_cast<RPC_WSTR>(const_cast<std::wstring::value_type*>(std::data(input))), &guid);
123+
auto result = UuidFromStringW(reinterpret_cast<RPC_WSTR>(const_cast<std::wstring_view::value_type*>(std::data(input))), &guid);
123124
if (result != NOERROR) {
124125
return std::nullopt;
125126
}
126127

127128
return guid;
128129
}
130+
131+
/**
132+
* @brief Parses a string for a GUID and returns it, if valid.
133+
*
134+
* @tparam TString The type of input string to parse.
135+
* @param input The string to parse.
136+
* @return std::optional<GUID> An optional containing a GUID if the input was valid, std::nullopt otherwise.
137+
*/
138+
template <typename TString>
139+
inline std::optional<GUID>
140+
GuidFromString(const TString& input) noexcept;
141+
142+
/**
143+
* @brief Specialization for parsing a GUID from std::string.
144+
*
145+
* @tparam TString std::string
146+
* @param input
147+
* @return std::optional<GUID>
148+
*/
149+
template <>
150+
inline std::optional<GUID>
151+
GuidFromString(const std::string& input) noexcept
152+
{
153+
return GuidFromStringView(std::string_view{ input });
154+
}
155+
156+
/**
157+
* @brief Specialization for parsing a GUID from std::wstring.
158+
*
159+
* @tparam TString std::wstring
160+
* @param input
161+
* @return std::optional<GUID>
162+
*/
163+
template <>
164+
inline std::optional<GUID>
165+
GuidFromString(const std::wstring& input) noexcept
166+
{
167+
return GuidFromStringView(std::wstring_view{ input });
168+
}
129169
} // namespace notstd
130170

131171
namespace std

0 commit comments

Comments
 (0)