Pretty Diagnostics
Create your own pretty diagnostics
Loading...
Searching...
No Matches
pretty_diagnostics::Source Class Referenceabstract

Abstract interface for reading and mapping source text. More...

#include <source.hpp>

Inheritance diagram for pretty_diagnostics::Source:
[legend]

Public Member Functions

virtual ~Source ()=default
 
virtual Location from_coords (size_t row, size_t column) const =0
 Returns a location corresponding to the given row and column. More...
 
virtual Location from_index (size_t index) const =0
 Returns a location for the given absolute character index. More...
 
virtual std::string substr (const Location &start, const Location &end) const =0
 Returns the substring between two locations. More...
 
virtual std::string line (const Location &location) const =0
 Returns the full line at the given location. More...
 
virtual std::string line (size_t line_number) const =0
 Returns the contents of the specified line number. More...
 
virtual size_t line_count () const =0
 Returns the total number of lines in the source. More...
 
virtual std::string contents () const =0
 Returns the entire contents of the source. More...
 
virtual std::string path () const =0
 Returns a displayable path or identifier of the source. More...
 
virtual size_t size () const =0
 Returns the total size (in characters) of the source. More...
 

Detailed Description

Abstract interface for reading and mapping source text.

Constructor & Destructor Documentation

◆ ~Source()

virtual pretty_diagnostics::Source::~Source ( )
virtualdefault

Member Function Documentation

◆ contents()

virtual std::string pretty_diagnostics::Source::contents ( ) const
pure virtual

Returns the entire contents of the source.

Returns
Full source contents

Implemented in pretty_diagnostics::FileSource.

◆ from_coords()

virtual Location pretty_diagnostics::Source::from_coords ( size_t  row,
size_t  column 
) const
pure virtual

Returns a location corresponding to the given row and column.

Parameters
row0-based line number
column0-based column number
Returns
Mapped location.

Implemented in pretty_diagnostics::FileSource.

◆ from_index()

virtual Location pretty_diagnostics::Source::from_index ( size_t  index) const
pure virtual

Returns a location for the given absolute character index.

Parameters
index0-based absolute character index
Returns
Mapped location

Implemented in pretty_diagnostics::FileSource.

◆ line() [1/2]

virtual std::string pretty_diagnostics::Source::line ( const Location location) const
pure virtual

Returns the full line at the given location.

Parameters
locationA location within the desired line
Returns
The entire line contents without a trailing newline

Implemented in pretty_diagnostics::FileSource.

◆ line() [2/2]

virtual std::string pretty_diagnostics::Source::line ( size_t  line_number) const
pure virtual

Returns the contents of the specified line number.

Parameters
line_number1-based line number
Returns
The entire line contents without a trailing newline

Implemented in pretty_diagnostics::FileSource.

◆ line_count()

virtual size_t pretty_diagnostics::Source::line_count ( ) const
pure virtual

Returns the total number of lines in the source.

Returns
Line count

Implemented in pretty_diagnostics::FileSource.

◆ path()

virtual std::string pretty_diagnostics::Source::path ( ) const
pure virtual

Returns a displayable path or identifier of the source.

Returns
Display path or identifier

Implemented in pretty_diagnostics::FileSource.

◆ size()

virtual size_t pretty_diagnostics::Source::size ( ) const
pure virtual

Returns the total size (in characters) of the source.

Returns
Size of the source in characters

Implemented in pretty_diagnostics::FileSource.

◆ substr()

virtual std::string pretty_diagnostics::Source::substr ( const Location start,
const Location end 
) const
pure virtual

Returns the substring between two locations.

Parameters
startInclusive start location
endExclusive end location
Returns
Substring between start and end

Implemented in pretty_diagnostics::FileSource.


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