Skip to content

Location

#include <tpau-cpp-kernal/Location.h>

INCLUDE FILE
#include <tpau-cpp-kernal/Location.h>

class Location

Represents a location within a file, including the file name, start position, and end position.

Line and column numbers are 1-based, and 0 indicates that it is not specified.

DEFINITION
class Location;

class Position

A position within a file.

Line and column numbers are 1-based, and 0 indicates that it is not specified.

DEFINITION
class Position;

constructor Position

Create an empty position.

DEFINITION
Position ( );

constructor Position

Create a position.

DEFINITION
Position ( size_t  line_number,
size_t  column );
PARAMETERDESCRIPTION
line_number

The line number, or 0 if the line number is not specified.

column

The column number, or 0 if the column number is not specified.

method column_indexconst

Get the 0-based column index of the position. If the column number is not specified, 0 is returned.

DEFINITION
size_t  column_index ( ) const;
RETURNSDESCRIPTION
size_t

The 0-based column index of the position, or 0 if the column number is not specified.

method emptyconst

Check if the position is empty (i.e. has no line number).

DEFINITION
bool  empty ( ) const;
RETURNSDESCRIPTION
bool

method has_columnconst

Check if the column number is specified.

DEFINITION
bool  has_column ( ) const;
RETURNSDESCRIPTION
bool

true if the column number is specified, false otherwise.

method has_lineconst

Check if the line number is specified.

DEFINITION
bool  has_line ( ) const;
RETURNSDESCRIPTION
bool

true if the line number is specified, false otherwise.

method line_indexconst

Get the 0-based line index of the position. If the line number is not specified, 0 is returned.

DEFINITION
size_t  line_index ( ) const;
RETURNSDESCRIPTION
size_t

The 0-based line index of the position, or 0 if the line number is not specified.

method operator boolconst

DEFINITION
operator bool ( ) const;

method operator!=const

Check if two positions are not equal.

DEFINITION
bool  operator!= ( const Position & other ) const;
PARAMETERDESCRIPTION
other

The position to compare with.

RETURNSDESCRIPTION
bool

true if the positions are not equal, false otherwise.

method operator<const

Check if this position is before another position.

DEFINITION
bool  operator< ( const Position & other ) const;
PARAMETERDESCRIPTION
other

The position to compare with.

RETURNSDESCRIPTION
bool

true if this position is before the other position, false otherwise.

method operator<=const

Check if this position is before or equal to another position.

DEFINITION
bool  operator<= ( const Position & other ) const;
PARAMETERDESCRIPTION
other

The position to compare with.

RETURNSDESCRIPTION
bool

true if this position is before or equal to the other position, false otherwise.

method operator==const

Check if two positions are equal.

DEFINITION
bool  operator== ( const Position & other ) const;
PARAMETERDESCRIPTION
other

The position to compare with.

RETURNSDESCRIPTION
bool

true if the positions are equal, false otherwise.

method operator>const

Check if this position is after another position.

DEFINITION
bool  operator> ( const Position & other ) const;
PARAMETERDESCRIPTION
other

The position to compare with.

RETURNSDESCRIPTION
bool

true if this position is after the other position, false otherwise.

method operator>=const

Check if this position is after or equal to another position.

DEFINITION
bool  operator>= ( const Position & other ) const;
PARAMETERDESCRIPTION
other

The position to compare with.

RETURNSDESCRIPTION
bool

true if this position is after or equal to the other position, false otherwise.

method to_stringconst

Convert the position to a string representation.

DEFINITION
std::string  to_string ( ) const;
RETURNSDESCRIPTION
std::string

The string representation of the position.

member column

The column number, or 0 if the column number is not specified.

DEFINITION
size_t  column;

member line_number

The line number, or 0 if the line number is not specified.

DEFINITION
size_t  line_number;

constructor Location

Empty location.

DEFINITION
Location ( );

constructor Location

Create a location that covers the range from the start of one location to the end of another location. If the two locations are in different files, the second location will be ignored.

DEFINITION
Location ( const Location & a,
const Location & b );
PARAMETERDESCRIPTION
a

The first location.

b

The second location.

constructor Location

Create a location.

DEFINITION
Location ( Symbol  file,
size_t  line_number,
size_t  start_column,
size_t  end_column );
PARAMETERDESCRIPTION
file
line_number

The line number, or 0 if the line number is not specified.

start_column

The starting column number, or 0 if the column number is not specified.

end_column

The ending column number, or 0 if the column number is not specified.

constructor Location

Create a location with a file name, line number, and column range.

DEFINITION
Location ( Symbol  file,
size_t  start_line_number,
size_t  start_column,
size_t  end_line_number,
size_t  end_column );
PARAMETERDESCRIPTION
file

The file symbol.

start_line_number

The starting line number, or 0 if the line number is not specified.

start_column

The starting column number, or 0 if the column number is not specified.

end_line_number

The ending line number, or 0 if the line number is not specified.

end_column

The ending column number, or 0 if the column number is not specified.

constructor Location

Create a location with only a file name.

DEFINITION
Location ( Symbol  file_name );
PARAMETERDESCRIPTION
file_name

The name of the file.

method emptyconst

Check if the location is empty (i.e. has no file).

DEFINITION
bool  empty ( ) const;
RETURNSDESCRIPTION
bool

true if the location is empty, false otherwise.

method extend

Extend the location by a number of columns.

DEFINITION
void  extend ( size_t  amount );
PARAMETERDESCRIPTION
amount

The number of columns to extend the location by.

method extend

Extend the location to include another location. If the other location is not in the same file, it will be ignored.

DEFINITION
void  extend ( const Location & other );
PARAMETERDESCRIPTION
other

method is_one_lineconst

Check if the location is within a single line.

DEFINITION
bool  is_one_line ( ) const;
RETURNSDESCRIPTION
bool

true if the location is within a single line, false otherwise.

method operator!=const

Check if two locations are not equal.

DEFINITION
bool  operator!= ( const Location & other ) const;
PARAMETERDESCRIPTION
other
RETURNSDESCRIPTION
bool

method operator<const

Check if this location is before another location.

Locations are ordered first by line number, then by column number. Locations in different files are not comparable.

DEFINITION
bool  operator< ( const Location & other ) const;
PARAMETERDESCRIPTION
other

The location to compare with.

RETURNSDESCRIPTION
bool

true if this location is before the other location, false otherwise.

method operator<=const

Check if this location is before or equal to another location.

DEFINITION
bool  operator<= ( const Location & other ) const;
PARAMETERDESCRIPTION
other

The location to compare with.

RETURNSDESCRIPTION
bool

true if this location is before or equal to the other location, false otherwise.

method operator==const

Check if two locations are equal.

DEFINITION
bool  operator== ( const Location & other ) const;
PARAMETERDESCRIPTION
other

The location to compare with.

RETURNSDESCRIPTION
bool

true if the locations are equal, false otherwise.

method operator>const

Check if this location is after another location.

Locations are ordered first by line number, then by column number. Locations in different files are not comparable.

DEFINITION
bool  operator> ( const Location & other ) const;
PARAMETERDESCRIPTION
other

The location to compare with.

RETURNSDESCRIPTION
bool

true if this location is after the other location, false otherwise.

method operator>=const

Check if this location is after or equal to another location.

DEFINITION
bool  operator>= ( const Location & other ) const;
PARAMETERDESCRIPTION
other

The location to compare with.

RETURNSDESCRIPTION
bool

true if this location is after or equal to the other location, false otherwise.

method to_stringconst

Convert the location to a string representation of the start of the location.

DEFINITION
std::string  to_string ( ) const;
RETURNSDESCRIPTION
std::string

A string representation of the start of the location.

method widthconst

Get the width of the location in columns.

If the location is not on a single line, or no start or end column is known, 0 is returned.

DEFINITION
size_t  width ( ) const;
RETURNSDESCRIPTION
size_t

The width of the location in columns, or 0 if it is not well defined.

member end

The position where the location ends.

DEFINITION
Position  end;

member file

The file.

DEFINITION
Symbol  file;

member start

The position where the location starts.

DEFINITION
Position  start;

class Position

A position within a file.

Line and column numbers are 1-based, and 0 indicates that it is not specified.

DEFINITION
class Position;

constructor Position

Create an empty position.

DEFINITION
Position ( );

constructor Position

Create a position.

DEFINITION
Position ( size_t  line_number,
size_t  column );
PARAMETERDESCRIPTION
line_number

The line number, or 0 if the line number is not specified.

column

The column number, or 0 if the column number is not specified.

method column_indexconst

Get the 0-based column index of the position. If the column number is not specified, 0 is returned.

DEFINITION
size_t  column_index ( ) const;
RETURNSDESCRIPTION
size_t

The 0-based column index of the position, or 0 if the column number is not specified.

method emptyconst

Check if the position is empty (i.e. has no line number).

DEFINITION
bool  empty ( ) const;
RETURNSDESCRIPTION
bool

method has_columnconst

Check if the column number is specified.

DEFINITION
bool  has_column ( ) const;
RETURNSDESCRIPTION
bool

true if the column number is specified, false otherwise.

method has_lineconst

Check if the line number is specified.

DEFINITION
bool  has_line ( ) const;
RETURNSDESCRIPTION
bool

true if the line number is specified, false otherwise.

method line_indexconst

Get the 0-based line index of the position. If the line number is not specified, 0 is returned.

DEFINITION
size_t  line_index ( ) const;
RETURNSDESCRIPTION
size_t

The 0-based line index of the position, or 0 if the line number is not specified.

method operator boolconst

DEFINITION
operator bool ( ) const;

method operator!=const

Check if two positions are not equal.

DEFINITION
bool  operator!= ( const Position & other ) const;
PARAMETERDESCRIPTION
other

The position to compare with.

RETURNSDESCRIPTION
bool

true if the positions are not equal, false otherwise.

method operator<const

Check if this position is before another position.

DEFINITION
bool  operator< ( const Position & other ) const;
PARAMETERDESCRIPTION
other

The position to compare with.

RETURNSDESCRIPTION
bool

true if this position is before the other position, false otherwise.

method operator<=const

Check if this position is before or equal to another position.

DEFINITION
bool  operator<= ( const Position & other ) const;
PARAMETERDESCRIPTION
other

The position to compare with.

RETURNSDESCRIPTION
bool

true if this position is before or equal to the other position, false otherwise.

method operator==const

Check if two positions are equal.

DEFINITION
bool  operator== ( const Position & other ) const;
PARAMETERDESCRIPTION
other

The position to compare with.

RETURNSDESCRIPTION
bool

true if the positions are equal, false otherwise.

method operator>const

Check if this position is after another position.

DEFINITION
bool  operator> ( const Position & other ) const;
PARAMETERDESCRIPTION
other

The position to compare with.

RETURNSDESCRIPTION
bool

true if this position is after the other position, false otherwise.

method operator>=const

Check if this position is after or equal to another position.

DEFINITION
bool  operator>= ( const Position & other ) const;
PARAMETERDESCRIPTION
other

The position to compare with.

RETURNSDESCRIPTION
bool

true if this position is after or equal to the other position, false otherwise.

method to_stringconst

Convert the position to a string representation.

DEFINITION
std::string  to_string ( ) const;
RETURNSDESCRIPTION
std::string

The string representation of the position.

member column

The column number, or 0 if the column number is not specified.

DEFINITION
size_t  column;

member line_number

The line number, or 0 if the line number is not specified.

DEFINITION
size_t  line_number;

function operator<<

Output location to a stream.

DEFINITION
std::ostream & operator<< ( std::ostream & os,
const Location & location );
PARAMETERDESCRIPTION
os

The stream to output to.

location

The location to output.

RETURNSDESCRIPTION
std::ostream &

The stream after outputting the location.