home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / lib / prstreams / prstrms.h < prev   
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.4 KB  |  129 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20.  * Robin J. Maxwell 11-22-96
  21.  */
  22.  
  23. #ifndef _PRSTRMS_H
  24. #define _PRSTRMS_H
  25.  
  26. #include "prtypes.h"
  27. #include "prio.h"
  28.  
  29. #ifdef _MSC_VER
  30. #pragma warning( disable : 4275)
  31. #endif
  32. #include <iostream.h>
  33.  
  34. #if defined (PRFSTREAMS_BROKEN)
  35.  
  36. // fix it sometime
  37.  
  38. #define     PRfilebuf    streambuf
  39. #define  PRifstream    ifstream
  40. #define     PRofstream    ofstream
  41. #define     PRfstream    fstream
  42.  
  43. #else
  44.  
  45. class PR_IMPLEMENT(PRfilebuf): public streambuf
  46. {
  47. public:
  48.     PRfilebuf();
  49.     PRfilebuf(PRFileDesc *fd);
  50.     PRfilebuf(PRFileDesc *fd, char * buffptr, int bufflen);
  51.     ~PRfilebuf();
  52.     virtual    int    overflow(int=EOF);
  53.     virtual    int    underflow();
  54.     virtual    streambuf *setbuf(char *buff, int bufflen);
  55.     virtual    streampos seekoff(streamoff, ios::seek_dir, int);
  56.     virtual int sync();
  57.     PRfilebuf *open(const char *name, int mode, int flags);
  58.        PRfilebuf *attach(PRFileDesc *fd);
  59.     PRfilebuf *close();
  60.        int    is_open() const {return (_fd != 0);}
  61.     PRFileDesc *fd(){return _fd;}
  62.  
  63. private:
  64.     PRFileDesc * _fd;
  65.     PRBool _opened;
  66.     PRBool _allocated;
  67. };
  68.  
  69. class PR_IMPLEMENT(PRifstream): public istream {
  70. public:
  71.     PRifstream();
  72.     PRifstream(const char *, int mode=ios::in, int flags = 0);
  73.     PRifstream(PRFileDesc *);
  74.     PRifstream(PRFileDesc *, char *, int);
  75.     ~PRifstream();
  76.  
  77.     streambuf * setbuf(char *, int);
  78.     PRfilebuf* rdbuf(){return (PRfilebuf*) ios::rdbuf(); }
  79.  
  80.     void attach(PRFileDesc *fd);
  81.     PRFileDesc *fd() {return rdbuf()->fd();}
  82.  
  83.     int is_open(){return rdbuf()->is_open();}
  84.     void open(const char *, int mode=ios::in, int flags= 0);
  85.     void close();
  86. };
  87.  
  88. class PR_IMPLEMENT(PRofstream) : public ostream {
  89. public:
  90.     PRofstream();
  91.     PRofstream(const char *, int mode=ios::out, int flags = 0);
  92.     PRofstream(PRFileDesc *);
  93.     PRofstream(PRFileDesc *, char *, int);
  94.     ~PRofstream();
  95.  
  96.     streambuf * setbuf(char *, int);
  97.     PRfilebuf* rdbuf() { return (PRfilebuf*) ios::rdbuf(); }
  98.  
  99.     void attach(PRFileDesc *);
  100.     PRFileDesc *fd() {return rdbuf()->fd();}
  101.  
  102.     int is_open(){return rdbuf()->is_open();}
  103.     void open(const char *, int =ios::out, int = 0);
  104.     void close();
  105. };
  106.     
  107. class PR_IMPLEMENT(PRfstream) : public iostream {
  108. public:
  109.     PRfstream();
  110.     PRfstream(const char *name, int mode, int flags= 0);
  111.     PRfstream(PRFileDesc *fd);
  112.     PRfstream(PRFileDesc *fd, char *buff, int bufflen);
  113.     ~PRfstream();
  114.  
  115.     streambuf * setbuf(char *, int);
  116.     PRfilebuf* rdbuf(){ return (PRfilebuf*) ostream::rdbuf(); }
  117.  
  118.     void attach(PRFileDesc *);
  119.     PRFileDesc *fd() { return rdbuf()->fd(); }
  120.  
  121.     int is_open() { return rdbuf()->is_open(); }
  122.     void open(const char *, int, int = 0);
  123.     void close();
  124. };
  125.  
  126. #endif
  127.  
  128. #endif /* _PRSTRMS_H */
  129.