Sync with 5.4.0
[deliverable/titan.core.git] / xsdconvert / SimpleType.hh
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2015 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 #ifndef SIMPLETYPE_H_
9 #define SIMPLETYPE_H_
10
11 #include "RootType.hh"
12
13 class SimpleType;
14
15 class LengthType {
16 LengthType & operator=(const LengthType &); // not implemented
17 // it's a bit strange that it has copy constructor but no assignment
18 public:
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
26 LengthType(SimpleType * p_parent);
27 // Default copy constructor and destructor are used
28
29 void applyReference(const LengthType & other);
30 void applyFacets();
31 void printToFile(FILE * file) const;
32 };
33
34 class PatternType {
35 PatternType & operator=(const PatternType &); // not implemented
36 // it's a bit strange that it has copy constructor but no assignment
37 public:
38 SimpleType * parent; // no responsibility for this member
39 bool modified;
40 Mstring facet;
41 Mstring value;
42
43 PatternType(SimpleType * p_parent);
44 // Default copy constructor and destructor are used
45
46 void applyReference(const PatternType & other);
47 void applyFacet();
48 void printToFile(FILE * file) const;
49 };
50
51 class EnumerationType {
52 EnumerationType & operator=(const EnumerationType &); // not implemented
53 // it's a bit strange that it has copy constructor but no assignment
54 public:
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;
63 List<Mstring> variants;
64
65 EnumerationType(SimpleType * p_parent);
66 // Default copy constructor and destructor are used
67
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();
73 };
74
75 class WhitespaceType {
76 WhitespaceType & operator=(const WhitespaceType &); // not implemented
77 // it's a bit strange that it has copy constructor but no assignment
78 public:
79 SimpleType * p_parent; // no responsibility for this member
80 bool modified;
81 Mstring facet;
82 Mstring value;
83
84 WhitespaceType(SimpleType * p_parent);
85 // Default copy constructor and destructor are used
86
87 void applyReference(const WhitespaceType & other);
88 void applyFacet();
89 void printToFile(FILE * file) const;
90 };
91
92 class ValueType {
93 ValueType & operator=(const ValueType &); // not implemented
94 // it's a bit strange that it has copy constructor but no assignment
95 public:
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;
107 bool not_a_number;
108 Mstring fixed_value;
109 Mstring default_value;
110 List<Mstring> items_with_value;
111
112 ValueType(SimpleType * p_parent);
113 // Default copy constructor and destructor are used
114
115 void applyReference(const ValueType & other);
116 void applyFacets();
117 void printToFile(FILE * file) const;
118 };
119
120 class ComplexType;
121
122 class ReferenceData {
123 public: // interface
124
125 ReferenceData()
126 : nst(0)
127 , uri()
128 , value()
129 , resolved(false)
130 , ref(NULL) {
131 }
132
133 void load(const Mstring& u, const Mstring& v, NamespaceType *n) {
134 uri = u;
135 value = v;
136 nst = n;
137 }
138
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 }
150
151 bool empty() const {
152 return uri.empty() && value.empty();
153 }
154
155 bool is_resolved() const {
156 return resolved;
157 }
158
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 }
167 private: // implementation
168 NamespaceType *nst;
169 Mstring uri;
170 Mstring value;
171 bool resolved;
172 RootType *ref; // not owned
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 */
187 class SimpleType : public RootType {
188 public:
189
190 enum Mode {
191 noMode,
192 restrictionMode,
193 extensionMode,
194 listMode
195 };
196
197 protected:
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
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;
221 Mstring substitionGroup;
222 ComplexType * subsGroup;
223 BlockValue block;
224
225
226 void addToSubstitutions();
227 void nameConversion_names();
228 virtual void nameConversion_types(const List<NamespaceType> & ns);
229
230 SimpleType & operator=(const SimpleType &); // not implemented
231 // it's a bit strange that it has copy constructor but no assignment
232 public:
233 SimpleType(XMLParser * a_parser, TTCN3Module * a_module, ConstructType a_construct);
234 SimpleType(const SimpleType& other);
235 // Default destructor is used
236
237 // Parent of the element (both complexType, and AttributeType) has this
238 // Not responsible for this member
239 ComplexType * parent;
240
241 /** Virtual methods
242 * inherited from RootType
243 */
244 void loadWithValues();
245 void printToFile(FILE * file);
246 void referenceResolving();
247 void nameConversion(const NameConversionMode mode, const List<NamespaceType> & ns);
248 void finalModification();
249 virtual bool hasUnresolvedReference();
250 void dump(const unsigned int depth) const;
251
252 void applyDefaultAttribute(const Mstring& default_value);
253 void applyFixedAttribute(const Mstring& fixed_value);
254 void applyNillableAttribute(const bool nillable_value);
255 void applyAbstractAttribute(const bool abstract_value);
256 void applySubstitionGroupAttribute(const Mstring& substition_group);
257 void applyBlockAttribute(const BlockValue block_);
258 void applyRefAttribute(const Mstring& ref_value);
259
260 const Mstring & getBuiltInBase() const {
261 return builtInBase;
262 }
263
264 const LengthType & getLength() const {
265 return length;
266 }
267
268 const ValueType & getValue() const {
269 return value;
270 }
271
272 const PatternType & getPattern() const {
273 return pattern;
274 }
275
276 const WhitespaceType & getWhitespace() const {
277 return whitespace;
278 }
279
280 const EnumerationType & getEnumeration() const {
281 return enumeration;
282 }
283
284 FormValue getElementFormAs() const {
285 return element_form_as;
286 }
287
288 FormValue getAttributeFormAs() const {
289 return attribute_form_as;
290 }
291
292 Mode getMode() const {
293 return mode;
294 }
295
296 bool isFromRef() const {
297 return fromRef;
298 }
299
300 const ReferenceData& getReference() const {
301 return outside_reference;
302 }
303
304 EnumerationType & getEnumeration() {
305 return enumeration;
306 }
307
308 void setBuiltInBase(const Mstring& base) {
309 builtInBase = base;
310 }
311
312 void setMode(Mode m) {
313 mode = m;
314 }
315
316 void setElementFormAs(FormValue f) {
317 element_form_as = f;
318 }
319
320 void setAttributeFormAs(FormValue f) {
321 attribute_form_as = f;
322 }
323
324 void setReference(const Mstring& ref, bool only_name_dependency = false);
325
326 void referenceForST(SimpleType * found_ST);
327 void referenceForCT(ComplexType * found_CT);
328
329 void setXsdtype(TagName xsdtype_) {
330 xsdtype = xsdtype_;
331 }
332
333 TagName getXsdtype() const {
334 return xsdtype;
335 }
336
337 ComplexType * getSubstitution() const {
338 return subsGroup;
339 }
340
341 BlockValue getBlock() const {
342 return block;
343 }
344
345 void addToNameDepList(SimpleType * t) {
346 if(subsGroup != NULL && this != (SimpleType*)subsGroup){
347 SimpleType * substitution = (SimpleType*)subsGroup;
348 substitution->addToNameDepList(t);
349 }else {
350 nameDepList.push_back(t);
351 }
352 }
353
354 };
355
356 #endif /* SIMPLETYPE_H_ */
This page took 0.037706 seconds and 6 git commands to generate.