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