The CyOS's stream modes have two basic streams that are abstractions for the sequential data access objects: Input and Output. Those streams can pump data to and from virtually any source, including disk file, network connection, console terminals and more. Those basic streams are used, in turn, with filter streams, that apply specific features to some abstract streams' filters.
Typical stream implementations include the file streams FileInput and FileOutput, console streams and various filters. Filter streams process the data from other streams. They take the other stream's objects while constructing, and are just like regular streams themselves. Typical filters are UNICODE/ASCII conversion, text formatting streams Reader and Writer and compressing streams Compressor and Decompressor.
Filters are intended to combine the desired stream implementation with the selected filter object, to combine the features that best suit your needs. This object is just an interface for an input stream.
Destructor.
#include <cywin.h> ... struct module_t main_module; struct Output* ptr_output; char tenth_byte = 100; ... ptr_output = Archive_open_write_Ex ( main_module.m_process->module->archive, "data.txt" ); ... Output_seekp( ptr_output, 10, SEEK_SET ); Output_write_byte( ptr_output, tenth_byte ); ... Output_dtor( ptr_output, FREE_MEMORY ); ...
Returns the current flags.
#include <cywin.h> ... char obtain_new_value(); ... struct module_t main_module; struct Output* ptr_output; char current_value; ... ptr_output = Archive_open_write_Ex ( main_module.m_process->module->archive, "data.txt" ); ... while( !( Output_get_flags(ptr_output) & FLAG_EOF ) ) { current_value = obtain_new_value(); Output_write_byte( ptr_output, current_value ); } ... Output_dtor( ptr_output, FREE_MEMORY ); ...
Returns the stream size (if applicable).
#include <cywin.h> ... char obtain_new_value(); ... struct module_t main_module; struct Output* ptr_output; char current_value; long size; ... ptr_output = Archive_open_write_Ex ( main_module.m_process->module->archive, "data.txt" ); ... size = Output_get_size( ptr_output ); for( index = 0; index < size; index++ ) { current_value = obtain_new_value(); Output_write_byte( ptr_output, current_value ); } ... Output_dtor( ptr_output, FREE_MEMORY ); ...
Returns TRUE if the BAD flag is set (stream is bad).
#include <cywin.h> ... struct Output *ptr_output; ... Output_ctor_Ex(ptr_output, "game.save"); if (!FileOutput_is_bad(ptr_output)) { //success } ... Output_dtor( ptr_output, LEAVE_MEMORY );
Returns TRUE if the EOF flag is set (stream reached end-of-file).
#include <cywin.h> ... char obtain_new_value(); ... struct module_t main_module; struct Output* ptr_output; char current_value; ... ptr_output = Archive_open_write_Ex ( main_module.m_process->module->archive, "data.txt" ); ... while( !( Output_is_eof(ptr_output)) { current_value = obtain_new_value(); Output_write_byte( ptr_output, current_value ); } ... Output_dtor( ptr_output, FREE_MEMORY ); ...
Returns TRUE if the BAD flag is not set (stream is good).
#include <cywin.h> ... struct Output *file_output; ... Output_ctor_Ex(file_output, "game.save"); if (FileOutput_is_good(file_output)) { //success } ... Output_dtor( &file_output, LEAVE_MEMORY );
Seeks an output stream.
If the stream supports a seek operation, it seeks to the specified position in the specified mode. If the requested seek operation cannot be done (not supported or wrong parameters), -1 will be returned. Seeking prior to the beginning of the stream sets the pointer to the stream's first byte. Seeking after the end of the stream sets the pointer to the end of the stream; then the stream will be extended with garbage bytes to the specified size.
#include <cywin.h> ... struct module_t main_module; struct Output* ptr_output; char tenth_byte = 100; ... ptr_output = Archive_open_write_Ex ( main_module.m_process->module->archive, "data.txt" ); ... Output_seekp( ptr_output, 10, SEEK_SET ); Output_write_byte( ptr_output, tenth_byte ); ... Output_dtor( ptr_output, FREE_MEMORY ); ...
Returns the stream's position.
#include <cywin.h> ... struct module_t main_module; struct Output* ptr_output; char tenth_byte = 100; long cur_pos; ... ptr_output = Archive_open_write_Ex ( main_module.m_process->module->archive, "data.txt" ); ... Output_seekp( ptr_output, 10, SEEK_SET ); Output_write_byte( ptr_output, tenth_byte ); // cur_pos will be equal to 11. cur_pos = Output_tellp( ptr_output ); ... Output_dtor( ptr_output, FREE_MEMORY ); ...
Writes the 'length' bytes to the stream.
#include <cywin.h> #include "score.h" ... struct Input* ptr_input; struct score_t high_scores[10]; ... struct module_t main_module; struct Output* ptr_output; char tenth_byte = 100; long cur_pos; ... ptr_output = Archive_open_write_Ex ( main_module.m_process->module->archive, "data.txt" ); ... Output_write( ptr_output, high_scores, sizeof( high_scores ) ); ... Output_dtor( ptr_output, FREE_MEMORY ); ...
Writes a byte to the stream.
#include <cywin.h> ... struct module_t main_module; struct Output* ptr_output; char tenth_byte = 100; ... ptr_output = Archive_open_write_Ex ( main_module.m_process->module->archive, "data.txt" ); ... Output_seekp( ptr_output, 10, SEEK_SET ); Output_write_byte( ptr_output, tenth_byte ); ... Output_dtor( ptr_output, FREE_MEMORY ); ...
Writes a 32-bit word, independent of hardware.
#include <cywin.h> ... long obtain_new_value(); ... struct module_t main_module; struct Output* ptr_output; long current_value; long size; ... ptr_output = Archive_open_write_Ex ( main_module.m_process->module->archive, "data.txt" ); ... size = Output_get_size( ptr_output )/sizeof(long); for( index = 0; index < size; index++ ) { current_value = obtain_new_value(); Output_write_dword( ptr_output, current_value ); } ... Output_dtor( ptr_output, FREE_MEMORY ); ...
Writes a 16-bit word, independent of hardware.
#include <cywin.h> ... int obtain_new_value(); ... struct module_t main_module; struct Output* ptr_output; int current_value; long size; ... ptr_output = Archive_open_write_Ex ( main_module.m_process->module->archive, "data.txt" ); ... size = Output_get_size( ptr_output )/sizeof(int); for( index = 0; index < size; index++ ) { current_value = obtain_new_value(); Output_write_word( ptr_output, current_value ); } ... Output_dtor( ptr_output, FREE_MEMORY ); ...