libsl3 1.2.41002
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 vale
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 verbose that a type 2.
43 *
44 * \return the type name as string
45 */
46 std::string typeName (Type);
47
48 /**
49 * \brief overloaded stream operator for sl3::Type
50 * \param os ostream
51 * \param t the Type
52 * \return the ostream
53 */
54 std::ostream& LIBSL3_API operator<< (std::ostream& os, const Type& t);
55
56 /**
57 * \brief A Container holding sl3::Type values.
58 *
59 * A fixed size list of sl3::Type values.
60 */
61 class LIBSL3_API Types : public Container<std::vector<Type>>
62 {
63 public:
64 //@{
65 using conatiner_type = Container::conatiner_type;
66 using iterator = conatiner_type::iterator;
67 using const_iterator = conatiner_type::const_iterator;
68 using value_type = conatiner_type::value_type;
69 using reference = conatiner_type::reference;
70 using const_reference = conatiner_type::const_reference;
71 using size_type = conatiner_type::size_type;
72 //@}
73
74#ifndef _MSC_VER
75 using Container::Container;
76
77#else
78 /**
79 * \brief c'tor
80 *
81 * Create an empty sl3::Type Container
82 */
83 Types () noexcept {}
84 using Base = Container<std::vector<Type>>;
85
86 /**
87 * \brief c'tor
88 *
89 * Create a container with given vector of sl3::Type elements.
90 *
91 * \param c vector of sl3::Type
92 */
93 Types (conatiner_type c) noexcept (
94 std::is_nothrow_move_constructible<conatiner_type>::value)
95 : Base (std::move (c))
96 {
97 }
98
99 /**
100 * \brief c'tor
101 *
102 * Create a container with given initializer list of sl3::Type elements.
103 *
104 * \param l initialer list of sl3::Type
105 */
106 Types (std::initializer_list<typename conatiner_type::value_type> l)
107 : Base (std::move (l))
108 {
109 }
110
111#endif
112
113 /**
114 * \brief Swap container
115 *
116 * Uses standard swap to change the contents.
117 *
118 * \param other Types to swap with
119 */
120 void swap (Types& other) noexcept;
121 };
122
123 /**
124 * A type for binary data
125 */
126 using Blob = std::vector<std::byte>;
127}
128
129#endif
Wrapper to provide begin, end and random access of a container.
Definition: container.hpp:29
A Container holding sl3::Type values.
Definition: types.hpp:62
void swap(Types &other) noexcept
Swap container.
Namespace of libSL3.
Definition: columns.hpp:18
Type
Definition: types.hpp:30
@ Int
Int value.
@ Variant
takes any type
@ Real
Real value.
@ Text
Text value.
@ Null
Null, no value.
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.
std::vector< std::byte > Blob
Definition: types.hpp:126