home *** CD-ROM | disk | FTP | other *** search
- /***
- *
- * CStream.h - I/O stream classes BBEdit extensions.
- * Copyright © 1995 by Christopher E. Hyde. All rights reserved.
- *
- ***/
-
- #pragma once
-
- enum {
- #ifndef EOF
- EOF = -1,
- #endif
- kGrowStream = 8 * 1024,
- kInitStream = 8 * 1024,
- kInitTempSize = 256,
- kInputStream = false,
- kOutputStream = true,
- kOwnsHandle = true
- };
-
-
- struct CStream {
- Handle fHandle;
- uchar* fBase;
- UInt32 fLength;
- UInt32 fOffset;
- bool fDirection;
- bool fOwnsHandle;
-
- // CStream (void);
- // ~CStream (void);
- void Open (Handle aHandle, bool direction, bool ownsHandle);
- void SetLength (UInt32 length);
- Handle GetHandle (void);
- void Flush (void);
- void Close (void);
- inline bool IsOutput (void) const { return fDirection; }
- inline bool OwnsHandle (void) const { return fOwnsHandle; }
-
- protected:
- static inline Handle NewHandle (UInt32 size) {
- return BBEdit->Allocate(size, false);
- }
- };
-
-
- struct CIStream : public CStream {
- // CIStream (WindowPtr window);
- // ~CIStream (void);
-
- void Open (Handle data, bool ownsHandle)
- { CStream::Open(data, kInputStream, ownsHandle); }
- void Open (WindowPtr window);
- void Open (WindowPtr window, long selStart, long selEnd);
- int Get (void);
- void Get (char* dst, int size);
- int CurChar (void) const;
- bool IsEOF (void) const { return fOffset >= fLength; }
- };
-
-
- struct COStream : public CStream {
- // COStream (UInt32 length);
- // ~COStream (void);
-
- bool fAutoFlush; // Automatically flush each write
-
- void Open (bool autoFlush = false, UInt32 length = kInitStream);
- void Put (char ch);
- void Put (const char* ptr, UInt32 length);
- void Put (ConstStr255Param aString);
- void Put (const char* str);
- void NewLine (void);
- };
-
-
- #define Min(a, b) (((a) < (b)) ? (a) : (b))
- #define Max(a, b) (((a) > (b)) ? (a) : (b))
-