home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / MYLINE.H < prev    next >
C/C++ Source or Header  |  1997-07-05  |  1KB  |  46 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. // myLine.h
  4. //
  5. // Donated to the public domain; no restrictions on reuse or abuse apply.
  6. // by David Nugent, 7th June, 1993.
  7. // Simple line input class for istream to demonstrate input of a complete
  8. // line rather than whitespace separated tokens (the default for operator<<
  9. // for char* and other built-in types).
  10. // Works by overloading operator>> for a customised class - this functionality
  11. // is easily incorporated into your favourite String class
  12. //
  13.  
  14. # if !defined(_myLine_h)
  15. # define _myLine_h 1
  16.  
  17. # define AUTO_GROW 1            // Allow autogrowth of buffer to fit
  18. # define ALLOC_LEN 80           // Standard length & growth increment
  19.  
  20.     // Class declaration
  21.  
  22. class myLine
  23. {
  24.  
  25.   public:
  26.  
  27.     myLine (short buflen =ALLOC_LEN);
  28.     myLine (char * usebuf, short buflen =ALLOC_LEN);
  29.     ~myLine (void);
  30.                                        // Get buffer address
  31.     char const * buf (void) const { return mybuf; }
  32.                                        // Conversion operators
  33.     char const * operator() (void) const { return mybuf; } // Explicit cast
  34.     operator char const * (void) const { return mybuf; }   // Implicit cast
  35.                                        // istream operator>>
  36.     friend istream & operator>> (istream &, myLine &);
  37.  
  38.   private:
  39.  
  40.     short len, xalloc;
  41.     char * mybuf;
  42.  
  43. };
  44.  
  45. # endif     // _myLine_h
  46.