1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
16 #ifndef SQUIRRELJME_STREAM_H
17 #define SQUIRRELJME_STREAM_H
23 #ifndef SJME_CXX_IS_EXTERNED
24 #define SJME_CXX_IS_EXTERNED
25 #define SJME_CXX_SQUIRRELJME_STREAM_H
27 #endif /* #ifdef SJME_CXX_IS_EXTERNED */
28 #endif /* #ifdef __cplusplus */
30 /*--------------------------------------------------------------------------*/
33 * Represents a data stream that can be read from.
37 typedef struct sjme_stream_inputCore
* sjme_stream_input
;
40 * Represents a data stream that can be written to.
44 typedef struct sjme_stream_outputCore
* sjme_stream_output
;
47 * Determines the number of bytes which are quickly available before blocking
50 * @param stream The stream to read from.
51 * @param outAvail The number of bytes which are available.
52 * @return On any resultant error or {@code null}.
55 sjme_errorCode
sjme_stream_inputAvailable(
56 sjme_attrInNotNull sjme_stream_input stream
,
57 sjme_attrOutNotNull sjme_attrOutNegativeOnePositive sjme_jint
* outAvail
);
60 * Closes an input stream.
62 * @param stream The stream to close.
63 * @return Any resultant error, if any.
66 sjme_errorCode
sjme_stream_inputClose(
67 sjme_attrInNotNull sjme_stream_input stream
);
70 * Creates a stream which reads from the given block of memory.
72 * Memory based streams are never blocking.
74 * @param inPool The pool to allocate within.
75 * @param outStream The resultant stream.
76 * @param buffer The buffer to access.
77 * @param length The length of the buffer.
78 * @return On any resultant error, if any.
81 sjme_errorCode
sjme_stream_inputOpenMemory(
82 sjme_attrInNotNull sjme_alloc_pool
* inPool
,
83 sjme_attrOutNotNull sjme_stream_input
* outStream
,
84 sjme_attrInNotNull
void* buffer
,
85 sjme_attrInPositive sjme_jint length
);
88 * Reads from the given input stream and writes to the destination buffer.
90 * @param stream The stream to read from.
91 * @param readCount The number of bytes which were read.
92 * @param dest The destination buffer.
93 * @param length The number of bytes to read.
94 * @return Any resultant error, if any.
97 sjme_errorCode
sjme_stream_inputRead(
98 sjme_attrInNotNull sjme_stream_input stream
,
99 sjme_attrOutNotNull sjme_attrOutPositive sjme_jint
* readCount
,
100 sjme_attrOutNotNullBuf(length
) void* dest
,
101 sjme_attrInPositive sjme_jint length
);
104 * Reads from the given input stream and writes to the destination buffer.
106 * @param stream The stream to read from.
107 * @param readCount The number of bytes which were read.
108 * @param dest The destination buffer.
109 * @param offset The offset into the destination buffer.
110 * @param length The number of bytes to read.
111 * @return Any resultant error, if any.
114 sjme_errorCode
sjme_stream_inputReadIter(
115 sjme_attrInNotNull sjme_stream_input stream
,
116 sjme_attrOutNotNull sjme_attrOutPositive sjme_jint
* readCount
,
117 sjme_attrOutNotNullBuf(length
) void* dest
,
118 sjme_attrInPositive sjme_jint offset
,
119 sjme_attrInPositive sjme_jint length
);
122 * Closes an output stream.
124 * @param stream The stream to close.
125 * @return Any resultant error, if any.
128 sjme_errorCode
sjme_stream_outputClose(
129 sjme_attrInNotNull sjme_stream_output stream
);
131 /*--------------------------------------------------------------------------*/
135 #ifdef SJME_CXX_SQUIRRELJME_STREAM_H
137 #undef SJME_CXX_SQUIRRELJME_STREAM_H
138 #undef SJME_CXX_IS_EXTERNED
139 #endif /* #ifdef SJME_CXX_SQUIRRELJME_STREAM_H */
140 #endif /* #ifdef __cplusplus */
142 #endif /* SQUIRRELJME_STREAM_H */