home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-17 | 1.9 KB | 115 lines | [TEXT/CWIE] |
- // FileInStream.cp
-
- #ifndef FileInStream_h
- #include "FileInStream.h"
- #endif
- #ifndef Data_h
- #include "Data.h"
- #endif
- #ifndef FileReadingPath_h
- #include "FileReadingPath.h"
- #endif
- #ifndef __DEVICES__
- #include <Devices.h>
- #endif
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- FileInStream::FileInStream()
- {
- ioParam.ioPosMode = fsFromStart;
- }
-
- Task *FileInStream::NonblockingRead( Data buffer )
- {
- return BlockingRead( buffer );
- }
-
- Task *FileInStream::BlockingRead( Data buffer )
- {
- Assert( !Running() );
- ioParam.ioBuffer = reinterpret_cast<Ptr>( buffer.Start() );
- ioParam.ioReqCount = buffer.Length();
-
- return this;
- }
-
- void FileInStream::Launch()
- {
- Assert( !Running() );
- PBReadAsync( this );
- }
-
- void FileInStream::Kill()
- {
- }
-
- void FileInStream::AtCompletion()
- {
- Assert( !Running() );
-
- ReportRead( ioParam.ioActCount );
-
- if ( ioParam.ioResult != noErr )
- {
- if ( ioParam.ioResult == eofErr )
- ReportEnd();
- else
- ReportFailure();
- }
- }
-
- void FileInStream::SetFile( const FileReadingPath& path,
- uint32 position )
- {
- Assert( !Running() );
- Assert( path.IsOpen() );
-
- ioParam.ioRefNum = path.RefNum();
- ioParam.ioPosOffset = position;
- Reset();
- }
-
- void FileInStream::ClearFile()
- {
- Assert( !Running() );
- ioParam.ioRefNum = 0;
- Reset();
- }
-
- uint32 FileInStream::Position() const
- {
- Assert( !Running() );
- Assert( HasFile() );
- return ioParam.ioPosOffset;
- }
-
- void FileInStream::SetPosition( uint32 p )
- {
- Assert( !Running() );
- Assert( HasFile() );
- ioParam.ioPosOffset = p;
- Reset();
- }
-
- void FileInStream::SuggestCaching()
- {
- Assert( !Running() );
- ioParam.ioPosMode |= cacheBit;
- ioParam.ioPosMode &= ~noCacheBit;
- }
-
- void FileInStream::SuggestNoCaching()
- {
- Assert( !Running() );
- ioParam.ioPosMode |= noCacheBit;
- ioParam.ioPosMode &= ~cacheBit;
- }
-
- void FileInStream::ClearCachingSuggestion()
- {
- Assert( !Running() );
- ioParam.ioPosMode &= ~( noCacheBit | cacheBit );
- }
-