home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / vrac / cuj0796.zip / COLNER.ZIP / STRING.CPP < prev   
C/C++ Source or Header  |  1996-05-08  |  2KB  |  66 lines

  1. #include <iomanip.h>
  2. #ifdef _MSC_VER        // for Microsoft's parameterized io manipulators
  3. #define CAST_IOMANIP(CLASS) \
  4.     inline CLASS& operator \
  5. <<(CLASS& _s, const SMANIP(int)& _f) { \
  6.     (ostream&)_s << _f ; return _s; \
  7.     } \
  8.     inline CLASS& operator \
  9. <<(CLASS& _s, const SMANIP(long)& _f) { \
  10.     (ostream&)_s << _f ; return _s; \
  11.     }
  12. #else               // for Borland's template class io manipulators
  13. #define CAST_IOMANIP(CLASS) \
  14.     inline CLASS& operator \
  15. <<(CLASS& _s, smanip<int>& _f) { \
  16.     (ostream&)_s << _f ; \
  17.     return _s; \
  18.     } \
  19.     inline CLASS& operator \
  20. <<(CLASS& _s, smanip<long>& _f) { \
  21.     (ostream&)_s << _f ; \
  22.     return _s; \
  23.     }
  24. #endif
  25.     class
  26. String : public ostrstream{
  27.     String& replace(const char * const str);
  28.   public:
  29.       CAST_INJECTORS(String)
  30.     String() : ostrstream(){}
  31.     String(const char * const s){
  32.         (ostrstream&)*this << s;
  33.         }
  34.     String(String& str){
  35.         if(str.notNull())
  36.             (ostrstream&)*this << (const char * const)str;
  37.         }
  38.         String&
  39.     testType(){ return *this;}
  40.         String&
  41.     setNull();
  42.         int
  43.     notNull(){ return rdbuf()->out_waiting();}
  44.         int
  45.     isNull(){ return !notNull();}
  46.         String& operator
  47.     = (const char * const val) {
  48.         return replace(val);
  49.         }
  50.         int operator
  51.     != ( String& val) {
  52.         return (strcmp((char*)*this,(char*)val) != 0);
  53.         }
  54.         int operator
  55.     == ( String& val) {
  56.         return !strcmp((char*)*this,(char*)val);
  57.         }
  58.     operator char*  (void);
  59.     };
  60.     inline ostream& operator
  61. <<(ostream& out, String& s){
  62.     return (out << (char *)s);
  63.     }
  64. CAST_IOMANIP(String)
  65. #endif
  66.