2 * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
5 * Silicon Graphics Computer Systems, Inc.
10 * This material is provided "as is", with absolutely no warranty expressed
11 * or implied. Any use is at your own risk.
13 * Permission to use or copy this software for any purpose is hereby granted
14 * without fee, provided the above notices are retained on all copies.
15 * Permission to modify the code and to distribute modified code is granted,
16 * provided the above notices are retained, and a notice that the code was
17 * modified is included with the above copyright notice.
20 #ifndef _STLP_INTERNAL_STRSTREAM
21 #define _STLP_INTERNAL_STRSTREAM
23 #ifndef _STLP_INTERNAL_STREAMBUF
24 # include <stl/_streambuf.h>
27 #ifndef _STLP_INTERNAL_ISTREAM
28 # include <stl/_istream.h> // Includes <ostream>, <ios>, <iosfwd>
31 #ifndef _STLP_INTERNAL_STRING_H
32 # include <stl/_string.h>
37 #ifndef _STLP_USE_NAMESPACES
38 # define strstream _STLP_strstream
39 # define ostrstream _STLP_ostrstream
40 # define istrstream _STLP_istrstream
41 # define strstreambuf _STLP_strstreambuf
44 //----------------------------------------------------------------------
45 // Class strstreambuf, a streambuf class that manages an array of char.
46 // Note that this class is not a template.
48 class _STLP_CLASS_DECLSPEC strstreambuf : public basic_streambuf<char, char_traits<char> > {
50 typedef char_traits<char> _Traits;
51 typedef basic_streambuf<char, char_traits<char> > _Base;
52 typedef void* (*__alloc_fn)(size_t);
53 typedef void (*__free_fn)(void*);
54 public: // Constructor, destructor
56 _STLP_DECLSPEC explicit strstreambuf(streamsize _Initial_capacity = 0);
58 _STLP_DECLSPEC strstreambuf(__alloc_fn, __free_fn);
60 _STLP_DECLSPEC strstreambuf(char* __get, streamsize __n, char* __put = 0);
61 _STLP_DECLSPEC strstreambuf(signed char* __get, streamsize __n, signed char* __put = 0);
62 _STLP_DECLSPEC strstreambuf(unsigned char* __get, streamsize __n, unsigned char* __put=0);
64 _STLP_DECLSPEC strstreambuf(const char* __get, streamsize __n);
65 _STLP_DECLSPEC strstreambuf(const signed char* __get, streamsize __n);
66 _STLP_DECLSPEC strstreambuf(const unsigned char* __get, streamsize __n);
68 _STLP_DECLSPEC virtual ~strstreambuf();
70 public: // strstreambuf operations.
71 _STLP_DECLSPEC void freeze(bool = true);
72 _STLP_DECLSPEC char* str();
73 _STLP_DECLSPEC int pcount() const;
75 protected: // Overridden virtual member functions.
76 _STLP_DECLSPEC virtual int_type overflow(int_type __c = _Traits::eof());
77 _STLP_DECLSPEC virtual int_type pbackfail(int_type __c = _Traits::eof());
78 _STLP_DECLSPEC virtual int_type underflow();
79 _STLP_DECLSPEC virtual _Base* setbuf(char* __buf, streamsize __n);
80 _STLP_DECLSPEC virtual pos_type seekoff(off_type __off, ios_base::seekdir __dir,
81 ios_base::openmode __mode
82 = ios_base::in | ios_base::out);
83 _STLP_DECLSPEC virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode
84 = ios_base::in | ios_base::out);
86 private: // Helper functions.
87 // Dynamic allocation, possibly using _M_alloc_fun and _M_free_fun.
88 char* _M_alloc(size_t);
91 // Helper function used in constructors.
92 void _M_setup(char* __get, char* __put, streamsize __n);
93 private: // Data members.
94 __alloc_fn _M_alloc_fun;
95 __free_fn _M_free_fun;
101 //----------------------------------------------------------------------
102 // Class istrstream, an istream that manages a strstreambuf.
104 class _STLP_CLASS_DECLSPEC istrstream : public basic_istream<char, char_traits<char> > {
106 _STLP_DECLSPEC explicit istrstream(char*);
107 _STLP_DECLSPEC explicit istrstream(const char*);
108 _STLP_DECLSPEC istrstream(char* , streamsize);
109 _STLP_DECLSPEC istrstream(const char*, streamsize);
110 _STLP_DECLSPEC virtual ~istrstream();
112 _STLP_DECLSPEC strstreambuf* rdbuf() const;
113 _STLP_DECLSPEC char* str();
119 //----------------------------------------------------------------------
122 class _STLP_CLASS_DECLSPEC ostrstream : public basic_ostream<char, char_traits<char> >
125 _STLP_DECLSPEC ostrstream();
126 _STLP_DECLSPEC ostrstream(char*, int, ios_base::openmode = ios_base::out);
127 _STLP_DECLSPEC virtual ~ostrstream();
129 _STLP_DECLSPEC strstreambuf* rdbuf() const;
130 _STLP_DECLSPEC void freeze(bool = true);
131 _STLP_DECLSPEC char* str();
132 _STLP_DECLSPEC int pcount() const;
138 //----------------------------------------------------------------------
141 class _STLP_CLASS_DECLSPEC strstream : public basic_iostream<char, char_traits<char> > {
143 typedef char char_type;
144 typedef char_traits<char>::int_type int_type;
145 typedef char_traits<char>::pos_type pos_type;
146 typedef char_traits<char>::off_type off_type;
148 _STLP_DECLSPEC strstream();
149 _STLP_DECLSPEC strstream(char*, int, ios_base::openmode = ios_base::in | ios_base::out);
150 _STLP_DECLSPEC virtual ~strstream();
152 _STLP_DECLSPEC strstreambuf* rdbuf() const;
153 _STLP_DECLSPEC void freeze(bool = true);
154 _STLP_DECLSPEC int pcount() const;
155 _STLP_DECLSPEC char* str();
160 //explicitely defined as private to avoid warnings:
161 strstream(strstream const&);
162 strstream& operator = (strstream const&);
167 #endif /* _STLP_INTERNAL_STRSTREAM */