|
9 | 9 | #include <utility> |
10 | 10 | #include "../config/config.h" |
11 | 11 | #include "../core/any.hpp" |
| 12 | +#include "../core/bit.hpp" |
12 | 13 | #include "../core/fwd.hpp" |
13 | 14 | #include "../core/iterator.hpp" |
14 | 15 | #include "../core/type_info.hpp" |
@@ -912,6 +913,18 @@ struct meta_data { |
912 | 913 | return it != node->prop.cend() ? meta_prop{*ctx, it->second} : meta_prop{}; |
913 | 914 | } |
914 | 915 |
|
| 916 | + /** |
| 917 | + * @brief Returns all meta traits for a given meta object. |
| 918 | + * @tparam Type The type to convert the meta traits to. |
| 919 | + * @return The registered meta traits, if any. |
| 920 | + */ |
| 921 | + template<typename Type> |
| 922 | + [[nodiscard]] Type traits() const noexcept { |
| 923 | + static_assert(std::is_enum_v<Type>, "Invalid enum type"); |
| 924 | + constexpr auto shift = popcount(static_cast<std::underlying_type_t<internal::meta_traits>>(internal::meta_traits::_user_defined_traits)); |
| 925 | + return Type{static_cast<std::underlying_type_t<Type>>(static_cast<std::underlying_type_t<internal::meta_traits>>(node->traits) >> shift)}; |
| 926 | + } |
| 927 | + |
915 | 928 | /** |
916 | 929 | * @brief Returns true if an object is valid, false otherwise. |
917 | 930 | * @return True if the object is valid, false otherwise. |
@@ -996,10 +1009,6 @@ struct meta_func { |
996 | 1009 |
|
997 | 1010 | /** |
998 | 1011 | * @brief Invokes the underlying function, if possible. |
999 | | - * |
1000 | | - * @warning |
1001 | | - * The context of the arguments is **never** changed. |
1002 | | - * |
1003 | 1012 | * @param instance An opaque instance of the underlying type. |
1004 | 1013 | * @param args Parameters to use to invoke the function. |
1005 | 1014 | * @param sz Number of parameters to use to invoke the function. |
@@ -1038,6 +1047,18 @@ struct meta_func { |
1038 | 1047 | return it != node->prop.cend() ? meta_prop{*ctx, it->second} : meta_prop{}; |
1039 | 1048 | } |
1040 | 1049 |
|
| 1050 | + /** |
| 1051 | + * @brief Returns all meta traits for a given meta object. |
| 1052 | + * @tparam Type The type to convert the meta traits to. |
| 1053 | + * @return The registered meta traits, if any. |
| 1054 | + */ |
| 1055 | + template<typename Type> |
| 1056 | + [[nodiscard]] Type traits() const noexcept { |
| 1057 | + static_assert(std::is_enum_v<Type>, "Invalid enum type"); |
| 1058 | + constexpr auto shift = popcount(static_cast<std::underlying_type_t<internal::meta_traits>>(internal::meta_traits::_user_defined_traits)); |
| 1059 | + return Type{static_cast<std::underlying_type_t<Type>>(static_cast<std::underlying_type_t<internal::meta_traits>>(node->traits) >> shift)}; |
| 1060 | + } |
| 1061 | + |
1041 | 1062 | /** |
1042 | 1063 | * @brief Returns the next overload of a given function, if any. |
1043 | 1064 | * @return The next overload of the given function, if any. |
@@ -1373,10 +1394,6 @@ class meta_type { |
1373 | 1394 |
|
1374 | 1395 | /** |
1375 | 1396 | * @brief Creates an instance of the underlying type, if possible. |
1376 | | - * |
1377 | | - * @warning |
1378 | | - * The context of the arguments is **never** changed. |
1379 | | - * |
1380 | 1397 | * @param args Parameters to use to construct the instance. |
1381 | 1398 | * @param sz Number of parameters to use to construct the instance. |
1382 | 1399 | * @return A wrapper containing the new instance, if any. |
@@ -1423,10 +1440,6 @@ class meta_type { |
1423 | 1440 |
|
1424 | 1441 | /** |
1425 | 1442 | * @brief Invokes a function given an identifier, if possible. |
1426 | | - * |
1427 | | - * @warning |
1428 | | - * The context of the arguments is **never** changed. |
1429 | | - * |
1430 | 1443 | * @param id Unique identifier. |
1431 | 1444 | * @param instance An opaque instance of the underlying type. |
1432 | 1445 | * @param args Parameters to use to invoke the function. |
@@ -1510,6 +1523,18 @@ class meta_type { |
1510 | 1523 | return elem ? meta_prop{*ctx, *elem} : meta_prop{}; |
1511 | 1524 | } |
1512 | 1525 |
|
| 1526 | + /** |
| 1527 | + * @brief Returns all meta traits for a given meta object. |
| 1528 | + * @tparam Type The type to convert the meta traits to. |
| 1529 | + * @return The registered meta traits, if any. |
| 1530 | + */ |
| 1531 | + template<typename Type> |
| 1532 | + [[nodiscard]] Type traits() const noexcept { |
| 1533 | + static_assert(std::is_enum_v<Type>, "Invalid enum type"); |
| 1534 | + constexpr auto shift = popcount(static_cast<std::underlying_type_t<internal::meta_traits>>(internal::meta_traits::_user_defined_traits)); |
| 1535 | + return Type{static_cast<std::underlying_type_t<Type>>(static_cast<std::underlying_type_t<internal::meta_traits>>(node.traits) >> shift)}; |
| 1536 | + } |
| 1537 | + |
1513 | 1538 | /** |
1514 | 1539 | * @brief Returns true if an object is valid, false otherwise. |
1515 | 1540 | * @return True if the object is valid, false otherwise. |
|
0 commit comments