1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtXmlPatterns module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
44 #include "qsourcelocation.h"
50 \class QSourceLocation
53 \brief The QSourceLocation class identifies a location in a resource by URI, line, and column.
56 QSourceLocation is a simple value based class that has three
57 properties, uri(), line(), and column(), that, taken together,
58 identify a certain point in a resource, e.g., a file or an in-memory
61 line() and column() refer to character counts (not byte counts), and
62 they both start from 1, as opposed to 0.
66 Construct a QSourceLocation that doesn't identify anything at all.
68 For a default constructed QSourceLocation(), isNull() returns \c true.
70 QSourceLocation::QSourceLocation() : m_line(-1), m_column(-1)
75 Constructs a QSourceLocation that is a copy of \a other.
77 QSourceLocation::QSourceLocation(const QSourceLocation &other)
78 : m_line(other.m_line), m_column(other.m_column), m_uri(other.m_uri)
83 Constructs a QSourceLocation with URI \a u, line \a l and column \a c.
85 QSourceLocation::QSourceLocation(const QUrl &u, int l, int c)
86 : m_line(l), m_column(c), m_uri(u)
93 QSourceLocation::~QSourceLocation()
98 Returns true if this QSourceLocation is identical to \a other.
100 Two QSourceLocation instances are equal if their uri(), line() and
103 QSourceLocation instances for which isNull() returns true are
106 bool QSourceLocation::operator==(const QSourceLocation &other) const
108 return m_line == other.m_line
109 && m_column == other.m_column
110 && m_uri == other.m_uri;
114 Returns the opposite of applying operator==() for this QXmlName
117 bool QSourceLocation::operator!=(const QSourceLocation &other) const
119 return operator==(other);
123 Assigns this QSourceLocation instance to \a other.
125 QSourceLocation &QSourceLocation::operator=(const QSourceLocation &other)
129 m_line = other.m_line;
130 m_column = other.m_column;
138 Returns the current column number. The column number refers to the
139 count of characters, not bytes. The first column is column 1, not 0.
140 The default value is -1, indicating the column number is unknown.
142 qint64 QSourceLocation::column() const
148 Sets the column number to \a newColumn. 0 is an invalid column
149 number. The first column number is 1.
151 void QSourceLocation::setColumn(qint64 newColumn)
153 Q_ASSERT_X(newColumn != 0, Q_FUNC_INFO,
154 "0 is an invalid column number. The first column number is 1.");
155 m_column = newColumn;
159 Returns the current line number. The first line number is 1, not 0.
160 The default value is -1, indicating the line number is unknown.
162 qint64 QSourceLocation::line() const
168 Sets the line number to \a newLine. 0 is an invalid line
169 number. The first line number is 1.
171 void QSourceLocation::setLine(qint64 newLine)
177 Returns the resource that this QSourceLocation refers to. For
178 example, the resource could be a file in the local file system,
179 if the URI scheme is \c file.
181 QUrl QSourceLocation::uri() const
187 Sets the URI to \a newUri.
189 void QSourceLocation::setUri(const QUrl &newUri)
195 \relates QSourceLocation
198 Prints \a sourceLocation to the debug stream \a debug.
200 #ifndef QT_NO_DEBUG_STREAM
201 QDebug operator<<(QDebug debug, const QSourceLocation &sourceLocation)
203 debug << "QSourceLocation("
204 << sourceLocation.uri()
206 << sourceLocation.line()
208 << sourceLocation.column()
215 Returns \c true if this QSourceLocation doesn't identify anything.
217 For a default constructed QSourceLocation, this function returns \c
218 true. The same applies for any other QSourceLocation whose uri() is
221 bool QSourceLocation::isNull() const
223 return !m_uri.isValid();
229 Computes a hash key for the QSourceLocation \a location.
231 \relates QSourceLocation
233 uint qHash(const QSourceLocation &location)
235 /* Not the world's best hash function exactly. */
236 return qHash(location.uri().toString()) + location.line() + location.column();