1 #ifndef VCSN_MISC_STREAM_HH
2 # define VCSN_MISC_STREAM_HH
16 extern std::ostream
cnull;
19 extern std::wostream
wcnull;
24 bracketed(std::istream& i,
const char lbracket,
const char rbracket);
27 template <
typename ValueSet,
typename... Args>
29 conv(
const ValueSet& vs,
const std::string& str, Args&&... args)
30 -> decltype(vs.conv(std::declval<std::istream&>(),
31 std::forward<Args>(args)...))
33 std::istringstream i{str};
34 auto res = vs.conv(i, std::forward<Args>(args)...);
36 vs.sname(),
": invalid value: ", str,
46 char eat(std::istream&
is,
char c);
53 const std::string&
eat(std::istream&
is,
const std::string& s);
64 template <
typename ValueSet,
typename... Args>
67 const typename ValueSet::value_t& v, Args&&... args)
71 vs.print(v, o, std::forward<Args>(args)...);
88 #endif // !VCSN_MISC_STREAM_HH
std::string bracketed(std::istream &i, const char lbracket, const char rbracket)
Extract the string which is here between lbracket and rbracket.
std::ostream cnull
An narrow-char stream that discards the output.
std::string get_file_contents(const std::string &file)
Return the contents of file.
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 std::string &str)
Output a string, escaping special characters.
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.
std::istringstream is
The input stream: the specification to translate.
std::shared_ptr< std::istream > open_input_file(const std::string &file)
Open file for reading and return its autoclosing stream.
char eat(std::istream &is, char c)
Check lookahead character and advance.
std::wostream wcnull
An wide-char stream that discards the output.
ATTRIBUTE_NORETURN void fail_reading(std::istream &is, std::string explanation)
Throw an exception after failing to read from is.
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.
std::string to_string(direction d)
Conversion to string.