SourceLocation.h revision fce4895d
1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef SOURCE_LOCATION_H
6#define SOURCE_LOCATION_H
7
8#include <SupportDefs.h>
9
10
11class SourceLocation {
12public:
13	SourceLocation(int32 line = 0, int32 column = 0)
14		:
15		fLine(line),
16		fColumn(column)
17	{
18	}
19
20	SourceLocation(const SourceLocation& other)
21		:
22		fLine(other.fLine),
23		fColumn(other.fColumn)
24	{
25	}
26
27	SourceLocation& operator=(const SourceLocation& other)
28	{
29		fLine = other.fLine;
30		fColumn = other.fColumn;
31		return *this;
32	}
33
34	bool operator==(const SourceLocation& other) const
35	{
36		return fLine == other.fLine && fColumn == other.fColumn;
37	}
38
39	bool operator!=(const SourceLocation& other) const
40	{
41		return !(*this == other);
42	}
43
44	bool operator<(const SourceLocation& other) const
45	{
46		return fLine < other.fLine
47			|| (fLine == other.fLine && fColumn < other.fColumn);
48	}
49
50	bool operator<=(const SourceLocation& other) const
51	{
52		return fLine < other.fLine
53			|| (fLine == other.fLine && fColumn <= other.fColumn);
54	}
55
56	int32 Line() const
57	{
58		return fLine;
59	}
60
61	int32 Column() const
62	{
63		return fColumn;
64	}
65
66private:
67	int32	fLine;
68	int32	fColumn;
69};
70
71
72#endif	// SOURCE_LOCATION_H
73