Removed type names with leading underscore followed by capital letter; #9

This commit is contained in:
Patrick Urbanke
2023-11-11 14:11:29 +01:00
parent 9aeca3b141
commit c206699f64
6 changed files with 133 additions and 131 deletions
+31 -31
View File
@@ -14,10 +14,10 @@
namespace rfl {
/// Used to define a field in the NamedTuple.
template <internal::StringLiteral _name, class _Type>
template <internal::StringLiteral _name, class T>
struct Field {
/// The underlying type.
using Type = _Type;
using Type = T;
/// The name of the field.
using Name = rfl::Literal<_name>;
@@ -26,31 +26,31 @@ struct Field {
Field(Type&& _value) noexcept : value_(std::move(_value)) {}
Field(Field<_name, _Type>&& _field) noexcept = default;
Field(Field<_name, T>&& _field) noexcept = default;
Field(const Field<_name, Type>& _field) = default;
template <class T>
Field(const Field<_name, T>& _field) : value_(_field.get()) {}
template <class U>
Field(const Field<_name, U>& _field) : value_(_field.get()) {}
template <class T>
Field(Field<_name, T>&& _field) : value_(_field.get()) {}
template <class U>
Field(Field<_name, U>&& _field) : value_(_field.get()) {}
template <class T, typename std::enable_if<std::is_convertible_v<T, Type>,
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
bool>::type = true>
Field(const T& _value) : value_(_value) {}
Field(const U& _value) : value_(_value) {}
template <class T, typename std::enable_if<std::is_convertible_v<T, Type>,
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
bool>::type = true>
Field(T&& _value) noexcept : value_(std::forward<T>(_value)) {}
Field(U&& _value) noexcept : value_(std::forward<U>(_value)) {}
template <class T, typename std::enable_if<std::is_convertible_v<T, Type>,
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
bool>::type = true>
Field(const Field<_name, T>& _field) : value_(_field.value()) {}
Field(const Field<_name, U>& _field) : value_(_field.value()) {}
/// Assigns the underlying object to its default value.
template <class T = Type,
typename std::enable_if<std::is_default_constructible_v<T>,
template <class U = Type,
typename std::enable_if<std::is_default_constructible_v<U>,
bool>::type = true>
Field(const Default& _default) : value_(Type()) {}
@@ -81,16 +81,16 @@ struct Field {
}
/// Assigns the underlying object.
template <class T, typename std::enable_if<std::is_convertible_v<T, Type>,
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
bool>::type = true>
auto& operator=(const T& _value) {
auto& operator=(const U& _value) {
value_ = _value;
return *this;
}
/// Assigns the underlying object to its default value.
template <class T = Type,
typename std::enable_if<std::is_default_constructible_v<T>,
template <class U = Type,
typename std::enable_if<std::is_default_constructible_v<U>,
bool>::type = true>
auto& operator=(const Default& _default) {
value_ = Type();
@@ -98,21 +98,21 @@ struct Field {
}
/// Assigns the underlying object.
Field<_name, _Type>& operator=(const Field<_name, _Type>& _field) = default;
Field<_name, T>& operator=(const Field<_name, T>& _field) = default;
/// Assigns the underlying object.
Field<_name, _Type>& operator=(Field<_name, _Type>&& _field) = default;
Field<_name, T>& operator=(Field<_name, T>&& _field) = default;
/// Assigns the underlying object.
template <class T>
auto& operator=(const Field<_name, T>& _field) {
template <class U>
auto& operator=(const Field<_name, U>& _field) {
value_ = _field.get();
return *this;
}
/// Assigns the underlying object.
template <class T>
auto& operator=(Field<_name, T>&& _field) {
template <class U>
auto& operator=(Field<_name, U>&& _field) {
value_ = std::forward<T>(_field.value_);
return *this;
}
@@ -133,14 +133,14 @@ struct Field {
Type value_;
};
template <internal::StringLiteral _name, class _Type>
inline auto make_field(_Type&& _value) {
return Field<_name, _Type>(std::forward<_Type>(_value));
template <internal::StringLiteral _name, class T>
inline auto make_field(T&& _value) {
return Field<_name, T>(std::forward<T>(_value));
}
template <internal::StringLiteral _name, class _Type>
inline auto make_field(const _Type& _value) {
return Field<_name, _Type>(_value);
template <internal::StringLiteral _name, class T>
inline auto make_field(const T& _value) {
return Field<_name, T>(_value);
}
} // namespace rfl
+64 -63
View File
@@ -10,91 +10,92 @@
namespace rfl {
/// Used to embed another struct into the generated output.
template <class _Type>
template <class T>
struct Flatten {
/// The underlying type.
using Type = std::decay_t<_Type>;
/// The underlying type.
using Type = std::decay_t<T>;
Flatten(const Type& _value) : value_(_value) {}
Flatten(const Type& _value) : value_(_value) {}
Flatten(Type&& _value) noexcept : value_(std::forward<Type>(_value)) {}
Flatten(Type&& _value) noexcept : value_(std::forward<Type>(_value)) {}
Flatten(const Flatten<_Type>& _f) = default;
Flatten(const Flatten<T>& _f) = default;
Flatten(Flatten<_Type>&& _f) noexcept = default;
Flatten(Flatten<T>&& _f) noexcept = default;
template <class T>
Flatten(const Flatten<T>& _f) : value_(_f.get()) {}
template <class U>
Flatten(const Flatten<U>& _f) : value_(_f.get()) {}
template <class T>
Flatten(Flatten<T>&& _f) : value_(_f.get()) {}
template <class U>
Flatten(Flatten<U>&& _f) : value_(_f.get()) {}
template <class T, typename std::enable_if<std::is_convertible_v<T, Type>,
bool>::type = true>
Flatten(const T& _value) : value_(_value) {}
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
bool>::type = true>
Flatten(const U& _value) : value_(_value) {}
template <class T, typename std::enable_if<std::is_convertible_v<T, Type>,
bool>::type = true>
Flatten(T&& _value) : value_(_value) {}
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
bool>::type = true>
Flatten(U&& _value) : value_(_value) {}
~Flatten() = default;
~Flatten() = default;
/// Returns the underlying object.
const Type& get() const { return value_; }
/// Returns the underlying object.
const Type& get() const { return value_; }
/// Returns the underlying object.
Type& operator()() { return value_; }
/// Returns the underlying object.
Type& operator()() { return value_; }
/// Returns the underlying object.
const Type& operator()() const { return value_; }
/// Returns the underlying object.
const Type& operator()() const { return value_; }
/// Assigns the underlying object.
Flatten<_Type>& operator=(const _Type& _value) {
value_ = _value;
return *this;
}
/// Assigns the underlying object.
Flatten<T>& operator=(const T& _value) {
value_ = _value;
return *this;
}
/// Assigns the underlying object.
Flatten<_Type>& operator=(_Type&& _value) {
value_ = std::forward<Type>(_value);
return *this;
}
/// Assigns the underlying object.
Flatten<T>& operator=(T&& _value) {
value_ = std::forward<Type>(_value);
return *this;
}
/// Assigns the underlying object.
template <class T, typename std::enable_if<std::is_convertible_v<T, Type>,
bool>::type = true>
Flatten<_Type>& operator=(const T& _value) {
value_ = _value;
return *this;
}
/// Assigns the underlying object.
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
bool>::type = true>
Flatten<T>& operator=(const U& _value) {
value_ = _value;
return *this;
}
/// Assigns the underlying object.
Flatten<_Type>& operator=(const Flatten<_Type>& _f) = default;
/// Assigns the underlying object.
Flatten<T>& operator=(const Flatten<T>& _f) = default;
/// Assigns the underlying object.
Flatten<_Type>& operator=(Flatten<_Type>&& _f) = default;
/// Assigns the underlying object.
template <class T>
Flatten<_Type>& operator=(const Flatten<T>& _f) {
value_ = _f.get();
return *this;
}
/// Assigns the underlying object.
Flatten<T>& operator=(Flatten<T>&& _f) = default;
/// Assigns the underlying object.
template <class T>
Flatten<_Type>& operator=(Flatten<T>&& _f) {
value_ = std::forward<T>(_f);
return *this;
}
/// Assigns the underlying object.
template <class U>
Flatten<T>& operator=(const Flatten<U>& _f) {
value_ = _f.get();
return *this;
}
/// Assigns the underlying object.
void set(const Type& _value) { value_ = _value; }
/// Assigns the underlying object.
template <class U>
Flatten<T>& operator=(Flatten<U>&& _f) {
value_ = std::forward<U>(_f);
return *this;
}
/// Assigns the underlying object.
void set(Type&& _value) { value_ = std::forward<Type>(_value); }
/// Assigns the underlying object.
void set(const Type& _value) { value_ = _value; }
/// The underlying value.
Type value_;
/// Assigns the underlying object.
void set(Type&& _value) { value_ = std::forward<Type>(_value); }
/// The underlying value.
Type value_;
};
} // namespace rfl
+15 -16
View File
@@ -10,27 +10,26 @@ namespace rfl {
namespace internal {
/// Finds the index of the field signified by _field_name
template <StringLiteral _field_name, class _Fields, int I = 0>
template <StringLiteral _field_name, class Fields, int I = 0>
constexpr static int find_index() {
using FieldType =
std::decay_t<typename std::tuple_element<I, _Fields>::type>;
using FieldType = std::decay_t<typename std::tuple_element<I, Fields>::type>;
constexpr bool name_i_matches = (FieldType::name_ == _field_name);
constexpr bool name_i_matches = (FieldType::name_ == _field_name);
if constexpr (name_i_matches) {
return I;
if constexpr (name_i_matches) {
return I;
} else {
constexpr bool out_of_range = I + 1 == std::tuple_size<Fields>{};
static_assert(!out_of_range, "Field name not found!");
if constexpr (out_of_range) {
// This is to avoid very confusing error messages.
return I;
} else {
constexpr bool out_of_range = I + 1 == std::tuple_size<_Fields>{};
static_assert(!out_of_range, "Field name not found!");
if constexpr (out_of_range) {
// This is to avoid very confusing error messages.
return I;
} else {
return find_index<_field_name, _Fields, I + 1>();
}
return find_index<_field_name, Fields, I + 1>();
}
}
}
} // namespace internal
+16 -16
View File
@@ -10,28 +10,28 @@
namespace rfl {
namespace internal {
template <internal::StringLiteral _name, class _Type>
inline auto to_ptr_field(Field<_name, _Type>& _field) {
using T = std::remove_reference_t<_Type>;
return Field<_name, T*>(&_field.value_);
template <internal::StringLiteral _name, class Type>
inline auto to_ptr_field(Field<_name, Type>& _field) {
using T = std::remove_reference_t<Type>;
return Field<_name, T*>(&_field.value_);
}
template <internal::StringLiteral _name, class _Type>
inline auto to_ptr_field(const Field<_name, _Type>& _field) {
using T = std::remove_cvref_t<_Type>;
return Field<_name, const T*>(&_field.value_);
template <internal::StringLiteral _name, class Type>
inline auto to_ptr_field(const Field<_name, Type>& _field) {
using T = std::remove_cvref_t<Type>;
return Field<_name, const T*>(&_field.value_);
}
template <class _Type>
inline auto to_ptr_field(Flatten<_Type>& _field) {
using T = std::remove_reference_t<_Type>;
return Flatten<T*>(&_field.value_);
template <class Type>
inline auto to_ptr_field(Flatten<Type>& _field) {
using T = std::remove_reference_t<Type>;
return Flatten<T*>(&_field.value_);
}
template <class _Type>
inline auto to_ptr_field(const Flatten<_Type>& _field) {
using T = std::remove_cvref_t<_Type>;
return Flatten<const T*>(&_field.value_);
template <class Type>
inline auto to_ptr_field(const Flatten<Type>& _field) {
using T = std::remove_cvref_t<Type>;
return Flatten<const T*>(&_field.value_);
}
} // namespace internal
+5 -5
View File
@@ -15,9 +15,9 @@ namespace rfl {
template <class T>
struct remove_ptr;
template <internal::StringLiteral _name, class _Type>
struct remove_ptr<Field<_name, _Type>> {
using FieldType = Field<_name, std::decay_t<std::remove_pointer_t<_Type>>>;
template <internal::StringLiteral _name, class T>
struct remove_ptr<Field<_name, T>> {
using FieldType = Field<_name, std::decay_t<std::remove_pointer_t<T>>>;
};
template <class T>
@@ -25,8 +25,8 @@ struct remove_ptrs_nt;
template <class... FieldTypes>
struct remove_ptrs_nt<NamedTuple<FieldTypes...>> {
using NamedTupleType =
NamedTuple<typename remove_ptr<FieldTypes>::FieldType...>;
using NamedTupleType =
NamedTuple<typename remove_ptr<FieldTypes>::FieldType...>;
};
/// Generates the named tuple that is equivalent to the struct T.
+2
View File
@@ -146,6 +146,8 @@ struct Parser {
}
};
// ----------------------------------------------------------------------------
template <class R, class W, class T>
requires AreReaderAndWriter<R, W, T*>
struct Parser<R, W, T*> {