Evo C++ Library v0.5.1
Classes | Namespaces | Macros | Functions
io.h File Reference

Evo I/O streams and Console I/O. More...

#include "iobase.h"
#include "thread_inert.h"

Go to the source code of this file.

Classes

struct  Console
 Console I/O. More...
 
struct  ConsoleNotMT
 Single threaded console I/O. More...
 
struct  Pipe
 Pipe stream access. More...
 
class  PipeIn
 Input stream for reading from pipe. More...
 
class  PipeOut
 Output stream for writing to pipe. More...
 
struct  StreamExtMT< T, M >
 Extends an existing stream with mutex for multithreaded synchronization. More...
 
class  StreamIn< T >
 Input stream implementation. More...
 
class  StreamOut< T >
 Output stream implementation. More...
 

Namespaces

 evo
 Evo C++ Library namespace.
 

Macros

#define EVO_CATCH(CODE)
 Catch Evo Exception and print error message to stderr. More...
 
#define EVO_CONSOLE   static evo::Console& c = evo::con()
 Shortcut to define a Console for I/O. More...
 
#define INCL_evo_io_h
 

Functions

Console & con ()
 Shortcut for Console::get(). More...
 

Detailed Description

Evo I/O streams and Console I/O.

Macro Definition Documentation

◆ EVO_CATCH

#define EVO_CATCH (   CODE)
Value:
catch (const evo::Exception& e) { \
evo::Console& c = evo::con(); \
c.err << evo::NL << e.msg() << evo::SubString(" -- ", 4); \
evo::errormsg_out(c.err, e.error()); \
c.err << evo::NL; \
CODE; \
}
TOut & errormsg_out(TOut &out, Error err)
Write error message with errno to output stream/string.
Definition: sys.h:1203
Console & con()
Shortcut for Console::get().
Definition: io.h:1015
Evo base exception class.
Definition: sys.h:1214
static const NewlineDefault & NL
Default newline type.
Definition: sys.h:785
const char * msg() const
Get exception message.
Definition: sys.h:1254
Error error() const
Get error code.
Definition: sys.h:1260
Reference and access existing string data.
Definition: substring.h:229

Catch Evo Exception and print error message to stderr.

  • This does not terminate the program when the exception is caught, pass abort() (or return if applicable) in CODE to do that
  • Use after a try or catch block, where a "catch" would normally go (see example below)
  • For thread-safe variant see EVO_CATCH_MT()
Parameters
CODECode to run if exception is caught, abort() to terminate process, use just a semi-colon for none
Example
#include <evo/io.h>
int main() {
try {
// ...
return 0;
} EVO_CATCH(abort())
}

◆ EVO_CONSOLE

#define EVO_CONSOLE   static evo::Console& c = evo::con()

Shortcut to define a Console for I/O.

  • This defines "static Console& c" in current scope
  • This is normally used at the top of each function using Console streams
    • This may be used globally (not recommended), but you'll run into "redefinition of 'c'" errors if used (or included) in multiple source files
      • Note: Evo examples often use a static global for simplicity
    • This won't work in a class or struct outside of a function (must initialize static member out of line)
  • For thread-safe variant see EVO_CONSOLE_MT
Example
#include <evo/io.h>
using namespace evo;
void hello() {
c.out << "Hello" << NL;
}
int main() {
c.out << "Calling hello()" << NL;
hello();
return 0;
}

◆ INCL_evo_io_h

#define INCL_evo_io_h