Change copyrights from Nokia to Digia
[profile/ivi/qtxmlpatterns.git] / src / xmlpatterns / api / qsourcelocation.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 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 #include "qdebug_p.h"
43
44 #include "qsourcelocation.h"
45
46
47 QT_BEGIN_NAMESPACE
48
49 /*!
50   \class QSourceLocation
51   \reentrant
52   \since 4.4
53   \brief The QSourceLocation class identifies a location in a resource by URI, line, and column.
54   \ingroup xml-tools
55   \inmodule QtXmlPatterns
56
57   QSourceLocation is a simple value based class that has three
58   properties, uri(), line(), and column(), that, taken together,
59   identify a certain point in a resource, e.g., a file or an in-memory
60   document.
61
62   line() and column() refer to character counts (not byte counts), and
63   they both start from 1, as opposed to 0.
64  */
65
66 /*!
67    Construct a QSourceLocation that doesn't identify anything at all.
68
69    For a default constructed QSourceLocation(), isNull() returns \c true.
70  */
71 QSourceLocation::QSourceLocation() : m_line(-1), m_column(-1)
72 {
73 }
74
75 /*!
76   Constructs a QSourceLocation that is a copy of \a other.
77  */
78 QSourceLocation::QSourceLocation(const QSourceLocation &other)
79   : m_line(other.m_line), m_column(other.m_column), m_uri(other.m_uri)
80 {
81 }
82
83 /*!
84  Constructs a QSourceLocation with URI \a u, line \a l and column \a c.
85  */
86 QSourceLocation::QSourceLocation(const QUrl &u, int l, int c)
87   : m_line(l), m_column(c), m_uri(u)
88 {
89 }
90
91 /*!
92   Destructor.
93  */
94 QSourceLocation::~QSourceLocation()
95 {
96 }
97
98 /*!
99   Returns true if this QSourceLocation is identical to \a other.
100
101   Two QSourceLocation instances are equal if their uri(), line() and
102   column() are equal.
103
104   QSourceLocation instances for which isNull() returns true are
105   considered equal.
106  */
107 bool QSourceLocation::operator==(const QSourceLocation &other) const
108 {
109     return    m_line == other.m_line
110            && m_column == other.m_column
111            && m_uri == other.m_uri;
112 }
113
114 /*!
115   Returns the opposite of applying operator==() for this QXmlName
116   and \a other.
117  */
118 bool QSourceLocation::operator!=(const QSourceLocation &other) const
119 {
120     return operator==(other);
121 }
122
123 /*!
124   Assigns this QSourceLocation instance to \a other.
125  */
126 QSourceLocation &QSourceLocation::operator=(const QSourceLocation &other)
127 {
128     if(this != &other)
129     {
130         m_line = other.m_line;
131         m_column = other.m_column;
132         m_uri = other.m_uri;
133     }
134
135     return *this;
136 }
137
138 /*!
139   Returns the current column number. The column number refers to the
140   count of characters, not bytes. The first column is column 1, not 0.
141   The default value is -1, indicating the column number is unknown.
142  */
143 qint64 QSourceLocation::column() const
144 {
145     return m_column;
146 }
147
148 /*!
149   Sets the column number to \a newColumn. 0 is an invalid column
150   number. The first column number is 1.
151  */
152 void QSourceLocation::setColumn(qint64 newColumn)
153 {
154     Q_ASSERT_X(newColumn != 0, Q_FUNC_INFO,
155                "0 is an invalid column number. The first column number is 1.");
156     m_column = newColumn;
157 }
158
159 /*!
160   Returns the current line number. The first line number is 1, not 0.
161   The default value is -1, indicating the line number is unknown.
162  */
163 qint64 QSourceLocation::line() const
164 {
165     return m_line;
166 }
167
168 /*!
169   Sets the line number to \a newLine. 0 is an invalid line
170   number. The first line number is 1.
171  */
172 void QSourceLocation::setLine(qint64 newLine)
173 {
174     m_line = newLine;
175 }
176
177 /*!
178   Returns the resource that this QSourceLocation refers to. For
179   example, the resource could be a file in the local file system,
180   if the URI scheme is \c file.
181  */
182 QUrl QSourceLocation::uri() const
183 {
184     return m_uri;
185 }
186
187 /*!
188   Sets the URI to \a newUri.
189  */
190 void QSourceLocation::setUri(const QUrl &newUri)
191 {
192     m_uri = newUri;
193 }
194
195 /*!
196   \relates QSourceLocation
197   \since 4.4
198
199   Prints \a sourceLocation to the debug stream \a debug.
200  */
201 #ifndef QT_NO_DEBUG_STREAM
202 QDebug operator<<(QDebug debug, const QSourceLocation &sourceLocation)
203 {
204     debug << "QSourceLocation("
205           << sourceLocation.uri()
206           << ", line:"
207           << sourceLocation.line()
208           << ", column:"
209           << sourceLocation.column()
210           << ')';
211     return debug;
212 }
213 #endif
214
215 /*!
216   Returns \c true if this QSourceLocation doesn't identify anything.
217
218   For a default constructed QSourceLocation, this function returns \c
219   true. The same applies for any other QSourceLocation whose uri() is
220   invalid.
221  */
222 bool QSourceLocation::isNull() const
223 {
224     return !m_uri.isValid();
225 }
226
227 /*!
228  \since 4.4
229
230  Computes a hash key for the QSourceLocation \a location.
231
232  \relates QSourceLocation
233  */
234 uint qHash(const QSourceLocation &location)
235 {
236     /* Not the world's best hash function exactly. */
237     return qHash(location.uri().toString()) + location.line() + location.column();
238 }
239
240 QT_END_NAMESPACE
241