Mercurial > hg > aim92
diff stitch/source.h @ 0:5242703e91d3 tip
Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author | tomwalters |
---|---|
date | Fri, 20 May 2011 15:19:45 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stitch/source.h Fri May 20 15:19:45 2011 +0100 @@ -0,0 +1,191 @@ +/* + source.h + ======== + + + +*/ + +#ifndef _SOURCE_H_ +#define _SOURCE_H_ + +#include "buffer.h" + +/* standard entry points */ + +#define PullSome( _source, _bytes ) ( _SPTR( _source )->returned = _SPTR( _source )->pull( _SPTR( _source ), (ByteCount *) ( _bytes ) ) ) +#define FillSome( _source, _bytes, _buffer ) ( _SPTR( _source )->returned = _SPTR( _source )->fill( _SPTR( _source ), (ByteCount *) ( _bytes ), (Pointer ) ( _buffer ) ) ) +#define RollSome( _source, _bytes, _kept ) ( _SPTR( _source )->returned = _SPTR( _source )->roll( _SPTR( _source ), (ByteCount *) ( _bytes ), (ByteCount) ( _kept ) ) ) + +/* for compatability */ + +#define Pull( _source, _bytes ) ( _SPTR( _source )->returned = oldPull( _SPTR( _source ), (ByteCount ) ( _bytes ) ) ) +#define Fill( _source, _bytes, _buffer ) ( _SPTR( _source )->returned = oldFill( _SPTR( _source ), (ByteCount ) ( _bytes ), (Pointer ) ( _buffer ) ) ) +#define Roll( _source, _bytes, _kept ) ( _SPTR( _source )->returned = oldRoll( _SPTR( _source ), (ByteCount ) ( _bytes ), (ByteCount) ( _kept ) ) ) + +/* for more compatability */ + +#define Shift( _source, _bytes, _kept ) Roll( _source, _bytes, _kept ) + +/* count conversions */ + +#define ToPoints( _type, _bytes ) ( ( _bytes ) >> ( sizeof(_type) >> 1 ) ) +#define ToBytes( _type, _points ) ( ( char *) ( (_type *) 0l + ( _points ) ) - ( char *) 0l ) + +/* for convenience */ + +#define PullItems( _source, _number, _type ) ( (_type *) Pull( _source, ToBytes( _type, _number ) ) ) + +#define PullChars( _source, _number ) PullItems( _source, _number, char ) +#define PullShorts( _source, _number ) PullItems( _source, _number, short ) +#define PullInts( _source, _number ) PullItems( _source, _number, int ) +#define PullDoubles( _source, _number ) PullItems( _source, _number, double ) + + +#define FillItems( _source, _number, _buffer, _type ) ( (_type *) Fill( _source, ToBytes( _type, _number ), (Pointer) ( _buffer ) ) ) + +#define FillChars( _source, _number, _buffer ) FillItems( _source, _number, _buffer, char ) +#define FillShorts( _source, _number, _buffer ) FillItems( _source, _number, _buffer, short ) +#define FillInts( _source, _number, _buffer ) FillItems( _source, _number, _buffer, int ) +#define FillDoubles( _source, _number, _buffer ) FillItems( _source, _number, _buffer, double ) + + +#define RollItems( _source, _number, _keep, _type ) ( (_type *) Roll( _source, ToBytes( _type, _number ), ( _keep ) * sizeof ( _type ) ) ) + +#define RollChars( _source, _number, _keep ) RollItems( _source, _number, _keep, char ) +#define RollShorts( _source, _number, _keep ) RollItems( _source, _number, _keep, short ) +#define RollInts( _source, _number, _keep ) RollItems( _source, _number, _keep, int ) +#define RollDoubles( _source, _number, _keep ) RollItems( _source, _number, _keep, double ) + +/* operators on sources */ + +#define SetSource( _src, _puller, _filler, _roller, _name ) setSource( (struct _source *) _src, _puller, _filler, _roller, _name ) +#define TypeSource( _src, _type ) typeSource( (struct _source *) _src, _type ) +#define SourceType( _src ) sourceType( (struct _source *) _src ) +#define SourceName( _src ) sourceName( (struct _source *) _src ) +#define DeleteSource( _src ) deleteSource( (struct _source *) _src ) + +#if 00 +#define NameOfClass BasicSourceClass + +#define SetSource( _source, _puller, _filler, _roller, _name ) NameOfClass.set( (struct _source *) _source, _puller, _filler, _roller, _name ) +#define TypeSource( _source, _type ) NameOfClass.setType( (struct _source *) _source, _type ) +#define SourceType( _source ) NameOfClass.getType( (struct _source *) _source ) +#define SourceName( _source ) NameOfClass.getName( (struct _source *) _source ) +#define DeleteSource( _source ) NameOfClass.delete( (struct _source *) _source ) +#endif + + + +#define SinkSource( _source, _framebytes , _frames ) \ + sinkSource( _source, (ByteCount) ( _framebytes ), (long) _frames ) + +#define SinkAndCloseSource( _source, _framebytes , _frames ) \ + sinkAndCloseSource( _source, (ByteCount) ( _framebytes ), (long) _frames ) + +/* moving towards buffer abstraction, slowly */ + +#define SourceBuffer( _source ) ( ( _source )->buffer ) +#define SetSourceBuffer( _source, _buffer ) ( ( _source )->buffer = _buffer ) + +/* only pure source */ + +#define NewTappingSource( _source , _state, _callback, _close, _name ) \ + newTappingSource( (Pointer) ( _source ), _state, _callback, _close, _name ) + +#define NewRollableSource( _source ) \ + newRollableSource( _source ) + +#if 0 +/* for compatability */ + +#define NewShiftableSource( _source ) \ + NewRollableSource( _source ) +#endif + +/* for binding with C++ perhaps someday */ + +#if defined(__cplusplus) || defined(c_plusplus) +#define CPLPL 1 +#else +#define CPLPL 0 +#endif + +#if CPLPL + +#define _SPTR( _s ) ((_s).ptr) +#define _MANY_ARGS ... +#define _ONE_SOURCE Source source +#define _TWO_SOURCES Source source1, Source source2 +#define _ONE_SOURCE_PLUS Source source... + +typedef class _source &Source ; /* ?? or something */ + +#else + +#define _SPTR( _s ) _s +#define _MANY_ARGS /* ... */ +#define _ONE_SOURCE /* Source source */ +#define _TWO_SOURCES /* Source source1, Source source2 */ +#define _ONE_SOURCE_PLUS /* Source source... */ + +/* basic types */ + +typedef struct _source *Source, *SourceArray[1] ; + +#endif + +typedef Source CharSource, ShortSource, IntSource, FloatSource, DoubleSource, ComplexSource ; +typedef SourceArray CharSourceArray, ShortSourceArray, IntSourceArray, FloatSourceArray, DoubleSourceArray, ComplexSourceArray ; + +typedef int ByteCount ; + +/* dependant on type of source */ + +struct _source { Pointer (*pull)(), (*fill)(), (*roll)(), returned ; char *name, *type ; int opened ; Source (*open)() ; } ; +struct _source_operators { Source (*set)() ; Pointer (*delete)() ; Source (*setType)() ; char *(*getType)() ; char *(*getName)() ; } ; + +struct _pullable_source { struct _source parent ; } ; +struct _fillable_source { struct _source parent ; Buffer buffer ; } ; + +#if 00 +extern struct _source_operators NameOfClass ; +extern struct _source *call_conversions ; +#endif + +extern Source setSource() ; +extern Source typeSource() ; +extern char *sourceType() ; +extern char *sourceName() ; +extern Pointer deleteSource() ; + +extern Pointer oldPull(), oldFill(), oldRoll() ; + + +extern void sinkSource() ; +extern void CloseSource() ; +extern void sinkAndCloseSource() ; + +/* derived source types for different purposes */ + +extern Source newTappingSource() ; +extern Source newRollableSource() ; + +extern Pointer nonRoller() ; + +#include "pullable.h" + +#include "fillable.h" + +extern Source *BindSources() ; + +/* for compatability... for now */ + +extern Source stdStaticSource() ; +extern Source stdSlaveSource() ; +extern Source stdAutoSource() ; +extern Source stdSelfSource() ; + +#endif + +extern Source EmptySource ;