/usr/include/kdevelop-pg-qt/kdev-pg-location-table.h is in kdevelop-pg-qt 1.0.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | /*
This file is part of kdev-pg
Copyright 2002-2006 Roberto Raggi <roberto@kdevelop.org>
Copyright 2009 Milian Wolff <mail@milianw.de>
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
KDEVELOP TEAM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//krazy:excludeall=inline
#ifndef KDEV_PG_LOCATION_TABLE_H
#define KDEV_PG_LOCATION_TABLE_H
#include <QtCore/QtGlobal>
#include <QtCore/qalgorithms.h> // krazy:exclude=includes
namespace KDevPG
{
class LocationTable
{
public:
inline LocationTable(qint64 size = 1024)
: lines(0), lineCount(0), currentLine(0), lastLine(0)
{
resize(size);
lines[currentLine++] = 0;
}
inline ~LocationTable()
{
free(lines);
}
inline qint64 size() const
{ return lineCount; }
void resize(qint64 size)
{
Q_ASSERT(size > 0);
lines = (qint64*) ::realloc(lines, sizeof(qint64) * size);
lineCount = size;
}
/**
* Returns the \a line and \a column of the given \a offset in this table.
*/
void positionAt(qint64 offset, qint64 *line, qint64 *column) const
{
if ( offset < 0 ) {
// invalid offset
*line = -1;
*column = -1;
return;
} else if ( offset > lines[currentLine - 1] ) {
// overflow
*line = currentLine - 1;
*column = offset - lines[currentLine - 1];
return;
}
qint64 i = -1;
// search relative to last line (next line and the one after that)
if ( lastLine + 1 < currentLine && lines[lastLine] <= offset ) {
if ( lines[lastLine + 1] > offset ) {
// last matched line matches again
i = lastLine;
} else if ( lastLine + 2 < currentLine && lines[lastLine + 2] > offset ) {
// next line relative to last matched matches
i = lastLine + 1;
}
}
if ( i == -1 ) {
// fallback to binary search
qint64 *it = qLowerBound(lines, lines + currentLine, offset);
Q_ASSERT(it != lines + currentLine);
if (*it != offset) {
--it;
}
*line = it - lines;
*column = offset - *it;
} else {
*line = i;
*column = offset - lines[i];
}
lastLine = *line;
}
/**
* Marks an \a offset as the character before the first one in the next line.
* The positionAt() function relies on newline() being called properly.
*/
inline void newline(qint64 offset)
{
if (currentLine == lineCount)
resize(currentLine * 2);
lines[currentLine++] = offset+1;
}
inline qint64 &operator[](int index)
{ return lines[index]; }
protected:
/// An array of input buffer offsets
qint64 *lines;
/// The size of the allocated array
qint64 lineCount;
/// The index to the next index in the lines array
qint64 currentLine;
/// Last line as found by positionAt
mutable qint64 lastLine;
private:
LocationTable(LocationTable const &other);
void operator=(LocationTable const &other);
};
}
#endif // KDEV_PG_LOCATION_TABLE_H
|