Lightweight 0.20260303.0
Loading...
Searching...
No Matches
SqlRealName.hpp
1// SPDX-License-Identifier: Apache-2.0
2#pragma once
3
4#include <algorithm>
5#include <string_view>
6
7namespace Lightweight
8{
9
10/// @brief Helper class, used to represent a real SQL column names as template arguments.
11///
12/// @see Field, BelongsTo
13template <size_t N>
15{
16 /// The length of the name string (excluding null terminator).
17 static constexpr size_t length = (N > 0) ? (N - 1) : 0;
18
19 /// Returns the length of the name string.
20 [[nodiscard]] constexpr size_t size() const noexcept
21 {
22 return length;
23 }
24
25 constexpr ~SqlRealName() noexcept = default;
26 constexpr SqlRealName() noexcept = default;
27 /// Default copy constructor.
28 constexpr SqlRealName(SqlRealName const&) noexcept = default;
29 /// Default move constructor.
30 constexpr SqlRealName(SqlRealName&&) noexcept = default;
31 /// Default copy assignment operator.
32 constexpr SqlRealName& operator=(SqlRealName const&) noexcept = default;
33 /// Default move assignment operator.
34 constexpr SqlRealName& operator=(SqlRealName&&) noexcept = default;
35
36 /// Constructs a SqlRealName from a character array literal.
37 constexpr SqlRealName(char const (&str)[N]) noexcept
38 {
39 std::copy_n(str, N, value);
40 }
41
42 /// The underlying character buffer storing the name.
43 char value[N] {};
44
45 /// Returns true if the name is empty.
46 [[nodiscard]] constexpr bool empty() const noexcept
47 {
48 return length == 0;
49 }
50
51 /// Returns a pointer to the beginning of the name string.
52 [[nodiscard]] constexpr char const* begin() const noexcept
53 {
54 return value;
55 }
56
57 /// Returns a pointer past the end of the name string.
58 [[nodiscard]] constexpr char const* end() const noexcept
59 {
60 return value + length;
61 }
62
63 /// Three-way comparison operator.
64 [[nodiscard]] constexpr auto operator<=>(SqlRealName const&) const = default;
65
66 /// Returns the name as a string_view.
67 // NOLINTNEXTLINE(readability-identifier-naming)
68 [[nodiscard]] constexpr std::string_view sv() const noexcept
69 {
70 return { value, length };
71 }
72
73 [[nodiscard]] constexpr operator std::string_view() const noexcept
74 {
75 return { value, length };
76 }
77};
78
79} // namespace Lightweight
Helper class, used to represent a real SQL column names as template arguments.
constexpr char const * end() const noexcept
Returns a pointer past the end of the name string.
constexpr size_t size() const noexcept
Returns the length of the name string.
constexpr std::string_view sv() const noexcept
Returns the name as a string_view.
constexpr auto operator<=>(SqlRealName const &) const =default
Three-way comparison operator.
constexpr char const * begin() const noexcept
Returns a pointer to the beginning of the name string.
constexpr bool empty() const noexcept
Returns true if the name is empty.
char value[N]
The underlying character buffer storing the name.
static constexpr size_t length
The length of the name string (excluding null terminator).