libsl3 1.3.51003
A C++ interface for SQLite
Loading...
Searching...
No Matches
types.hpp
1/******************************************************************************
2 ------------- Copyright (c) 2009-2023 H a r a l d A c h i t z ---------------
3 ---------- < h a r a l d dot a c h i t z at g m a i l dot c o m > ------------
4 ---- This Source Code Form is subject to the terms of the Mozilla Public -----
5 ---- License, v. 2.0. If a copy of the MPL was not distributed with this -----
6 ---------- file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------
7 ******************************************************************************/
8
9#ifndef SL3_TYPES_HPP_
10#define SL3_TYPES_HPP_
11
12#include <cstddef>
13#include <iosfwd>
14#include <string>
15#include <vector>
16
17#include <sl3/config.hpp>
18#include <sl3/container.hpp>
19
20namespace sl3
21{
22 /**
23 * Enumeration of different value types
24 *
25 * These are the types known by sqlite.
26 * They are used when reading from or writing to a database.
27 *
28 */
29 enum class Type
30 {
31 Null = 0, //!< Null, no value
32 Int = 1, //!< Int value
33 Real = 2, //!< Real value
34 Text = 3, //!< Text value
35 Blob = 4, //!< Blob value
36 Variant = 5 //!< takes any type
37 };
38
39 /**
40 * \brief Get the type name as string
41 *
42 * For example, in log messages a type "Real" is more expressive than
43 * type 2.
44 *
45 * \return the type name as string
46 */
47 std::string typeName (Type);
48
49 /**
50 * \brief overloaded stream operator for sl3::Type
51 * \param os ostream
52 * \param t the Type
53 * \return the ostream
54 */
55 std::ostream& LIBSL3_API operator<< (std::ostream& os, const Type& t);
56
57 /**
58 * \brief A Container holding sl3::Type values.
59 *
60 * A fixed size list of sl3::Type values.
61 */
62 class LIBSL3_API Types : public Container<std::vector<Type>>
63 {
64 public:
65 //@{
66 using container_type = Container::container_type;
67 using iterator = container_type::iterator;
68 using const_iterator = container_type::const_iterator;
69 using value_type = container_type::value_type;
70 using reference = container_type::reference;
71 using const_reference = container_type::const_reference;
72 using size_type = container_type::size_type;
73 //@}
74
76
77 /**
78 * \brief Swap container
79 *
80 * Uses standard swap to change the contents.
81 *
82 * \param other Types to swap with
83 */
84 void swap (Types& other) noexcept;
85 };
86
87 /**
88 * A type for binary data
89 */
90 using Blob = std::vector<std::byte>;
91}
92
93#endif
Container() noexcept
Constructor.
Definition container.hpp:47
A Container holding sl3::Type values.
Definition types.hpp:63
void swap(Types &other) noexcept
Swap container.
Container() noexcept
Constructor.
Definition container.hpp:47
Namespace of libSL3.
Definition columns.hpp:18
std::vector< std::byte > Blob
Definition types.hpp:90
Type
Definition types.hpp:30
@ Int
Int value.
Definition types.hpp:32
@ Variant
takes any type
Definition types.hpp:36
@ Real
Real value.
Definition types.hpp:33
@ Text
Text value.
Definition types.hpp:34
@ Null
Null, no value.
Definition types.hpp:31
LIBSL3_API std::ostream & operator<<(std::ostream &stm, const sl3::DbValue &v)
Stream op for a DbValue.
std::string typeName(Type)
Get the type name as string.