Qt 4.8
qnamepool_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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_NamePool_H
53 #define Patternist_NamePool_H
54 
55 #include <QHash>
56 #include <QReadLocker>
57 #include <QReadWriteLock>
58 #include <QSharedData>
59 #include <QString>
60 #include <QVector>
61 #include <QXmlName>
62 
63 #include <QtXmlPatterns/private/qprimitives_p.h>
64 
66 
68 
69 namespace QPatternist
70 {
88  {
89  public:
91 
92  private:
93  friend class StandardNamespaces;
94 
95  enum
96  {
97  NoSuchValue = -1,
102  StandardNamespaceCount = 11,
103  StandardPrefixCount = 9,
104  StandardLocalNameCount = 141
105  };
106 
110 
120 
126 
128 
130  {
131  DefaultPrefixCapacity = 10,
132  DefaultURICapacity = DefaultPrefixCapacity,
140  DefaultLocalNameCapacity = 60
141  };
142 
143  public:
144  NamePool();
145 
158  QXmlName allocateBinding(const QString &prefix, const QString &uri);
159 
160  QXmlName allocateQName(const QString &uri, const QString &localName, const QString &prefix = QString());
161 
163  {
164  /* We don't lock here, but we do in allocateLocalName(). */
165  return QXmlName(uri, allocateLocalName(ln));
166  }
167 
168  inline const QString &stringForLocalName(const QXmlName::LocalNameCode code) const
169  {
170  const QReadLocker l(&lock);
171  return m_localNames.at(code);
172  }
173 
174  inline const QString &stringForPrefix(const QXmlName::PrefixCode code) const
175  {
176  const QReadLocker l(&lock);
177  return m_prefixes.at(code);
178  }
179 
180  inline const QString &stringForNamespace(const QXmlName::NamespaceCode code) const
181  {
182  const QReadLocker l(&lock);
183  return m_namespaces.at(code);
184  }
185 
186  QString displayName(const QXmlName qName) const;
187 
188  inline QString toLexical(const QXmlName qName) const
189  {
190  const QReadLocker l(&lock);
191  Q_ASSERT_X(!qName.isNull(), "", "It makes no sense to call toLexical() on a null name.");
192 
193  if(qName.hasPrefix())
194  {
195  const QString &p = m_prefixes.at(qName.prefix());
196  return p + QLatin1Char(':') + m_localNames.at(qName.localName());
197  }
198  else
199  return m_localNames.at(qName.localName());
200  }
201 
203  {
204  const QWriteLocker l(&lock);
205  return unlockedAllocateNamespace(uri);
206  }
207 
209  {
210  const QWriteLocker l(&lock);
211  return unlockedAllocateLocalName(ln);
212  }
213 
215  {
216  const QWriteLocker l(&lock);
217  return unlockedAllocatePrefix(prefix);
218  }
219 
220  QString toClarkName(const QXmlName &name) const;
221  QXmlName fromClarkName(const QString &clarkName);
222 
223  private:
227  QXmlName::NamespaceCode unlockedAllocateNamespace(const QString &uri);
228 
232  QXmlName::LocalNameCode unlockedAllocateLocalName(const QString &ln);
233 
239  QXmlName::PrefixCode unlockedAllocatePrefix(const QString &prefix);
240 
242 
243 
246  const QString &displayPrefix(const QXmlName::NamespaceCode nc) const;
247 
249  };
250 
256  static inline QString formatKeyword(const NamePool::Ptr &np, const QXmlName name)
257  {
258  return QLatin1String("<span class='XQuery-keyword'>") +
259  escape(np->displayName(name)) +
260  QLatin1String("</span>");
261  }
262 
267  {
268  public:
269  enum ID
270  {
277  empty = 0,
278  fn,
282  xs,
294 
300 
305  InternalXSLT
306  };
307  };
308 
309  // const QString * a = &*qset.insert("foo");
311  {
312  public:
313  enum
314  {
367  id,
407  remove,
455  zero_or_one
456  };
457  };
458 
460  {
461  public:
462  enum
463  {
470  empty = 0,
471  fn,
475  xs,
478  StopNamespaceInheritance
479  };
480  };
481 }
482 
484 {
485  return (m_qNameCode & LocalNameMask) >> LocalNameOffset;
486 }
487 
489 {
490  return (m_qNameCode & PrefixMask) >> PrefixOffset;
491 }
492 
493 inline bool QXmlName::hasPrefix() const
494 {
495  return prefix() != 0;
496 }
497 
498 inline bool QXmlName::hasNamespace() const
499 {
500  return namespaceURI() != 0;
501 }
502 
504 {
505  return (m_qNameCode & NamespaceMask) >> NamespaceOffset;
506 }
507 
508 inline bool QXmlName::isLexicallyEqual(const QXmlName &other) const
509 {
510  return (m_qNameCode & LexicalQNameMask) == (other.m_qNameCode & LexicalQNameMask);
511 }
512 
513 inline void QXmlName::setPrefix(const PrefixCode c)
514 {
515  m_qNameCode |= (c << PrefixOffset);
516 }
517 
519 {
520  m_qNameCode |= (c << NamespaceOffset);
521 }
522 
524 {
525  m_qNameCode |= (c << LocalNameOffset);
526 }
527 
529 {
530  return m_qNameCode;
531 }
532 
534  const LocalNameCode ln,
535  const PrefixCode p) : m_qNameCode((uri << NamespaceOffset) +
536  (ln << LocalNameOffset) +
537  (p << PrefixOffset))
538 {
539  /* We can't use members like prefix() here because if one of the
540  * values are to large, they would overflow into the others. */
541  Q_ASSERT_X(p <= MaximumPrefixes, "",
542  qPrintable(QString::fromLatin1("NamePool prefix limits: max is %1, therefore %2 exceeds.").arg(MaximumPrefixes).arg(p)));
543  Q_ASSERT_X(ln <= MaximumLocalNames, "",
544  qPrintable(QString::fromLatin1("NamePool local name limits: max is %1, therefore %2 exceeds.").arg(MaximumLocalNames).arg(ln)));
545  Q_ASSERT_X(uri <= MaximumNamespaces, "",
546  qPrintable(QString::fromLatin1("NamePool namespace limits: max is %1, therefore %2 exceeds.").arg(MaximumNamespaces).arg(uri)));
547 }
548 
549 
551 
553 
555 
556 #endif
const QString & stringForLocalName(const QXmlName::LocalNameCode code) const
Definition: qnamepool_p.h:168
QHash< QString, QXmlName::PrefixCode > m_prefixMapping
Definition: qnamepool_p.h:119
unsigned char c[8]
Definition: qnumeric_p.h:62
QString Q_AUTOTEST_EXPORT escape(const QString &input)
Similar to Qt::escape(), but also escapes apostrophes and quotes, such that the result is suitable as...
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool hasNamespace() const
Returns true if this QXmlName has a non-empty namespace URI.
Definition: qnamepool_p.h:498
NamespaceCode LocalNameCode
Definition: qxmlname.h:84
QHash< QString, QXmlName::LocalNameCode > m_localNameMapping
Definition: qnamepool_p.h:127
void setPrefix(const PrefixCode c)
Definition: qnamepool_p.h:513
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
Store names such as namespace bindings and QNames and allows them to be referenced in efficient ways...
Definition: qnamepool_p.h:87
qint16 NamespaceCode
Definition: qxmlname.h:82
A special value that when passed as the namespace part to NamespaceResolver::addBinding(), undeclares the prefix.
Definition: qnamepool_p.h:293
static QString formatKeyword(const NamePool::Ptr &np, const QXmlName name)
Formats QName.
Definition: qnamepool_p.h:256
LocalNameCode localName() const
Definition: qnamepool_p.h:483
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
QVector< QString > m_localNames
Definition: qnamepool_p.h:109
QXmlName::NamespaceCode allocateNamespace(const QString &uri)
Definition: qnamepool_p.h:202
PrefixCode prefix() const
Definition: qnamepool_p.h:488
The QString class provides a Unicode character string.
Definition: qstring.h:83
QHash< QString, QXmlName::NamespaceCode > m_namespaceMapping
Definition: qnamepool_p.h:125
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
QXmlName::PrefixCode allocatePrefix(const QString &prefix)
Definition: qnamepool_p.h:214
const QString & stringForPrefix(const QXmlName::PrefixCode code) const
Definition: qnamepool_p.h:174
QXmlName::LocalNameCode allocateLocalName(const QString &ln)
Definition: qnamepool_p.h:208
bool hasPrefix() const
Returns true if this QXmlName has a non-empty prefix.
Definition: qnamepool_p.h:493
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QXmlName allocateQName(const QXmlName::NamespaceCode uri, const QString &ln)
Definition: qnamepool_p.h:162
Q_DECLARE_TYPEINFO(QPatternist::NamePool::Ptr, Q_MOVABLE_TYPE)
QExplicitlySharedDataPointer< NamePool > Ptr
Definition: qnamepool_p.h:90
const char * name
The namespace for the internal API of QtXmlPatterns.
QVector< QString > m_namespaces
Definition: qnamepool_p.h:108
bool isLexicallyEqual(const QXmlName &other) const
Returns true if this and other are lexically equal.
Definition: qnamepool_p.h:508
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
QReadWriteLock lock
Definition: qnamepool_p.h:248
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QVector< QString > m_prefixes
Definition: qnamepool_p.h:107
QString localName(const QXmlNamePool &query) const
Returns the local name.
Definition: qxmlname.cpp:387
NamespaceCode namespaceURI() const
Definition: qnamepool_p.h:503
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QXmlName()
Constructs an uninitialized QXmlName.
Definition: qxmlname.cpp:239
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
The QSharedData class is a base class for shared data objects.
Definition: qshareddata.h:56
void setLocalName(const LocalNameCode c)
Definition: qnamepool_p.h:523
The QReadWriteLock class provides read-write locking.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
const QString & stringForNamespace(const QXmlName::NamespaceCode code) const
Definition: qnamepool_p.h:180
static QReadWriteLock lock
Definition: proxyconf.cpp:399
Code code() const
Returns the internal code that contains the id codes for the local name, prefix and namespace URI...
Definition: qnamepool_p.h:528
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
QFactoryLoader * l
Code m_qNameCode
Definition: qxmlname.h:131
QString toLexical(const QXmlName qName) const
Definition: qnamepool_p.h:188
#define qPrintable(string)
Definition: qglobal.h:1750
#define QT_END_HEADER
Definition: qglobal.h:137
qint64 Code
Stores the QXmlNamePool {name pool} identifiers for the namespace URI, local name, and prefix.
Definition: qxmlname.h:107
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void setNamespaceURI(const NamespaceCode c)
Definition: qnamepool_p.h:518
bool isNull() const
Returns true if this QXmlName is not initialized with a valid combination of {namespace URI}...
Definition: qxmlname.cpp:224
NamespaceCode PrefixCode
Definition: qxmlname.h:83