Commit | Line | Data |
---|---|---|
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 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 | ||
3abe9331 | 33 | enum VariantMode { |
34 | V_abstract, | |
970ed795 EL |
35 | V_anyAttributes, |
36 | V_anyElement, | |
37 | V_attribute, | |
38 | V_attributeFormQualified, | |
39 | V_attributeGroup, | |
3abe9331 | 40 | V_block, |
970ed795 EL |
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, | |
3abe9331 | 51 | V_onlyValueHidden, |
970ed795 EL |
52 | V_untagged, |
53 | V_useNil, | |
54 | V_useNumber, | |
55 | V_useOrder, | |
56 | V_useUnion, | |
3abe9331 | 57 | V_whiteSpace, |
58 | V_fractionDigits | |
970ed795 EL |
59 | }; |
60 | ||
3abe9331 | 61 | enum OriginType { |
970ed795 EL |
62 | from_simpleType, |
63 | from_element, | |
64 | from_attribute, | |
65 | from_complexType, | |
66 | from_group, | |
67 | from_attributeGroup, | |
68 | from_unknown | |
69 | }; | |
70 | ||
3abe9331 | 71 | class NameType { |
970ed795 EL |
72 | public: |
73 | Mstring originalValueWoPrefix; | |
74 | Mstring convertedValue; | |
75 | bool list_extension; | |
3abe9331 | 76 | bool no_replace; |
970ed795 | 77 | |
3abe9331 | 78 | NameType() : originalValueWoPrefix(), convertedValue(), list_extension(false), no_replace(false) { |
79 | } | |
970ed795 EL |
80 | // Default copy constructor, assignment operator and destructor are used |
81 | ||
3abe9331 | 82 | void upload(const Mstring& input) { |
970ed795 EL |
83 | if (input.empty()) return; |
84 | convertedValue = input; | |
85 | originalValueWoPrefix = input.getValueWithoutPrefix(':'); | |
86 | } | |
87 | }; | |
88 | ||
89 | class SimpleType; | |
90 | class XMLParser; | |
91 | class TTCN3Module; | |
92 | ||
93 | /** | |
94 | * This type is used as the base class for the used classes | |
95 | * that represent the main datatypes in the generated TTCN-3 modules | |
96 | * | |
97 | * It is installed to have possibility to store main types in one container | |
98 | * | |
99 | */ | |
100 | ||
3abe9331 | 101 | class RootType { |
970ed795 | 102 | protected: |
3abe9331 | 103 | XMLParser * parser; // no responsibility for this member |
104 | TTCN3Module * module; // no responsibility for this member | |
970ed795 EL |
105 | |
106 | NameType name; | |
107 | NameType type; | |
970ed795 EL |
108 | unsigned long long int minOccurs; |
109 | unsigned long long int maxOccurs; | |
110 | List<Mstring> variant; | |
111 | List<Mstring> variant_ref; | |
3abe9331 | 112 | List<Mstring> hidden_variant; |
113 | List<Mstring> comment; | |
970ed795 EL |
114 | |
115 | ConstructType construct; | |
116 | OriginType origin; | |
117 | bool visible; | |
3abe9331 | 118 | |
970ed795 EL |
119 | /// List of types that depend on this one. |
120 | /// Used to propagate the effect of name conversion to the dependents | |
121 | List<SimpleType*> nameDepList; // no responsibility for elements | |
122 | ||
123 | public: | |
3abe9331 | 124 | RootType(XMLParser * a_parser, TTCN3Module * a_module, const ConstructType a_construct); |
125 | ||
126 | virtual ~RootType() { | |
127 | } | |
970ed795 EL |
128 | // Default copy constructor and assignment operator is used |
129 | ||
3abe9331 | 130 | virtual void loadWithValues() = 0; |
131 | virtual void printToFile(FILE * file) = 0; | |
970ed795 | 132 | |
3abe9331 | 133 | virtual void modifyValues() { |
134 | } | |
970ed795 | 135 | |
3abe9331 | 136 | virtual void referenceResolving() { |
137 | } | |
970ed795 | 138 | |
3abe9331 | 139 | virtual void nameConversion(const NameConversionMode, const List<NamespaceType> &) { |
140 | } | |
141 | ||
142 | virtual void finalModification() { | |
143 | } | |
970ed795 | 144 | |
3abe9331 | 145 | virtual bool hasUnresolvedReference() { |
146 | return false; | |
147 | } | |
148 | ||
149 | virtual void dump(const unsigned int) const { | |
150 | } | |
151 | ||
152 | void setNameValue(const Mstring& str) { | |
153 | name.convertedValue = str; | |
154 | } | |
155 | ||
156 | void setTypeValue(const Mstring& str) { | |
157 | type.convertedValue = str; | |
158 | } | |
159 | ||
160 | void useNameListProperty() { | |
161 | name.convertedValue += "_list"; | |
162 | } | |
163 | ||
164 | void setInvisible() { | |
165 | visible = false; | |
166 | } | |
167 | ||
168 | const NameType & getName() const { | |
169 | return name; | |
170 | } | |
171 | ||
172 | const NameType & getType() const { | |
173 | return type; | |
174 | } | |
175 | ||
176 | unsigned long long int getMinOccurs() const { | |
177 | return minOccurs; | |
178 | } | |
179 | ||
180 | unsigned long long int getMaxOccurs() const { | |
181 | return maxOccurs; | |
182 | } | |
183 | ||
184 | const List<Mstring> & getVariant() const { | |
185 | return variant; | |
186 | } | |
187 | ||
188 | const List<Mstring> & getVariantRef() const { | |
189 | return variant_ref; | |
190 | } | |
191 | ||
192 | const List<Mstring> & getHiddenVariant() const { | |
193 | return hidden_variant; | |
194 | } | |
195 | ||
196 | ConstructType getConstruct() const { | |
197 | return construct; | |
198 | } | |
199 | ||
200 | OriginType getOrigin() const { | |
201 | return origin; | |
202 | } | |
203 | ||
204 | bool isVisible() const { | |
205 | return visible; | |
206 | } | |
207 | ||
208 | List<Mstring> & getComment() { | |
209 | return comment; | |
210 | } | |
211 | ||
212 | XMLParser * getParser() const { | |
213 | return parser; | |
214 | } | |
215 | ||
216 | TTCN3Module * getModule() const { | |
217 | return module; | |
218 | } | |
219 | ||
220 | void setModule(TTCN3Module * mod) { | |
221 | module = mod; | |
222 | } | |
970ed795 | 223 | |
3abe9331 | 224 | bool hasVariant(const Mstring& var) const; |
970ed795 | 225 | |
3abe9331 | 226 | void addVariant(const VariantMode var, const Mstring& var_value = empty_string, const bool into_variant_ref = false); |
227 | virtual void printVariant(FILE * file); | |
970ed795 | 228 | |
3abe9331 | 229 | virtual void addComment(const Mstring& text); |
230 | virtual void printComment(FILE * file, int level = 0); | |
970ed795 | 231 | |
3abe9331 | 232 | void printMinOccursMaxOccurs(FILE * file, const bool inside_union, |
233 | const bool empty_allowed = true) const; | |
970ed795 | 234 | |
3abe9331 | 235 | friend bool compareTypes(RootType * lhs, RootType * rhs); |
970ed795 EL |
236 | }; |
237 | ||
3abe9331 | 238 | inline bool compareTypes(RootType * lhs, RootType * rhs) { |
970ed795 EL |
239 | return lhs->name.originalValueWoPrefix < rhs->name.originalValueWoPrefix; |
240 | } | |
241 | ||
242 | #endif /* BASETYPE_HH_ */ |