Pretty Diagnostics
Create your own pretty diagnostics
Loading...
Searching...
No Matches
pretty_diagnostics::FileSource Class Referencefinal

A Source implementation that reads from a file on disk. More...

#include <source.hpp>

Inheritance diagram for pretty_diagnostics::FileSource:
[legend]

Public Member Functions

 FileSource (const std::filesystem::path &path, const std::filesystem::path &working_path=std::filesystem::current_path())
 Creates a file source from a filesystem path. More...
 
- Public Member Functions inherited from pretty_diagnostics::StringSource
 StringSource (std::string contents, std::string display_path="<memory>")
 Creates a string source with an optional display path. More...
 
Location from_coords (size_t row, size_t column) const override
 Maps (row, column) to a Location within the string. More...
 
Location from_index (size_t index) const override
 Maps an absolute index to a Location within the string. More...
 
std::string substr (const Location &start, const Location &end) const override
 Extracts a substring delimited by two locations. More...
 
std::string line (const Location &location) const override
 Returns the contents of the line containing the given location. More...
 
std::string line (size_t line_number) const override
 Returns the contents of the specified line number. More...
 
size_t line_count () const override
 Returns the total number of lines in the string. More...
 
const std::string & contents () const override
 Returns the entire contents of the source. More...
 
std::string path () const override
 Returns a displayable path or identifier of the source. More...
 
size_t size () const override
 Returns the total size (in characters) of the source. More...
 
- Public Member Functions inherited from pretty_diagnostics::Source
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 const 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...
 

Friends

bool operator== (const FileSource &lhs, const FileSource &rhs)
 Equality compares path. More...
 
bool operator!= (const FileSource &lhs, const FileSource &rhs)
 Inequality based on operator== More...
 

Detailed Description

A Source implementation that reads from a file on disk.

Constructor & Destructor Documentation

◆ FileSource()

pretty_diagnostics::FileSource::FileSource ( const std::filesystem::path &  path,
const std::filesystem::path &  working_path = std::filesystem::current_path() 
)
explicit

Creates a file source from a filesystem path.

Parameters
pathPath to the file on disk (absolute or relative)
working_pathOptional path to make the path relative

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const FileSource lhs,
const FileSource rhs 
)
friend

Inequality based on operator==

Parameters
lhsLeft-hand file source
rhsRight-hand file source
Returns
True if the paths differ

◆ operator==

bool operator== ( const FileSource lhs,
const FileSource rhs 
)
friend

Equality compares path.

Parameters
lhsLeft-hand file source
rhsRight-hand file source
Returns
True if paths are equal

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