25 #ifndef UCOMMON_SYSRUNTIME
26 #ifndef _UCOMMON_STREAM_H_
27 #define _UCOMMON_STREAM_H_
29 #ifndef _UCOMMON_CONFIG_H
33 #ifndef _UCOMMON_PROTOCOLS_H_
37 #ifndef _UCOMMON_THREAD_H_
41 #ifndef _UCOMMON_SOCKET_H_
45 #ifndef _UCOMMON_FSYS_H_
49 #ifndef _UCOMMON_SHELL_H_
64 class __EXPORT
StreamBuffer :
protected std::streambuf,
public std::iostream
83 int uflow() __OVERRIDE;
87 void allocate(
size_t size);
96 inline bool is_open(
void)
const
99 inline operator bool()
const
100 {
return bufsize > 0;}
102 inline bool operator!()
const
103 {
return bufsize == 0;}
117 __LOCAL
void allocate(
unsigned size);
118 __LOCAL
void reset(
void);
124 virtual ssize_t _read(
char *buffer,
size_t size);
126 virtual ssize_t _write(
const char *buffer,
size_t size);
128 virtual bool _wait(
void);
141 int underflow(
void) __OVERRIDE;
149 int overflow(
int ch) __OVERRIDE;
151 inline socket_t getsocket(
void)
const {
175 tcpstream(
int family = PF_INET, timeout_t timeout = 0);
196 inline operator bool()
const {
197 return so != INVALID_SOCKET && bufsize > 0;
205 return so == INVALID_SOCKET || bufsize == 0;
221 void open(
const char *host,
const char *service,
unsigned segment = 536);
247 __LOCAL
void allocate(
size_t size, access_t mode);
266 int underflow(
void) __OVERRIDE;
275 int overflow(
int ch) __OVERRIDE;
291 pipestream(
const char *command, access_t access,
char **args,
char **env = NULL,
size_t size = 512);
302 inline operator bool()
const {
303 return (bufsize > 0);
322 void open(
const char *path, access_t access,
char **args,
char **env = NULL,
size_t buffering = 512);
333 void terminate(
void);
335 inline void cancel(
void) {
369 int underflow(
void) __OVERRIDE;
378 int overflow(
int ch) __OVERRIDE;
410 inline operator bool()
const {
411 return (bufsize > 0);
425 void open(
const char *filename,
fsys::access_t access,
size_t buffering = 512);
430 void open(
const char *filename,
unsigned mode,
fsys::access_t access,
size_t buffering = 512);
448 inline int err(
void)
const
456 class __EXPORT
imemstream :
protected std::streambuf,
public std::istream
462 const uint8_t *pos, *bp;
468 int underflow() __OVERRIDE;
470 int uflow() __OVERRIDE;
472 inline size_t remains()
const {
476 inline const uint8_t *mem()
const {
480 inline const char *chr()
const {
481 return (
const char *)bp;
484 inline size_t len()
const {
485 return (
size_t)(pos - bp) + count;
492 class __EXPORT
omemstream :
protected std::streambuf,
public std::ostream
502 explicit omemstream(uint8_t *data,
size_t size);
505 int overflow(
int ch) __OVERRIDE;
507 inline size_t remains()
const {
511 inline uint8_t *mem()
const {
515 inline char *chr()
const {
519 inline size_t len()
const {
520 return (
size_t)(pos - bp);
524 bool __EXPORT getline(std::istream& in,
char *buffer,
size_t size);
526 bool __EXPORT putline(std::ostream& out,
const char *buffer);
538 static std::ostream& print(std::ostream& out,
const PrintProtocol& format);
540 static std::istream& input(std::istream& inp,
InputProtocol& format);
542 static std::ostream& print(std::ostream& out,
const string_t& str);
544 static std::istream& input(std::istream& inp,
string_t& str);
546 static std::ostream& print(std::ostream& out,
const stringlist_t& list);
548 static std::istream& input(std::istream& in,
stringlist_t& list);
550 static std::string& append(std::string& target,
String& source);
553 inline std::ostream& operator<< (std::ostream& out,
const PrintProtocol& format) {
554 return _stream_operators::print(out, format);
557 inline std::istream& operator>> (std::istream& inp, InputProtocol& format) {
558 return _stream_operators::input(inp, format);
561 inline std::ostream& operator<< (std::ostream& out,
const string_t& str) {
562 return _stream_operators::print(out, str);
565 inline std::istream& operator>> (std::istream& inp,
string_t& str) {
566 return _stream_operators::input(inp, str);
569 inline std::ostream& operator<< (std::ostream& out,
const stringlist_t& list) {
570 return _stream_operators::print(out, list);
573 inline std::istream& operator>> (std::istream& in,
stringlist_t& list) {
574 return _stream_operators::input(in, list);
577 inline std::string& operator+(std::string& target, String& source) {
578 return _stream_operators::append(target, source);
581 inline std::string& operator+=(std::string& target, String& source) {
582 return _stream_operators::append(target, source);
585 inline std::ostream& operator<<(std::ostream& os, Socket::address&
addr) {
587 char buf[INET6_ADDRSTRLEN];
589 char buf[INET_ADDRSTRLEN];
591 addr.print(buf,
sizeof(buf),
false,
true);
599 extern __EXPORT iostream& null;