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