home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TTokenExample.h
-
- Contains: The TToken class can carry (maintain information about) an object and
- can give the object an ID. Here the TBufferToken is a token with buffer
- of x bytes.
-
- Copyright: © 1993 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #ifndef __TTOKENEXAMPLE__
- #define __TTOKENEXAMPLE__
-
- ///————————————————————————————————————————————————————————————————————————————————————
- /// TBufferToken
- ///————————————————————————————————————————————————————————————————————————————————————
-
- class TBufferToken : public TToken {
- public:
- TBufferToken();
- virtual ~TBufferToken();
- virtual void BufRead(); // read from the buffer
- virtual void BufWrite(char *); // write to the buffer
- private:
- short fBufPos; // current buffer position
- };
-
- ///————————————————————————————————————————————————————————————————————————————————————
- /// TBufferToken IMPLEMENTATION
- ///————————————————————————————————————————————————————————————————————————————————————
-
- TBufferToken::TBufferToken()
- {
- fObject = new char[256]; // allocate some space for our buffer
- fBufPos = 0;
- }
-
- TBufferToken::~TBufferToken()
- {
- // the TToken destructor will delete fID for us
- delete fObject;
- }
-
- void TBufferToken::BufRead()
- {
- if( fObject )
- cout << "Buffer = " << (char *)fObject << endl;
- }
-
- void TBufferToken::BufWrite(char *string)
- {
- if( fObject ) {
- size_t len = strlen(string);
- strcpy( ((char *)fObject)+fBufPos, string );
- fBufPos += len;
- }
- }
-
- #endif