17 #ifndef AWALI_MISC_STREAM_HH
18 # define AWALI_MISC_STREAM_HH
29 namespace awali {
namespace sttc {
40 bracketed(std::istream& i,
const char lbracket,
const char rbracket);
43 template <
typename ValueSet,
typename... Args>
45 conv(
const ValueSet& vs,
const std::string& str, Args&&... args)
46 -> decltype(vs.conv(std::declval<std::istream&>(),
47 std::forward<Args>(args)...))
49 std::istringstream i{str};
50 auto res = vs.conv(i, std::forward<Args>(args)...);
52 throw std::domain_error(vs.sname() +
": invalid value: " + str
62 void eat(std::istream& is,
char c){
73 void eat(std::istream& is,
const std::string& expect){
76 size_t cnt = expect.size();
77 while (cnt && is >>
c)
97 std::getline(is, buf,
'\n');
107 template <
typename ValueSet,
typename... Args>
110 const typename ValueSet::value_t& v, Args&&... args)
113 std::ostringstream o;
114 vs.print(v, o, std::forward<Args>(args)...);
The semiring of complex numbers.
Definition: c.hh:44
void eat(std::istream &is, char c)
Check lookahead character and advance.
Definition: stream.hh:62
ATTRIBUTE_NORETURN void fail_reading(std::istream &is, std::string explanation)
Throw an exception after failing to read from is.
Definition: stream.hh:93
std::shared_ptr< std::ostream > open_output_file(const std::string &file)
Open file for writing and return its autoclosing stream.
std::ostream & str_escape(std::ostream &os, const int c)
Definition: escape.hh:30
std::string bracketed(std::istream &i, const char lbracket, const char rbracket)
An narrow-char stream that discards the output.
auto format(const ValueSet &vs, const typename ValueSet::value_t &v, Args &&... args) -> std::string
Format v via vs.print.
Definition: stream.hh:109
std::string get_file_contents(const std::string &file)
Return the contents of file.
std::shared_ptr< std::istream > open_input_file(const std::string &file)
Open file for reading and return its autoclosing stream.
void require(bool b, Args &&... args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:55
auto conv(const ValueSet &vs, const std::string &str, Args &&... args) -> decltype(vs.conv(std::declval< std::istream & >(), std::forward< Args >(args)...))
Parse str via vs.conv.
Definition: stream.hh:45
Main namespace of Awali.
Definition: ato.hh:22