| 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_XsdFacet_H |
| 51 | #define Patternist_XsdFacet_H |
| 52 | |
| 53 | #include <private/qitem_p.h> |
| 54 | #include <private/qnamedschemacomponent_p.h> |
| 55 | #include <private/qxsdannotated_p.h> |
| 56 | #include <private/qxsdassertion_p.h> |
| 57 | |
| 58 | #include <QtCore/QList> |
| 59 | |
| 60 | QT_BEGIN_NAMESPACE |
| 61 | |
| 62 | namespace QPatternist |
| 63 | { |
| 64 | /** |
| 65 | * @short Represents a XSD facet object. |
| 66 | * |
| 67 | * This class represents one of the following XML schema objects: |
| 68 | * |
| 69 | * <ul> |
| 70 | * <li><em>length</em> <a href="http://www.w3.org/TR/xmlschema-2/#rf-length">Definition</a></li> |
| 71 | * <li><em>minLength</em> <a href="http://www.w3.org/TR/xmlschema-2/#rf-minLength">Definition</a></li> |
| 72 | * <li><em>maxLength</em> <a href="http://www.w3.org/TR/xmlschema-2/#rf-maxLength">Definition</a></li> |
| 73 | * <li><em>pattern</em> <a href="http://www.w3.org/TR/xmlschema-2/#rf-pattern">Definition</a></li> |
| 74 | * <li><em>whiteSpace</em> <a href="http://www.w3.org/TR/xmlschema-2/#rf-whiteSpace">Definition</a></li> |
| 75 | * <li><em>maxInclusive</em> <a href="http://www.w3.org/TR/xmlschema-2/#rf-maxInclusive">Definition</a></li> |
| 76 | * <li><em>maxExclusive</em> <a href="http://www.w3.org/TR/xmlschema-2/#rf-maxExclusive">Definition</a></li> |
| 77 | * <li><em>minInclusive</em> <a href="http://www.w3.org/TR/xmlschema-2/#rf-minInclusive">Definition</a></li> |
| 78 | * <li><em>minExclusive</em> <a href="http://www.w3.org/TR/xmlschema-2/#rf-minExclusive">Definition</a></li> |
| 79 | * <li><em>totalDigits</em> <a href="http://www.w3.org/TR/xmlschema-2/#rf-totalDigits">Definition</a></li> |
| 80 | * <li><em>fractionDigits</em> <a href="http://www.w3.org/TR/xmlschema-2/#rf-fractionDigits">Definition</a></li> |
| 81 | * <li><em>enumeration</em> <a href="http://www.w3.org/TR/xmlschema-2/#rf-enumeration">Definition</a></li> |
| 82 | * <li><em>assertion</em> <a href="http://www.w3.org/TR/xmlschema-2/#rf-assertion">Definition</a></li> |
| 83 | * </ul> |
| 84 | * |
| 85 | * @see <a href="http://www.w3.org/Submission/2004/SUBM-xmlschema-api-20040309/xml-schema-api.html#Interface-XSFacet">XML Schema API reference</a> |
| 86 | * @ingroup Patternist_schema |
| 87 | * @author Tobias Koenig <tobias.koenig@nokia.com> |
| 88 | */ |
| 89 | class XsdFacet : public NamedSchemaComponent, public XsdAnnotated |
| 90 | { |
| 91 | public: |
| 92 | typedef QExplicitlySharedDataPointer<XsdFacet> Ptr; |
| 93 | |
| 94 | /** |
| 95 | * Describes the type of the facet. |
| 96 | */ |
| 97 | enum Type |
| 98 | { |
| 99 | None = 0, ///< An invalid facet. |
| 100 | Length = 1 << 0, ///< Match the exact length (<a href="http://www.w3.org/TR/xmlschema-2/#rf-length">Length Definition</a>) |
| 101 | MinimumLength = 1 << 1, ///< Match the minimum length (<a href="http://www.w3.org/TR/xmlschema-2/#rf-minLength">Minimum Length Definition</a>) |
| 102 | MaximumLength = 1 << 2, ///< Match the maximum length (<a href="http://www.w3.org/TR/xmlschema-2/#rf-maxLength">Maximum Length Definition</a>) |
| 103 | Pattern = 1 << 3, ///< Match a regular expression (<a href="http://www.w3.org/TR/xmlschema-2/#rf-pattern">Pattern Definition</a>) |
| 104 | WhiteSpace = 1 << 4, ///< Match a whitespace rule (<a href="http://www.w3.org/TR/xmlschema-2/#rf-whiteSpace">White Space Definition</a>) |
| 105 | MaximumInclusive = 1 << 5, ///< Match a maximum inclusive (<a href="http://www.w3.org/TR/xmlschema-2/#rf-maxInclusive">Maximum Inclusive Definition</a>) |
| 106 | MaximumExclusive = 1 << 6, ///< Match a maximum exclusive (<a href="http://www.w3.org/TR/xmlschema-2/#rf-maxExclusive">Maximum Exclusive Definition</a>) |
| 107 | MinimumInclusive = 1 << 7, ///< Match a minimum inclusive (<a href="http://www.w3.org/TR/xmlschema-2/#rf-minInclusive">Minimum Inclusive Definition</a>) |
| 108 | MinimumExclusive = 1 << 8, ///< Match a minimum exclusive (<a href="http://www.w3.org/TR/xmlschema-2/#rf-minExclusive">Minimum Exclusive Definition</a>) |
| 109 | TotalDigits = 1 << 9, ///< Match some integer digits (<a href="http://www.w3.org/TR/xmlschema-2/#rf-totalDigits">Total Digits Definition</a>) |
| 110 | FractionDigits = 1 << 10, ///< Match some double digits (<a href="http://www.w3.org/TR/xmlschema-2/#rf-fractionDigits">Fraction Digits Definition</a>) |
| 111 | Enumeration = 1 << 11, ///< Match an enumeration (<a href="http://www.w3.org/TR/xmlschema-2/#rf-enumeration">Enumeration Definition</a>) |
| 112 | Assertion = 1 << 12, ///< Match an assertion (<a href="http://www.w3.org/TR/xmlschema-2/#rf-assertion">Assertion Definition</a>) |
| 113 | }; |
| 114 | typedef QHash<XsdFacet::Type, XsdFacet::Ptr> Hash; |
| 115 | |
| 116 | /** |
| 117 | * Creates a new facet object of type None. |
| 118 | */ |
| 119 | XsdFacet(); |
| 120 | |
| 121 | /** |
| 122 | * Sets the @p type of the facet. |
| 123 | * |
| 124 | * @see Type |
| 125 | */ |
| 126 | void setType(Type type); |
| 127 | |
| 128 | /** |
| 129 | * Returns the type of the facet. |
| 130 | */ |
| 131 | Type type() const; |
| 132 | |
| 133 | /** |
| 134 | * Sets the @p value of the facet. |
| 135 | * |
| 136 | * Depending on the type of the facet the |
| 137 | * value can be a string, interger, double etc. |
| 138 | * |
| 139 | * @note This method should be used for all types of facets |
| 140 | * except Pattern, Enumeration and Assertion. |
| 141 | */ |
| 142 | void setValue(const AtomicValue::Ptr &value); |
| 143 | |
| 144 | /** |
| 145 | * Returns the value of the facet or an empty pointer if facet |
| 146 | * type is Pattern, Enumeration or Assertion. |
| 147 | */ |
| 148 | AtomicValue::Ptr value() const; |
| 149 | |
| 150 | /** |
| 151 | * Sets the @p value of the facet. |
| 152 | * |
| 153 | * @note This method should be used for if the type of the |
| 154 | * facet is Pattern or Enumeration. |
| 155 | */ |
| 156 | void setMultiValue(const AtomicValue::List &value); |
| 157 | |
| 158 | /** |
| 159 | * Returns the value of the facet or an empty pointer if facet |
| 160 | * type is not of type Pattern or Enumeration. |
| 161 | */ |
| 162 | AtomicValue::List multiValue() const; |
| 163 | |
| 164 | /** |
| 165 | * Sets the @p assertions of the facet. |
| 166 | * |
| 167 | * @note This method should be used if the type of the |
| 168 | * facet is Assertion. |
| 169 | */ |
| 170 | void setAssertions(const XsdAssertion::List &assertions); |
| 171 | |
| 172 | /** |
| 173 | * Returns the assertions of the facet or an empty pointer if facet |
| 174 | * type is not of type Assertion. |
| 175 | */ |
| 176 | XsdAssertion::List assertions() const; |
| 177 | |
| 178 | /** |
| 179 | * Sets whether the facet is @p fixed. |
| 180 | * |
| 181 | * All facets except pattern, enumeration and assertion can be fixed. |
| 182 | */ |
| 183 | void setFixed(bool fixed); |
| 184 | |
| 185 | /** |
| 186 | * Returns whether the facet is fixed. |
| 187 | */ |
| 188 | bool fixed() const; |
| 189 | |
| 190 | /** |
| 191 | * Returns the textual description of the facet @p type. |
| 192 | */ |
| 193 | static QString typeName(Type type); |
| 194 | |
| 195 | private: |
| 196 | Type m_type; |
| 197 | AtomicValue::Ptr m_value; |
| 198 | AtomicValue::List m_multiValue; |
| 199 | XsdAssertion::List m_assertions; |
| 200 | bool m_fixed; |
| 201 | }; |
| 202 | } |
| 203 | |
| 204 | QT_END_NAMESPACE |
| 205 | |
| 206 | #endif |
| 207 | |