00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _ATX_STREAMS_H_
00011 #define _ATX_STREAMS_H_
00012
00013
00014
00015
00016 #include "AtxInterfaces.h"
00017 #include "AtxTypes.h"
00018 #include "AtxResults.h"
00019 #include "AtxDataBuffer.h"
00020 #include "AtxString.h"
00021
00022
00023
00024
00025 #define ATX_ERROR_EOS (ATX_ERROR_BASE_BYTE_STREAM - 0)
00026
00027
00028
00029
00030 #define ATX_INPUT_STREAM_PROPERTY_SEEK_SPEED "SeekSpeed"
00031 #define ATX_INPUT_STREAM_SEEK_SPEED_NO_SEEK 0
00032 #define ATX_INPUT_STREAM_SEEK_SPEED_SLOW 1
00033 #define ATX_INPUT_STREAM_SEEK_SPEED_MEDIUM 2
00034 #define ATX_INPUT_STREAM_SEEK_SPEED_FAST 3
00036
00037
00038
00039 ATX_DECLARE_INTERFACE(ATX_InputStream)
00040 ATX_BEGIN_INTERFACE_DEFINITION(ATX_InputStream)
00041 ATX_Result (*Read)(ATX_InputStream* self,
00042 ATX_Any buffer,
00043 ATX_Size bytes_to_read,
00044 ATX_Size* bytes_read);
00045 ATX_Result (*Seek)(ATX_InputStream* self, ATX_Position offset);
00046 ATX_Result (*Tell)(ATX_InputStream* self, ATX_Position* offset);
00047 ATX_Result (*GetSize)(ATX_InputStream* self, ATX_Size* size);
00048 ATX_Result (*GetAvailable)(ATX_InputStream* self,
00049 ATX_Size* available);
00050 ATX_END_INTERFACE_DEFINITION
00051
00052
00053
00054
00055 ATX_DECLARE_INTERFACE(ATX_OutputStream)
00056 ATX_BEGIN_INTERFACE_DEFINITION(ATX_OutputStream)
00057 ATX_Result (*Write)(ATX_OutputStream* self,
00058 ATX_AnyConst buffer,
00059 ATX_Size bytes_to_write,
00060 ATX_Size* bytes_written);
00061 ATX_Result (*Seek)(ATX_OutputStream* self, ATX_Position offset);
00062 ATX_Result (*Tell)(ATX_OutputStream* self, ATX_Position* offset);
00063 ATX_Result (*Flush)(ATX_OutputStream* self);
00064 ATX_END_INTERFACE_DEFINITION
00065
00066
00067
00068
00069 #ifdef __cplusplus
00070 extern "C" {
00071 #endif
00072
00073 ATX_Result ATX_OutputStream_WriteFully(ATX_OutputStream* stream,
00074 ATX_AnyConst buffer,
00075 ATX_Size bytes_to_write);
00076 ATX_Result ATX_OutputStream_WriteString(ATX_OutputStream* stream,
00077 ATX_CString string);
00078 ATX_Result ATX_OutputStream_WriteLine(ATX_OutputStream* stream,
00079 ATX_CString line);
00080 ATX_Result ATX_InputStream_ReadLine(ATX_InputStream* stream,
00081 char* line,
00082 ATX_Size line_size,
00083 ATX_Size* chars_read);
00084
00085 ATX_Result ATX_InputStream_ReadLineString(ATX_InputStream* stream,
00086 ATX_String* string,
00087 ATX_Size max_length);
00088
00089 ATX_Result ATX_InputStream_ReadFully(ATX_InputStream* stream,
00090 ATX_Any buffer,
00091 ATX_Size bytes_to_read);
00092
00093 ATX_Result ATX_InputStream_Skip(ATX_InputStream* stream,
00094 ATX_Size count);
00095
00096 ATX_Result ATX_InputStream_Load(ATX_InputStream* stream,
00097 ATX_Size max_read,
00098 ATX_DataBuffer** buffer);
00099 #ifdef __cplusplus
00100 }
00101 #endif
00102
00103
00104
00105
00106 #define ATX_InputStream_Read(object, buffer, bytes_to_read, bytes_read)\
00107 ATX_INTERFACE(object)->Read(object, \
00108 buffer, \
00109 bytes_to_read, \
00110 bytes_read)
00111
00112 #define ATX_InputStream_Seek(object, where) \
00113 ATX_INTERFACE(object)->Seek(object, where)
00114
00115 #define ATX_InputStream_Tell(object, where) \
00116 ATX_INTERFACE(object)->Tell(object, where)
00117
00118 #define ATX_InputStream_GetSize(object, size) \
00119 ATX_INTERFACE(object)->GetSize(object, size)
00120
00121 #define ATX_InputStream_GetAvailable(object, available) \
00122 ATX_INTERFACE(object)->GetAvailable(object, available)
00123
00124 #define ATX_OutputStream_Write(object, buffer, bytes_to_write, bytes_written) \
00125 ATX_INTERFACE(object)->Write(object, \
00126 buffer, \
00127 bytes_to_write, \
00128 bytes_written)
00129
00130 #define ATX_OutputStream_Seek(object, where) \
00131 ATX_INTERFACE(object)->Seek(object, where)
00132
00133 #define ATX_OutputStream_Tell(object, where) \
00134 ATX_INTERFACE(object)->Tell(object, where)
00135
00136 #define ATX_OutputStream_Flush(object) \
00137 ATX_INTERFACE(object)->Flush(object)
00138
00139
00140
00141
00142 ATX_DECLARE_INTERFACE(ATX_StreamTransformer)
00143 ATX_BEGIN_INTERFACE_DEFINITION(ATX_StreamTransformer)
00144 ATX_Result (*Transform)(ATX_StreamTransformer* self,
00145 ATX_AnyConst buffer,
00146 ATX_Size size);
00147 ATX_END_INTERFACE_DEFINITION
00148
00149 #define ATX_StreamTransformer_Transform(object, buffer, size) \
00150 ATX_INTERFACE(object)->Transform(object, buffer, size)
00151
00152
00153
00154
00155 typedef struct ATX_MemoryStream ATX_MemoryStream;
00156
00157 #ifdef __cplusplus
00158 extern "C" {
00159 #endif
00160
00161 ATX_Result
00162 ATX_MemoryStream_Create(ATX_Size size, ATX_MemoryStream** stream);
00163
00164 ATX_Result
00165 ATX_MemoryStream_Destroy(ATX_MemoryStream* self);
00166
00167 ATX_Result
00168 ATX_MemoryStream_GetBuffer(ATX_MemoryStream* self,
00169 const ATX_DataBuffer** buffer);
00170
00171 ATX_Result
00172 ATX_MemoryStream_GetInputStream(ATX_MemoryStream* self,
00173 ATX_InputStream** stream);
00174
00175 ATX_Result
00176 ATX_MemoryStream_GetOutputStream(ATX_MemoryStream* self,
00177 ATX_OutputStream** stream);
00178 #ifdef __cplusplus
00179 }
00180 #endif
00181
00182
00183
00184
00185 #ifdef __cplusplus
00186 extern "C" {
00187 #endif
00188
00189 ATX_Result ATX_SubInputStream_Create(ATX_InputStream* parent,
00190 ATX_Position offset,
00191 ATX_Size size,
00192 ATX_StreamTransformer* transformer,
00193 ATX_InputStream** stream);
00194
00195 ATX_Result ATX_SubOutputStream_Create(ATX_OutputStream* parent,
00196 ATX_Position offset,
00197 ATX_Size size,
00198 ATX_StreamTransformer* transformer,
00199 ATX_OutputStream** stream);
00200
00201 #ifdef __cplusplus
00202 }
00203 #endif
00204
00205 #endif
00206