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_XsdIdcHelper_H
51#define Patternist_XsdIdcHelper_H
52
53#include <private/qreportcontext_p.h>
54#include <private/qschematype_p.h>
55
56#include <QtXmlPatterns/QXmlItem>
57
58QT_BEGIN_NAMESPACE
59
60namespace QPatternist
61{
62
63 /**
64 * @short A helper class for validating identity constraints.
65 *
66 * This class represents a field node from the key-sequence as defined in
67 * the validation rules at http://www.w3.org/TR/xmlschema11-1/#d0e32243.
68 */
69 class FieldNode
70 {
71 public:
72 /**
73 * Creates an empty field node.
74 */
75 FieldNode();
76
77 /**
78 * Creates a field node that is bound to a xml node.
79 *
80 * @param item The xml node the field is bound to.
81 * @param data The string content of that field.
82 * @param type The type that is bound to that field.
83 */
84 FieldNode(const QXmlItem &item, const QString &data, const SchemaType::Ptr &type);
85
86 /**
87 * Returns whether this field is empty.
88 *
89 * A field can be empty, if the xpath expression selects an absent attribute
90 * or element.
91 */
92 bool isEmpty() const;
93
94 /**
95 * Returns whether this field is equal to the @p other field.
96 *
97 * Equal means that both have the same type and there content is equal in the
98 * types value space.
99 */
100 bool isEqualTo(const FieldNode &other, const NamePool::Ptr &namePool, const ReportContext::Ptr &context, const SourceLocationReflection *const reflection) const;
101
102 /**
103 * Returns the xml node item the field is bound to.
104 */
105 QXmlItem item() const;
106
107 private:
108 QXmlItem m_item;
109 QString m_data;
110 SchemaType::Ptr m_type;
111 };
112
113 /**
114 * @short A helper class for validating identity constraints.
115 *
116 * This class represents a target or qualified node from the target or qualified
117 * node set as defined in the validation rules at http://www.w3.org/TR/xmlschema11-1/#d0e32243.
118 *
119 * A target node is part of the qualified node set, if all of its fields are not empty.
120 */
121 class TargetNode
122 {
123 public:
124 /**
125 * Defines a set of target nodes.
126 */
127 typedef QSet<TargetNode> Set;
128
129 /**
130 * Creates a new target node that is bound to the xml node @p item.
131 */
132 explicit TargetNode(const QXmlItem &item);
133
134 /**
135 * Returns the xml node item the target node is bound to.
136 */
137 QXmlItem item() const;
138
139 /**
140 * Returns all xml node items, the fields of that target node are bound to.
141 */
142 QVector<QXmlItem> fieldItems() const;
143
144 /**
145 * Returns the number of fields that are empty.
146 */
147 int emptyFieldsCount() const;
148
149 /**
150 * Returns whether the target node has the same fields as the @p other target node.
151 */
152 bool fieldsAreEqual(const TargetNode &other, const NamePool::Ptr &namePool, const ReportContext::Ptr &context, const SourceLocationReflection *const reflection) const;
153
154 /**
155 * Adds a new field to the target node with the given values.
156 */
157 void addField(const QXmlItem &item, const QString &data, const SchemaType::Ptr &type);
158
159 /**
160 * Returns whether the target node is equal to the @p other target node.
161 */
162 bool operator==(const TargetNode &other) const;
163
164 private:
165 QXmlItem m_item;
166 QVector<FieldNode> m_fields;
167 };
168
169 /**
170 * Creates a hash value for the given target @p node.
171 */
172 inline uint qHash(const QPatternist::TargetNode &node)
173 {
174 return qHash(index: node.item().toNodeModelIndex());
175 }
176}
177
178QT_END_NAMESPACE
179
180#endif
181

source code of qtxmlpatterns/src/xmlpatterns/schema/qxsdidchelper_p.h