1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtXmlPatterns module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | // |
41 | // W A R N I N G |
42 | // ------------- |
43 | // |
44 | // This file is not part of the Qt API. It exists purely as an |
45 | // implementation detail. This header file may change from version to |
46 | // version without notice, or even be removed. |
47 | // |
48 | // We mean it. |
49 | |
50 | #ifndef Patternist_SchemaType_H |
51 | #define Patternist_SchemaType_H |
52 | |
53 | #include <private/qnamepool_p.h> |
54 | #include <private/qschemacomponent_p.h> |
55 | #include <QXmlName> |
56 | |
57 | template<typename N, typename M> class QHash; |
58 | template<typename N> class QList; |
59 | |
60 | QT_BEGIN_NAMESPACE |
61 | |
62 | namespace QPatternist |
63 | { |
64 | class AtomicType; |
65 | |
66 | /** |
67 | * @short Base class for W3C XML Schema types. |
68 | * |
69 | * This is the base class of all data types in a W3C XML Schema. |
70 | * |
71 | * @ingroup Patternist_types |
72 | * @author Frans Englich <frans.englich@nokia.com> |
73 | */ |
74 | class SchemaType : public SchemaComponent |
75 | { |
76 | public: |
77 | |
78 | typedef QExplicitlySharedDataPointer<SchemaType> Ptr; |
79 | typedef QHash<QXmlName, SchemaType::Ptr> Hash; |
80 | typedef QList<SchemaType::Ptr> List; |
81 | |
82 | /** |
83 | * Schema types are divided into different categories such as |
84 | * complex type, atomic imple type, union simple type, and so forth. This |
85 | * enumerator, which category() returns a value of, identifies what |
86 | * category the type belong to. |
87 | * |
88 | * @todo Add docs & links for the enums |
89 | */ |
90 | enum TypeCategory |
91 | { |
92 | None = 0, |
93 | /** |
94 | * A simple atomic type. These are also sometimes |
95 | * referred to as primitive types. An example of this type is |
96 | * xs:string. |
97 | * |
98 | * Formally speaking, a simple type with variety atomic. |
99 | */ |
100 | SimpleTypeAtomic, |
101 | SimpleTypeList, |
102 | SimpleTypeUnion, |
103 | ComplexType |
104 | }; |
105 | |
106 | enum DerivationMethod |
107 | { |
108 | DerivationRestriction = 1, |
109 | DerivationExtension = 2, |
110 | DerivationUnion = 4, |
111 | DerivationList = 8, |
112 | /** |
113 | * Used for <tt>xs:anyType</tt>. |
114 | */ |
115 | NoDerivation = 16 |
116 | }; |
117 | |
118 | /** |
119 | * Describes the derivation constraints that are given by the 'final' or 'block' attributes. |
120 | */ |
121 | enum DerivationConstraint |
122 | { |
123 | RestrictionConstraint = 1, |
124 | ExtensionConstraint = 2, |
125 | ListConstraint = 4, |
126 | UnionConstraint = 8 |
127 | }; |
128 | Q_DECLARE_FLAGS(DerivationConstraints, DerivationConstraint) |
129 | |
130 | SchemaType(); |
131 | virtual ~SchemaType(); |
132 | |
133 | /** |
134 | * Determines how this SchemaType is derived from its super type. |
135 | * |
136 | * @note Despite that DerivationMethod is designed for being |
137 | * used for bitwise OR'd value, this function may only return one enum |
138 | * value. If the type does not derive from any type, which is the case of |
139 | * <tt>xs:anyType</tt>, this function returns NoDerivation. |
140 | * |
141 | * @see SchemaType::wxsSuperType() |
142 | * @see <a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#TypeInfo-DerivationMethods">Document |
143 | * Object Model (DOM) Level 3 Core Specification, Definition group DerivationMethods</a> |
144 | * @returns a DerivationMethod enumerator signifiying how |
145 | * this SchemaType is derived from its base type |
146 | */ |
147 | virtual DerivationMethod derivationMethod() const = 0; |
148 | |
149 | /** |
150 | * Determines what derivation constraints exists for the type. |
151 | */ |
152 | virtual DerivationConstraints derivationConstraints() const = 0; |
153 | |
154 | /** |
155 | * Determines whether the type is an abstract type. |
156 | * |
157 | * @note It is important a correct value is returned, since |
158 | * abstract types must not be instantiated. |
159 | */ |
160 | virtual bool isAbstract() const = 0; |
161 | |
162 | /** |
163 | * @short Returns the name of the type. |
164 | * |
165 | * The reason to why we take the name pool argument, is that the basic |
166 | * types, @c xs:anySimpleType and so on, are stored globally in |
167 | * BuiltinTypes and ComonSequenceTypes, and therefore cannot be tied to |
168 | * a certain name pool. Type instances that knows they always will be |
169 | * used with a certain name pool, can therefore ignore @p np and return |
170 | * a QXmlName instance stored as a member. |
171 | * |
172 | * If the type code was refactored to not be store globally and |
173 | * therefore by design would be tied to a name pool, this argument could |
174 | * be removed. |
175 | */ |
176 | virtual QXmlName name(const NamePool::Ptr &np) const = 0; |
177 | |
178 | /** |
179 | * @short Returns a suitable display name for this type. |
180 | * |
181 | * See name() for an explanation to why we take a NamePool as argument. |
182 | */ |
183 | virtual QString displayName(const NamePool::Ptr &np) const = 0; |
184 | |
185 | /** |
186 | * @returns the W3C XML Schema base type that this type derives from. All types |
187 | * returns an instance, except for the xs:anyType since it |
188 | * is the very base type of all types, and it returns 0. Hence, |
189 | * one can walk the hierarchy of a schema type by recursively calling |
190 | * wxsSuperType, until zero is returned. |
191 | * |
192 | * This function walks the Schema hierarchy. Some simple types, the atomic types, |
193 | * is also part of the XPath Data Model hierarchy, and their super type in that |
194 | * hierarchy can be introspected with xdtSuperType(). |
195 | * |
196 | * wxsSuperType() can be said to correspond to the {base type definition} property |
197 | * in the Post Schema Valid Infoset(PSVI). |
198 | * |
199 | * @see ItemType::xdtSuperType() |
200 | */ |
201 | virtual SchemaType::Ptr wxsSuperType() const = 0; |
202 | |
203 | /** |
204 | * @returns @c true if @p other is identical to 'this' schema type or if @p other |
205 | * is either directly or indirectly a base type of 'this'. Hence, calling |
206 | * AnyType::wxsTypeMatches() with @p other as argument returns @c true for all types, |
207 | * since all types have @c xs:anyType as super type. |
208 | */ |
209 | virtual bool wxsTypeMatches(const SchemaType::Ptr &other) const = 0; |
210 | |
211 | virtual TypeCategory category() const = 0; |
212 | |
213 | /** |
214 | * Determines whether the type is a simple type, by introspecting |
215 | * the result of category(). |
216 | * |
217 | * @note Do not re-implement this function, but instead override category() |
218 | * and let it return an appropriate value. |
219 | */ |
220 | virtual bool isSimpleType() const; |
221 | |
222 | /** |
223 | * Determines whether the type is a complex type, by introspecting |
224 | * the result of category(). |
225 | * |
226 | * @note Do not re-implement this function, but instead override category() |
227 | * and let it return an appropriate value. |
228 | */ |
229 | virtual bool isComplexType() const; |
230 | |
231 | /** |
232 | * Returns whether the value has been defined by a schema (is not a built in type). |
233 | */ |
234 | virtual bool isDefinedBySchema() const; |
235 | }; |
236 | |
237 | Q_DECLARE_OPERATORS_FOR_FLAGS(SchemaType::DerivationConstraints) |
238 | } |
239 | |
240 | QT_END_NAMESPACE |
241 | |
242 | #endif |
243 | |