diff --git a/git-main/enum__name__impl_8hpp_source.html b/git-main/enum__name__impl_8hpp_source.html index defac16..e4def7f 100644 --- a/git-main/enum__name__impl_8hpp_source.html +++ b/git-main/enum__name__impl_8hpp_source.html @@ -198,124 +198,132 @@
150 "", enum_type::template name<Enum, Is>()...};
151 }
152
-
162 template <typename Enum, int Min, int Max>
-
163 MGUTILITY_CNSTXPR inline auto to_enum_impl(mgutility::string_view str) noexcept
-
164 -> mgutility::optional<Enum>
+
161 template <typename Enum, int Min = mgutility::enum_range<Enum>::min, int Max = mgutility::enum_range<Enum>::max>
+
162 MGUTILITY_CNSTXPR inline auto
+
163 get_enum_array() noexcept
+
164 -> std::array<mgutility::string_view, Max - Min + 1>
165 {
-
166 MGUTILITY_CNSTXPR auto arr =
-
167 get_enum_array<Enum>(detail::make_enum_sequence<Enum, Min, Max>());
-
168 const auto index{std::find(arr.begin() + 1, arr.end(), str)};
-
169 return index == arr.end() ? mgutility::nullopt
-
170 : mgutility::optional<Enum>{static_cast<Enum>(
-
171 std::distance(arr.begin(), index) + Min - 1)};
-
172 }
-
173
-
183 template <typename Enum, int Min, int Max>
-
184 MGUTILITY_CNSTXPR auto to_enum_bitmask_impl(mgutility::string_view str) noexcept
-
185 -> mgutility::optional<Enum>
-
186 {
-
187
-
188 // Check if the string contains a '|' character
-
189 if (str.find('|') == mgutility::string_view::npos)
-
190 {
-
191 return to_enum_impl<Enum, Min, Max>(str);
-
192 }
-
193
-
194 mgutility::optional<Enum> result{mgutility::nullopt};
-
195 std::size_t index = 0;
-
196
-
197 for (std::size_t i = 0; i < str.size(); ++i)
-
198 {
-
199 if (str[i] == '|')
-
200 {
-
201 auto name = str.substr(index, i - index);
-
202 auto maybe_enum = to_enum_impl<Enum, Min, Max>(name);
+
166 return get_enum_array<Enum>(detail::make_enum_sequence<Enum, Min, Max>());
+
167 }
+
168
+
178 template <typename Enum, int Min, int Max>
+
179 MGUTILITY_CNSTXPR inline auto to_enum_impl(mgutility::string_view str) noexcept
+
180 -> mgutility::optional<Enum>
+
181 {
+
182 MGUTILITY_CNSTXPR auto arr =
+
183 get_enum_array<Enum, Min, Max>();
+
184 const auto index{std::find(arr.begin() + 1, arr.end(), str)};
+
185 return index == arr.end() ? mgutility::nullopt
+
186 : mgutility::optional<Enum>{static_cast<Enum>(
+
187 std::distance(arr.begin(), index) + Min - 1)};
+
188 }
+
189
+
199 template <typename Enum, int Min, int Max>
+
200 MGUTILITY_CNSTXPR auto to_enum_bitmask_impl(mgutility::string_view str) noexcept
+
201 -> mgutility::optional<Enum>
+
202 {
203
-
204 if (!name.empty() && maybe_enum)
-
205 {
-
206 result.emplace(result ? static_cast<Enum>(*result | *maybe_enum)
-
207 : *maybe_enum);
-
208 }
+
204 // Check if the string contains a '|' character
+
205 if (str.find('|') == mgutility::string_view::npos)
+
206 {
+
207 return to_enum_impl<Enum, Min, Max>(str);
+
208 }
209
-
210 index = i + 1;
-
211 }
-
212 }
-
213
-
214 auto maybe_enum = to_enum_impl<Enum, Min, Max>(str.substr(index));
-
215 if (result && maybe_enum)
-
216 {
-
217 result.emplace(static_cast<Enum>(*result | *maybe_enum));
-
218 }
-
219 else
-
220 {
-
221 result.reset();
-
222 }
-
223
-
224 return result;
-
225 }
-
226
-
236 template <typename Enum, int Min, int Max,
-
237 detail::enable_if_t<!detail::has_bit_or<Enum>::value, bool> = true>
-
238 MGUTILITY_CNSTXPR auto enum_name_impl(Enum e) noexcept
-
239 -> mgutility::string_view
-
240 {
-
241 MGUTILITY_CNSTXPR auto arr =
-
242 get_enum_array<Enum>(detail::make_enum_sequence<Enum, Min, Max>());
-
243 const auto index{(Min < 0 ? Min * -1 : Min) + static_cast<int>(e) + 1};
-
244 return arr[(index < Min || index > arr.size() - 1) ? 0 : index];
-
245 }
-
246
-
257 template <typename Enum, int Min, int Max,
-
258 detail::enable_if_t<detail::has_bit_or<Enum>::value, bool> = true>
-
259 MGUTILITY_CNSTXPR_CLANG_WA inline auto enum_name_impl(Enum e) noexcept
-
260 -> detail::string_or_view_t<Enum>
-
261 {
+
210 mgutility::optional<Enum> result{mgutility::nullopt};
+
211 std::size_t index = 0;
+
212
+
213 for (std::size_t i = 0; i < str.size(); ++i)
+
214 {
+
215 if (str[i] == '|')
+
216 {
+
217 auto name = str.substr(index, i - index);
+
218 auto maybe_enum = to_enum_impl<Enum, Min, Max>(name);
+
219
+
220 if (!name.empty() && maybe_enum)
+
221 {
+
222 result.emplace(result ? static_cast<Enum>(*result | *maybe_enum)
+
223 : *maybe_enum);
+
224 }
+
225
+
226 index = i + 1;
+
227 }
+
228 }
+
229
+
230 auto maybe_enum = to_enum_impl<Enum, Min, Max>(str.substr(index));
+
231 if (result && maybe_enum)
+
232 {
+
233 result.emplace(static_cast<Enum>(*result | *maybe_enum));
+
234 }
+
235 else
+
236 {
+
237 result.reset();
+
238 }
+
239
+
240 return result;
+
241 }
+
242
+
252 template <typename Enum, int Min, int Max,
+
253 detail::enable_if_t<!detail::has_bit_or<Enum>::value, bool> = true>
+
254 MGUTILITY_CNSTXPR auto enum_name_impl(Enum e) noexcept
+
255 -> mgutility::string_view
+
256 {
+
257 MGUTILITY_CNSTXPR auto arr =
+
258 get_enum_array<Enum, Min, Max>();
+
259 const auto index{(Min < 0 ? Min * -1 : Min) + static_cast<int>(e) + 1};
+
260 return arr[(index < Min || index > arr.size() - 1) ? 0 : index];
+
261 }
262
-
263 // Get the array of enum names
-
264 MGUTILITY_CNSTXPR auto arr =
-
265 get_enum_array<Enum>(detail::make_enum_sequence<Enum, Min, Max>());
-
266
-
267 // Calculate the index in the array
-
268 const auto index = (Min < 0 ? -Min : Min) + static_cast<int>(e) + 1;
-
269 const auto name =
-
270 arr[(index < Min || index >= static_cast<int>(arr.size())) ? 0 : index];
-
271
-
272 // Lambda to check if a character is a digit
-
273 const auto is_digit = [](char c)
-
274 { return c >= '0' && c <= '9'; };
-
275
-
276 // Return the name if it's valid
-
277 if (!name.empty() && !is_digit(name[0]))
-
278 {
-
279 return std::string{name};
-
280 }
-
281
-
282 // Construct bitmasked name
-
283 std::string bitmasked_name;
-
284 for (auto i = Min; i < Max; ++i)
-
285 {
-
286 const auto idx = (Min < 0 ? -Min : Min) + i + 1;
-
287 if (idx >= 0 && idx < static_cast<int>(arr.size()) && !arr[idx].empty() &&
-
288 !is_digit(arr[idx][0]) &&
-
289 (e & static_cast<Enum>(i)) == static_cast<Enum>(i))
-
290 {
-
291 bitmasked_name.append(arr[idx]).append("|");
-
292 }
-
293 }
-
294
-
295 // Remove the trailing '|' if present
-
296 if (!bitmasked_name.empty())
-
297 {
-
298 bitmasked_name.pop_back();
-
299 }
-
300
-
301 return bitmasked_name.find('|') != std::string::npos ? bitmasked_name
-
302 : std::string{""};
-
303 }
-
304 } // namespace detail
-
305} // namespace mgutility
-
306
-
307#endif // DETAIL_ENUM_NAME_IMPL_HPP
+
273 template <typename Enum, int Min, int Max,
+
274 detail::enable_if_t<detail::has_bit_or<Enum>::value, bool> = true>
+
275 MGUTILITY_CNSTXPR_CLANG_WA inline auto enum_name_impl(Enum e) noexcept
+
276 -> detail::string_or_view_t<Enum>
+
277 {
+
278
+
279 // Get the array of enum names
+
280 MGUTILITY_CNSTXPR auto arr =
+
281 get_enum_array<Enum, Min, Max>();
+
282
+
283 // Calculate the index in the array
+
284 const auto index = (Min < 0 ? -Min : Min) + static_cast<int>(e) + 1;
+
285 const auto name =
+
286 arr[(index < Min || index >= static_cast<int>(arr.size())) ? 0 : index];
+
287
+
288 // Lambda to check if a character is a digit
+
289 const auto is_digit = [](char c)
+
290 { return c >= '0' && c <= '9'; };
+
291
+
292 // Return the name if it's valid
+
293 if (!name.empty() && !is_digit(name[0]))
+
294 {
+
295 return std::string{name};
+
296 }
+
297
+
298 // Construct bitmasked name
+
299 std::string bitmasked_name;
+
300 for (auto i = Min; i < Max; ++i)
+
301 {
+
302 const auto idx = (Min < 0 ? -Min : Min) + i + 1;
+
303 if (idx >= 0 && idx < static_cast<int>(arr.size()) && !arr[idx].empty() &&
+
304 !is_digit(arr[idx][0]) &&
+
305 (e & static_cast<Enum>(i)) == static_cast<Enum>(i))
+
306 {
+
307 bitmasked_name.append(arr[idx]).append("|");
+
308 }
+
309 }
+
310
+
311 // Remove the trailing '|' if present
+
312 if (!bitmasked_name.empty())
+
313 {
+
314 bitmasked_name.pop_back();
+
315 }
+
316
+
317 return bitmasked_name.find('|') != std::string::npos ? bitmasked_name
+
318 : std::string{""};
+
319 }
+
320 } // namespace detail
+
321} // namespace mgutility
+
322
+
323#endif // DETAIL_ENUM_NAME_IMPL_HPP
mgutility::basic_string_view
A basic string view class template.
Definition string_view.hpp:62
mgutility::optional
A class template that provides optional (nullable) objects.
Definition optional.hpp:64
MGUTILITY_CNSTXPR_CLANG_WA
#define MGUTILITY_CNSTXPR_CLANG_WA
Defines the MGUTILITY_CNSTXPR macro based on the C++ standard.
Definition definitions.hpp:69
@@ -323,6 +331,7 @@
mgutility::nullopt
auto nullopt
A global instance of nullopt_t to represent null optional.
Definition optional.hpp:336
mgutility::detail::enum_type
Definition enum_name_impl.hpp:80
mgutility::detail::enum_type::name
static MGUTILITY_CNSTXPR auto name() noexcept -> mgutility::string_view
Gets the name of an unscoped enum value.
Definition enum_name_impl.hpp:91
+
mgutility::enum_range
Provides the range for an enumeration type.
Definition meta.hpp:161