00001 #include "dt_stream_base.h" 00002 00003 #include <assert.h> 00004 00005 00006 #ifndef NDEBUG 00007 00008 unsigned dt_reader_instance_count = 0; 00010 unsigned dt_writer_instance_count = 0; 00011 #endif 00012 00013 00019 dt_bool dt_read ( dt_reader* obj, dt_stream_step* step ) 00020 { 00021 assert( (!!obj) && (obj->read_impl) && (obj->free_impl) ); 00022 assert( !! step ); 00023 00024 return obj->read_impl( obj, step ); 00025 } 00026 00028 void dt_free_reader( dt_reader* obj ) 00029 { 00030 assert( (!!obj) && (obj->read_impl) && (obj->free_impl) ); 00031 00032 obj->free_impl( obj ); 00033 #ifndef NDEBUG 00034 -- dt_reader_instance_count; 00035 #endif 00036 } 00037 00038 00044 dt_bool dt_write( dt_writer* obj, dt_stream_step const* step) 00045 { 00046 assert( (!!obj) && (obj->write_impl) && (obj->free_impl) ); 00047 assert( !! step ); 00048 00049 return obj->write_impl( obj, step ); 00050 } 00051 00053 void dt_free_writer( dt_writer* obj ) 00054 { 00055 assert( (!!obj) && (obj->write_impl) && (obj->free_impl) ); 00056 00057 obj->free_impl( obj ); 00058 #ifndef NDEBUG 00059 -- dt_writer_instance_count; 00060 #endif 00061 } 00062 00063 00064 00065 void dt_init_reader_base( dt_reader* reader 00066 , void (*free_impl)(dt_reader*) 00067 , dt_bool (*read_impl)(dt_reader*, dt_stream_step*) 00068 ) 00069 { 00070 reader->free_impl = free_impl; 00071 reader->read_impl = read_impl; 00072 #ifndef NDEBUG 00073 ++ dt_reader_instance_count; 00074 #endif 00075 } 00076 00077 void dt_init_writer_base( dt_writer* writer 00078 , void (*free_impl)(dt_writer*) 00079 , dt_bool (*write_impl)(dt_writer*, dt_stream_step const*) 00080 ) 00081 { 00082 writer->free_impl = free_impl; 00083 writer->write_impl = write_impl; 00084 #ifndef NDEBUG 00085 ++ dt_writer_instance_count; 00086 #endif 00087 } 00088 00089