Qt 4.8
Public Types | Public Functions | Private Types | Private Functions | Properties | Friends | List of all members
QPatternist::NamePool Class Reference

Store names such as namespace bindings and QNames and allows them to be referenced in efficient ways. More...

#include <qnamepool_p.h>

Inheritance diagram for QPatternist::NamePool:
QSharedData

Public Types

typedef QExplicitlySharedDataPointer< NamePoolPtr
 

Public Functions

QXmlName allocateBinding (const QString &prefix, const QString &uri)
 Allocates a namespace binding for prefix and uri. More...
 
QXmlName::LocalNameCode allocateLocalName (const QString &ln)
 
QXmlName::NamespaceCode allocateNamespace (const QString &uri)
 
QXmlName::PrefixCode allocatePrefix (const QString &prefix)
 
QXmlName allocateQName (const QString &uri, const QString &localName, const QString &prefix=QString())
 
QXmlName allocateQName (const QXmlName::NamespaceCode uri, const QString &ln)
 
QString displayName (const QXmlName qName) const
 
QXmlName fromClarkName (const QString &clarkName)
 
 NamePool ()
 
const QStringstringForLocalName (const QXmlName::LocalNameCode code) const
 
const QStringstringForNamespace (const QXmlName::NamespaceCode code) const
 
const QStringstringForPrefix (const QXmlName::PrefixCode code) const
 
QString toClarkName (const QXmlName &name) const
 
QString toLexical (const QXmlName qName) const
 
- Public Functions inherited from QSharedData
 QSharedData ()
 Constructs a QSharedData object with a reference count of 0. More...
 
 QSharedData (const QSharedData &)
 Constructs a QSharedData object with reference count 0. More...
 

Private Types

enum  { NoSuchValue = -1, StandardNamespaceCount = 11, StandardPrefixCount = 9, StandardLocalNameCount = 141 }
 
enum  DefaultCapacities { DefaultPrefixCapacity = 10, DefaultURICapacity = DefaultPrefixCapacity, DefaultLocalNameCapacity = 60 }
 

Private Functions

const QStringdisplayPrefix (const QXmlName::NamespaceCode nc) const
 
QXmlName::LocalNameCode unlockedAllocateLocalName (const QString &ln)
 
QXmlName::NamespaceCode unlockedAllocateNamespace (const QString &uri)
 
QXmlName::PrefixCode unlockedAllocatePrefix (const QString &prefix)
 

Properties

QReadWriteLock lock
 
QHash< QString, QXmlName::LocalNameCodem_localNameMapping
 
QVector< QStringm_localNames
 
QHash< QString, QXmlName::NamespaceCodem_namespaceMapping
 
QVector< QStringm_namespaces
 
QVector< QStringm_prefixes
 
QHash< QString, QXmlName::PrefixCodem_prefixMapping
 

Friends

class StandardNamespaces
 

Additional Inherited Members

- Public Variables inherited from QSharedData
QAtomicInt ref
 

Detailed Description

Store names such as namespace bindings and QNames and allows them to be referenced in efficient ways.

Once a string have been inserted it stays there and cannot be removed. The only way to deallocate any string in the NamePool is to deallocate the NamePool itself, as a whole.

This class is not only reentrant, it is thread-safe in all sense of the word. All functions of this class can be called concurrently. This is achieved by internal locking.

Author
Frans Englich frans.nosp@m..eng.nosp@m.lich@.nosp@m.noki.nosp@m.a.com

Definition at line 87 of file qnamepool_p.h.

Typedefs

◆ Ptr

Definition at line 90 of file qnamepool_p.h.

Enumerations

◆ anonymous enum

anonymous enum
private
Enumerator
NoSuchValue 
StandardNamespaceCount 

This must be identical to the amount of members in StandardNamespaces.

StandardPrefixCount 
StandardLocalNameCount 

Definition at line 95 of file qnamepool_p.h.

◆ DefaultCapacities

Enumerator
DefaultPrefixCapacity 
DefaultURICapacity 
DefaultLocalNameCapacity 

It looks like it's quite common with 40-60 different local names per XML vocabulary. For background, see:

Definition at line 129 of file qnamepool_p.h.

Constructors and Destructors

◆ NamePool()

NamePool::NamePool ( )

Definition at line 53 of file qnamepool.cpp.

54 {
61 
62  /* Namespaces. */
63  {
65  unlockedAllocateNamespace(QLatin1String("http://www.w3.org/2005/xpath-functions"));
66  unlockedAllocateNamespace(QLatin1String("http://www.w3.org/2005/xquery-local-functions"));
67  unlockedAllocateNamespace(QLatin1String("http://www.w3.org/XML/1998/namespace"));
68  unlockedAllocateNamespace(QLatin1String("http://www.w3.org/2000/xmlns/"));
69  unlockedAllocateNamespace(QLatin1String("http://www.w3.org/2001/XMLSchema"));
70  unlockedAllocateNamespace(QLatin1String("http://www.w3.org/2001/XMLSchema-instance"));
71  unlockedAllocateNamespace(QLatin1String("http://www.w3.org/1999/XSL/Transform"));
72 
73  /* For UndeclarePrefix, StopNamespaceInheritance and InternalXSLT. We use two
74  * arbitrary strings that aren't used. For instance, if we just used an
75  * empty QString, unlockedAllocateNamespace() would assign it
76  * StandardNamespaces::empty. However, it's important that the string
77  * is an invalid namespace, since otherwise user strings would get
78  * assigned the same IDs. */
81  unlockedAllocateNamespace(QLatin1String(" | InternalXSLT"));
82 
84  qPrintable(QString::fromLatin1("Expected is %1, actual is %2.").arg(StandardNamespaceCount).arg(m_namespaces.count())));
85  }
86 
87  /* Prefixes. */
88  {
97  unlockedAllocatePrefix(QLatin1String("|||")); /* Invalid NCName, for StopNamespaceInheritance. */
98 
100  qPrintable(QString::fromLatin1("Expected is %1, actual is %2.").arg(StandardPrefixCount).arg(m_prefixes.count())));
101  }
102 
103  /* Local names. */
104  {
105  /* Same order as the enum in StandardLocalNames. That is, alphabetically. */
107  unlockedAllocateLocalName(QLatin1String("adjust-dateTime-to-timezone"));
108  unlockedAllocateLocalName(QLatin1String("adjust-date-to-timezone"));
109  unlockedAllocateLocalName(QLatin1String("adjust-time-to-timezone"));
117  unlockedAllocateLocalName(QLatin1String("codepoint-equal"));
118  unlockedAllocateLocalName(QLatin1String("codepoints-to-string"));
125  unlockedAllocateLocalName(QLatin1String("current-date"));
126  unlockedAllocateLocalName(QLatin1String("current-dateTime"));
127  unlockedAllocateLocalName(QLatin1String("current-time"));
130  unlockedAllocateLocalName(QLatin1String("day-from-date"));
131  unlockedAllocateLocalName(QLatin1String("day-from-dateTime"));
132  unlockedAllocateLocalName(QLatin1String("days-from-duration"));
135  unlockedAllocateLocalName(QLatin1String("default-collation"));
136  unlockedAllocateLocalName(QLatin1String("distinct-values"));
138  unlockedAllocateLocalName(QLatin1String("doc-available"));
140  unlockedAllocateLocalName(QLatin1String("document-uri"));
141  unlockedAllocateLocalName(QLatin1String("element-available"));
143  unlockedAllocateLocalName(QLatin1String("encode-for-uri"));
146  unlockedAllocateLocalName(QLatin1String("escape-html-uri"));
151  unlockedAllocateLocalName(QLatin1String("function-available"));
152  unlockedAllocateLocalName(QLatin1String("function-name"));
154  unlockedAllocateLocalName(QLatin1String("generic-string-join"));
155  unlockedAllocateLocalName(QLatin1String("hours-from-dateTime"));
156  unlockedAllocateLocalName(QLatin1String("hours-from-duration"));
157  unlockedAllocateLocalName(QLatin1String("hours-from-time"));
160  unlockedAllocateLocalName(QLatin1String("implicit-timezone"));
162  unlockedAllocateLocalName(QLatin1String("in-scope-prefixes"));
163  unlockedAllocateLocalName(QLatin1String("insert-before"));
165  unlockedAllocateLocalName(QLatin1String("is-schema-aware"));
170  unlockedAllocateLocalName(QLatin1String("local-name-from-QName"));
175  unlockedAllocateLocalName(QLatin1String("minutes-from-dateTime"));
176  unlockedAllocateLocalName(QLatin1String("minutes-from-duration"));
177  unlockedAllocateLocalName(QLatin1String("minutes-from-time"));
178  unlockedAllocateLocalName(QLatin1String("month-from-date"));
179  unlockedAllocateLocalName(QLatin1String("month-from-dateTime"));
180  unlockedAllocateLocalName(QLatin1String("months-from-duration"));
182  unlockedAllocateLocalName(QLatin1String("namespace-uri"));
183  unlockedAllocateLocalName(QLatin1String("namespace-uri-for-prefix"));
184  unlockedAllocateLocalName(QLatin1String("namespace-uri-from-QName"));
187  unlockedAllocateLocalName(QLatin1String("normalize-space"));
188  unlockedAllocateLocalName(QLatin1String("normalize-unicode"));
193  unlockedAllocateLocalName(QLatin1String("prefix-from-QName"));
194  unlockedAllocateLocalName(QLatin1String("product-name"));
195  unlockedAllocateLocalName(QLatin1String("product-version"));
196  unlockedAllocateLocalName(QLatin1String("property-name"));
200  unlockedAllocateLocalName(QLatin1String("resolve-QName"));
205  unlockedAllocateLocalName(QLatin1String("round-half-to-even"));
206  unlockedAllocateLocalName(QLatin1String("seconds-from-dateTime"));
207  unlockedAllocateLocalName(QLatin1String("seconds-from-duration"));
208  unlockedAllocateLocalName(QLatin1String("seconds-from-time"));
211  unlockedAllocateLocalName(QLatin1String("static-base-uri"));
214  unlockedAllocateLocalName(QLatin1String("string-length"));
215  unlockedAllocateLocalName(QLatin1String("string-to-codepoints"));
218  unlockedAllocateLocalName(QLatin1String("substring-after"));
219  unlockedAllocateLocalName(QLatin1String("substring-before"));
221  unlockedAllocateLocalName(QLatin1String("supports-backwards-compatibility"));
222  unlockedAllocateLocalName(QLatin1String("supports-serialization"));
223  unlockedAllocateLocalName(QLatin1String("system-property"));
224  unlockedAllocateLocalName(QLatin1String("timezone-from-date"));
225  unlockedAllocateLocalName(QLatin1String("timezone-from-dateTime"));
226  unlockedAllocateLocalName(QLatin1String("timezone-from-time"));
231  unlockedAllocateLocalName(QLatin1String("type-available"));
233  unlockedAllocateLocalName(QLatin1String("unparsed-entity-public-id"));
234  unlockedAllocateLocalName(QLatin1String("unparsed-entity-uri"));
235  unlockedAllocateLocalName(QLatin1String("unparsed-text"));
236  unlockedAllocateLocalName(QLatin1String("unparsed-text-available"));
243  unlockedAllocateLocalName(QLatin1String("year-from-date"));
244  unlockedAllocateLocalName(QLatin1String("year-from-dateTime"));
245  unlockedAllocateLocalName(QLatin1String("years-from-duration"));
248  }
249 }
QHash< QString, QXmlName::PrefixCode > m_prefixMapping
Definition: qnamepool_p.h:119
QHash< QString, QXmlName::LocalNameCode > m_localNameMapping
Definition: qnamepool_p.h:127
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QVector< QString > m_localNames
Definition: qnamepool_p.h:109
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QXmlName::LocalNameCode unlockedAllocateLocalName(const QString &ln)
Definition: qnamepool.cpp:289
QHash< QString, QXmlName::NamespaceCode > m_namespaceMapping
Definition: qnamepool_p.h:125
void reserve(int size)
Ensures that the QHash&#39;s internal hash table consists of at least size buckets.
Definition: qhash.h:846
QVector< QString > m_namespaces
Definition: qnamepool_p.h:108
QXmlName::NamespaceCode unlockedAllocateNamespace(const QString &uri)
Definition: qnamepool.cpp:320
QVector< QString > m_prefixes
Definition: qnamepool_p.h:107
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
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
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
#define qPrintable(string)
Definition: qglobal.h:1750
QXmlName::PrefixCode unlockedAllocatePrefix(const QString &prefix)
Definition: qnamepool.cpp:306
#define Q_FUNC_INFO
Definition: qglobal.h:1871

Functions

◆ allocateBinding()

QXmlName NamePool::allocateBinding ( const QString prefix,
const QString uri 
)

Allocates a namespace binding for prefix and uri.

In the returned QXmlName, the local name is StandardLocalNames::empty, and QXmlName::prefix() and QXmlName::namespaceUri() returns prefix and uri, respectively.

In older versions of this code, the class NamespaceBinding existed, but as part of having the public class QXmlName, it was dropped and a special interpretation/convention involving use of QXmlName was adopted.

Definition at line 275 of file qnamepool.cpp.

Referenced by QPatternist::AccelTreeResourceLoader::streamToReceiver().

276 {
277  QWriteLocker l(&lock);
278 
279  Q_ASSERT_X(prefix.isEmpty() || QXmlUtils::isNCName(prefix), Q_FUNC_INFO,
280  qPrintable(QString::fromLatin1("%1 is an invalid prefix.").arg(prefix)));
282 
283  Q_ASSERT(prefix.isEmpty() || QXmlUtils::isNCName(prefix));
284  const QXmlName::PrefixCode prefixCode = unlockedAllocatePrefix(prefix);
285 
286  return QXmlName(nsCode, StandardLocalNames::empty, prefixCode);
287 }
qint16 NamespaceCode
Definition: qxmlname.h:82
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QXmlName::NamespaceCode unlockedAllocateNamespace(const QString &uri)
Definition: qnamepool.cpp:320
QReadWriteLock lock
Definition: qnamepool_p.h:248
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
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
QFactoryLoader * l
#define qPrintable(string)
Definition: qglobal.h:1750
static bool isNCName(const QStringRef &ncName)
Determines whether c is a valid instance of production [4]NCName in the XML 1.0 Namespaces specificat...
Definition: qxmlutils.cpp:377
QXmlName::PrefixCode unlockedAllocatePrefix(const QString &prefix)
Definition: qnamepool.cpp:306
#define Q_FUNC_INFO
Definition: qglobal.h:1871
NamespaceCode PrefixCode
Definition: qxmlname.h:83

◆ allocateLocalName()

QXmlName::LocalNameCode QPatternist::NamePool::allocateLocalName ( const QString ln)
inline

Definition at line 208 of file qnamepool_p.h.

Referenced by QPatternist::XsdInstanceReader::convertToQName(), QPatternist::XsdTypeChecker::convertToQName(), and QPatternist::NamespaceSupport::processName().

209  {
210  const QWriteLocker l(&lock);
211  return unlockedAllocateLocalName(ln);
212  }
QXmlName::LocalNameCode unlockedAllocateLocalName(const QString &ln)
Definition: qnamepool.cpp:289
QReadWriteLock lock
Definition: qnamepool_p.h:248
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
QFactoryLoader * l

◆ allocateNamespace()

QXmlName::NamespaceCode QPatternist::NamePool::allocateNamespace ( const QString uri)
inline

Definition at line 202 of file qnamepool_p.h.

Referenced by QPatternist::NamespaceSupport::setPrefixes(), QPatternist::XsdSchemaParser::setTargetNamespaceExtended(), termMatches(), QPatternist::FunctionAvailableFN::typeCheck(), and QPatternist::XsdValidatingInstanceReader::validateAttributeWildcard().

203  {
204  const QWriteLocker l(&lock);
205  return unlockedAllocateNamespace(uri);
206  }
QXmlName::NamespaceCode unlockedAllocateNamespace(const QString &uri)
Definition: qnamepool.cpp:320
QReadWriteLock lock
Definition: qnamepool_p.h:248
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
QFactoryLoader * l

◆ allocatePrefix()

QXmlName::PrefixCode QPatternist::NamePool::allocatePrefix ( const QString prefix)
inline

Definition at line 214 of file qnamepool_p.h.

Referenced by QPatternist::XsdInstanceReader::convertToQName(), QPatternist::XsdTypeChecker::convertToQName(), QPatternist::NamespaceURIForPrefixFN::evaluateSingleton(), QPatternist::NamespaceSupport::processName(), and QPatternist::NamespaceSupport::setPrefixes().

215  {
216  const QWriteLocker l(&lock);
217  return unlockedAllocatePrefix(prefix);
218  }
QReadWriteLock lock
Definition: qnamepool_p.h:248
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
QFactoryLoader * l
QXmlName::PrefixCode unlockedAllocatePrefix(const QString &prefix)
Definition: qnamepool.cpp:306

◆ allocateQName() [1/2]

QXmlName NamePool::allocateQName ( const QString uri,
const QString localName,
const QString prefix = QString() 
)

Definition at line 251 of file qnamepool.cpp.

Referenced by QPatternist::XsdSchema::addAnonymousType(), QPatternist::XsdSchemaParserContext::createAnonymousName(), QPatternist::URILoader::createRequest(), QPatternist::QNameFN::evaluateSingleton(), QPatternist::ProcessingInstructionConstructor::evaluateTardata(), fromClarkName(), QPatternist::AnyType::name(), QPatternist::AnySimpleType::name(), QPatternist::Untyped::name(), QPatternist::XsdSchemaParser::parseGlobalAttribute(), QPatternist::XsdSchemaParser::parseGlobalComplexType(), QPatternist::XsdSchemaParser::parseGlobalElement(), QPatternist::XsdSchemaParser::parseGlobalSimpleType(), QPatternist::XsdSchemaParser::parseKey(), QPatternist::XsdSchemaParser::parseKeyRef(), QPatternist::XsdSchemaParser::parseLocalAttribute(), QPatternist::XsdSchemaParser::parseLocalElement(), QPatternist::XsdSchemaParser::parseNamedAttributeGroup(), QPatternist::XsdSchemaParser::parseNamedGroup(), QPatternist::XsdSchemaParser::parseNotation(), QPatternist::XsdSchemaParser::parseUnique(), QXmlName::QXmlName(), QPatternist::AccelTreeResourceLoader::streamToReceiver(), QPatternist::XsdSchemaTypesFactory::XsdSchemaTypesFactory(), and QPatternist::XsdValidatingInstanceReader::XsdValidatingInstanceReader().

252 {
253  QWriteLocker l(&lock);
254 
255  /*
256  QString codepoints;
257  for(int i = 0; i < localName.length(); ++i)
258  codepoints.append(QString::number(localName.at(i).unicode()) + QLatin1Char(' '));
259 
260  pDebug() << Q_FUNC_INFO << localName << "codepoints:" << codepoints;
261  */
262 
264  qPrintable(QString::fromLatin1("'%1' is an invalid NCName.").arg(localName)));
265 
267  const QXmlName::LocalNameCode localCode = unlockedAllocateLocalName(localName);
268 
269  Q_ASSERT(prefix.isEmpty() || QXmlUtils::isNCName(prefix));
270  const QXmlName::PrefixCode prefixCode = unlockedAllocatePrefix(prefix);
271 
272  return QXmlName(nsCode, localCode, prefixCode);
273 }
NamespaceCode LocalNameCode
Definition: qxmlname.h:84
qint16 NamespaceCode
Definition: qxmlname.h:82
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QXmlName::LocalNameCode unlockedAllocateLocalName(const QString &ln)
Definition: qnamepool.cpp:289
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QXmlName::NamespaceCode unlockedAllocateNamespace(const QString &uri)
Definition: qnamepool.cpp:320
QReadWriteLock lock
Definition: qnamepool_p.h:248
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
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
QFactoryLoader * l
#define qPrintable(string)
Definition: qglobal.h:1750
static bool isNCName(const QStringRef &ncName)
Determines whether c is a valid instance of production [4]NCName in the XML 1.0 Namespaces specificat...
Definition: qxmlutils.cpp:377
QXmlName::PrefixCode unlockedAllocatePrefix(const QString &prefix)
Definition: qnamepool.cpp:306
#define Q_FUNC_INFO
Definition: qglobal.h:1871
NamespaceCode PrefixCode
Definition: qxmlname.h:83

◆ allocateQName() [2/2]

QXmlName QPatternist::NamePool::allocateQName ( const QXmlName::NamespaceCode  uri,
const QString ln 
)
inline

Definition at line 162 of file qnamepool_p.h.

163  {
164  /* We don't lock here, but we do in allocateLocalName(). */
165  return QXmlName(uri, allocateLocalName(ln));
166  }
QXmlName::LocalNameCode allocateLocalName(const QString &ln)
Definition: qnamepool_p.h:208
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58

◆ displayName()

QString NamePool::displayName ( const QXmlName  qName) const

Definition at line 347 of file qnamepool.cpp.

Referenced by QPatternist::XsdSchemaParser::addAttribute(), QPatternist::XsdSchemaParser::addElement(), QPatternist::QNameTest::displayName(), QPatternist::AnySimpleType::displayName(), QPatternist::XsdSimpleType::displayName(), QPatternist::NamedSchemaComponent::displayName(), QPatternist::FunctionSignature::displayName(), QPatternist::XsdComplexType::displayName(), QPatternist::AccelTree::printStats(), QPatternist::XsdValidatingInstanceReader::qNameAttribute(), QPatternist::XsdValidatingInstanceReader::read(), QPatternist::XsdValidatingInstanceReader::validate(), and QPatternist::XsdValidatingInstanceReader::validateElementComplexType().

348 {
349  QReadLocker l(&lock);
350 
351  if(qName.hasNamespace())
352  {
354  return QLatin1Char('#') + m_localNames.at(qName.localName());
355 
356  const QString &p = displayPrefix(qName.namespaceURI());
357 
358  if(p.isEmpty())
359  return QLatin1Char('{') + m_namespaces.at(qName.namespaceURI()) + QLatin1Char('}') + toLexical(qName);
360  else
361  return p + QLatin1Char(':') + m_localNames.at(qName.localName());
362  }
363  else
364  return m_localNames.at(qName.localName());
365 }
bool hasNamespace() const
Returns true if this QXmlName has a non-empty namespace URI.
Definition: qnamepool_p.h:498
QVector< QString > m_localNames
Definition: qnamepool_p.h:109
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QVector< QString > m_namespaces
Definition: qnamepool_p.h:108
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
QReadWriteLock lock
Definition: qnamepool_p.h:248
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QString localName(const QXmlNamePool &query) const
Returns the local name.
Definition: qxmlname.cpp:387
NamespaceCode namespaceURI() const
Definition: qnamepool_p.h:503
QFactoryLoader * l
QString toLexical(const QXmlName qName) const
Definition: qnamepool_p.h:188
const QString & displayPrefix(const QXmlName::NamespaceCode nc) const
Definition: qnamepool.cpp:334
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ displayPrefix()

const QString & NamePool::displayPrefix ( const QXmlName::NamespaceCode  nc) const
private
Note
This function can not be called concurrently.

Definition at line 334 of file qnamepool.cpp.

Referenced by displayName().

◆ fromClarkName()

QXmlName NamePool::fromClarkName ( const QString clarkName)

Definition at line 389 of file qnamepool.cpp.

Referenced by QXmlName::fromClarkName().

390 {
391  if(clarkName.isEmpty())
392  return QXmlName();
393 
394  if(clarkName.at(0) == QLatin1Char('{'))
395  {
396  const int indexOfRight = clarkName.indexOf(QLatin1Char('}'));
397  const QString qName(clarkName.right((clarkName.length() - indexOfRight) - 1));
398 
399  if(!XPathHelper::isQName(qName))
400  return QXmlName();
401 
402  QString localName;
403  QString prefix;
404 
405  XPathHelper::splitQName(qName, prefix, localName);
406 
407  return allocateQName(clarkName.mid(1, indexOfRight - 1),
408  localName, prefix);
409  }
410  else
411  {
412  if(QXmlName::isNCName(clarkName))
413  return allocateQName(QString(), clarkName);
414  else
415  return QXmlName();
416  }
417 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
QString right(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n rightmost characters of the string.
Definition: qstring.cpp:3682
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
static bool isNCName(const QString &candidate)
Returns true if candidate is an NCName.
Definition: qxmlname.cpp:445
QXmlName allocateQName(const QString &uri, const QString &localName, const QString &prefix=QString())
Definition: qnamepool.cpp:251
static void splitQName(const QString &qName, QString &prefix, QString &localName)
Splits qName into localName and prefix.
static bool isQName(const QString &qName)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ stringForLocalName()

const QString& QPatternist::NamePool::stringForLocalName ( const QXmlName::LocalNameCode  code) const
inline

Definition at line 168 of file qnamepool_p.h.

Referenced by QPatternist::XsdSchema::addAnonymousType(), QXmlQuery::bindVariable(), QPatternist::LocalNameTest::displayName(), QPatternist::ReportContext::error(), QPatternist::LocalNameFN::evaluateSingleton(), QPatternist::LocalNameFromQNameFN::evaluateSingleton(), QXmlName::localName(), QPatternist::XsdSchemaParser::parseGlobalAttribute(), QPatternist::XsdSchemaParser::parseLocalAttribute(), QPatternist::XsdValidatingInstanceReader::selectNodeSets(), and toClarkName().

169  {
170  const QReadLocker l(&lock);
171  return m_localNames.at(code);
172  }
QVector< QString > m_localNames
Definition: qnamepool_p.h:109
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
QReadWriteLock lock
Definition: qnamepool_p.h:248
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
QFactoryLoader * l

◆ stringForNamespace()

const QString& QPatternist::NamePool::stringForNamespace ( const QXmlName::NamespaceCode  code) const
inline

◆ stringForPrefix()

const QString& QPatternist::NamePool::stringForPrefix ( const QXmlName::PrefixCode  code) const
inline

Definition at line 174 of file qnamepool_p.h.

Referenced by QPatternist::PrefixFromQNameFN::evaluateSingleton(), QPatternist::QNameConstructor::namespaceForPrefix(), QXmlName::prefix(), QPatternist::AccelTree::printStats(), and toClarkName().

175  {
176  const QReadLocker l(&lock);
177  return m_prefixes.at(code);
178  }
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
QReadWriteLock lock
Definition: qnamepool_p.h:248
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
QFactoryLoader * l

◆ toClarkName()

QString NamePool::toClarkName ( const QXmlName name) const

Definition at line 367 of file qnamepool.cpp.

Referenced by QXmlName::toClarkName().

368 {
369  if(name.isNull())
370  return QLatin1String("QXmlName(null)");
371  else
372  {
373  if(name.hasNamespace())
374  {
375  const QString ns(stringForNamespace(name.namespaceURI()));
376  const QString p(stringForPrefix(name.prefix()));
377  const QString l(stringForLocalName(name.localName()));
378 
379  return QChar::fromLatin1('{')
380  + ns
381  + QChar::fromLatin1('}')
382  + (p.isEmpty() ? l : p + QChar::fromLatin1(':') + l);
383  }
384  else
385  return stringForLocalName(name.localName());
386  }
387 }
const QString & stringForLocalName(const QXmlName::LocalNameCode code) const
Definition: qnamepool_p.h:168
bool hasNamespace() const
Returns true if this QXmlName has a non-empty namespace URI.
Definition: qnamepool_p.h:498
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
const QString & stringForPrefix(const QXmlName::PrefixCode code) const
Definition: qnamepool_p.h:174
static QChar fromLatin1(char c)
Converts the Latin-1 character c to its equivalent QChar.
Definition: qchar.h:378
QString localName(const QXmlNamePool &query) const
Returns the local name.
Definition: qxmlname.cpp:387
NamespaceCode namespaceURI() const
Definition: qnamepool_p.h:503
const QString & stringForNamespace(const QXmlName::NamespaceCode code) const
Definition: qnamepool_p.h:180
QFactoryLoader * l
bool isNull() const
Returns true if this QXmlName is not initialized with a valid combination of {namespace URI}...
Definition: qxmlname.cpp:224

◆ toLexical()

QString QPatternist::NamePool::toLexical ( const QXmlName  qName) const
inline

Definition at line 188 of file qnamepool_p.h.

Referenced by displayName(), QPatternist::NameFN::evaluateSingleton(), and QPatternist::QNameValue::stringValue().

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  }
QVector< QString > m_localNames
Definition: qnamepool_p.h:109
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString prefix(const QXmlNamePool &query) const
Returns the prefix.
Definition: qxmlname.cpp:370
bool hasPrefix() const
Returns true if this QXmlName has a non-empty prefix.
Definition: qnamepool_p.h:493
The QReadLocker class is a convenience class that simplifies locking and unlocking read-write locks f...
QReadWriteLock lock
Definition: qnamepool_p.h:248
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
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QFactoryLoader * l
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
bool isNull() const
Returns true if this QXmlName is not initialized with a valid combination of {namespace URI}...
Definition: qxmlname.cpp:224

◆ unlockedAllocateLocalName()

QXmlName::LocalNameCode NamePool::unlockedAllocateLocalName ( const QString ln)
private
Note
This function can not be called concurrently.

Definition at line 289 of file qnamepool.cpp.

Referenced by allocateQName(), and NamePool().

290 {
292  qPrintable(QString::fromLatin1("Invalid local name: \"%1\"").arg(ln)));
293 
294  int indexInLocalNames = m_localNameMapping.value(ln, NoSuchValue);
295 
296  if(indexInLocalNames == NoSuchValue)
297  {
298  indexInLocalNames = m_localNames.count();
299  m_localNames.append(ln);
300  m_localNameMapping.insert(ln, indexInLocalNames);
301  }
302 
303  return indexInLocalNames;
304 }
QHash< QString, QXmlName::LocalNameCode > m_localNameMapping
Definition: qnamepool_p.h:127
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QVector< QString > m_localNames
Definition: qnamepool_p.h:109
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
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
#define qPrintable(string)
Definition: qglobal.h:1750
static bool isNCName(const QStringRef &ncName)
Determines whether c is a valid instance of production [4]NCName in the XML 1.0 Namespaces specificat...
Definition: qxmlutils.cpp:377
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ unlockedAllocateNamespace()

QXmlName::NamespaceCode NamePool::unlockedAllocateNamespace ( const QString uri)
private
Note
This function can not be called concurrently.

Definition at line 320 of file qnamepool.cpp.

Referenced by allocateBinding(), allocateQName(), and NamePool().

321 {
322  int indexInURIs = m_namespaceMapping.value(uri, NoSuchValue);
323 
324  if(indexInURIs == NoSuchValue)
325  {
326  indexInURIs = m_namespaces.count();
327  m_namespaces.append(uri);
328  m_namespaceMapping.insert(uri, indexInURIs);
329  }
330 
331  return indexInURIs;
332 }
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
QHash< QString, QXmlName::NamespaceCode > m_namespaceMapping
Definition: qnamepool_p.h:125
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QVector< QString > m_namespaces
Definition: qnamepool_p.h:108

◆ unlockedAllocatePrefix()

QXmlName::PrefixCode NamePool::unlockedAllocatePrefix ( const QString prefix)
private

It's assumed that prefix is a valid NCName.

Note
This function can not be called concurrently.

Definition at line 306 of file qnamepool.cpp.

Referenced by allocateBinding(), allocateQName(), and NamePool().

307 {
308  int indexInPrefixes = m_prefixMapping.value(prefix, NoSuchValue);
309 
310  if(indexInPrefixes == NoSuchValue)
311  {
312  indexInPrefixes = m_prefixes.count();
313  m_prefixes.append(prefix);
314  m_prefixMapping.insert(prefix, indexInPrefixes);
315  }
316 
317  return indexInPrefixes;
318 }
QHash< QString, QXmlName::PrefixCode > m_prefixMapping
Definition: qnamepool_p.h:119
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QVector< QString > m_prefixes
Definition: qnamepool_p.h:107

Friends and Related Functions

◆ StandardNamespaces

friend class StandardNamespaces
friend

Definition at line 93 of file qnamepool_p.h.

Properties

◆ lock

QReadWriteLock QPatternist::NamePool::lock
mutableprivate

Definition at line 248 of file qnamepool_p.h.

Referenced by allocateBinding(), allocateQName(), and displayName().

◆ m_localNameMapping

QHash<QString, QXmlName::LocalNameCode> QPatternist::NamePool::m_localNameMapping
private

Definition at line 127 of file qnamepool_p.h.

Referenced by NamePool(), and unlockedAllocateLocalName().

◆ m_localNames

QVector<QString> QPatternist::NamePool::m_localNames
private

Definition at line 109 of file qnamepool_p.h.

Referenced by displayName(), NamePool(), and unlockedAllocateLocalName().

◆ m_namespaceMapping

QHash<QString, QXmlName::NamespaceCode> QPatternist::NamePool::m_namespaceMapping
private

Same as m_prefixMapping but applies for URIs, and hence m_namespaces instead of m_prefixes.

Definition at line 125 of file qnamepool_p.h.

Referenced by NamePool(), and unlockedAllocateNamespace().

◆ m_namespaces

QVector<QString> QPatternist::NamePool::m_namespaces
private

Definition at line 108 of file qnamepool_p.h.

Referenced by displayName(), NamePool(), and unlockedAllocateNamespace().

◆ m_prefixes

QVector<QString> QPatternist::NamePool::m_prefixes
private

Definition at line 107 of file qnamepool_p.h.

Referenced by displayPrefix(), NamePool(), and unlockedAllocatePrefix().

◆ m_prefixMapping

QHash<QString, QXmlName::PrefixCode> QPatternist::NamePool::m_prefixMapping
private

This hash contains no essential data, but speeds up finding a prefix in m_prefixes by mapping a prefix(the key) to the index into m_prefixes(which the value is).

In other words, one can skip this variable at the cost of having to linearly loop over prefixes, in order to find the entry.

Definition at line 119 of file qnamepool_p.h.

Referenced by NamePool(), and unlockedAllocatePrefix().


The documentation for this class was generated from the following files: