11/* *
2- * @file ClassCast .h
2+ * @file DynamicCast .h
33 * @brief Functor for performing runtime conversions between types.
44 *
55 * @author Retro & Chill
2020#define RETROLIB_EXPORT
2121#endif
2222
23- namespace retro {
23+ namespace Retro {
2424
2525 /* *
2626 * Attempts to dynamically cast a reference of type U to a reference of type T.
@@ -38,16 +38,16 @@ namespace retro {
3838 * Optional reference to T is returned.
3939 */
4040 RETROLIB_EXPORT template <Class T, Class U, bool Checked = false >
41- constexpr decltype (auto ) dyn_cast_ref (U &value ) {
41+ constexpr decltype (auto ) DynCastRef (U &Value ) {
4242 if constexpr (std::is_base_of_v<T, U>) {
43- return static_cast <T &>(value );
43+ return static_cast <T &>(Value );
4444 } else {
45- auto ptr = dynamic_cast <T *>(&value );
45+ auto Ptr = dynamic_cast <T *>(&Value );
4646 if constexpr (Checked) {
47- RETROLIB_ASSERT (valid_ptr (ptr ));
48- return dynamic_cast <T &>(value );
47+ RETROLIB_ASSERT (valid_ptr (Ptr ));
48+ return dynamic_cast <T &>(Value );
4949 } else {
50- return ptr != nullptr ? Optional<T &>(*ptr ) : Optional<T &>();
50+ return Ptr != nullptr ? Optional<T &>(*Ptr ) : Optional<T &>();
5151 }
5252 }
5353 }
@@ -63,19 +63,19 @@ namespace retro {
6363 * @tparam Checked A boolean template parameter to indicate whether to perform runtime checks during casting.
6464 */
6565 template <Class T, bool Checked = false >
66- struct ClassCast {
66+ struct DynamicCastFunction {
6767 /* *
6868 * Overloaded function call operator which performs a dynamic cast of a reference type.
6969 * This function attempts to cast a reference of type U to a reference of type T.
7070 * If the Checked parameter is considered, it might involve runtime checks for safety.
71- *
72- * @param value A reference to a value of type U that is to be casted.
71+ *D
72+ * @param Value A reference to a value of type U that is to be casted.
7373 * @return The result of the dynamic cast to type T. The return is of the same reference type,
7474 * which is determined by the use of `decltype(auto)`.
7575 */
7676 template <Class U>
77- constexpr decltype (auto ) operator()(U &value ) {
78- return dyn_cast_ref <T, U, Checked>(value );
77+ constexpr decltype (auto ) operator()(U &Value ) {
78+ return DynCastRef <T, U, Checked>(Value );
7979 }
8080
8181 /* *
@@ -84,25 +84,25 @@ namespace retro {
8484 * This operator function checks if the provided value is a valid pointer, and depending on compile-time
8585 * conditions, it performs a dynamic cast or derives reference conversion.
8686 *
87- * @param value A universal reference to a value that will be checked for validity and conditionally
87+ * @param Value A universal reference to a value that will be checked for validity and conditionally
8888 * transformed. This can be a pointer or a reference to an object.
8989 *
9090 * @return An Optional containing a reference to the object of type T if the pointer is valid and the
9191 * cast/conversion succeeds. If the pointer is invalid, an empty Optional is returned.
9292 */
9393 template <PointerType U>
94- constexpr decltype (auto ) operator()(U &&value ) const {
94+ constexpr decltype (auto ) operator()(U &&Value ) const {
9595 if constexpr (Checked) {
96- RETROLIB_ASSERT (valid_ptr (std::forward<U>(value )));
97- return dyn_cast_ref <T, std::remove_pointer_t <U>, Checked>(*std::forward<U>(value ));
96+ RETROLIB_ASSERT (valid_ptr (std::forward<U>(Value )));
97+ return DynCastRef <T, std::remove_pointer_t <U>, Checked>(*std::forward<U>(Value ));
9898 } else if constexpr (std::derived_from<std::decay_t <DereferencedType<U>>, std::decay_t <T>>) {
99- return valid_ptr (std::forward<U>(value )) ? Optional<T &>(*std::forward<U>(value )) : Optional<T &>();
99+ return ValidPtr (std::forward<U>(Value )) ? Optional<T &>(*std::forward<U>(Value )) : Optional<T &>();
100100 } else {
101- if (!valid_ptr (std::forward<U>(value ))) {
101+ if (!ValidPtr (std::forward<U>(Value ))) {
102102 return Optional<T &>();
103103 }
104104
105- return dyn_cast_ref <T, std::decay_t <DereferencedType<U>>, Checked>(*std::forward<U>(value ));
105+ return DynCastRef <T, std::decay_t <DereferencedType<U>>, Checked>(*std::forward<U>(Value ));
106106 }
107107 }
108108
@@ -111,15 +111,15 @@ namespace retro {
111111 * to a Polymorphic object, effectively de-referencing it and invoking the functor on the
112112 * underlying object that the Polymorphic reference points to.
113113 *
114- * @param value A reference to a Polymorphic<U> object, where U must be a type that supports
114+ * @param Value A reference to a Polymorphic<U> object, where U must be a type that supports
115115 * the operations defined within the functor.
116116 * @return The result of invoking the functor on the de-referenced object. The return type is
117117 * deduced using decltype(auto), meaning it will preserve the value category and type
118118 * of the final operation's result.
119119 */
120120 template <Class U>
121- constexpr decltype (auto ) operator()(Polymorphic<U> &value ) const {
122- return (*this )(*value );
121+ constexpr decltype (auto ) operator()(Polymorphic<U> &Value ) const {
122+ return (*this )(*Value );
123123 }
124124
125125 /* *
@@ -128,12 +128,12 @@ namespace retro {
128128 * This operator allows the functor to be called on a given polymorphic object,
129129 * effectively dereferencing it and calling the functor with its underlying value.
130130 *
131- * @param value A constant reference to a Polymorphic object containing the value.
131+ * @param Value A constant reference to a Polymorphic object containing the value.
132132 * @return The result of applying the functor to the dereferenced value stored in the Polymorphic object.
133133 */
134134 template <Class U>
135- constexpr decltype (auto ) operator()(const Polymorphic<U> &value ) const {
136- return (*this )(*value );
135+ constexpr decltype (auto ) operator()(const Polymorphic<U> &Value ) const {
136+ return (*this )(*Value );
137137 }
138138
139139 constexpr Optional<T &> operator ()(std::nullptr_t ) const
@@ -156,7 +156,7 @@ namespace retro {
156156 * @tparam T The target class type to which the casting is to be performed.
157157 */
158158 RETROLIB_EXPORT template <Class T>
159- constexpr ClassCast <T> class_cast ;
159+ constexpr DynamicCastFunction <T> DynamicCast ;
160160
161161 /* *
162162 * @brief A compile-time constant expression representing a checked class cast operation.
@@ -170,6 +170,6 @@ namespace retro {
170170 * be specified to indicate the destination class type for the casting operation.
171171 */
172172 RETROLIB_EXPORT template <Class T>
173- constexpr ClassCast <T, true > class_cast_checked ;
173+ constexpr DynamicCastFunction <T, true > ClassCastChecked ;
174174
175175} // namespace retro
0 commit comments