implemented decmatch (artf724241)
[deliverable/titan.core.git] / xsdconvert / SimpleType.hh
1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * >
10 * Balasko, Jeno
11 * Beres, Szabolcs
12 * Godar, Marton
13 * Raduly, Csaba
14 * Szabo, Bence Janos
15 *
16 ******************************************************************************/
17 #ifndef SIMPLETYPE_H_
18 #define SIMPLETYPE_H_
19
20 #include "RootType.hh"
21
22 class SimpleType;
23
24 class LengthType {
25 LengthType & operator=(const LengthType &); // not implemented
26 // it's a bit strange that it has copy constructor but no assignment
27 public:
28 SimpleType * parent; // no responsibility for this member
29 bool modified;
30 unsigned long long int facet_minLength;
31 unsigned long long int facet_maxLength;
32 unsigned long long int lower;
33 unsigned long long int upper;
34
35 LengthType(SimpleType * p_parent);
36 // Default copy constructor and destructor are used
37
38 void applyReference(const LengthType & other);
39 void applyFacets();
40 void printToFile(FILE * file) const;
41 };
42
43 class PatternType {
44 PatternType & operator=(const PatternType &); // not implemented
45 // it's a bit strange that it has copy constructor but no assignment
46 public:
47 SimpleType * parent; // no responsibility for this member
48 bool modified;
49 Mstring facet;
50 Mstring value;
51
52 PatternType(SimpleType * p_parent);
53 // Default copy constructor and destructor are used
54
55 void applyReference(const PatternType & other);
56 void applyFacet();
57 void printToFile(FILE * file) const;
58 };
59
60 class EnumerationType {
61 EnumerationType & operator=(const EnumerationType &); // not implemented
62 // it's a bit strange that it has copy constructor but no assignment
63 public:
64 SimpleType * parent; // no responsibility for this member
65 bool modified;
66 List<Mstring> facets;
67 List<QualifiedName> items_string;
68 List<int> items_int;
69 List<double> items_float;
70 List<QualifiedName> items_time;
71 List<Mstring> items_misc;
72 List<Mstring> variants;
73
74 EnumerationType(SimpleType * p_parent);
75 // Default copy constructor and destructor are used
76
77 void applyReference(const EnumerationType & other);
78 void applyFacets();
79 void sortFacets();
80 void printToFile(FILE * file, unsigned int indent_level = 0) const;
81 void insertVariants();
82 };
83
84 class WhitespaceType {
85 WhitespaceType & operator=(const WhitespaceType &); // not implemented
86 // it's a bit strange that it has copy constructor but no assignment
87 public:
88 SimpleType * p_parent; // no responsibility for this member
89 bool modified;
90 Mstring facet;
91 Mstring value;
92
93 WhitespaceType(SimpleType * p_parent);
94 // Default copy constructor and destructor are used
95
96 void applyReference(const WhitespaceType & other);
97 void applyFacet();
98 void printToFile(FILE * file) const;
99 };
100
101 class ValueType {
102 ValueType & operator=(const ValueType &); // not implemented
103 // it's a bit strange that it has copy constructor but no assignment
104 public:
105 SimpleType * parent; // no responsibility for this member
106 bool modified;
107 long double facet_minInclusive;
108 long double facet_maxInclusive;
109 long double facet_minExclusive;
110 long double facet_maxExclusive;
111 int facet_totalDigits;
112 long double lower;
113 long double upper;
114 bool lowerExclusive;
115 bool upperExclusive;
116 bool not_a_number;
117 Mstring fixed_value;
118 Mstring default_value;
119 List<Mstring> items_with_value;
120
121 ValueType(SimpleType * p_parent);
122 // Default copy constructor and destructor are used
123
124 void applyReference(const ValueType & other);
125 void applyFacets();
126 void printToFile(FILE * file) const;
127 };
128
129 class ComplexType;
130
131 class ReferenceData {
132 public: // interface
133
134 ReferenceData()
135 : nst(0)
136 , uri()
137 , value()
138 , resolved(false)
139 , ref(NULL) {
140 }
141
142 void load(const Mstring& u, const Mstring& v, NamespaceType *n) {
143 uri = u;
144 value = v;
145 nst = n;
146 }
147
148 const Mstring& get_uri() const {
149 return uri;
150 }
151
152 const Mstring& get_val() const {
153 return value;
154 }
155
156 RootType *get_ref() const {
157 return ref;
158 }
159
160 bool empty() const {
161 return uri.empty() && value.empty();
162 }
163
164 bool is_resolved() const {
165 return resolved;
166 }
167
168 void set_resolved(RootType *st /*= NULL*/) {
169 resolved = true;
170 ref = st;
171 }
172
173 Mstring repr() const {
174 return uri + Mstring("|") + value;
175 }
176 private: // implementation
177 NamespaceType *nst;
178 Mstring uri;
179 Mstring value;
180 bool resolved;
181 RootType *ref; // not owned
182 };
183
184 /**
185 * Type that contains information coming from XSD simpleTypes, elements and attributes
186 *
187 * Source in XSD:
188 *
189 * * <simpleType>, <element> and <attribute> element whose parent element is <schema>
190 *
191 * Result in TTCN-3:
192 *
193 * * TTCN-3 type
194 *
195 */
196 class SimpleType : public RootType {
197 public:
198
199 enum Mode {
200 noMode,
201 restrictionMode,
202 extensionMode,
203 listMode,
204 restrictionAfterListMode
205 };
206
207 protected:
208 Mstring builtInBase;
209
210 LengthType length;
211 PatternType pattern;
212 EnumerationType enumeration;
213 WhitespaceType whitespace;
214 ValueType value;
215
216 FormValue element_form_as;
217 FormValue attribute_form_as;
218
219 Mode mode;
220
221 ReferenceData outside_reference;
222
223 /// true if name_dependency would be set (not empty)
224 bool in_name_only;
225
226 // True if element or attribute used with ref attribute
227 bool fromRef;
228 // XSD Type of the type
229 TagName xsdtype;
230 bool isOptional;
231 Mstring substitutionGroup;
232 //Pointer to the generated element substitution group
233 ComplexType * subsGroup;
234 //Pointer to the generated type substitution group
235 ComplexType * typeSubsGroup;
236 //To determine if already added to type substitution
237 bool addedToTypeSubstitution;
238 BlockValue block;
239
240 //Special use: true if an element of a complexType is restricted to a list
241 // in a simpleType, or a simpleType is a restriction of a list, which is a
242 // restriction of a simpleType
243 bool inList;
244 // We are inside a list if inList is true and mode == listMode
245
246 //Element substitution
247 void addToSubstitutions();
248
249 //Type substitution
250 void addToTypeSubstitutions();
251 //Returns the type substitution which the builtInType belongs
252 ComplexType * findBuiltInTypeInStoredTypeSubstitutions(const Mstring& builtInType);
253
254 //Only used when type substitution is enabled
255 //If an element reference is found then it is put to a container
256 //to know if type substitution is possible
257 void collectElementTypes(SimpleType * found_ST = NULL, ComplexType * found_CT = NULL);
258 void nameConversion_names();
259 virtual void nameConversion_types(const List<NamespaceType> & ns);
260
261 SimpleType & operator=(const SimpleType &); // not implemented
262 // it's a bit strange that it has copy constructor but no assignment
263 public:
264 SimpleType(XMLParser * a_parser, TTCN3Module * a_module, ConstructType a_construct);
265 SimpleType(const SimpleType& other);
266 // Default destructor is used
267
268 // Parent of the element (both complexType, and AttributeType) has this
269 // Not responsible for this member
270 ComplexType * parent;
271
272 /** Virtual methods
273 * inherited from RootType
274 */
275 void loadWithValues();
276 void printToFile(FILE * file);
277 void referenceResolving();
278 void nameConversion(const NameConversionMode mode, const List<NamespaceType> & ns);
279 void finalModification();
280 virtual bool hasUnresolvedReference();
281 void dump(const unsigned int depth) const;
282
283 void applyDefaultAttribute(const Mstring& default_value);
284 void applyFixedAttribute(const Mstring& fixed_value);
285 void applyNillableAttribute(const bool nillable_value);
286 void applyAbstractAttribute(const bool abstract_value);
287 void applySubstitionGroupAttribute(const Mstring& substition_group);
288 void applyBlockAttribute(const BlockValue block_);
289 void applyRefAttribute(const Mstring& ref_value);
290
291 const Mstring & getBuiltInBase() const {
292 return builtInBase;
293 }
294
295 const LengthType & getLength() const {
296 return length;
297 }
298
299 const ValueType & getValue() const {
300 return value;
301 }
302
303 const PatternType & getPattern() const {
304 return pattern;
305 }
306
307 const WhitespaceType & getWhitespace() const {
308 return whitespace;
309 }
310
311 const EnumerationType & getEnumeration() const {
312 return enumeration;
313 }
314
315 FormValue getElementFormAs() const {
316 return element_form_as;
317 }
318
319 FormValue getAttributeFormAs() const {
320 return attribute_form_as;
321 }
322
323 Mode getMode() const {
324 return mode;
325 }
326
327 bool isFromRef() const {
328 return fromRef;
329 }
330
331 const ReferenceData& getReference() const {
332 return outside_reference;
333 }
334
335 EnumerationType & getEnumeration() {
336 return enumeration;
337 }
338
339 void setBuiltInBase(const Mstring& base) {
340 builtInBase = base;
341 }
342
343 void setMode(Mode m) {
344 mode = m;
345 }
346
347 void setElementFormAs(FormValue f) {
348 element_form_as = f;
349 }
350
351 void setAttributeFormAs(FormValue f) {
352 attribute_form_as = f;
353 }
354
355 void setReference(const Mstring& ref, bool only_name_dependency = false);
356
357 void referenceForST(SimpleType * found_ST);
358 void referenceForCT(ComplexType * found_CT);
359
360 void setXsdtype(TagName xsdtype_) {
361 xsdtype = xsdtype_;
362 }
363
364 TagName getXsdtype() const {
365 return xsdtype;
366 }
367
368 ComplexType * getSubstitution() const {
369 return subsGroup;
370 }
371
372 ComplexType * getTypeSubstitution() const {
373 return typeSubsGroup;
374 }
375
376 BlockValue getBlock() const {
377 return block;
378 }
379
380 void setList(const bool value) {
381 inList = value;
382 }
383
384 void addToNameDepList(SimpleType * t) {
385 //If the type has a substitution, we add the namedep to the substitution
386 if(subsGroup != NULL && this != (SimpleType*)subsGroup){
387 SimpleType * substitution = (SimpleType*)subsGroup;
388 substitution->addToNameDepList(t);
389 }else if(typeSubsGroup != NULL && this != (SimpleType*)typeSubsGroup){
390 SimpleType * substitution = (SimpleType*)typeSubsGroup;
391 substitution->addToNameDepList(t);
392 }else {
393 nameDepList.push_back(t);
394 }
395 }
396
397 };
398
399 #endif /* SIMPLETYPE_H_ */
400
This page took 0.037844 seconds and 5 git commands to generate.