Clingo
Loading...
Searching...
No Matches
Clingo::Position Class Reference

Class representing a position in a file. More...

#include <core.hh>

Public Member Functions

 Position (clingo_position_t const *pos)
 Constructs a position from an existing C representation.
 
 Position (Library const &lib, std::string_view file, size_t line, size_t column)
 Constructs a position from a file, line, and column.
 
auto file () const -> std::string_view
 Get the file name of the position.
 
auto line () const -> size_t
 Get the line number of the position.
 
auto column () const -> size_t
 Get the column number of the position.
 
auto to_string () const -> std::string
 Convert the position to a string representation.
 
auto hash () const noexcept -> size_t
 Compute the hash of the position.
 

Friends

auto c_cast (Position const &x) -> clingo_position_t const *
 Cast a position to its C representation.
 
auto operator== (Position const &a, Position const &b) noexcept -> bool
 Compare two positions for equality.
 
auto operator<=> (Position const &a, Position const &b) noexcept -> std::strong_ordering
 Compare two positions.
 

Detailed Description

Class representing a position in a file.

Positions implement value semantics supporting ordering and hashing.

Constructor & Destructor Documentation

◆ Position() [1/2]

Clingo::Position::Position ( clingo_position_t const pos)
inlineexplicit

Constructs a position from an existing C representation.

For internal use.

Parameters
posthe C representation of the position

◆ Position() [2/2]

Clingo::Position::Position ( Library const lib,
std::string_view  file,
size_t  line,
size_t  column 
)
inlineexplicit

Constructs a position from a file, line, and column.

Parameters
libthe library to store symbols
filethe file name
linethe line number (1-based)
columnthe column number (1-based)

Member Function Documentation

◆ column()

auto Clingo::Position::column ( ) const -> size_t
inline

Get the column number of the position.

Returns
the column number (1-based)

◆ file()

auto Clingo::Position::file ( ) const -> std::string_view
inline

Get the file name of the position.

Returns
the file name as a string view

◆ hash()

auto Clingo::Position::hash ( ) const -> size_t
inlinenoexcept

Compute the hash of the position.

There is also a corresponding specialization of std::hash.

Returns
the hash value of the position

◆ line()

auto Clingo::Position::line ( ) const -> size_t
inline

Get the line number of the position.

Returns
the line number (1-based)

◆ to_string()

auto Clingo::Position::to_string ( ) const -> std::string
inline

Convert the position to a string representation.

Returns
the string representation of the position

Friends And Related Symbol Documentation

◆ c_cast

auto c_cast ( Position const x) -> clingo_position_t const *
friend

Cast a position to its C representation.

Parameters
xthe position to cast
Returns
the C representation of the position

◆ operator<=>

auto operator<=> ( Position const a,
Position const b 
) -> std::strong_ordering
friend

Compare two positions.

Parameters
athe first position to compare
bthe second position to compare
Returns
the comparison result

◆ operator==

auto operator== ( Position const a,
Position const b 
) -> bool
friend

Compare two positions for equality.

Parameters
athe first position to compare
bthe second position to compare
Returns
whether the two positions are equal

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