Zen API

- Home
- Topics
- Types
- Files

All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kStream.h
Go to the documentation of this file.
1
10 #ifndef K_API_STREAM_H
11 #define K_API_STREAM_H
12
13 #include <kApi/kApiDef.h>
14 #include <kApi/Io/kStream.x.h>
15
22 //typedef kObject kStream; --forward-declared in kApiDef.x.h
23
24 /*
25 * Public
26 */
27
37 kInlineFx(kStatus) kStream_Read(kStream stream, void* buffer, kSize size)
38 {
39 kObj(kStream, stream);
40
41 if ((obj->readEnd - obj->readBegin) < size)
42 {
43 return xkStream_VTable(stream)->VReadSomeImpl(stream, buffer, size, size, kNULL);
44 }
45
46 kMemCopy(buffer, &obj->readBuffer[obj->readBegin], size);
47 obj->readBegin += size;
48
49 return kOK;
50 }
51
63 kInlineFx(kStatus) kStream_ReadSome(kStream stream, void* buffer, kSize minCount, kSize maxCount, kSize* bytesRead)
64 {
65 kObj(kStream, stream);
66 kSize bufferAvailable = obj->readEnd - obj->readBegin;
67
68 if (bufferAvailable < minCount)
69 {
70 return xkStream_VTable(stream)->VReadSomeImpl(stream, buffer, minCount, maxCount, bytesRead);
71 }
72 else
73 {
74 kSize size = kMin_(bufferAvailable, maxCount);
75
76 kMemCopy(buffer, &obj->readBuffer[obj->readBegin], size);
77 obj->readBegin += size;
78
79 if (!kIsNull(bytesRead))
80 {
81 *bytesRead = size;
82 }
83 }
84
85 return kOK;
86 }
87
97 kInlineFx(kStatus) kStream_Write(kStream stream, const void* buffer, kSize size)
98 {
99 kObj(kStream, stream);
100
101 if ((obj->writeEnd - obj->writeBegin) < size)
102 {
103 return xkStream_VTable(stream)->VWriteImpl(stream, buffer, size);
104 }
105
106 kMemCopy(&obj->writeBuffer[obj->writeBegin], buffer, size);
107 obj->writeBegin += size;
108
109 return kOK;
110 }
111
121 kInlineFx(kStatus) kStream_Copy(kStream stream, kStream source, kSize size)
122 {
123 return kStream_CopyEx(stream, source, size, kNULL, kNULL);
124 }
125
141 kFx(kStatus) kStream_CopyEx(kStream stream, kStream source, kSize size, kCallbackFx progress, kPointer context);
142
151 kFx(kStatus) kStream_CopyAll(kStream stream, kStream source);
152
162 kInlineFx(kStatus) kStream_Seek(kStream stream, k64s offset, kSeekOrigin origin)
163 {
164 return xkStream_VTable(stream)->VSeek(stream, offset, origin);
165 }
166
174 kInlineFx(kStatus) kStream_Flush(kStream stream)
175 {
176 return xkStream_VTable(stream)->VFlush(stream);
177 }
178
186 kInlineFx(kStatus) kStream_Fill(kStream stream)
187 {
188 kObj(kStream, stream);
189
190 kCheckState(!kIsNull(obj->readBuffer));
191
192 if ((obj->readEnd - obj->readBegin) > 0)
193 {
194 return kOK;
195 }
196
197 return xkStream_VTable(stream)->VFill(stream);
198 }
199
207 kInlineFx(k64u) kStream_BytesRead(kStream stream)
208 {
209 kObj(kStream, stream);
210
211 return obj->bytesRead - (k64u)(obj->readEnd - obj->readBegin);
212 }
213
221 kInlineFx(k64u) kStream_BytesWritten(kStream stream)
222 {
223 kObj(kStream, stream);
224
225 return obj->bytesWritten + (k64u)obj->writeBegin;
226 }
227
235 kInlineFx(kStatus) kStream_ClearStats(kStream stream)
236 {
237 kObj(kStream, stream);
238
239 obj->bytesRead = 0;
240 obj->bytesWritten = 0;
241
242 return kOK;
243 }
244
245 /*
246 * Protected
247 */
248
260 kInlineFx(kStatus) kStream_Init(kStream stream, kType type, kAlloc allocator)
261 {
262 kCheck(kObject_Init(stream, type, allocator));
263
264 kInitFields(kStream, stream);
265
266 return kOK;
267 }
268
277 kInlineFx(kStatus) kStream_VRelease(kStream stream)
278 {
279 return kObject_VRelease(stream);
280 }
281
304 kInlineFx(kStatus) kStream_VReadSomeImpl(kStream stream, void* buffer, kSize minCount, kSize maxCount, kSize* bytesRead)
305 {
306 //legacy support: for classes that haven't been updated to implement VReadSomeImpl,
307 //try VReadImpl instead (deprecated, but still in the vtable)
308 kCheck(xkStream_VTable(stream)->VReadImpl(stream, buffer, minCount));
309
310 if (!kIsNull(bytesRead))
311 {
312 *bytesRead = minCount;
313 }
314
315 return kOK;
316 }
317
329 kInlineFx(kStatus) kStream_VWriteImpl(kStream stream, const void* buffer, kSize size)
330 {
331 return kERROR_UNIMPLEMENTED;
332 }
333
345 kInlineFx(kStatus) kStream_VSeek(kStream stream, k64s offset, kSeekOrigin origin)
346 {
347 return kERROR_UNIMPLEMENTED;
348 }
349
359 kInlineFx(kStatus) kStream_VFlush(kStream stream)
360 {
361 return kOK;
362 }
363
373 kInlineFx(kStatus) kStream_VFill(kStream stream)
374 {
375 return kERROR_UNIMPLEMENTED;
376 }
377
378 #endif
kObject::kObject_VRelease
kStatus kObject_VRelease(kObject object)
Protected virtual method that deallocates any resources owned by the object.
Definition: kObject.h:436
kStream::kStream_VFlush
kStatus kStream_VFlush(kStream stream)
Protected virtual method that flushes buffered writes to the underlying medium.
Definition: kStream.h:359
kStream::kStream_BytesRead
k64u kStream_BytesRead(kStream stream)
Reports the number of bytes read from this stream.
Definition: kStream.h:207
kMin_
#define kMin_(A, B)
Returns the minimum of two numbers.
Definition: kApiDef.h:1811
k64u
Represents a 64-bit unsigned integer.
kPointer
Represents a void pointer.
kPointer::kIsNull
#define kIsNull(POINTER)
Tests for equality with null pointer.
Definition: kApiDef.h:339
kStream::kStream_Copy
kStatus kStream_Copy(kStream stream, kStream source, kSize size)
Copies the specified number of bytes from one stream to another.
Definition: kStream.h:121
kStream::kStream_Flush
kStatus kStream_Flush(kStream stream)
Flushes buffered writes to the underlying medium.
Definition: kStream.h:174
kStream::kStream_VRelease
kStatus kStream_VRelease(kStream stream)
Protected virtual method that deallocates any resources owned by the object.
Definition: kStream.h:277
kObject::kObject_Init
kStatus kObject_Init(kObject object, kType type, kAlloc alloc)
Protected method called by derived classes to initialize the kObject base class.
Definition: kObject.h:347
kSize
Represents an unsigned integer that can store a pointer address.
kAlloc
Abstract base class for memory allocator types.
kCheck
#define kCheck(EXPRESSION)
Executes a return statement if the given expression is not kOK.
Definition: kApiDef.h:559
kStream::kStream_ReadSome
kStatus kStream_ReadSome(kStream stream, void *buffer, kSize minCount, kSize maxCount, kSize *bytesRead)
Reads up to the specified number of bytes from the stream.
Definition: kStream.h:63
kStream::kStream_VWriteImpl
kStatus kStream_VWriteImpl(kStream stream, const void *buffer, kSize size)
Protected virtual method that writes the specified number of bytes to the stream. ...
Definition: kStream.h:329
kInlineFx
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:26
kStream::kStream_Seek
kStatus kStream_Seek(kStream stream, k64s offset, kSeekOrigin origin)
Moves the read/write pointer to the specified location, if supported by the underlying stream...
Definition: kStream.h:162
kUtils::kMemCopy
kStatus kMemCopy(void *dest, const void *src, kSize size)
Copies memory from a source buffer to a non-overlapping destination.
kSeekOrigin
Represents a stream seek origin.
kStream::kStream_VReadSomeImpl
kStatus kStream_VReadSomeImpl(kStream stream, void *buffer, kSize minCount, kSize maxCount, kSize *bytesRead)
Protected virtual method that deallocates any resources owned by the object.
Definition: kStream.h:304
kStream::kStream_VFill
kStatus kStream_VFill(kStream stream)
Protected virtual method that partially fills the read buffer with bytes from the underlying medium...
Definition: kStream.h:373
kObj
#define kObj(TypeName_T, T_object)
Declares a local "obj" (this-pointer) variable and initializes it from a type-checked object handle...
Definition: kApiDef.h:2892
kStream::kStream_CopyAll
kStatus kStream_CopyAll(kStream stream, kStream source)
Copies all bytes from one stream to another.
kStream::kStream_VSeek
kStatus kStream_VSeek(kStream stream, k64s offset, kSeekOrigin origin)
Protected virtual method that moves the read/write pointer to the specified location.
Definition: kStream.h:345
kCheckState
#define kCheckState(EXPRESSION)
Executes a return statement if the given expression is not kTRUE.
Definition: kApiDef.h:593
kApiDef.h
Core Zen type declarations.
kStream
Represents an I/O stream.
kStream::kStream_Fill
kStatus kStream_Fill(kStream stream)
Partially fills the read buffer with bytes from the underlying medium.
Definition: kStream.h:186
kCallbackFx
kStatus(kCall * kCallbackFx)(kPointer receiver, kPointer sender, void *args)
Callback signature for a generic event handler.
Definition: kApiDef.h:1706
k64s
Represents a 64-bit signed integer.
kStream::kStream_CopyEx
kStatus kStream_CopyEx(kStream stream, kStream source, kSize size, kCallbackFx progress, kPointer context)
Copies the specified number of bytes from one stream to another, with progress feedback.
kStatus::kERROR_UNIMPLEMENTED
#define kERROR_UNIMPLEMENTED
Feature not implemented.
Definition: kApiDef.h:492
kStream::kStream_BytesWritten
k64u kStream_BytesWritten(kStream stream)
Reports the number of bytes written to this stream.
Definition: kStream.h:221
kType
Represents metadata about a type (class, interface, or value).
kInitFields
#define kInitFields(TYPE, OBJECT)
Zero-initializes the instance fields of the specified object.
Definition: kApiDef.h:2953
kStatus::kOK
#define kOK
Operation successful.
Definition: kApiDef.h:513
kStatus
Represents an error code.
kStream::kStream_Write
kStatus kStream_Write(kStream stream, const void *buffer, kSize size)
Writes the specified number of bytes to the stream.
Definition: kStream.h:97
kNULL
#define kNULL
Null pointer.
Definition: kApiDef.h:267
kStream::kStream_Init
kStatus kStream_Init(kStream stream, kType type, kAlloc allocator)
Protected method called by derived classes to initialize the kStream base class.
Definition: kStream.h:260
kStream::kStream_Read
kStatus kStream_Read(kStream stream, void *buffer, kSize size)
Reads the specified number of bytes from the stream.
Definition: kStream.h:37
kStream::kStream_ClearStats
kStatus kStream_ClearStats(kStream stream)
Clears stream statistics (e.g.
Definition: kStream.h:235