Sync usage with man page.
[netbsd-mini2440.git] / gnu / lib / libg++ / g++-include / streambuf.h
blob61a3de5e9c7f342e84d33c1b8c5be5f5cfd7f453
1 // This may look like C code, but it is really -*- C++ -*-
2 /*
3 Copyright (C) 1988 Free Software Foundation
4 written by Doug Lea (dl@rocky.oswego.edu)
6 This file is part of GNU CC.
8 GNU CC is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY. No author or distributor
10 accepts responsibility to anyone for the consequences of using it
11 or for whether it serves any particular purpose or works at all,
12 unless he says so in writing. Refer to the GNU CC General Public
13 License for full details.
15 Everyone is granted permission to copy, modify and redistribute
16 GNU CC, but only under the conditions described in the
17 GNU CC General Public License. A copy of this license is
18 supposed to have been given to you along with GNU CC so you
19 can know your rights and responsibilities. It should be in a
20 file named COPYING. Among other things, the copyright notice
21 and this notice must be preserved on all copies.
24 #ifndef _streambuf_h
25 #ifdef __GNUG__
26 #pragma once
27 #pragma interface
28 #endif
29 #define _streambuf_h 1
31 /* streambufs.
32 basic streambufs and filebufs are as in Stroustrup, ch 8,
33 but the base class contains virtual extensions that allow
34 most capabilities of libg++ Files to be used as streambufs
35 via `Filebufs'.
38 #include <stdio.h>
39 #include <builtin.h>
40 #include <Fmodes.h>
42 // see below for NO_LINE_BUFFER_STREAMBUFS
44 #ifndef BUFSIZE
45 #ifdef BUFSIZ
46 #define BUFSIZE BUFSIZ
47 #else
48 #define BUFSIZE 1024
49 #endif
50 #endif
52 enum open_mode // filebuf open modes
54 input=0,
55 output=1,
56 append=2
57 };
59 class streambuf
61 public:
62 char* base; // start of buffer
63 char* pptr; // put-pointer (and gptr fence)
64 char* gptr; // get-pointer
65 char* eptr; // last valid addr in buffer
67 char alloc; // true if we own freestore alloced buffer
69 streambuf();
70 streambuf(char* buf, int buflen);
72 virtual ~streambuf();
74 int doallocate();
75 int allocate();
78 int must_overflow(int ch); // true if should call overflow
80 virtual int overflow(int c = EOF); // flush -- return EOF if fail
81 virtual int underflow(); // fill -- return EOF if fail
83 int sgetc(); // get one char (as int) or EOF
84 int snextc(); // get and advance
85 void stossc(); // advance only
87 int sputbackc(char); // unget
89 int sputc(int c = EOF); // write one char
91 virtual streambuf* setbuf(char* buf, int buflen, int preloaded_count = 0);
92 // (not virtual in AT&T)
94 // the following aren't in AT&T version:
96 int sputs(const char* s); // write null-terminated str
97 int sputsn(const char* s, int len); // write len bytes
99 virtual const char* name();
102 virtual streambuf* open(const char* name, open_mode m);
103 virtual streambuf* open(const char* filename, io_mode m, access_mode a);
104 virtual streambuf* open(const char* filename, const char* m);
105 virtual streambuf* open(int filedesc, io_mode m);
106 virtual streambuf* open(FILE* fileptr);
108 virtual int is_open();
109 virtual int close();
111 virtual void error();
115 #if defined(__OPTIMIZE__) || defined(USE_LIBGXX_INLINES)
118 inline int streambuf::must_overflow(int ch)
120 #ifndef NO_LINE_BUFFER_STREAMBUF
121 return pptr >= eptr || ch == '\n';
122 #else
123 return pptr >= eptr;
124 #endif
128 inline int streambuf::allocate()
130 return (base == 0)? doallocate() : 0;
133 inline int streambuf::sgetc()
135 return (gptr >= pptr)? underflow() : int((unsigned char)(*gptr));
139 inline int streambuf::snextc()
141 ++gptr;
142 return (gptr >= pptr)? underflow() : int((unsigned char)(*gptr));
146 inline void streambuf::stossc()
148 if (gptr >= pptr) underflow(); else gptr++;
152 inline int streambuf::sputbackc(char ch)
154 return (gptr > base)? int((unsigned char)(*--gptr = ch)) : EOF;
157 inline int streambuf::sputc(int ch)
159 return must_overflow(ch)? overflow(ch) :
160 int((unsigned char)(*pptr++ = char(ch)));
163 #endif
165 #endif