1926b5f894d0d4a15b3f6f2851aa52a8c3f8be0d
[deliverable/titan.core.git] / xsdconvert / RootType.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 * Balasko, Jeno
10 * Raduly, Csaba
11 * Szabo, Bence Janos
12 *
13 ******************************************************************************/
14 #ifndef BASETYPE_HH_
15 #define BASETYPE_HH_
16
17 #include "GeneralTypes.hh"
18 #include "Mstring.hh"
19 #include "List.hh"
20
21 #include <cmath> // for using "pow" function
22 #include <cfloat>
23 #include <cctype>
24 #include <cerrno>
25 #include <climits>
26 #ifndef ULLONG_MAX
27 #define ULLONG_MAX 18446744073709551615ULL
28 #endif
29 #ifndef LLONG_MIN
30 #define LLONG_MIN -9223372036854775808LL
31 #endif
32 #ifndef LLONG_MAX
33 #define LLONG_MAX 9223372036854775807LL
34 #endif
35
36 extern bool c_flag_used;
37 extern bool e_flag_used;
38
39 enum VariantMode {
40 V_abstract,
41 V_anyAttributes,
42 V_anyElement,
43 V_attribute,
44 V_attributeFormQualified,
45 V_attributeGroup,
46 V_block,
47 V_controlNamespace,
48 V_defaultForEmpty,
49 V_element,
50 V_elementFormQualified,
51 V_embedValues,
52 V_formAs,
53 V_list,
54 V_nameAs,
55 V_namespaceAs,
56 V_onlyValue,
57 V_onlyValueHidden,
58 V_untagged,
59 V_useNil,
60 V_useNumber,
61 V_useOrder,
62 V_useType,
63 V_useUnion,
64 V_whiteSpace,
65 V_fractionDigits
66 };
67
68 enum OriginType {
69 from_simpleType,
70 from_element,
71 from_attribute,
72 from_complexType,
73 from_group,
74 from_attributeGroup,
75 from_unknown
76 };
77
78 class NameType {
79 public:
80 Mstring originalValueWoPrefix;
81 Mstring convertedValue;
82 bool list_extension;
83 bool no_replace;
84
85 NameType() : originalValueWoPrefix(), convertedValue(), list_extension(false), no_replace(false) {
86 }
87 // Default copy constructor, assignment operator and destructor are used
88
89 void upload(const Mstring& input) {
90 if (input.empty()) return;
91 convertedValue = input;
92 originalValueWoPrefix = input.getValueWithoutPrefix(':');
93 }
94 };
95
96 class SimpleType;
97 class XMLParser;
98 class TTCN3Module;
99
100 /**
101 * This type is used as the base class for the used classes
102 * that represent the main datatypes in the generated TTCN-3 modules
103 *
104 * It is installed to have possibility to store main types in one container
105 *
106 */
107
108 class RootType {
109 protected:
110 XMLParser * parser; // no responsibility for this member
111 TTCN3Module * module; // no responsibility for this member
112
113 NameType name;
114 NameType type;
115 unsigned long long int minOccurs;
116 unsigned long long int maxOccurs;
117 List<Mstring> variant;
118 List<Mstring> variant_ref;
119 List<Mstring> hidden_variant;
120 List<Mstring> comment;
121
122 ConstructType construct;
123 OriginType origin;
124 bool visible;
125
126 /// List of types that depend on this one.
127 /// Used to propagate the effect of name conversion to the dependents
128 List<SimpleType*> nameDepList; // no responsibility for elements
129
130 public:
131 RootType(XMLParser * a_parser, TTCN3Module * a_module, const ConstructType a_construct);
132
133 virtual ~RootType() {
134 }
135 // Default copy constructor and assignment operator is used
136
137 virtual void loadWithValues() = 0;
138 virtual void printToFile(FILE * file) = 0;
139
140 virtual void modifyValues() {
141 }
142
143 virtual void referenceResolving() {
144 }
145
146 virtual void nameConversion(const NameConversionMode, const List<NamespaceType> &) {
147 }
148
149 virtual void finalModification() {
150 }
151
152 virtual bool hasUnresolvedReference() {
153 return false;
154 }
155
156 virtual void dump(const unsigned int) const {
157 }
158
159 void setNameValue(const Mstring& str) {
160 name.convertedValue = str;
161 }
162
163 void setTypeValue(const Mstring& str) {
164 type.convertedValue = str;
165 }
166
167 void useNameListProperty() {
168 name.convertedValue += "_list";
169 }
170
171 void setInvisible() {
172 visible = false;
173 }
174
175 void setVisible() {
176 visible = true;
177 }
178
179 const NameType & getName() const {
180 return name;
181 }
182
183 const NameType & getType() const {
184 return type;
185 }
186
187 unsigned long long int getMinOccurs() const {
188 return minOccurs;
189 }
190
191 unsigned long long int getMaxOccurs() const {
192 return maxOccurs;
193 }
194
195 const List<Mstring> & getVariant() const {
196 return variant;
197 }
198
199 const List<Mstring> & getVariantRef() const {
200 return variant_ref;
201 }
202
203 const List<Mstring> & getHiddenVariant() const {
204 return hidden_variant;
205 }
206
207 ConstructType getConstruct() const {
208 return construct;
209 }
210
211 OriginType getOrigin() const {
212 return origin;
213 }
214
215 bool isVisible() const {
216 return visible;
217 }
218
219 List<Mstring> & getComment() {
220 return comment;
221 }
222
223 List<SimpleType*> & getNameDepList() {
224 return nameDepList;
225 }
226
227 XMLParser * getParser() const {
228 return parser;
229 }
230
231 TTCN3Module * getModule() const {
232 return module;
233 }
234
235 void setModule(TTCN3Module * mod) {
236 module = mod;
237 }
238
239 bool hasVariant(const Mstring& var) const;
240
241 void addVariant(const VariantMode var, const Mstring& var_value = empty_string, const bool into_variant_ref = false);
242 virtual void printVariant(FILE * file);
243
244 virtual void addComment(const Mstring& text);
245 virtual void printComment(FILE * file, int level = 0);
246
247 void printMinOccursMaxOccurs(FILE * file, const bool inside_union,
248 const bool empty_allowed = true) const;
249
250 friend bool compareTypes(RootType * lhs, RootType * rhs);
251 };
252
253 inline bool compareTypes(RootType * lhs, RootType * rhs) {
254 return lhs->name.originalValueWoPrefix < rhs->name.originalValueWoPrefix;
255 }
256
257 #endif /* BASETYPE_HH_ */
This page took 0.036289 seconds and 4 git commands to generate.