Defined in header <cparse/Cursor.hh>

std::string const& getFilename() const noexcept;

Returns the filename string held by the cursor, by const reference. The reference is stable for the lifetime of any Cursor referring to the same source (they all share the underlying string via shared_ptr).

If the cursor was constructed with an empty filename, returns a reference to a static empty string.

Parameters

None.

Return value

A const reference to the filename string. Never returns a dangling reference — the pointer's target is always allocated by the constructor, and the empty-name path returns a reference to a static std::string.

Exceptions

noexcept.

Notes

Used by Parser::recordError() to fill in the filename field of every emitted ParseError. Grammars typically read it in the same way when they need to construct a diagnostic themselves.

Example

#include <cparse/Cursor.hh>
#include <iostream>

int main()
{
    fedem::parser::Cursor c("input.txt");
    std::cout << "reading from: " << c.getFilename() << '\n';
    // reading from: input.txt
}

See also