StormByte-Database 3.0.0
C++26 database module of the StormByte suite
Loading...
Searching...
No Matches
row.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Database.
5 *
6 * StormByte-Database original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Database source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, and in particular the bundled StormByte-Logger tree and
23 * the PostgreSQL, MariaDB and SQLite trees), which remain under their own
24 * licenses.
25 *
26 * Neither license grants any patent rights. Any patent licenses required
27 * to use this software or third-party components must be obtained separately
28 * from the patent holders.
29 *
30 * StormByte-Database is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU Lesser General Public License for more details.
34 *
35 * You should have received a copy of the GNU Lesser General Public License
36 * version 3 along with StormByte-Database. If not, see
37 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
38 *
39 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
40 */
41
42#pragma once
43
45#include <StormByte/safe/map.hxx>
46#include <StormByte/safe/optional.hxx>
47#include <StormByte/safe/vector.hxx>
48#include <StormByte/size.hxx>
49#include <StormByte/type_traits.hxx>
50
51#include <iterator>
52#include <string_view>
53#include <utility>
54
59namespace StormByte {
64 namespace Database {
70 public:
74 using const_reference = const NamedValue&;
76 using const_pointer = const NamedValue*;
77 using iterator = pointer;
81
85 Row() noexcept;
86
91 Row(const Row &other);
92
96 Row(Row &&other) noexcept;
97
101 ~Row() noexcept;
102
108 Row &operator=(const Row &other);
109
113 Row &operator=(Row &&other) noexcept;
114
120 bool operator==(const Row &other) const;
121
127 bool operator!=(const Row &other) const;
128
133 iterator begin() noexcept;
134
139 const_iterator begin() const noexcept;
140
145 iterator end() noexcept;
146
151 const_iterator end() const noexcept;
152
157 const_iterator cbegin() const noexcept;
158
163 const_iterator cend() const noexcept;
164
170
176
182
187 const_reverse_iterator rend() const noexcept;
188
194
200
205 StormByte::Size size() const noexcept;
206
211 bool empty() const noexcept;
212
219 const Value &operator[](std::string_view columnName) const &;
220
227 Value &operator[](std::string_view columnName) &;
228
235 Value operator[](std::string_view columnName) &&;
236
243 const NamedValue &operator[](StormByte::Size index) const &;
244
251 template <StormByte::Type::Integral T>
252 const NamedValue &operator[](T index) const & {
253 return (*this)[StormByte::Size{index}];
254 }
255
263
270 template <StormByte::Type::Integral T>
271 NamedValue &operator[](T index) & {
272 return (*this)[StormByte::Size{index}];
273 }
274
282
289 template <StormByte::Type::Integral T>
290 NamedValue operator[](T index) && {
291 return std::move(*this)[StormByte::Size{index}];
292 }
293
299 void add(std::string_view columnName, Value &&value);
300
305 void add(NamedValue value);
306
312 bool has_item(const NamedValue &value) const;
313
318 StormByte::Size Count() const noexcept;
319
320 private:
321 StormByte::Safe::Vector<NamedValue> m_columns;
322 mutable StormByte::Safe::Optional<StormByte::Safe::Map<StormByte::Safe::String, StormByte::Size>> m_name_index;
323
327 void BuildNameIndex() const;
328 };
329 }
330}
331
Abstract backend.
Definition database.hxx:73
Value plus column name.
Definition named_value.hxx:63
reverse_iterator rbegin() noexcept
Mutable reverse begin.
NamedValue operator[](StormByte::Size index) &&
Access a column by zero-based index (rvalue).
Row() noexcept
Default constructor.
reverse_iterator rend() noexcept
Mutable reverse end.
bool has_item(const NamedValue &value) const
Search for an equal named value.
const_pointer const_iterator
Read-only pointer iterator.
Definition row.hxx:78
StormByte::Size Count() const noexcept
Number of columns.
StormByte::Size size() const noexcept
Number of columns.
const NamedValue & const_reference
Read-only column reference.
Definition row.hxx:74
const_iterator cbegin() const noexcept
Read-only begin pointer.
iterator begin() noexcept
Mutable begin pointer.
NamedValue * pointer
Mutable column pointer.
Definition row.hxx:75
void add(std::string_view columnName, Value &&value)
Append a named column.
NamedValue operator[](T index) &&
Access a column by integral zero-based index (rvalue).
Definition row.hxx:290
NamedValue & reference
Mutable column reference.
Definition row.hxx:73
bool empty() const noexcept
Whether the row has no columns.
iterator end() noexcept
Mutable end pointer.
const_iterator cend() const noexcept
Read-only end pointer.
pointer iterator
Mutable pointer iterator.
Definition row.hxx:77
NamedValue value_type
Column value type.
Definition row.hxx:71
NamedValue & operator[](T index) &
Access a column by integral zero-based index (lvalue).
Definition row.hxx:271
StormByte::Safe::Vector< NamedValue >::reverse_iterator reverse_iterator
Mutable reverse iterator.
Definition row.hxx:79
StormByte::Safe::Vector< NamedValue >::const_reverse_iterator const_reverse_iterator
Read-only reverse iterator.
Definition row.hxx:80
StormByte::Size size_type
Column count and index type.
Definition row.hxx:72
const_reverse_iterator crbegin() const noexcept
Read-only reverse begin.
const_reverse_iterator crend() const noexcept
Read-only reverse end.
void add(NamedValue value)
Append a named value.
NamedValue & operator[](StormByte::Size index) &
Access a column by zero-based index (lvalue).
const NamedValue * const_pointer
Read-only column pointer.
Definition row.hxx:76
Type-erased SQL value (NULL, integers, double, text, blob, bool).
Definition value.hxx:71
std::reverse_iterator< const_iterator > const_reverse_iterator
std::reverse_iterator< iterator > reverse_iterator
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Logger::Exception)
Database module of the StormByte suite.
Root namespace of the StormByte C++ suite.
STL namespace.
#define STORMBYTE_DATABASE_PUBLIC
Definition visibility.h:54