44 #define EVO_CONSOLE static evo::Console& c = evo::con() 66 #if EVO_CATCH_DEBUG == 0 67 #define EVO_CATCH(CODE) catch (const evo::Exception& e) { \ 68 evo::Console& c = evo::con(); \ 69 c.err << evo::NL << e.msg() << evo::SubString(" -- ", 4); \ 70 evo::errormsg_out(c.err, e.error()); \ 75 #define EVO_CATCH(CODE) catch (const evo::Exception& e) { \ 76 evo::Console& c = evo::con(); \ 79 c.err << e.file() << '(' << e.line() << evo::SubString("): ", 3); \ 80 c.err << e.msg() << evo::SubString(" -- ", 4); \ 81 evo::errormsg_out(c.err, e.error()); \ 225 This& operator=(
const This&);
377 bool quote_optional =
false;
381 if (quote_optional && optional)
385 const char ch =
"'\"`"[(uint)type];
386 const Size result = size + 2;
394 const char* str = &
"'''\"\"\"```"[(uint(type) - 3) * 3];
395 const Size result = size + 6;
401 const char* str =
"`\x7F";
402 const Size result = size + 4;
416 ulong writtensize = bufwr_.writetext(
error_,
device_, buf, size);
418 if (writtensize == 0 || !bufwr_.writebin(
error_,
device_, bufwr_.newline, bufwr_.newlinesize) ) {
422 return writtensize + bufwr_.newlinesize;
429 if (size > bufwr_.size) {
433 if (bufwr_.avail() < size) {
441 return bufwr_.data + bufwr_.used;
445 if (reserve_size > bufwr_.avail()) {
451 if (reserve_size > bufwr_.size)
452 available = (
Size)bufwr_.size;
454 available = reserve_size;
456 available = reserve_size;
457 if (reserve_size == 0)
461 return bufwr_.data + bufwr_.used;
465 bufwr_.used += written_size;
466 assert( bufwr_.used <= bufwr_.size );
474 if (reserve_size > bufwr_.size) {
475 available = (
Size)bufwr_.size;
477 available = reserve_size;
478 if (reserve_size == 0)
487 assert( bufwr_.used <= bufwr_.size );
606 error_ = bufwr_.writefmtdump(
device_, fmt, bufwr_.newline, bufwr_.newlinesize);
636 writebin(bufwr_.newline, bufwr_.newlinesize);
646 const char* nl_str = nl.
getnewline(nl_size, bufwr_.newline, bufwr_.newlinesize);
693 template<
class TSize>
694 This& operator<<(const ListBase<char,TSize>& str) {
704 { writenum(num);
return *
this; }
708 { writenum(num);
return *
this; }
712 { writenum(num);
return *
this; }
716 { writenumu(num);
return *
this; }
720 { writenumu(num);
return *
this; }
724 { writenumu(num);
return *
this; }
728 This& operator<<(const IntegerT<U>& num) {
731 writenum(num.value());
733 writenumu(num.value());
740 { writenumf(num);
return *
this; }
744 { writenumf(num);
return *
this; }
748 { writenumf(num);
return *
this; }
752 This& operator<<(const FloatT<U>& num) {
768 const char* newline_str = fmt.
newline.
getnewline(newline_size, bufwr_.newline, bufwr_.newlinesize);
771 for (uint notfirst=0; str.token_line(line); ) {
774 if (
writebin(newline_str, newline_size) == 0)
793 substr.
set(line.
data(), i).stripr();
811 { writefmtnum(fmt.
num, fmt.
fmt);
return *
this; }
815 { writefmtnum(fmt.
num, fmt.
fmt);
return *
this; }
819 { writefmtnum(fmt.
num, fmt.
fmt);
return *
this; }
823 { writefmtnum(fmt.
num, fmt.
fmt);
return *
this; }
827 { writefmtnumu(fmt.
num, fmt.
fmt);
return *
this; }
831 { writefmtnumu(fmt.
num, fmt.
fmt);
return *
this; }
835 { writefmtnumu(fmt.
num, fmt.
fmt);
return *
this; }
839 { writefmtnumu(fmt.
num, fmt.
fmt);
return *
this; }
843 { writefmtnumf(fmt.
num, fmt.
fmt);
return *
this; }
847 { writefmtnumf(fmt.
num, fmt.
fmt);
return *
this; }
851 { writefmtnumf(fmt.
num, fmt.
fmt);
return *
this; }
855 This& operator<<(const FmtFieldNum<U>& fmt) {
857 writefmtnum(fmt.num.num, fmt.num.fmt, &fmt.field);
859 writefmtnumu(fmt.num.num, fmt.num.fmt, &fmt.field);
865 This& operator<<(const FmtFieldFloat<U>& fmt)
866 { writefmtnumf(fmt.num.num, fmt.num.fmt, &fmt.field);
return *
this; }
870 { writefmtnumu((ulong)fmtptr.
ptr, fmtptr.
fmt);
return *
this; }
874 { writefmtdump(fmt);
return *
this; }
882 void init(
bool flushlines=
false) {
883 bufwr_.
open(flushlines);
888 This& operator=(
const This&);
994 static const ulong IN_BUFSZ = 4096;
995 static const ulong OUT_BUFSZ = 4096;
996 static const ulong ERR_BUFSZ = 1024;
1004 out.
attach(HOUT,
false,
false);
1005 err.
attach(HERR,
false,
true);
1024 template<
class T,
class M>
1039 This& operator=(This&);
bool empty() const
Get whether empty.
Error readline(String &str, T &in, ulong maxlen=0)
Read a line from file using buffer.
Definition: sysio.h:947
void open(bool flushlines_val=false)
Initialize and open for output (writing).
Definition: sysio.h:1051
CharBreakType ascii_breaktype(char ch)
Get ASCII character word-break type.
Definition: str.h:91
bool flush()
Flush any pending output in stream write buffer, if buffered.
Definition: io.h:349
This & operator<<(ulong num)
Write formatted number to stream.
Definition: io.h:719
This & operator<<(char ch)
Write character to stream.
Definition: io.h:672
StreamExtMT< T, M > This
This type.
Definition: io.h:1026
const char * getnewline(Newline newline=NL)
Get newline string for given type.
Definition: sys.h:793
This & operator<<(int num)
Write formatted number to stream.
Definition: io.h:703
bool writenumu(TNum num, int base=fDEC)
Write formatted unsigned number.
Definition: io.h:508
SubString & triml(Size size)
Trim left (beginning) items.
Definition: substring.h:1307
This & operator<<(const FmtLongL &fmt)
Write formatted number field to stream.
Definition: io.h:822
Holds integer formatting attributes.
Definition: str.h:2589
This & operator<<(bool val)
Append a bool value to stream.
Definition: io.h:661
Output stream implementation.
Definition: io.h:261
This & operator<<(ulongl num)
Write formatted number to stream.
Definition: io.h:723
Holds a Newline value that can be null, which implicitly converts to NL_SYS (system default newline)...
Definition: sys.h:813
This & operator<<(const FmtDump &fmt)
Write formatted data dump to stream.
Definition: io.h:873
This & operator<<(uint num)
Write formatted number to stream.
Definition: io.h:715
This & operator<<(This &)
No-op used by formatting helpers.
Definition: io.h:620
StringBase str
Definition: str.h:3006
This & operator<<(const FmtString &fmt)
Write formatted string field to stream.
Definition: io.h:763
Invalid argument or data.
Definition: sys.h:1123
bool readline(String &str, ulong maxlen=0)
Read text line input from stream.
Definition: io.h:204
bool excep() const
Get whether exceptions are enabled.
Definition: iobase.h:52
Extends an existing stream with mutex for multithreaded synchronization.
Definition: io.h:1025
Handle detach()
Detach current stream.
Definition: io.h:311
ulong readbin(Error &err, T &in, void *buf, ulong bufsize)
Read from file using buffer.
Definition: sysio.h:751
bool writenum(TNum num, int base=fDEC)
Write formatted signed number.
Definition: io.h:493
T::ExceptionInT ExceptionInT
Stream input exception type
Definition: io.h:125
Single-quotes: '
Definition: strscan.h:1898
PipeOut(bool exceptions=1)
Constructor.
Definition: io.h:922
This & operator<<(double num)
Write formatted floating-point number to stream.
Definition: io.h:743
T::Handle Handle
Low-level handle type (OS dependent)
Definition: io.h:263
ulong readtext(Error &err, T &in, char *buf, ulong bufsize)
Read from file using buffer.
Definition: sysio.h:826
bool isopen() const
Get whether stream is open.
Definition: io.h:186
Console & con()
Shortcut for Console::get().
Definition: io.h:1015
bool write_direct_finish(Size size)
Finish writing directly to buffer.
Definition: io.h:485
PipeOut::Format Format
Stream output formatter with state.
Definition: io.h:1051
Console I/O.
Definition: io.h:972
Error error_
Last error code.
Definition: iobase.h:133
This & operator<<(Newline nl)
Write an explicit newline and flush stream.
Definition: io.h:624
Automatic floating point precision – either normal decimal notation or E notation, whichever is shorter (default)
Definition: str.h:2343
Single threaded console I/O.
Definition: io.h:1050
IoWriter & bufwrite()
Advanced: Access primary write buffer.
Definition: io.h:288
Backtick: `
Definition: strscan.h:1900
Triple backtick: ```
Definition: strscan.h:1903
Triple single-quotes: '''
Definition: strscan.h:1901
bool writefmtchar(char ch, ulong count, const FmtSetField &field)
Write formatted and/or repeated character.
Definition: io.h:537
virtual bool flush()
Flush any pending output in stream write buffer, if buffered.
Definition: iobase.h:127
bool isopen() const
Get whether stream is open.
Definition: io.h:344
This & operator<<(const FmtInt &fmt)
Write formatted number field to stream.
Definition: io.h:814
uint count
Character repeat count.
Definition: str.h:2916
bool excep_
Whether to throw exceptions.
Definition: iobase.h:134
Base text and binary stream interface.
Definition: iobase.h:145
Output stream exception for stream write errors, see Exception.
Definition: sys.h:1401
OutT err
Write to console, error output.
Definition: io.h:1058
Newline
Newline type.
Definition: sys.h:748
#define EVO_THROW_ERR_CHECK(TYPE, MSG, ERROR, COND)
Throw an Evo exception with error code if COND is true.
Definition: sys.h:1513
virtual ulong writechar(char ch, ulong count=1)
Write repeat character as text output to stream.
Definition: iobase.h:219
PipeIn(bool exceptions=1)
Constructor.
Definition: io.h:902
void open()
Initialize and open for input (reading).
Definition: sysio.h:690
PipeIn InT
Input type.
Definition: io.h:974
This & operator<<(const FmtULong &fmt)
Write formatted number field to stream.
Definition: io.h:834
StreamOut(Newline newlines=NL_SYS)
Constructor.
Definition: io.h:274
PipeOut err
Write to console, error output.
Definition: io.h:979
ulong writeline(const char *buf, ulong size)
Write text line output to stream.
Definition: io.h:415
Basic integer type.
Definition: type.h:980
char * write_direct(Size size)
Get pointer for writing directly to buffer to append data.
Definition: io.h:428
FmtSetFloat fmt
Definition: str.h:3156
bool writefmtnumf(TNum num, const FmtSetFloat &fmt, const FmtSetField *field=NULL)
Write formatted floating point number with field alignment.
Definition: io.h:590
int width
Definition: str.h:3007
Size size() const
Get size.
This & operator<<(const FmtUInt &fmt)
Write formatted number field to stream.
Definition: io.h:830
PipeOut OutT
Output type.
Definition: io.h:975
No error.
Definition: sys.h:1115
Reached end of resource (not an error)
Definition: sys.h:1116
Evo inert synchronization implementation.
#define EVO_EXCEPTIONS
Whether to throw exceptions on error by default.
Definition: evo_config.h:35
StreamExtMT< PipeOut, MutexInert > OutT
Output type.
Definition: io.h:1053
virtual ulong writebin(const void *buf, ulong size)
Write binary output to stream.
Definition: iobase.h:113
uint getnewlinesize(Newline newline=NL)
Get newline string size for given type.
Definition: sys.h:804
Base 10: decimal (default)
Definition: str.h:2323
ulong writechar(char ch, ulong count=1)
Write repeat character as text output to stream.
Definition: io.h:364
String container.
Definition: string.h:674
char * write_direct_multi(Size &available, Size reserve_size)
Definition: io.h:444
Evo base I/O stream classes.
Pipe stream access.
Definition: io.h:935
This & operator<<(const NewlineValue &nl)
Write newline value and flush stream.
Definition: io.h:643
Buffered reader for IoDevice (used internally).
Definition: sysio.h:658
Key findnonwordr(Key start=0, Key end=END) const
Find last non-word character with reverse search.
Definition: substring.h:949
T::ExceptionOutT ExceptionOutT
Stream output exception type
Definition: io.h:269
IoWriter bufwr_
Write buffer.
Definition: io.h:879
InT in
Read console input.
Definition: io.h:1056
Input stream implementation.
Definition: io.h:120
Flush
Signals an output stream to flush pending data.
Definition: sys.h:739
ulong writebin(const void *buf, ulong size)
Write binary output to stream.
Definition: io.h:358
SubString & stripl()
Strip left (beginning) whitespace (spaces and tabs).
Definition: substring.h:1090
void init()
Initialize and reset buffers for a new stream.
Definition: io.h:219
bool writefmtnumu(TNum num, const FmtSetInt &fmt, const FmtSetField *field=NULL)
Write formatted unsigned number with field alignment.
Definition: io.h:575
This & operator<<(const FmtULongL &fmt)
Write formatted number field to stream.
Definition: io.h:838
OutT out
Write to console, normal output.
Definition: io.h:1057
This & operator<<(NewlineDefault nl)
Write default newline and flush stream.
Definition: io.h:633
StreamIn< T > This
This stream type.
Definition: io.h:123
This & operator<<(const FmtUShort &fmt)
Write formatted number field to stream.
Definition: io.h:826
RawBuffer readbuf
Primary read buffer – filtering may involve additional buffers.
Definition: sysio.h:661
Explicitly format an integer.
Definition: str.h:3065
Inert lock that doesn't do anything.
Definition: thread_inert.h:27
StreamOut< T > This
This stream type.
Definition: io.h:264
const char * getnewline() const
Get newline string pointer for current value.
Definition: sys.h:885
This & operator<<(long num)
Write formatted number to stream.
Definition: io.h:707
bool writenumf(TNum num, int precision=fPREC_AUTO)
Write formatted floating-point number.
Definition: io.h:523
bool writefmtdump(const FmtDump &fmt)
Write formatted data dump.
Definition: io.h:604
This & operator<<(const FmtPtr &fmtptr)
Writer formatted pointer field to stream.
Definition: io.h:869
void attach(Handle handle, bool owned=true)
Attach existing input stream.
Definition: io.h:147
This & operator<<(const FmtFloatL &fmt)
Write formatted number field to stream.
Definition: io.h:850
Handle handle() const
Get stream handle for low-level calls.
Definition: io.h:284
This & operator<<(const FmtStringWrap &fmt)
Definition: io.h:766
This & operator<<(const FmtFloatD &fmt)
Write formatted number field to stream.
Definition: io.h:846
PipeIn in
Read console input.
Definition: io.h:977
FmtSetInt fmt
Formatting attributes.
Definition: str.h:3266
ulong Size
Data size type (ulong)
Definition: iobase.h:146
RawBuffer & bufread()
Advanced: Access primary read buffer.
Definition: io.h:140
Double-quotes: "
Definition: strscan.h:1899
RawBuffer & resize(ulong newsize)
Resize buffer.
Definition: rawbuffer.h:116
This & operator<<(const SubString &str)
Write substring to stream.
Definition: io.h:686
Triple double-quotes: """
Definition: strscan.h:1902
This & operator<<(Flush)
Flush buffer by writing to stream.
Definition: io.h:654
Evo C++ Library namespace.
Definition: alg.h:11
Out & write_out()
Definition: io.h:425
static const EndT NONE
Special integer value for indicating no item or unknown item.
Definition: type.h:1832
StreamExtMT< PipeIn, MutexInert > InT
Input type.
Definition: io.h:1052
bool writefmtstr(const char *buf, ulong size, const FmtSetField &field)
Write text with field alignment.
Definition: io.h:548
Holds floating point formatting attributes.
Definition: str.h:2775
Explicitly format a string.
Definition: str.h:2931
ulong readtext(char *buf, ulong size)
Read text input from stream.
Definition: io.h:198
~StreamOut()
Destructor.
Definition: io.h:280
PipeOut out
Write to console, normal output.
Definition: io.h:978
bool owned_
Whether handle is owned (to be closed here)
Definition: io.h:878
StreamExtMT(T &stream)
Constructor.
Definition: io.h:1034
M mutex
Stream mutex.
Definition: io.h:1028
bool owned_
Whether handle is owned (to be closed here)
Definition: io.h:215
T num
Definition: str.h:3155
This & operator<<(const FmtChar &fmt)
Write repeated character to stream.
Definition: io.h:759
bool close()
Close stream.
Definition: io.h:174
This Out
Type returned by write_out()
Definition: io.h:265
FmtSetInt fmt
Formatting attributes.
Definition: str.h:3072
This & operator<<(ldouble num)
Write formatted floating-point number to stream.
Definition: io.h:747
void attach(Handle handle, bool owned=true, bool flushlines=false)
Attach existing output stream.
Definition: io.h:296
bool writefmtnum(TNum num, const FmtSetInt &fmt, const FmtSetField *field=NULL)
Write formatted signed number with field alignment.
Definition: io.h:560
static const Newline NL_SYS
Current system newline type.
Definition: sys.h:763
Buffered writer for IoDevice (used internally).
Definition: sysio.h:1023
T * data_
Data pointer, NULL if null.
Definition: sys.h:979
Backtick followed by DEL char (7F) – last resort (rare)
Definition: strscan.h:1904
PipeOut::Format Format
Stream output formatter with state.
Definition: io.h:973
Explicitly format a repeated character.
Definition: str.h:2914
PipeIn in
Definition: io.h:936
This & operator<<(const FmtFloat &fmt)
Write formatted number field to stream.
Definition: io.h:842
Handle handle() const
Get stream handle for low-level calls.
Definition: io.h:136
char * write_direct_flush(Size &available, Size written_size, Size reserve_size)
Definition: io.h:464
Default newline type, implicitly converts to NL_SYS (system default newline).
Definition: sys.h:773
StreamFormatter< This > Format
Stream output formatter with state.
Definition: io.h:267
Explicitly format a pointer.
Definition: str.h:3264
Size writequoted(const char *buf, Size size, char delim, bool optional=false)
Write quoted text output to string.
Definition: io.h:376
StreamIn(Newline newlines=NL_SYS)
Constructor.
Definition: io.h:130
int indent
Definition: str.h:3008
static Type get(const char *data, ulong data_size)
Definition: strscan.h:1917
This & operator<<(float num)
Write formatted floating-point number to stream.
Definition: io.h:739
T::Handle Handle
Low-level handle type (OS dependent)
Definition: io.h:122
TSize size_
Data size as item count, 0 if empty or null.
Definition: sys.h:980
StringBase str
Definition: str.h:2936
ulong readbin(void *buf, ulong size)
Read binary input from stream.
Definition: io.h:192
Handle detach()
Detach current stream.
Definition: io.h:161
This & operator<<(const FmtLong &fmt)
Write formatted number field to stream.
Definition: io.h:818
const void * ptr
Pointer to format.
Definition: str.h:3265
PipeOut out
Definition: io.h:937
T & stream
Stream object.
Definition: io.h:1029
Punctuation used before a word begins, break words before this ( ([{< )
Definition: str.h:63
This & operator<<(const char *str)
Write terminated string to stream.
Definition: io.h:679
SubString & set(const char *data)
Set as reference to terminated string.
Definition: substring.h:353
Reference and access existing string data.
Definition: substring.h:229
IoReader bufrd_
Buffered reader.
Definition: io.h:216
char ch
Character to format.
Definition: str.h:2915
Input stream for reading from pipe.
Definition: io.h:895
FmtSetField fmt
Definition: str.h:2937
void close()
Close input.
Definition: sysio.h:699
ulong writetext(const char *buf, ulong size)
Write text output to stream.
Definition: io.h:370
Output stream for writing to pipe.
Definition: io.h:915
Explicitly format a floating pointer number.
Definition: str.h:3148
Simple raw memory buffer.
Definition: rawbuffer.h:34
Holds field and alignment formatting attributes.
Definition: str.h:2481
T num
Number to format.
Definition: str.h:3071
NewlineValue newline
Definition: str.h:3009
This & operator<<(longl num)
Write formatted number to stream.
Definition: io.h:711
void init(bool flushlines=false)
Initialize and reset buffers for a new stream.
Definition: io.h:882
bool close()
Close stream.
Definition: io.h:327
T device_
I/O handle.
Definition: io.h:214
Data not quotable (invalid text)
Definition: strscan.h:1905
Explicitly format a hex dump from buffer.
Definition: str.h:3294
#define EVO_PARAM_UNUSED(NAME)
Mark function parameter as unused to suppress "unreferenced parameter" compiler warnings on it...
Definition: sys.h:427
static Console & get()
Get console instance to use.
Definition: io.h:984
const char * data() const
Get data pointer.
MutexInert::Lock Lock
Mutex lock type.
Definition: io.h:1054
This & operator<<(const FmtShort &fmt)
Write formatted number field to stream.
Definition: io.h:810
Type
Quoting type.
Definition: strscan.h:1897
T device_
I/O handle.
Definition: io.h:877