Qt 4.8
qvariabledeclaration_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_VariableDeclaration_H
53 #define Patternist_VariableDeclaration_H
54 
55 #include <QSharedData>
56 
57 #include "qexpression_p.h"
58 #include "qpatternistlocale_p.h"
59 #include "qvariablereference_p.h"
60 
62 
64 
65 template<typename T> class QStack;
66 
67 namespace QPatternist
68 {
78  {
79  public:
83 
88 
89  enum Type
90  {
96 
104 
110  };
111 
118  const VariableSlotID varSlot,
119  const Type t,
120  const SequenceType::Ptr &seqType) : name(n)
121  , slot(varSlot)
122  , type(t)
123  , sequenceType(seqType)
124  , canSourceRewrite(true)
125  {
126  Q_ASSERT(!name.isNull());
127  Q_ASSERT(t == ExternalVariable || t == TemplateParameter || varSlot > -1);
128  }
129 
130  inline bool isUsed() const
131  {
132  return !references.isEmpty();
133  }
134 
135  inline const Expression::Ptr &expression() const
136  {
137  return m_expression;
138  }
139 
140  inline void setExpression(const Expression::Ptr &expr)
141  {
142  m_expression = expr;
143  }
144 
148  inline bool usedByMany() const
149  {
150  return references.count() > 1;
151  }
152 
156  static bool contains(const VariableDeclaration::List &list,
157  const QXmlName &lookup);
158 
159  const QXmlName name;
161  const Type type;
162 
171 
178 
179  private:
182  };
183 
190  const NamePool::Ptr &np)
191  {
192  Q_ASSERT(var);
193  Q_ASSERT(np);
194  return formatKeyword(np->displayName(var->name));
195  }
196 
197 }
198 
200 
202 
203 #endif
qint32 VariableSlotID
QExplicitlySharedDataPointer< VariableDeclaration > Ptr
static QString formatKeyword(const VariableDeclaration::Ptr &var, const NamePool::Ptr &np)
Formats var appropriately for display.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
Represents a declared variable. Only used at the compilation stage.
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QExplicitlySharedDataPointer class represents a pointer to an explicitly shared object...
Definition: qshareddata.h:136
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
bool canSourceRewrite
Whether a reference can rewrite itself to expression().
The QStack class is a template class that provides a stack.
Definition: qcontainerfwd.h:63
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
QStack< VariableDeclaration::Ptr > Stack
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
QList< VariableDeclaration::Ptr > List
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The namespace for the internal API of QtXmlPatterns.
static bool contains(const VariableDeclaration::List &list, const QXmlName &lookup)
Returns true if list contains lookup.
VariableDeclaration(const QXmlName n, const VariableSlotID varSlot, const Type t, const SequenceType::Ptr &seqType)
The QXmlName class represents the name of an XML node, in an efficient, namespace-aware way...
Definition: qxmlname.h:58
Contains functions used for formatting arguments, such as keywords and paths, in translated strings...
The QSharedData class is a base class for shared data objects.
Definition: qshareddata.h:56
void setExpression(const Expression::Ptr &expr)
QHash< QXmlName, VariableDeclaration::Ptr > Hash
The key is the variable name.
bool usedByMany() const
Returns how many times this variable is used.
QList< QAElement > lookup(const QList< QAInterface > &interfaces)
#define QT_END_HEADER
Definition: qglobal.h:137
const Expression::Ptr & expression() const
bool isNull() const
Returns true if this QXmlName is not initialized with a valid combination of {namespace URI}...
Definition: qxmlname.cpp:224