sptk2 logo
SPTK Home Page
WSComplexType.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/FieldList.h>
30#include <sptk5/Variant.h>
31#include <sptk5/db/QueryParameterList.h>
32#include <sptk5/threads/Locks.h>
33#include <sptk5/wsdl/WSArray.h>
34#include <sptk5/wsdl/WSBasicTypes.h>
35#include <sptk5/wsdl/WSFieldIndex.h>
36#include <sptk5/xdoc/Node.h>
37
38namespace sptk {
39
48class SP_EXPORT WSComplexType
49 : public WSType
50{
51public:
57 WSComplexType(const char* name, bool optional = false)
58 : WSType(name)
59 , m_optional(optional)
60 {
61 }
62
67 WSComplexType(const WSComplexType& other) = default;
68
73 WSComplexType(WSComplexType&& other) noexcept = default;
74
78 ~WSComplexType() override = default;
79
84 WSComplexType& operator=(const WSComplexType& other) = default;
85
90 WSComplexType& operator=(WSComplexType&& other) noexcept = default;
91
95 String className() const override
96 {
97 return "WSComplexType";
98 }
99
103 void clear() override
104 {
105 _clear();
106 }
107
112 void copyFrom(const WSComplexType& other);
113
119 void load(const xdoc::SNode& input, bool nullLargeData = false) override;
120
128 virtual void load(const sptk::FieldList& input, bool nullLargeData = false);
129
134 virtual void unload(const xdoc::SNode& output) const;
135
140 virtual void unload(QueryParameterList& output) const;
141
148 static void unload(QueryParameterList& output, const char* paramName, const WSBasicType* elementOrAttribute);
149
155 void exportTo(const xdoc::SNode& parent, const char* name = nullptr) const override;
156
160 bool isNull() const override;
161
165 virtual bool isOptional() const
166 {
167 return m_optional;
168 }
169
175 virtual String toString(bool asJSON = true, bool formatted = false) const;
176
181 void throwIfNull(const String& parentTypeName) const;
182
187 void exportable(bool flag)
188 {
189 m_exportable = flag;
190 }
191
192protected:
196 bool loaded() const
197 {
198 return m_loaded;
199 }
200
205 void setLoaded(bool flag)
206 {
207 m_loaded = flag;
208 }
209
213 virtual void _clear()
214 {
215 m_fields.forEach([](WSType* field) {
216 field->clear();
217 return true;
218 });
219 }
220
221 const WSFieldIndex& getFields() const
222 {
223 return m_fields;
224 }
225
226 void setElements(const Strings& fieldNames, std::initializer_list<WSType*> fields)
227 {
228 m_fields.setElements(fieldNames, fields);
229 }
230
231 void setAttributes(const Strings& fieldNames, std::initializer_list<WSType*> fields)
232 {
233 m_fields.setAttributes(fieldNames, fields);
234 }
235
239 virtual void checkRestrictions() const
240 {
241 // Implement in derived class
242 }
243
244private:
245 bool m_optional {false};
246 bool m_loaded {false};
247 bool m_exportable {true};
248 WSFieldIndex m_fields;
249
250 static bool loadField(const FieldList& input, bool nullLargeData, WSType* field);
251};
252
257} // namespace sptk
Definition: FieldList.h:50
Definition: QueryParameterList.h:57
Definition: String.h:49
Definition: WSBasicTypes.h:41
Definition: WSComplexType.h:50
bool loaded() const
Definition: WSComplexType.h:196
static void unload(QueryParameterList &output, const char *paramName, const WSBasicType *elementOrAttribute)
void copyFrom(const WSComplexType &other)
void setLoaded(bool flag)
Definition: WSComplexType.h:205
WSComplexType(const char *name, bool optional=false)
Definition: WSComplexType.h:57
virtual void checkRestrictions() const
Definition: WSComplexType.h:239
WSComplexType(WSComplexType &&other) noexcept=default
void load(const xdoc::SNode &input, bool nullLargeData=false) override
virtual void load(const sptk::FieldList &input, bool nullLargeData=false)
void clear() override
Definition: WSComplexType.h:103
virtual String toString(bool asJSON=true, bool formatted=false) const
String className() const override
Definition: WSComplexType.h:95
virtual bool isOptional() const
Definition: WSComplexType.h:165
virtual void unload(QueryParameterList &output) const
virtual void _clear()
Definition: WSComplexType.h:213
virtual void unload(const xdoc::SNode &output) const
void throwIfNull(const String &parentTypeName) const
bool isNull() const override
void exportTo(const xdoc::SNode &parent, const char *name=nullptr) const override
WSComplexType & operator=(const WSComplexType &other)=default
void exportable(bool flag)
Definition: WSComplexType.h:187
WSComplexType & operator=(WSComplexType &&other) noexcept=default
~WSComplexType() override=default
WSComplexType(const WSComplexType &other)=default
Definition: WSFieldIndex.h:38
void setElements(const Strings &fieldNames, std::initializer_list< WSType * > fieldList)
Definition: WSType.h:42
virtual void clear()=0

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