Back to index

lightning-sunbird  0.9+nobinonly
prstrms.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039  * Robin J. Maxwell 11-22-96
00040  */
00041 
00042 #ifndef _PRSTRMS_H
00043 #define _PRSTRMS_H
00044 
00045 #include "prtypes.h"
00046 #include "prio.h"
00047 
00048 #ifdef _MSC_VER
00049 #pragma warning( disable : 4275)
00050 #endif
00051 #include <iostream.h>
00052 
00053 #if defined(AIX) && defined(__64BIT__)
00054 typedef long PRstreambuflen;
00055 #else
00056 typedef int PRstreambuflen;
00057 #endif
00058 
00059 #if defined (PRFSTREAMS_BROKEN)
00060 
00061 // fix it sometime
00062 
00063 #define        PRfilebuf    streambuf
00064 #define  PRifstream  ifstream
00065 #define        PRofstream   ofstream
00066 #define        PRfstream    fstream
00067 
00068 #else
00069 
00070 class PR_IMPLEMENT(PRfilebuf): public streambuf
00071 {
00072 public:
00073     PRfilebuf();
00074     PRfilebuf(PRFileDesc *fd);
00075     PRfilebuf(PRFileDesc *fd, char * buffptr, int bufflen);
00076     ~PRfilebuf();
00077     virtual   int    overflow(int=EOF);
00078     virtual   int    underflow();
00079     virtual   streambuf *setbuf(char *buff, PRstreambuflen bufflen);
00080     virtual   streampos seekoff(streamoff, ios::seek_dir, int);
00081     virtual int sync();
00082     PRfilebuf *open(const char *name, int mode, int flags);
00083        PRfilebuf *attach(PRFileDesc *fd);
00084     PRfilebuf *close();
00085        int    is_open() const {return (_fd != 0);}
00086     PRFileDesc *fd(){return _fd;}
00087 
00088 private:
00089     PRFileDesc * _fd;
00090     PRBool _opened;
00091        PRBool _allocated;
00092 };
00093 
00094 class PR_IMPLEMENT(PRifstream): public istream {
00095 public:
00096        PRifstream();
00097        PRifstream(const char *, int mode=ios::in, int flags = 0);
00098        PRifstream(PRFileDesc *);
00099        PRifstream(PRFileDesc *, char *, int);
00100        ~PRifstream();
00101 
00102        streambuf * setbuf(char *, int);
00103        PRfilebuf* rdbuf(){return (PRfilebuf*) ios::rdbuf(); }
00104 
00105        void attach(PRFileDesc *fd);
00106        PRFileDesc *fd() {return rdbuf()->fd();}
00107 
00108        int is_open(){return rdbuf()->is_open();}
00109        void open(const char *, int mode=ios::in, int flags= 0);
00110        void close();
00111 };
00112 
00113 class PR_IMPLEMENT(PRofstream) : public ostream {
00114 public:
00115        PRofstream();
00116        PRofstream(const char *, int mode=ios::out, int flags = 0);
00117        PRofstream(PRFileDesc *);
00118        PRofstream(PRFileDesc *, char *, int);
00119        ~PRofstream();
00120 
00121        streambuf * setbuf(char *, int);
00122        PRfilebuf* rdbuf() { return (PRfilebuf*) ios::rdbuf(); }
00123 
00124        void attach(PRFileDesc *);
00125        PRFileDesc *fd() {return rdbuf()->fd();}
00126 
00127        int is_open(){return rdbuf()->is_open();}
00128        void open(const char *, int =ios::out, int = 0);
00129        void close();
00130 };
00131        
00132 class PR_IMPLEMENT(PRfstream) : public iostream {
00133 public:
00134        PRfstream();
00135        PRfstream(const char *name, int mode, int flags= 0);
00136        PRfstream(PRFileDesc *fd);
00137        PRfstream(PRFileDesc *fd, char *buff, int bufflen);
00138        ~PRfstream();
00139 
00140        streambuf * setbuf(char *, int);
00141        PRfilebuf* rdbuf(){ return (PRfilebuf*) ostream::rdbuf(); }
00142 
00143        void attach(PRFileDesc *);
00144        PRFileDesc *fd() { return rdbuf()->fd(); }
00145 
00146        int is_open() { return rdbuf()->is_open(); }
00147        void open(const char *, int, int = 0);
00148        void close();
00149 };
00150 
00151 #endif
00152 
00153 #endif /* _PRSTRMS_H */