13 #ifndef _ERRORHANDLER_H
14 #define _ERRORHANDLER_H
22 template <
typename Iterator>
26 template <
typename,
typename,
typename>
37 : first(first), last(last) {}
45 template <
typename Message,
typename What>
47 Message
const& message,
49 Iterator err_pos)
const
52 Iterator line_start =
get_pos(err_pos, line);
55 std::cout << message << what <<
" line " << line <<
':' << std::endl;
56 std::cout <<
get_line(line_start) << std::endl;
57 for (; line_start != err_pos; ++line_start)
59 std::cout <<
'^' << std::endl;
63 std::cout <<
"Unexpected end of file. ";
64 std::cout << message << what <<
" line " << line << std::endl;
72 Iterator
get_pos(Iterator err_pos,
int& line)
const
76 Iterator line_start =
first;
80 if (i != err_pos && *i ==
'\r')
85 if (i != err_pos && *i ==
'\n')
103 Iterator i = err_pos;
105 while (i !=
last && (*i !=
'\r' && *i !=
'\n'))
107 return std::string(err_pos, i);
std::string get_line(Iterator err_pos) const
get line from iterator
probably used as some kind of type traits
Iterator first
begin iterator
Iterator get_pos(Iterator err_pos, int &line) const
get position of error
ErrorHandler(Iterator first, Iterator last)
constructor
Iterator last
end iterator
void operator()(Message const &message, What const &what, Iterator err_pos) const
API to invoke the error handler.
std::vector< Iterator > iters
not sure what it is used and why it is here