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