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