Qt 4.8
Public Functions | Properties | Related Functions | List of all members
QSourceLocation Class Reference

The QSourceLocation class identifies a location in a resource by URI, line, and column. More...

#include <qsourcelocation.h>

Public Functions

qint64 column () const
 Returns the current column number. More...
 
bool isNull () const
 Returns true if this QSourceLocation doesn't identify anything. More...
 
qint64 line () const
 Returns the current line number. More...
 
bool operator!= (const QSourceLocation &other) const
 Returns the opposite of applying operator==() for this QXmlName and other. More...
 
QSourceLocationoperator= (const QSourceLocation &other)
 Assigns this QSourceLocation instance to other. More...
 
bool operator== (const QSourceLocation &other) const
 Returns true if this QSourceLocation is identical to other. More...
 
 QSourceLocation ()
 Construct a QSourceLocation that doesn't identify anything at all. More...
 
 QSourceLocation (const QSourceLocation &other)
 Constructs a QSourceLocation that is a copy of other. More...
 
 QSourceLocation (const QUrl &uri, int line=-1, int column=-1)
 Constructs a QSourceLocation with URI u, line l and column c. More...
 
void setColumn (qint64 newColumn)
 Sets the column number to newColumn. More...
 
void setLine (qint64 newLine)
 Sets the line number to newLine. More...
 
void setUri (const QUrl &newUri)
 Sets the URI to newUri. More...
 
QUrl uri () const
 Returns the resource that this QSourceLocation refers to. More...
 
 ~QSourceLocation ()
 Destructor. More...
 

Properties

union {
   qint64   m_line
 
   QSourceLocationPrivate *   m_ptr
 
}; 
 
qint64 m_column
 
QUrl m_uri
 

Related Functions

(Note that these are not member functions.)

QDebug operator<< (QDebug debug, const QSourceLocation &sourceLocation)
 Prints sourceLocation to the debug stream debug. More...
 
uint qHash (const QSourceLocation &location)
 

Detailed Description

The QSourceLocation class identifies a location in a resource by URI, line, and column.

Note
This class or function is reentrant.
Since
4.4

QSourceLocation is a simple value based class that has three properties, uri(), line(), and column(), that, taken together, identify a certain point in a resource, e.g., a file or an in-memory document.

line() and column() refer to character counts (not byte counts), and they both start from 1, as opposed to 0.

Definition at line 56 of file qsourcelocation.h.

Constructors and Destructors

◆ QSourceLocation() [1/3]

QSourceLocation::QSourceLocation ( )

Construct a QSourceLocation that doesn't identify anything at all.

For a default constructed QSourceLocation(), isNull() returns true.

Definition at line 73 of file qsourcelocation.cpp.

73  : m_line(-1), m_column(-1)
74 {
75 }

◆ QSourceLocation() [2/3]

QSourceLocation::QSourceLocation ( const QSourceLocation other)

Constructs a QSourceLocation that is a copy of other.

Definition at line 80 of file qsourcelocation.cpp.

81  : m_line(other.m_line), m_column(other.m_column), m_uri(other.m_uri)
82 {
83 }

◆ QSourceLocation() [3/3]

QSourceLocation::QSourceLocation ( const QUrl uri,
int  line = -1,
int  column = -1 
)

Constructs a QSourceLocation with URI u, line l and column c.

Definition at line 88 of file qsourcelocation.cpp.

89  : m_line(l), m_column(c), m_uri(u)
90 {
91 }
unsigned char c[8]
Definition: qnumeric_p.h:62
quint16 u
QFactoryLoader * l

◆ ~QSourceLocation()

QSourceLocation::~QSourceLocation ( )

Destructor.

Definition at line 96 of file qsourcelocation.cpp.

97 {
98 }

Functions

◆ column()

qint64 QSourceLocation::column ( ) const

Returns the current column number.

The column number refers to the count of characters, not bytes. The first column is column 1, not 0. The default value is -1, indicating the column number is unknown.

Definition at line 145 of file qsourcelocation.cpp.

Referenced by QPatternist::ColoringMessageHandler::handleMessage(), operator<<(), and qHash().

146 {
147  return m_column;
148 }

◆ isNull()

bool QSourceLocation::isNull ( ) const

Returns true if this QSourceLocation doesn't identify anything.

For a default constructed QSourceLocation, this function returns true. The same applies for any other QSourceLocation whose uri() is invalid.

Definition at line 227 of file qsourcelocation.cpp.

Referenced by QPatternist::GenericStaticContext::addLocation(), QPatternist::ColoringMessageHandler::handleMessage(), and QPatternist::ReportContext::lookupSourceLocation().

228 {
229  return !m_uri.isValid();
230 }
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
Definition: qurl.cpp:4303

◆ line()

qint64 QSourceLocation::line ( ) const

Returns the current line number.

The first line number is 1, not 0. The default value is -1, indicating the line number is unknown.

Definition at line 165 of file qsourcelocation.cpp.

Referenced by QPatternist::ColoringMessageHandler::handleMessage(), operator<<(), and qHash().

166 {
167  return m_line;
168 }

◆ operator!=()

bool QSourceLocation::operator!= ( const QSourceLocation other) const

Returns the opposite of applying operator==() for this QXmlName and other.

Definition at line 120 of file qsourcelocation.cpp.

121 {
122  return operator==(other);
123 }
bool operator==(const QSourceLocation &other) const
Returns true if this QSourceLocation is identical to other.

◆ operator=()

QSourceLocation & QSourceLocation::operator= ( const QSourceLocation other)

Assigns this QSourceLocation instance to other.

Definition at line 128 of file qsourcelocation.cpp.

129 {
130  if(this != &other)
131  {
132  m_line = other.m_line;
133  m_column = other.m_column;
134  m_uri = other.m_uri;
135  }
136 
137  return *this;
138 }

◆ operator==()

bool QSourceLocation::operator== ( const QSourceLocation other) const

Returns true if this QSourceLocation is identical to other.

Two QSourceLocation instances are equal if their uri(), line() and column() are equal.

QSourceLocation instances for which isNull() returns true are considered equal.

Definition at line 109 of file qsourcelocation.cpp.

Referenced by operator!=().

110 {
111  return m_line == other.m_line
112  && m_column == other.m_column
113  && m_uri == other.m_uri;
114 }

◆ setColumn()

void QSourceLocation::setColumn ( qint64  newColumn)

Sets the column number to newColumn.

0 is an invalid column number. The first column number is 1.

Definition at line 154 of file qsourcelocation.cpp.

Referenced by QPatternist::XsdSchemaParser::currentSourceLocation(), QPatternist::XsdSchemaChecker::sourceLocation(), and QPatternist::XsdSchemaResolver::sourceLocation().

155 {
156  Q_ASSERT_X(newColumn != 0, Q_FUNC_INFO,
157  "0 is an invalid column number. The first column number is 1.");
158  m_column = newColumn;
159 }
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
#define Q_FUNC_INFO
Definition: qglobal.h:1871

◆ setLine()

void QSourceLocation::setLine ( qint64  newLine)

Sets the line number to newLine.

0 is an invalid line number. The first line number is 1.

Definition at line 174 of file qsourcelocation.cpp.

Referenced by QPatternist::XsdSchemaParser::currentSourceLocation(), QPatternist::XsdSchemaChecker::sourceLocation(), and QPatternist::XsdSchemaResolver::sourceLocation().

175 {
176  m_line = newLine;
177 }

◆ setUri()

void QSourceLocation::setUri ( const QUrl newUri)

◆ uri()

QUrl QSourceLocation::uri ( ) const

Returns the resource that this QSourceLocation refers to.

For example, the resource could be a file in the local file system, if the URI scheme is file.

Definition at line 184 of file qsourcelocation.cpp.

Referenced by QPatternist::ColoringMessageHandler::handleMessage(), operator<<(), and qHash().

185 {
186  return m_uri;
187 }

Friends and Related Functions

◆ operator<<()

QDebug operator<< ( QDebug  debug,
const QSourceLocation sourceLocation 
)
related

Prints sourceLocation to the debug stream debug.

Since
4.4

Definition at line 207 of file qsourcelocation.cpp.

208 {
209  debug << "QSourceLocation("
210  << sourceLocation.uri()
211  << ", line:"
212  << sourceLocation.line()
213  << ", column:"
214  << sourceLocation.column()
215  << ')';
216  return debug;
217 }
qint64 line() const
Returns the current line number.
QUrl uri() const
Returns the resource that this QSourceLocation refers to.
qint64 column() const
Returns the current column number.

◆ qHash()

uint qHash ( const QSourceLocation location)
related
Since
4.4

Computes a hash key for the QSourceLocation location.

Definition at line 239 of file qsourcelocation.cpp.

240 {
241  /* Not the world's best hash function exactly. */
242  return qHash(location.uri().toString()) + location.line() + location.column();
243 }
qint64 line() const
Returns the current line number.
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
uint qHash(const QSourceLocation &location)
QUrl uri() const
Returns the resource that this QSourceLocation refers to.
qint64 column() const
Returns the current column number.

Properties

◆ @375

union { ... }

◆ m_column

qint64 QSourceLocation::m_column
private

Definition at line 83 of file qsourcelocation.h.

Referenced by column(), operator=(), operator==(), and setColumn().

◆ m_line

qint64 QSourceLocation::m_line

Definition at line 80 of file qsourcelocation.h.

Referenced by line(), operator=(), operator==(), and setLine().

◆ m_ptr

QSourceLocationPrivate* QSourceLocation::m_ptr

Definition at line 81 of file qsourcelocation.h.

◆ m_uri

QUrl QSourceLocation::m_uri
private

Definition at line 84 of file qsourcelocation.h.

Referenced by isNull(), operator=(), operator==(), setUri(), and uri().


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