acl/lib_acl_cpp/include/acl_cpp/stdlib/pipe_stream.hpp

167 lines
4.8 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
2014-11-19 00:25:21 +08:00
#include <list>
#include "noncopyable.hpp"
2017-06-02 14:47:24 +08:00
#include "string.hpp"
2014-11-19 00:25:21 +08:00
namespace acl {
/**
* ,
*
2014-11-19 00:25:21 +08:00
*/
class ACL_CPP_API pipe_stream : public noncopyable
2014-11-19 00:25:21 +08:00
{
public:
pipe_stream() {}
virtual ~pipe_stream() {}
/**
*
* @param in {const char*}
* @param len {size_t}
* @param out {string*}
* @param max {size_t} 0
* out
* @return {int} < 0
2014-11-19 00:25:21 +08:00
*/
virtual int push_pop(const char* in, size_t len,
string* out, size_t max = 0) = 0;
/**
*
* @param out {string*}
* @param max {size_t} 0
* out
* @return {int} < 0
2014-11-19 00:25:21 +08:00
*/
virtual int pop_end(string* out, size_t max = 0) = 0;
/**
*
2014-11-19 00:25:21 +08:00
*/
virtual void clear() {}
};
/**
*
2014-11-19 00:25:21 +08:00
*/
class ACL_CPP_API pipe_string : public pipe_stream
{
public:
pipe_string();
pipe_string(string& s);
virtual ~pipe_string();
// pipe_stream 基类中的四个虚函数
2014-11-19 00:25:21 +08:00
virtual int push_pop(const char* in, size_t len,
string* out, size_t max = 0);
virtual int pop_end(string* out, size_t max = 0);
virtual void clear()
{
m_pBuf->clear();
m_pos = 0;
}
string& get_buf() const
{
return (*m_pBuf);
}
char* c_str() const
{
return (m_pBuf->c_str());
}
size_t length() const
{
return (m_pBuf->length());
}
bool empty() const
{
return (m_pBuf->empty());
}
private:
string* m_pBuf;
string* m_pSavedBufPtr;
size_t m_pos;
};
/**
*
*
*
2014-11-19 00:25:21 +08:00
*/
class ACL_CPP_API pipe_manager : public noncopyable
2014-11-19 00:25:21 +08:00
{
public:
pipe_manager();
~pipe_manager();
/**
*
* @param stream {pipe_stream*}
* @return {bool} false
2014-11-19 00:25:21 +08:00
*/
bool push_back(pipe_stream* stream);
/**
*
* @param stream {pipe_stream*}
* @return {bool} false
2014-11-19 00:25:21 +08:00
*/
bool push_front(pipe_stream* stream);
/**
*
*
* @param src {const char*}
* @param len {size_t} src
* @param out {pipe_stream*}
*
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool update(const char* src, size_t len, pipe_stream* out = NULL);
/**
* 使
*
* @param out {pipe_stream*}
*
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool update_end(pipe_stream* out = NULL);
pipe_manager& operator<<(const string&);
pipe_manager& operator<<(const string*);
pipe_manager& operator<<(const char*);
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
pipe_manager& operator<<(__int64);
pipe_manager& operator<<(unsigned __int64);
#else
pipe_manager& operator<<(long long int);
pipe_manager& operator<<(unsigned long long int);
#endif
pipe_manager& operator<<(long);
pipe_manager& operator<<(unsigned long);
pipe_manager& operator<<(int);
pipe_manager& operator<<(unsigned int);
pipe_manager& operator<<(short);
pipe_manager& operator<<(unsigned short);
pipe_manager& operator<<(char);
pipe_manager& operator<<(unsigned char);
char* c_str() const;
size_t length() const;
void clear();
private:
std::list<pipe_stream*> m_streams;
string* m_pBuf1, *m_pBuf2;
pipe_string* m_pPipeStream;
};
} // namespace acl