12#ifndef TT_INCLUDE__STRAW_H
13#define TT_INCLUDE__STRAW_H
15class SCRIPTS_API Straw {
22 virtual void Get_From(Straw* straw);
23 virtual int Get(
void* source,
int slen);
25class SCRIPTS_API Buffer {
31 Buffer(
void* buffer,
long size);
32 Buffer(
long size) : BufferPtr(0), Size(size), IsAllocated(false)
36 BufferPtr =
new char[size];
51class SCRIPTS_API BufferStraw :
public Straw {
56 BufferStraw(
void* buffer,
int size);
58 int Get(
void* source,
int slen);
62class SCRIPTS_API FileStraw :
public Straw {
67 FileStraw(FileClass&);
69 int Get(
void* source,
int slen);
72class SCRIPTS_API CacheStraw :
public Straw {
78 CacheStraw(
int size) : BufferPtr(size), Index(0), Length(0)
83 return BufferPtr.Get_Buffer() != 0;
86 int Get(
void* source,
int slen)
88 char *src = (
char *)source;
92 if (BufferPtr.Get_Buffer())
94 for (
int i = source == 0;!i && len > 0;i = len2 == 0)
99 if (len > this->Length)
103 memmove(src,(
char *)BufferPtr.Get_Buffer() + Index,sz);
114 len2 = Straw::Get(BufferPtr.Get_Buffer(),BufferPtr.Get_Size());
123class SCRIPTS_API Pipe
129 Pipe() : ChainTo(0), ChainFrom(0)
136 ChainTo->ChainFrom = ChainFrom;
140 ChainFrom->Put_To(ChainTo);
149 return ChainTo->Flush();
160 virtual void Put_To(Pipe* pipe)
164 if (pipe && pipe->ChainFrom)
166 pipe->ChainFrom->Put_To(0);
171 ChainTo->ChainFrom = 0;
177 pipe->ChainFrom =
this;
181 virtual int Put(
const void *source,
int length)
185 return ChainTo->Put(source,length);
191class BufferPipe :
public Pipe
197 BufferPipe(
void *data,
int size) : BufferPtr(data,size), Index(0)
200 virtual int Put(
const void *source,
int length)
202 if (BufferPtr.Get_Buffer() && source && length > 0)
205 int size = BufferPtr.Get_Size();
216 memmove((
char *)(BufferPtr.Get_Buffer()) + Index,source,len);
224class FilePipe :
public Pipe
230 FilePipe(FileClass *file) : File(file), HasOpened(false)
235 if (File && HasOpened)
245 if (File && HasOpened)
252 virtual int Put(
const void *source,
int length)
254 if (File && source && length > 0)
256 if (!File->Is_Open())
261 return File->Write((
void *)source,length);