Lightweight 0.20260303.0
Loading...
Searching...
No Matches
Lightweight::Field< T, P1, P2 > Struct Template Reference

Represents a single column in a table. More...

#include <Field.hpp>

Public Types

using ValueType = T
 The underlying value type of this field.
 

Public Member Functions

constexpr Field (Field const &) noexcept=default
 Default copy constructor.
 
constexpr Fieldoperator= (Field const &) noexcept=default
 Default copy assignment operator.
 
constexpr Field (Field &&) noexcept=default
 Default move constructor.
 
constexpr Fieldoperator= (Field &&) noexcept=default
 Default move assignment operator.
 
template<typename... S>
requires std::constructible_from<T, S...>
constexpr Field (S &&... value) noexcept
 Constructs a new field with the given value.
 
template<typename S >
requires std::constructible_from<T, S> && (!std::same_as<std::remove_cvref_t<S>, Field<T, P1, P2>>)
constexpr Fieldoperator= (S &&value) noexcept
 Assigns a new value to the field.
 
constexpr std::weak_ordering operator<=> (Field const &other) const noexcept
 Compares two fields for equality.
 
constexpr bool operator== (Field const &other) const noexcept
 Compares the field value with the given value for equality.
 
constexpr bool operator!= (Field const &other) const noexcept
 Compares the field value with the given value for inequality.
 
template<typename S >
requires std::convertible_to<S, T>
constexpr bool operator== (S const &value) const noexcept
 Compares the field value with the given value for equality.
 
template<typename S >
requires std::convertible_to<S, T>
constexpr bool operator!= (S const &value) const noexcept
 Compares the field value with the given value for inequality.
 
std::string InspectValue () const
 Returns a string representation of the value, suitable for use in debugging and logging.
 
constexpr void SetModified (bool value) noexcept
 Sets the modified state of the field.
 
constexpr bool IsModified () const noexcept
 Checks if the field has been modified.
 
constexpr T const & Value () const noexcept
 Returns the value of the field.
 
constexpr auto ValueOr (auto &&defaultValue) const noexcept
 When the field type is optional, returns the value or the given default value.
 
constexpr T & MutableValue () noexcept
 
template<typename... S>
requires std::constructible_from<T, S...>
constexpr LIGHTWEIGHT_FORCE_INLINE Field (S &&... value) noexcept
 Constructs a new field with the given value.
 
template<typename S >
requires std::constructible_from<T, S> && (!std::same_as<std::remove_cvref_t<S>, Field<T, P1, P2>>)
constexpr LIGHTWEIGHT_FORCE_INLINE Field< T, P1, P2 > & operator= (S &&value) noexcept
 Assigns a new value to the field.
 
template<typename S >
requires std::convertible_to<S, T>
constexpr bool LIGHTWEIGHT_FORCE_INLINE operator== (S const &value) const noexcept
 Equality comparison operator with a convertible value.
 
template<typename S >
requires std::convertible_to<S, T>
constexpr bool LIGHTWEIGHT_FORCE_INLINE operator!= (S const &value) const noexcept
 Inequality comparison operator with a convertible value.
 

Static Public Attributes

static constexpr auto IsPrimaryKeyValue = detail::Choose<PrimaryKey>(PrimaryKey::No, P1, P2)
 The primary key mode for this field.
 
static constexpr auto ColumnNameOverride = detail::Choose<std::string_view>({}, P1, P2)
 If not empty, overrides the default column name in the database.
 
static constexpr auto IsOptional = detail::IsStdOptional<T>
 Indicates if the field is optional, i.e., it can be NULL.
 
static constexpr auto IsMandatory = !IsOptional
 Indicates if the field is mandatory, i.e., it cannot be NULL.
 
static constexpr auto IsPrimaryKey = IsPrimaryKeyValue != PrimaryKey::No
 Indicates if the field is a primary key.
 
static constexpr auto IsAutoAssignPrimaryKey = IsPrimaryKeyValue == PrimaryKey::AutoAssign
 Indicates if this is a primary key, it also is auto-assigned by the client.
 
static constexpr auto IsAutoIncrementPrimaryKey = IsPrimaryKeyValue == PrimaryKey::ServerSideAutoIncrement
 Indicates if this is a primary key, it also is auto-incremented by the database.
 

Detailed Description

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
struct Lightweight::Field< T, P1, P2 >

Represents a single column in a table.

This class is used to represent a single column in a table. It also keeps track of modified-state of the field.

The column name, index, nullability, and type are known at compile time.

See also
DataMapper ,

Definition at line 83 of file Field.hpp.

Member Typedef Documentation

◆ ValueType

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
using Lightweight::Field< T, P1, P2 >::ValueType = T

The underlying value type of this field.

Definition at line 86 of file Field.hpp.

Constructor & Destructor Documentation

◆ Field()

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
template<typename... S>
requires std::constructible_from<T, S...>
constexpr LIGHTWEIGHT_FORCE_INLINE Lightweight::Field< T, P1, P2 >::Field ( S &&...  value)
constexprnoexcept

Constructs a new field with the given value.

Definition at line 227 of file Field.hpp.

Member Function Documentation

◆ operator<=>()

template<detail::FieldElementType T, auto P1, auto P2>
constexpr std::weak_ordering LIGHTWEIGHT_FORCE_INLINE Lightweight::Field< T, P1, P2 >::operator<=> ( Field< T, P1, P2 > const &  other) const
constexprnoexcept

Compares two fields for equality.

Definition at line 244 of file Field.hpp.

◆ operator==() [1/2]

template<detail::FieldElementType T, auto P1, auto P2>
constexpr bool LIGHTWEIGHT_FORCE_INLINE Lightweight::Field< T, P1, P2 >::operator== ( Field< T, P1, P2 > const &  other) const
constexprnoexcept

Compares the field value with the given value for equality.

Definition at line 250 of file Field.hpp.

◆ operator!=() [1/2]

template<detail::FieldElementType T, auto P1, auto P2>
constexpr bool LIGHTWEIGHT_FORCE_INLINE Lightweight::Field< T, P1, P2 >::operator!= ( Field< T, P1, P2 > const &  other) const
constexprnoexcept

Compares the field value with the given value for inequality.

Definition at line 256 of file Field.hpp.

◆ InspectValue()

template<detail::FieldElementType T, auto P1, auto P2>
LIGHTWEIGHT_FORCE_INLINE std::string Lightweight::Field< T, P1, P2 >::InspectValue ( ) const
inline

Returns a string representation of the value, suitable for use in debugging and logging.

Definition at line 280 of file Field.hpp.

◆ SetModified()

template<detail::FieldElementType T, auto P1, auto P2>
constexpr LIGHTWEIGHT_FORCE_INLINE void Lightweight::Field< T, P1, P2 >::SetModified ( bool  value)
constexprnoexcept

Sets the modified state of the field.

Definition at line 316 of file Field.hpp.

◆ IsModified()

template<detail::FieldElementType T, auto P1, auto P2>
constexpr LIGHTWEIGHT_FORCE_INLINE bool Lightweight::Field< T, P1, P2 >::IsModified ( ) const
constexprnoexcept

Checks if the field has been modified.

Definition at line 322 of file Field.hpp.

◆ Value()

template<detail::FieldElementType T, auto P1, auto P2>
constexpr LIGHTWEIGHT_FORCE_INLINE T const & Lightweight::Field< T, P1, P2 >::Value ( ) const
constexprnoexcept

Returns the value of the field.

Definition at line 328 of file Field.hpp.

◆ ValueOr()

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
constexpr auto Lightweight::Field< T, P1, P2 >::ValueOr ( auto &&  defaultValue) const
inlineconstexprnoexcept

When the field type is optional, returns the value or the given default value.

Definition at line 164 of file Field.hpp.

◆ MutableValue()

template<detail::FieldElementType T, auto P1, auto P2>
constexpr LIGHTWEIGHT_FORCE_INLINE T & Lightweight::Field< T, P1, P2 >::MutableValue ( )
constexprnoexcept

Returns a mutable reference to the value of the field.

Note
If the field value is changed through this method, it will not be automatically marked as modified.

Definition at line 334 of file Field.hpp.

◆ operator=()

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
template<typename S >
requires std::constructible_from<T, S> && (!std::same_as<std::remove_cvref_t<S>, Field<T, P1, P2>>)
constexpr LIGHTWEIGHT_FORCE_INLINE Field< T, P1, P2 > & Lightweight::Field< T, P1, P2 >::operator= ( S &&  value)
constexprnoexcept

Assigns a new value to the field.

Definition at line 236 of file Field.hpp.

◆ operator==() [2/2]

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
template<typename S >
requires std::convertible_to<S, T>
constexpr bool LIGHTWEIGHT_FORCE_INLINE Lightweight::Field< T, P1, P2 >::operator== ( S const &  value) const
constexprnoexcept

Equality comparison operator with a convertible value.

Definition at line 265 of file Field.hpp.

◆ operator!=() [2/2]

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
template<typename S >
requires std::convertible_to<S, T>
constexpr bool LIGHTWEIGHT_FORCE_INLINE Lightweight::Field< T, P1, P2 >::operator!= ( S const &  value) const
constexprnoexcept

Inequality comparison operator with a convertible value.

Definition at line 274 of file Field.hpp.

Member Data Documentation

◆ IsPrimaryKeyValue

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
constexpr auto Lightweight::Field< T, P1, P2 >::IsPrimaryKeyValue = detail::Choose<PrimaryKey>(PrimaryKey::No, P1, P2)
staticconstexpr

The primary key mode for this field.

Definition at line 89 of file Field.hpp.

◆ ColumnNameOverride

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
constexpr auto Lightweight::Field< T, P1, P2 >::ColumnNameOverride = detail::Choose<std::string_view>({}, P1, P2)
staticconstexpr

If not empty, overrides the default column name in the database.

Definition at line 91 of file Field.hpp.

◆ IsOptional

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
constexpr auto Lightweight::Field< T, P1, P2 >::IsOptional = detail::IsStdOptional<T>
staticconstexpr

Indicates if the field is optional, i.e., it can be NULL.

Definition at line 118 of file Field.hpp.

◆ IsMandatory

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
constexpr auto Lightweight::Field< T, P1, P2 >::IsMandatory = !IsOptional
staticconstexpr

Indicates if the field is mandatory, i.e., it cannot be NULL.

Definition at line 121 of file Field.hpp.

◆ IsPrimaryKey

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
constexpr auto Lightweight::Field< T, P1, P2 >::IsPrimaryKey = IsPrimaryKeyValue != PrimaryKey::No
staticconstexpr

Indicates if the field is a primary key.

Definition at line 124 of file Field.hpp.

◆ IsAutoAssignPrimaryKey

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
constexpr auto Lightweight::Field< T, P1, P2 >::IsAutoAssignPrimaryKey = IsPrimaryKeyValue == PrimaryKey::AutoAssign
staticconstexpr

Indicates if this is a primary key, it also is auto-assigned by the client.

Definition at line 127 of file Field.hpp.

◆ IsAutoIncrementPrimaryKey

template<detail::FieldElementType T, auto P1 = std::nullopt, auto P2 = std::nullopt>
constexpr auto Lightweight::Field< T, P1, P2 >::IsAutoIncrementPrimaryKey = IsPrimaryKeyValue == PrimaryKey::ServerSideAutoIncrement
staticconstexpr

Indicates if this is a primary key, it also is auto-incremented by the database.

Definition at line 130 of file Field.hpp.


The documentation for this struct was generated from the following file: