[GENINCDATA]
[reactos.git] / include / stlport / stl / _strstream.h
1 /*
2 * Copyright (c) 1999
3 * Silicon Graphics Computer Systems, Inc.
4 *
5 * Copyright (c) 1999
6 * Boris Fomitchev
7 *
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
10 *
11 * Permission to use or copy this software for any purpose is hereby granted
12 * without fee, provided the above notices are retained on all copies.
13 * Permission to modify the code and to distribute modified code is granted,
14 * provided the above notices are retained, and a notice that the code was
15 * modified is included with the above copyright notice.
16 *
17 */
18 #ifndef _STLP_INTERNAL_STRSTREAM
19 #define _STLP_INTERNAL_STRSTREAM
20
21 #ifndef _STLP_INTERNAL_STREAMBUF
22 # include <stl/_streambuf.h>
23 #endif
24
25 #ifndef _STLP_INTERNAL_ISTREAM
26 # include <stl/_istream.h> // Includes <ostream>, <ios>, <iosfwd>
27 #endif
28
29 #ifndef _STLP_INTERNAL_STRING_H
30 # include <stl/_string.h>
31 #endif
32
33 _STLP_BEGIN_NAMESPACE
34
35 #ifndef _STLP_USE_NAMESPACES
36 # define strstream _STLP_strstream
37 # define ostrstream _STLP_ostrstream
38 # define istrstream _STLP_istrstream
39 # define strstreambuf _STLP_strstreambuf
40 #endif
41
42 //----------------------------------------------------------------------
43 // Class strstreambuf, a streambuf class that manages an array of char.
44 // Note that this class is not a template.
45
46 class _STLP_CLASS_DECLSPEC strstreambuf : public basic_streambuf<char, char_traits<char> > {
47 public: // Types.
48 typedef char_traits<char> _Traits;
49 typedef basic_streambuf<char, char_traits<char> > _Base;
50 typedef void* (*__alloc_fn)(size_t);
51 typedef void (*__free_fn)(void*);
52 public: // Constructor, destructor
53
54 explicit strstreambuf(streamsize _Initial_capacity = 0);
55
56 strstreambuf(__alloc_fn, __free_fn);
57
58 strstreambuf(char* __get, streamsize __n, char* __put = 0);
59 strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
60 strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
61
62 strstreambuf(const char* __get, streamsize __n);
63 strstreambuf(const signed char* __get, streamsize __n);
64 strstreambuf(const unsigned char* __get, streamsize __n);
65
66 virtual ~strstreambuf();
67
68 public: // strstreambuf operations.
69 void freeze(bool = true);
70 char* str();
71 int pcount() const;
72
73 protected: // Overridden virtual member functions.
74 virtual int_type overflow(int_type __c = _Traits::eof());
75 virtual int_type pbackfail(int_type __c = _Traits::eof());
76 virtual int_type underflow();
77 virtual _Base* setbuf(char* __buf, streamsize __n);
78 virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
79 ios_base::openmode __mode
80 = ios_base::in | ios_base::out);
81 virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
82 = ios_base::in | ios_base::out);
83
84 private: // Helper functions.
85 // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
86 char* _M_alloc(size_t);
87 void _M_free(char*);
88
89 // Helper function used in constructors.
90 void _M_setup(char* __get, char* __put, streamsize __n);
91 private: // Data members.
92 __alloc_fn _M_alloc_fun;
93 __free_fn _M_free_fun;
94 bool _M_dynamic : 1;
95 bool _M_frozen : 1;
96 bool _M_constant : 1;
97 };
98
99 //----------------------------------------------------------------------
100 // Class istrstream, an istream that manages a strstreambuf.
101
102 class _STLP_CLASS_DECLSPEC istrstream : public basic_istream<char, char_traits<char> > {
103 public:
104 explicit istrstream(char*);
105 explicit istrstream(const char*);
106 istrstream(char* , streamsize);
107 istrstream(const char*, streamsize);
108 virtual ~istrstream();
109
110 strstreambuf* rdbuf() const;
111 char* str();
112
113 private:
114 strstreambuf _M_buf;
115 };
116
117 //----------------------------------------------------------------------
118 // Class ostrstream
119
120 class _STLP_CLASS_DECLSPEC ostrstream : public basic_ostream<char, char_traits<char> >
121 {
122 public:
123 ostrstream();
124 ostrstream(char*, int, ios_base::openmode = ios_base::out);
125 virtual ~ostrstream();
126
127 strstreambuf* rdbuf() const;
128 void freeze(bool = true);
129 char* str();
130 int pcount() const;
131
132 private:
133 strstreambuf _M_buf;
134 };
135
136 //----------------------------------------------------------------------
137 // Class strstream
138
139 class _STLP_CLASS_DECLSPEC strstream : public basic_iostream<char, char_traits<char> > {
140 public:
141 typedef char char_type;
142 typedef char_traits<char>::int_type int_type;
143 typedef char_traits<char>::pos_type pos_type;
144 typedef char_traits<char>::off_type off_type;
145
146 strstream();
147 strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
148 virtual ~strstream();
149
150 strstreambuf* rdbuf() const;
151 void freeze(bool = true);
152 int pcount() const;
153 char* str();
154
155 private:
156 strstreambuf _M_buf;
157
158 //explicitely defined as private to avoid warnings:
159 strstream(strstream const&);
160 strstream& operator = (strstream const&);
161 };
162
163 _STLP_END_NAMESPACE
164
165 #endif /* _STLP_INTERNAL_STRSTREAM */