1 //
2 // MetaColumn.h
3 //
4 // Library: Data
5 // Package: DataCore
6 // Module: MetaColumn
7 //
8 // Definition of the MetaColumn class.
9 //
10 // Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
11 // and Contributors.
12 //
13 // SPDX-License-Identifier: BSL-1.0
14 //
15
16
17 #ifndef Data_MetaColumn_INCLUDED
18 #define Data_MetaColumn_INCLUDED
19
20
21 #include "Poco/Data/Data.h"
22 #include <cstddef>
23
24
25 namespace Poco {
26 namespace Data {
27
28
29 class Data_API MetaColumn
30 /// MetaColumn class contains column metadata information.
31 {
32 public:
33 enum ColumnDataType
34 {
35 FDT_BOOL,
36 FDT_INT8,
37 FDT_UINT8,
38 FDT_INT16,
39 FDT_UINT16,
40 FDT_INT32,
41 FDT_UINT32,
42 FDT_INT64,
43 FDT_UINT64,
44 FDT_FLOAT,
45 FDT_DOUBLE,
46 FDT_STRING,
47 FDT_WSTRING,
48 FDT_BLOB,
49 FDT_CLOB,
50 FDT_DATE,
51 FDT_TIME,
52 FDT_TIMESTAMP,
53 FDT_UNKNOWN
54 };
55
56 MetaColumn();
57 /// Creates the MetaColumn.
58
59 explicit MetaColumn(std::size_t position,
60 const std::string& name = "",
61 ColumnDataType type = FDT_UNKNOWN,
62 std::size_t length = 0,
63 std::size_t precision = 0,
64 bool nullable = false);
65 /// Creates the MetaColumn.
66
67 MetaColumn(const MetaColumn& other);
68 /// Copy constructor.
69
70 MetaColumn(MetaColumn&& other) noexcept;
71 /// Move constructor.
72
73 MetaColumn& operator = (const MetaColumn& other);
74 /// Assignment operator.
75
76 MetaColumn& operator = (MetaColumn&& other) noexcept;
77 /// Assignment operator.
78
79 void swap(MetaColumn& other);
80 /// Swaps the contents with another instance.
81
82 ~MetaColumn();
83 /// Destroys the MetaColumn.
84
85 const std::string& name() const;
86 /// Returns column name.
87
88 std::size_t length() const;
89 /// Returns column maximum length.
90
91 std::size_t precision() const;
92 /// Returns column precision.
93 /// Valid for floating point fields only
94 /// (zero for other data types).
95
96 std::size_t position() const;
97 /// Returns column position.
98
99 ColumnDataType type() const;
100 /// Returns column type.
101
102 bool isNullable() const;
103 /// Returns true if column allows null values, false otherwise.
104
105 protected:
106 void setName(const std::string& name);
107 /// Sets the column name.
108
109 void setLength(std::size_t length);
110 /// Sets the column length.
111
112 void setPrecision(std::size_t precision);
113 /// Sets the column precision.
114
115 void setType(ColumnDataType type);
116 /// Sets the column data type.
117
118 void setNullable(bool nullable);
119 /// Sets the column nullability.
120
121 private:
122 std::string _name;
123 std::size_t _length;
124 std::size_t _precision;
125 std::size_t _position;
126 ColumnDataType _type;
127 bool _nullable;
128 };
129
130
131 ///
132 /// inlines
133 ///
name()134 inline const std::string& MetaColumn::name() const
135 {
136 return _name;
137 }
138
139
length()140 inline std::size_t MetaColumn::length() const
141 {
142 return _length;
143 }
144
145
precision()146 inline std::size_t MetaColumn::precision() const
147 {
148 return _precision;
149 }
150
151
position()152 inline std::size_t MetaColumn::position() const
153 {
154 return _position;
155 }
156
157
type()158 inline MetaColumn::ColumnDataType MetaColumn::type() const
159 {
160 return _type;
161 }
162
163
isNullable()164 inline bool MetaColumn::isNullable() const
165 {
166 return _nullable;
167 }
168
169
setName(const std::string & name)170 inline void MetaColumn::setName(const std::string& name)
171 {
172 _name = name;
173 }
174
175
setLength(std::size_t length)176 inline void MetaColumn::setLength(std::size_t length)
177 {
178 _length = length;
179 }
180
181
setPrecision(std::size_t precision)182 inline void MetaColumn::setPrecision(std::size_t precision)
183 {
184 _precision = precision;
185 }
186
187
setType(ColumnDataType type)188 inline void MetaColumn::setType(ColumnDataType type)
189 {
190 _type = type;
191 }
192
193
setNullable(bool nullable)194 inline void MetaColumn::setNullable(bool nullable)
195 {
196 _nullable = nullable;
197 }
198
199
200 } } // namespace Poco::Data
201
202
203 #endif // Data_MetaColumn_INCLUDED
204