Merge pull request #77 from balaskoa/master
[deliverable/titan.core.git] / xsdconvert / RootType.hh
CommitLineData
d44e3c4f 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 ******************************************************************************/
970ed795
EL
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
36extern bool c_flag_used;
37extern bool e_flag_used;
38
3abe9331 39enum VariantMode {
40 V_abstract,
970ed795
EL
41 V_anyAttributes,
42 V_anyElement,
43 V_attribute,
44 V_attributeFormQualified,
45 V_attributeGroup,
3abe9331 46 V_block,
970ed795
EL
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,
3abe9331 57 V_onlyValueHidden,
970ed795
EL
58 V_untagged,
59 V_useNil,
60 V_useNumber,
61 V_useOrder,
51fa56b9 62 V_useType,
970ed795 63 V_useUnion,
3abe9331 64 V_whiteSpace,
65 V_fractionDigits
970ed795
EL
66};
67
3abe9331 68enum OriginType {
970ed795
EL
69 from_simpleType,
70 from_element,
71 from_attribute,
72 from_complexType,
73 from_group,
74 from_attributeGroup,
75 from_unknown
76};
77
3abe9331 78class NameType {
970ed795
EL
79public:
80 Mstring originalValueWoPrefix;
81 Mstring convertedValue;
82 bool list_extension;
3abe9331 83 bool no_replace;
970ed795 84
3abe9331 85 NameType() : originalValueWoPrefix(), convertedValue(), list_extension(false), no_replace(false) {
86 }
970ed795
EL
87 // Default copy constructor, assignment operator and destructor are used
88
3abe9331 89 void upload(const Mstring& input) {
970ed795
EL
90 if (input.empty()) return;
91 convertedValue = input;
92 originalValueWoPrefix = input.getValueWithoutPrefix(':');
93 }
94};
95
96class SimpleType;
97class XMLParser;
98class 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
3abe9331 108class RootType {
970ed795 109protected:
3abe9331 110 XMLParser * parser; // no responsibility for this member
111 TTCN3Module * module; // no responsibility for this member
970ed795
EL
112
113 NameType name;
114 NameType type;
970ed795
EL
115 unsigned long long int minOccurs;
116 unsigned long long int maxOccurs;
117 List<Mstring> variant;
118 List<Mstring> variant_ref;
3abe9331 119 List<Mstring> hidden_variant;
120 List<Mstring> comment;
970ed795
EL
121
122 ConstructType construct;
123 OriginType origin;
124 bool visible;
3abe9331 125
970ed795
EL
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
130public:
3abe9331 131 RootType(XMLParser * a_parser, TTCN3Module * a_module, const ConstructType a_construct);
132
133 virtual ~RootType() {
134 }
970ed795
EL
135 // Default copy constructor and assignment operator is used
136
3abe9331 137 virtual void loadWithValues() = 0;
138 virtual void printToFile(FILE * file) = 0;
970ed795 139
3abe9331 140 virtual void modifyValues() {
141 }
970ed795 142
3abe9331 143 virtual void referenceResolving() {
144 }
970ed795 145
3abe9331 146 virtual void nameConversion(const NameConversionMode, const List<NamespaceType> &) {
147 }
148
149 virtual void finalModification() {
150 }
970ed795 151
3abe9331 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
51fa56b9 175 void setVisible() {
176 visible = true;
177 }
178
3abe9331 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
51fa56b9 223 List<SimpleType*> & getNameDepList() {
224 return nameDepList;
225 }
226
3abe9331 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 }
970ed795 238
3abe9331 239 bool hasVariant(const Mstring& var) const;
970ed795 240
3abe9331 241 void addVariant(const VariantMode var, const Mstring& var_value = empty_string, const bool into_variant_ref = false);
242 virtual void printVariant(FILE * file);
970ed795 243
3abe9331 244 virtual void addComment(const Mstring& text);
245 virtual void printComment(FILE * file, int level = 0);
970ed795 246
3abe9331 247 void printMinOccursMaxOccurs(FILE * file, const bool inside_union,
248 const bool empty_allowed = true) const;
970ed795 249
3abe9331 250 friend bool compareTypes(RootType * lhs, RootType * rhs);
970ed795
EL
251};
252
3abe9331 253inline bool compareTypes(RootType * lhs, RootType * rhs) {
970ed795
EL
254 return lhs->name.originalValueWoPrefix < rhs->name.originalValueWoPrefix;
255}
256
257#endif /* BASETYPE_HH_ */
This page took 0.034402 seconds and 5 git commands to generate.