86 lines
1.4 KiB
C++
Executable File
86 lines
1.4 KiB
C++
Executable File
// TJP COPYRIGHT HEADER
|
|
|
|
#pragma once
|
|
|
|
#include <list>
|
|
#include <tjp/core/types/Types.h>
|
|
#include <tjp/core/threads/Lock.hpp>
|
|
#include <string.h>
|
|
|
|
namespace tjp {
|
|
namespace core {
|
|
|
|
template<typename Packet, typename Mutex=core::Mutex>
|
|
struct Pipe
|
|
{
|
|
mutable Mutex mutex;
|
|
|
|
Pipe();
|
|
~Pipe();
|
|
|
|
typedef std::list<Packet> PacketList;
|
|
PacketList pipe;
|
|
size_t size_;
|
|
bool open;
|
|
bool flush_;
|
|
|
|
size_t sizeReadRequested = 0;
|
|
size_t sizeRead = 0;
|
|
void clearSizeRead();
|
|
|
|
size_t write (Packet &&);
|
|
size_t write_no_lock (Packet &&);
|
|
|
|
Packet read ();
|
|
Packet read_no_lock ();
|
|
|
|
bool empty() const;
|
|
bool empty_no_lock() const;
|
|
|
|
void close();
|
|
bool isOpen() const;
|
|
bool eos() const;
|
|
bool finishing() const;
|
|
bool flushing() const;
|
|
|
|
void flush() { flush_ = true; }
|
|
bool flushed();
|
|
|
|
size_t offset;
|
|
|
|
template<typename PipeOut>
|
|
void readInto (PipeOut &rhs)
|
|
{
|
|
while (!empty())
|
|
{
|
|
rhs.write(read());
|
|
}
|
|
|
|
if (flushed())
|
|
rhs.flush();
|
|
}
|
|
|
|
size_t read (char *buffer, size_t size_t);
|
|
size_t read_no_lock (char *buffer, size_t size_t);
|
|
|
|
size_t write (const char *buffer, size_t size_t);
|
|
size_t peek (char *buffer, size_t size_t) const;
|
|
size_t peek_no_lock (char *buffer, size_t size_t) const;
|
|
|
|
size_t skip(size_t size);
|
|
size_t skip_no_lock(size_t size);
|
|
|
|
size_t resize (size_t maximumSize);
|
|
|
|
size_t size () const;
|
|
const Packet *peek() const;
|
|
|
|
void clear();
|
|
} ;
|
|
|
|
} // namespace
|
|
} // namespace
|
|
|
|
#include "Pipe.inl"
|
|
|