Commit | Line | Data |
---|---|---|
970ed795 EL |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (c) 2000-2014 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 | ||
34 | enum VariantMode | |
35 | { | |
36 | V_anyAttributes, | |
37 | V_anyElement, | |
38 | V_attribute, | |
39 | V_attributeFormQualified, | |
40 | V_attributeGroup, | |
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_untagged, | |
52 | V_useNil, | |
53 | V_useNumber, | |
54 | V_useOrder, | |
55 | V_useUnion, | |
56 | V_whiteSpace | |
57 | }; | |
58 | ||
59 | enum OriginType | |
60 | { | |
61 | from_simpleType, | |
62 | from_element, | |
63 | from_attribute, | |
64 | from_complexType, | |
65 | from_group, | |
66 | from_attributeGroup, | |
67 | from_unknown | |
68 | }; | |
69 | ||
70 | class NameType | |
71 | { | |
72 | public: | |
73 | Mstring originalValueWoPrefix; | |
74 | Mstring convertedValue; | |
75 | bool list_extension; | |
76 | ||
77 | NameType (): originalValueWoPrefix(), convertedValue(), list_extension(false) {} | |
78 | // Default copy constructor, assignment operator and destructor are used | |
79 | ||
80 | void upload (const Mstring& input) | |
81 | { | |
82 | if (input.empty()) return; | |
83 | convertedValue = input; | |
84 | originalValueWoPrefix = input.getValueWithoutPrefix(':'); | |
85 | } | |
86 | }; | |
87 | ||
88 | class SimpleType; | |
89 | class XMLParser; | |
90 | class TTCN3Module; | |
91 | ||
92 | /** | |
93 | * This type is used as the base class for the used classes | |
94 | * that represent the main datatypes in the generated TTCN-3 modules | |
95 | * | |
96 | * It is installed to have possibility to store main types in one container | |
97 | * | |
98 | */ | |
99 | ||
100 | class RootType | |
101 | { | |
102 | protected: | |
103 | XMLParser * parser; // no responsibility for this member | |
104 | TTCN3Module * module; // no responsibility for this member | |
105 | ||
106 | NameType name; | |
107 | NameType type; | |
108 | Mstring id; | |
109 | unsigned long long int minOccurs; | |
110 | unsigned long long int maxOccurs; | |
111 | List<Mstring> variant; | |
112 | List<Mstring> variant_ref; | |
113 | Mstring comment; | |
114 | ||
115 | ConstructType construct; | |
116 | OriginType origin; | |
117 | bool visible; | |
118 | /// List of types that depend on this one. | |
119 | /// Used to propagate the effect of name conversion to the dependents | |
120 | List<SimpleType*> nameDepList; // no responsibility for elements | |
121 | ||
122 | public: | |
123 | RootType(XMLParser * a_parser, TTCN3Module * a_module, ConstructType a_construct); | |
124 | virtual ~RootType () {} | |
125 | // Default copy constructor and assignment operator is used | |
126 | ||
127 | virtual void loadWithValues () = 0; | |
128 | virtual void printToFile (FILE * file) = 0; | |
129 | ||
130 | virtual void modifyValues () {} | |
131 | ||
132 | virtual void referenceResolving () {} | |
133 | virtual void nameConversion (NameConversionMode, const List<NamespaceType> &) {} | |
134 | virtual void finalModification () {} | |
135 | ||
136 | virtual bool hasUnresolvedReference () {return false;} | |
137 | virtual void dump (unsigned int) const {} | |
138 | ||
139 | void setNameValue (const Mstring& str) {name.convertedValue = str;} | |
140 | void setTypeValue (const Mstring& str) {type.convertedValue = str;} | |
141 | void useNameListProperty () {name.convertedValue += "_list";} | |
142 | void setInvisible () {visible = false;} | |
143 | void addToNameDepList (SimpleType * t) {nameDepList.push_back(t);} | |
144 | ||
145 | const NameType & getName () const {return name;} | |
146 | const NameType & getType () const {return type;} | |
147 | unsigned long long int getMinOccurs () const {return minOccurs;} | |
148 | unsigned long long int getMaxOccurs () const {return maxOccurs;} | |
149 | const List<Mstring> & getVariant () const {return variant;} | |
150 | const List<Mstring> & getVariantRef () const {return variant_ref;} | |
151 | ConstructType getConstruct () const {return construct;} | |
152 | OriginType getOrigin () const {return origin;} | |
153 | bool isVisible () const {return visible;} | |
154 | XMLParser * getParser () const {return parser;} | |
155 | TTCN3Module * getModule () const {return module;} | |
156 | ||
157 | void addVariant (VariantMode var, const Mstring& var_value = empty_string, bool into_variant_ref = false); | |
158 | void printVariant (FILE * file); | |
159 | ||
160 | void addComment (const Mstring& text); | |
161 | void printComment (FILE * file); | |
162 | ||
163 | void printMinOccursMaxOccurs (FILE * file, bool inside_union, | |
164 | bool empty_allowed = true) const; | |
165 | ||
166 | friend bool compareTypes (RootType * lhs, RootType * rhs); | |
167 | }; | |
168 | ||
169 | inline bool compareTypes (RootType * lhs, RootType * rhs) | |
170 | { | |
171 | return lhs->name.originalValueWoPrefix < rhs->name.originalValueWoPrefix; | |
172 | } | |
173 | ||
174 | #endif /* BASETYPE_HH_ */ |