sptk2 logo
SPTK Home Page
Field.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <sptk5/Buffer.h>
30#include <sptk5/DateTime.h>
31#include <sptk5/Variant.h>
32#include <sptk5/xdoc/Node.h>
33
34#include <string>
35
36namespace sptk {
37
43class Query;
44
45class FieldList;
46
52class SP_EXPORT Field
53 : public Variant
54{
55 friend class FieldList;
56
57public:
61 struct View {
62 signed int width : 10;
63 unsigned precision : 5;
64 unsigned flags : 16;
65 bool visible : 1;
66 };
67
72 explicit Field(const String& name);
73
78 Field(const Field& other) = default;
79
84 Field(Field&& other) noexcept = default;
85
86 ~Field() noexcept override = default;
87
91 View& view()
92 {
93 return m_view;
94 };
95
99 const String& fieldName() const
100 {
101 return m_name;
102 }
103
107 Field& operator=(const Field& other) = default;
108
112 Field& operator=(Field&& other) noexcept = default;
113
118 {
119 if (this == &C)
120 {
121 return *this;
122 }
123
124 setData(C);
125 return *this;
126 }
127
131 Field& operator=(bool value) override
132 {
133 setBool(value);
134 return *this;
135 }
136
140 Field& operator=(int32_t value) override
141 {
142 setInteger(value);
143 return *this;
144 }
145
149 Field& operator=(int64_t value) override
150 {
151 setInt64(value);
152 return *this;
153 }
154
158 Field& operator=(double value) override
159 {
160 setFloat(value);
161 return *this;
162 }
163
167 Field& operator=(const char* value) override
168 {
169 setString(value);
170 return *this;
171 }
172
176 Field& operator=(const sptk::String& value) override
177 {
178 setBuffer((const uint8_t*) value.c_str(), value.length(), VariantDataType::VAR_STRING);
179 return *this;
180 }
181
185 Field& operator=(DateTime value) override
186 {
187 setDateTime(value);
188 return *this;
189 }
190
194 Field& operator=(const uint8_t* value) override
195 {
196 setImagePtr(value);
197 return *this;
198 }
199
203 Field& operator=(const Buffer& value) override
204 {
205 setBuffer(value.data(), value.bytes(), VariantDataType::VAR_BUFFER);
206 return *this;
207 }
208
212 String asString() const override;
213
225 void exportTo(const xdoc::SNode& node, bool compactXmlMode, bool detailedInfo = false, bool nullLargeData = false) const;
226
227 String displayName() const
228 {
229 return m_displayName;
230 }
231
232 void displayName(const String& name)
233 {
234 m_displayName = name;
235 }
236
237protected:
238 virtual String doubleDataToString() const;
239
240private:
241 String m_name;
242 View m_view {};
243 String m_displayName;
244
245 String epochDataToDateTimeString() const;
246};
247
248using SField = std::shared_ptr<Field>;
249
253} // namespace sptk
size_t bytes() const
Definition: BufferStorage.h:213
uint8_t * data()
Definition: BufferStorage.h:106
Definition: Buffer.h:51
Definition: DateTime.h:86
Definition: FieldList.h:50
Definition: Field.h:54
Field & operator=(DateTime value) override
Definition: Field.h:185
Field & operator=(const Field &other)=default
Field & operator=(bool value) override
Definition: Field.h:131
Field & operator=(int32_t value) override
Definition: Field.h:140
String asString() const override
Field(const String &name)
Field & operator=(const Buffer &value) override
Definition: Field.h:203
Field(const Field &other)=default
Field & operator=(double value) override
Definition: Field.h:158
Field & operator=(const uint8_t *value) override
Definition: Field.h:194
Field & operator=(const sptk::String &value) override
Definition: Field.h:176
Field & operator=(const Variant &C)
Definition: Field.h:117
Field & operator=(const char *value) override
Definition: Field.h:167
Field & operator=(Field &&other) noexcept=default
Field & operator=(int64_t value) override
Definition: Field.h:149
const String & fieldName() const
Definition: Field.h:99
Field(Field &&other) noexcept=default
void exportTo(const xdoc::SNode &node, bool compactXmlMode, bool detailedInfo=false, bool nullLargeData=false) const
Definition: String.h:49
Definition: Variant.h:372
@ VAR_STRING
String pointer.
@ VAR_BUFFER
Data pointer, corresponding to BLOBS in database.
Definition: Field.h:61
unsigned flags
Field flags like alignment, etc.
Definition: Field.h:64
unsigned precision
Field precision.
Definition: Field.h:63
signed int width
Field width.
Definition: Field.h:62
bool visible
Is field visible?
Definition: Field.h:65

Fri Oct 14 2022 09:58:31: SPTK 5.4.1