home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / TimGA 1.2.1 / .cp / CMyFileStream.cp < prev    next >
Encoding:
Text File  |  1997-07-16  |  1.6 KB  |  58 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. //    CMyFileStream.cp        ©1995-97 Timo Eloranta        All rights reserved.
  3. // ===========================================================================
  4. // A subclass of LFileStream which is useful for reading in integers.
  5.  
  6. #include "CMyFileStream.h"
  7.  
  8. // ---------------------------------------------------------------------------
  9. //        • CMyFileStream(FSSpec&)
  10. // ---------------------------------------------------------------------------
  11. //    Contruct a FileStream from a Toolbox File System Specification
  12.  
  13. CMyFileStream::CMyFileStream(
  14.     FSSpec    &inFileSpec)
  15.         : LFileStream(inFileSpec)
  16. {
  17. }
  18.  
  19. // ---------------------------------------------------------------------------
  20. //        • ReadInt
  21. //
  22. //          Called by:    CGraphGADoc::OpenFile
  23. // ---------------------------------------------------------------------------
  24. //    Try to read an UNSIGNED integer from the data fork of a FileStream 
  25. //  to *outInt. Return true if *we think* operation was succesful...
  26.  
  27. Boolean
  28. CMyFileStream::ReadInt( 
  29.     Int16     &outInt )
  30. {
  31.     char    theChar;
  32.     Int16    theNbr = 0;
  33.     Int32    kSizeOfChar    = sizeof(theChar);
  34.  
  35.     // Go past everything until we find the first digit
  36.  
  37.     do {
  38.         if ( ReadData( &theChar, kSizeOfChar ) != kSizeOfChar )
  39.             return false;
  40.  
  41.     } while (! ('0' <= theChar && theChar <= '9' ));
  42.  
  43.     // Update the integer as long as there are digits left.
  44.     // Yes, overflow *is* possible so use with caution...
  45.  
  46.     do {
  47.         theNbr = (theNbr * 10) + (theChar - '0');
  48.         if ( ReadData( &theChar, kSizeOfChar ) != kSizeOfChar )
  49.             break;
  50.  
  51.     } while ( '0' <= theChar && theChar <= '9' );
  52.     
  53.     outInt = theNbr;
  54.     
  55.     return true;
  56. }
  57.  
  58.