sptk2 logo
SPTK Home Page
WSParserComplexType.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 "WSRestriction.h"
30#include <iostream>
31#include <list>
32#include <set>
33#include <sptk5/wsdl/WSBasicTypes.h>
34#include <sptk5/xdoc/Document.h>
35
36namespace sptk {
37
46enum class WSMultiplicity : uint8_t
47{
48 REQUIRED = 1,
49 ZERO_OR_ONE = 2,
50 ZERO_OR_MORE = 4,
51 ONE_OR_MORE = 8
52};
53
57class SP_EXPORT WSParserAttribute
58{
59public:
65 explicit WSParserAttribute(const String& name = "", const String& typeName = "");
66
71 WSParserAttribute(const WSParserAttribute& attr) = default;
72
76 String name() const
77 {
78 return m_name;
79 }
80
84 String generate(bool initialize) const;
85
90 {
91 return m_cxxTypeName;
92 }
93
98 {
99 return m_wsTypeName;
100 }
101
102private:
103 String m_name;
104 String m_wsTypeName;
105 String m_cxxTypeName;
106};
107
108class WSParserComplexType;
109
110using SWSParserAttribute = std::shared_ptr<WSParserAttribute>;
111using SWSParserComplexType = std::shared_ptr<WSParserComplexType>;
112using WSParserComplexTypeList = std::list<SWSParserComplexType>;
113
117class SP_EXPORT WSParserComplexType
118{
119public:
123 static String wsClassName(const String& className);
124
131 explicit WSParserComplexType(const xdoc::SNode& complexTypeElement, const String& name = "",
132 const String& typeName = "");
133
137 virtual ~WSParserComplexType() = default;
138
142 String name() const
143 {
144 return m_name;
145 }
146
151
156 {
157 return m_multiplicity;
158 }
159
163 bool isArray() const
164 {
165 return ((int) m_multiplicity & ((int) WSMultiplicity::ZERO_OR_MORE | (int) WSMultiplicity::ONE_OR_MORE)) != 0;
166 }
167
172 WSParserComplexTypeList sequence() const
173 {
174 return m_sequence;
175 }
176
181 SWSRestriction restriction() const
182 {
183 return m_restriction;
184 }
185
189 virtual void parse();
190
194 void parseSequence(const xdoc::SNode& sequence);
195
199 void generate(std::ostream& classDeclaration, std::ostream& classImplementation,
200 const String& externalHeader, const String& serviceNamespace) const;
201
202 static std::map<String, xdoc::SNode> SimpleTypeElements;
203
204 static xdoc::SNode findSimpleType(const String& typeName);
205
206protected:
211 void generateDefinition(std::ostream& classDeclaration, sptk::Strings& fieldNames,
212 sptk::Strings& elementNames, sptk::Strings& attributeNames,
213 const String& serviceNamespace) const;
214
219 void generateImplementation(std::ostream& classImplementation, const Strings& fieldNames,
220 const Strings& elementNames, const Strings& attributeNames,
221 const String& serviceNamespace) const;
222
223private:
224 class Initializer
225 {
226 public:
227 Strings ctor {"WSComplexType(elementName, optional)"};
228 Strings copyCtor {"WSComplexType(other)"};
229 Strings moveCtor {"WSComplexType(std::move(other))"};
230 Strings copyAssign;
231 Strings moveAssign;
232 };
233
234 class ImplementationParts
235 {
236 public:
237 std::stringstream declarations;
238 std::stringstream body;
239 std::stringstream checks;
240
241 size_t restrictionNumber {0};
242
243 void print(std::ostream& output) const;
244 };
245
249 using AttributeMap = std::map<std::string, SWSParserAttribute, std::less<>>;
250
251 String m_name;
252 String m_typeName;
253 xdoc::SNode m_element;
254 AttributeMap m_attributes;
255 WSParserComplexTypeList m_sequence;
256 WSMultiplicity m_multiplicity;
257 SWSRestriction m_restriction;
258 String m_documentation;
259
265 static void printImplementationIncludes(std::ostream& classImplementation, const String& className);
266
267 void printImplementationRestrictions(std::ostream& classImplementation, std::ostream& checks) const;
268
269 static void printDeclarationIncludes(std::ostream& classDeclaration, const std::set<String>& usedClasses);
270
271 std::set<String> getUsedClasses() const;
272
273 static void appendMemberDocumentation(std::ostream& classDeclaration, const SWSParserComplexType& complexType);
274
275 void appendClassAttributes(std::ostream& classDeclaration, Strings& fieldNames,
276 Initializer& initializer) const;
277
278 String addOptionalRestriction(std::ostream& implementation, const SWSParserComplexType& complexType,
279 size_t& restrictionIndex) const;
280
281 static String makeTagName(const String& className);
282
283 Initializer makeInitializer() const;
284
285 void printImplementationConstructors(std::ostream& classImplementation, const String& className,
286 const Strings& elementNames, const Strings& attributeNames) const;
287
288 void printImplementationCheckRestrictions(std::ostream& classImplementation, const String& className) const;
289
290 static void generateSetFieldIndex(std::ostream& classDeclaration, const Strings& elementNames,
291 const Strings& attributeNames);
292};
293
298
302using WSComplexTypeMap = std::map<String, SWSParserComplexType>;
303
307} // namespace sptk
Definition: String.h:49
Definition: Strings.h:52
Definition: WSParserComplexType.h:58
String name() const
Definition: WSParserComplexType.h:76
String generate(bool initialize) const
String cxxTypeName() const
Definition: WSParserComplexType.h:89
String wsTypeName() const
Definition: WSParserComplexType.h:97
WSParserAttribute(const String &name="", const String &typeName="")
WSParserAttribute(const WSParserAttribute &attr)=default
Definition: WSParserComplexType.h:118
String name() const
Definition: WSParserComplexType.h:142
WSMultiplicity multiplicity() const
Definition: WSParserComplexType.h:155
String className() const
void generateImplementation(std::ostream &classImplementation, const Strings &fieldNames, const Strings &elementNames, const Strings &attributeNames, const String &serviceNamespace) const
WSParserComplexTypeList sequence() const
Definition: WSParserComplexType.h:172
SWSRestriction restriction() const
Definition: WSParserComplexType.h:181
void generate(std::ostream &classDeclaration, std::ostream &classImplementation, const String &externalHeader, const String &serviceNamespace) const
void generateDefinition(std::ostream &classDeclaration, sptk::Strings &fieldNames, sptk::Strings &elementNames, sptk::Strings &attributeNames, const String &serviceNamespace) const
static String wsClassName(const String &className)
bool isArray() const
Definition: WSParserComplexType.h:163
virtual ~WSParserComplexType()=default
void parseSequence(const xdoc::SNode &sequence)
WSParserComplexType(const xdoc::SNode &complexTypeElement, const String &name="", const String &typeName="")
std::map< String, SWSParserComplexType > WSComplexTypeMap
Definition: WSParserComplexType.h:302
WSMultiplicity
Definition: WSParserComplexType.h:47
@ ZERO_OR_ONE
Element is optional.
@ ZERO_OR_MORE
Element may occur 0 or more times.
@ REQUIRED
Element is required.
@ ONE_OR_MORE
Element may occur one or more times.

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