Warning, /include/c++/v1/strstream is written in an unsupported language. File is not indexed.
0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009
0010 #ifndef _LIBCPP_STRSTREAM
0011 #define _LIBCPP_STRSTREAM
0012
0013 /*
0014 strstream synopsis
0015
0016 class strstreambuf // Removed in C++26
0017 : public basic_streambuf<char>
0018 {
0019 public:
0020 explicit strstreambuf(streamsize alsize_arg = 0); // before C++20
0021 strstreambuf() : strstreambuf(0) {} // C++20
0022 explicit strstreambuf(streamsize alsize_arg); // C++20
0023
0024 strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));
0025 strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = nullptr);
0026 strstreambuf(const char* gnext_arg, streamsize n);
0027
0028 strstreambuf(signed char* gnext_arg, streamsize n, signed char* pbeg_arg = nullptr);
0029 strstreambuf(const signed char* gnext_arg, streamsize n);
0030 strstreambuf(unsigned char* gnext_arg, streamsize n, unsigned char* pbeg_arg = nullptr);
0031 strstreambuf(const unsigned char* gnext_arg, streamsize n);
0032
0033 strstreambuf(strstreambuf&& rhs);
0034 strstreambuf& operator=(strstreambuf&& rhs);
0035
0036 virtual ~strstreambuf();
0037
0038 void swap(strstreambuf& rhs);
0039
0040 void freeze(bool freezefl = true);
0041 char* str();
0042 int pcount() const;
0043
0044 protected:
0045 virtual int_type overflow (int_type c = EOF);
0046 virtual int_type pbackfail(int_type c = EOF);
0047 virtual int_type underflow();
0048 virtual pos_type seekoff(off_type off, ios_base::seekdir way,
0049 ios_base::openmode which = ios_base::in | ios_base::out);
0050 virtual pos_type seekpos(pos_type sp,
0051 ios_base::openmode which = ios_base::in | ios_base::out);
0052 virtual streambuf* setbuf(char* s, streamsize n);
0053
0054 private:
0055 typedef T1 strstate; // exposition only
0056 static const strstate allocated; // exposition only
0057 static const strstate constant; // exposition only
0058 static const strstate dynamic; // exposition only
0059 static const strstate frozen; // exposition only
0060 strstate strmode; // exposition only
0061 streamsize alsize; // exposition only
0062 void* (*palloc)(size_t); // exposition only
0063 void (*pfree)(void*); // exposition only
0064 };
0065
0066 class istrstream // Removed in C++26
0067 : public basic_istream<char>
0068 {
0069 public:
0070 explicit istrstream(const char* s);
0071 explicit istrstream(char* s);
0072 istrstream(const char* s, streamsize n);
0073 istrstream(char* s, streamsize n);
0074
0075 virtual ~istrstream();
0076
0077 strstreambuf* rdbuf() const;
0078 char *str();
0079
0080 private:
0081 strstreambuf sb; // exposition only
0082 };
0083
0084 class ostrstream // Removed in C++26
0085 : public basic_ostream<char>
0086 {
0087 public:
0088 ostrstream();
0089 ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);
0090
0091 virtual ~ostrstream();
0092
0093 strstreambuf* rdbuf() const;
0094 void freeze(bool freezefl = true);
0095 char* str();
0096 int pcount() const;
0097
0098 private:
0099 strstreambuf sb; // exposition only
0100 };
0101
0102 class strstream // Removed in C++26
0103 : public basic_iostream<char>
0104 {
0105 public:
0106 // Types
0107 typedef char char_type;
0108 typedef char_traits<char>::int_type int_type;
0109 typedef char_traits<char>::pos_type pos_type;
0110 typedef char_traits<char>::off_type off_type;
0111
0112 // constructors/destructor
0113 strstream();
0114 strstream(char* s, int n, ios_base::openmode mode = ios_base::in | ios_base::out);
0115
0116 virtual ~strstream();
0117
0118 // Members:
0119 strstreambuf* rdbuf() const;
0120 void freeze(bool freezefl = true);
0121 int pcount() const;
0122 char* str();
0123
0124 private:
0125 strstreambuf sb; // exposition only
0126 };
0127
0128 } // std
0129
0130 */
0131
0132 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0133 # include <__cxx03/strstream>
0134 #else
0135 # include <__config>
0136
0137 # if _LIBCPP_HAS_LOCALIZATION
0138
0139 # include <__ostream/basic_ostream.h>
0140 # include <istream>
0141 # include <streambuf>
0142 # include <version>
0143
0144 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0145 # pragma GCC system_header
0146 # endif
0147
0148 # if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM) || defined(_LIBCPP_BUILDING_LIBRARY)
0149
0150 _LIBCPP_PUSH_MACROS
0151 # include <__undef_macros>
0152
0153 _LIBCPP_BEGIN_NAMESPACE_STD
0154
0155 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstreambuf : public streambuf {
0156 public:
0157 # ifndef _LIBCPP_CXX03_LANG
0158 _LIBCPP_HIDE_FROM_ABI strstreambuf() : strstreambuf(0) {}
0159 explicit strstreambuf(streamsize __alsize);
0160 # else
0161 explicit strstreambuf(streamsize __alsize = 0);
0162 # endif
0163 strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*));
0164 strstreambuf(char* __gnext, streamsize __n, char* __pbeg = nullptr);
0165 strstreambuf(const char* __gnext, streamsize __n);
0166
0167 strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = nullptr);
0168 strstreambuf(const signed char* __gnext, streamsize __n);
0169 strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = nullptr);
0170 strstreambuf(const unsigned char* __gnext, streamsize __n);
0171
0172 # ifndef _LIBCPP_CXX03_LANG
0173 _LIBCPP_HIDE_FROM_ABI strstreambuf(strstreambuf&& __rhs);
0174 _LIBCPP_HIDE_FROM_ABI strstreambuf& operator=(strstreambuf&& __rhs);
0175 # endif // _LIBCPP_CXX03_LANG
0176
0177 ~strstreambuf() override;
0178
0179 void swap(strstreambuf& __rhs);
0180
0181 void freeze(bool __freezefl = true);
0182 char* str();
0183 int pcount() const;
0184
0185 protected:
0186 int_type overflow(int_type __c = EOF) override;
0187 int_type pbackfail(int_type __c = EOF) override;
0188 int_type underflow() override;
0189 pos_type
0190 seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out) override;
0191 pos_type seekpos(pos_type __sp, ios_base::openmode __which = ios_base::in | ios_base::out) override;
0192
0193 private:
0194 typedef unsigned __mode_type;
0195 static const __mode_type __allocated = 0x01;
0196 static const __mode_type __constant = 0x02;
0197 static const __mode_type __dynamic = 0x04;
0198 static const __mode_type __frozen = 0x08;
0199 static const streamsize __default_alsize = 4096;
0200
0201 __mode_type __strmode_;
0202 streamsize __alsize_;
0203 void* (*__palloc_)(size_t);
0204 void (*__pfree_)(void*);
0205
0206 void __init(char* __gnext, streamsize __n, char* __pbeg);
0207 };
0208
0209 # ifndef _LIBCPP_CXX03_LANG
0210
0211 inline _LIBCPP_HIDE_FROM_ABI strstreambuf::strstreambuf(strstreambuf&& __rhs)
0212 : streambuf(__rhs),
0213 __strmode_(__rhs.__strmode_),
0214 __alsize_(__rhs.__alsize_),
0215 __palloc_(__rhs.__palloc_),
0216 __pfree_(__rhs.__pfree_) {
0217 __rhs.setg(nullptr, nullptr, nullptr);
0218 __rhs.setp(nullptr, nullptr);
0219 }
0220
0221 inline _LIBCPP_HIDE_FROM_ABI strstreambuf& strstreambuf::operator=(strstreambuf&& __rhs) {
0222 if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0) {
0223 if (__pfree_)
0224 __pfree_(eback());
0225 else
0226 delete[] eback();
0227 }
0228 streambuf::operator=(__rhs);
0229 __strmode_ = __rhs.__strmode_;
0230 __alsize_ = __rhs.__alsize_;
0231 __palloc_ = __rhs.__palloc_;
0232 __pfree_ = __rhs.__pfree_;
0233 __rhs.setg(nullptr, nullptr, nullptr);
0234 __rhs.setp(nullptr, nullptr);
0235 return *this;
0236 }
0237
0238 # endif // _LIBCPP_CXX03_LANG
0239
0240 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI istrstream : public istream {
0241 public:
0242 _LIBCPP_HIDE_FROM_ABI explicit istrstream(const char* __s) : istream(&__sb_), __sb_(__s, 0) {}
0243 _LIBCPP_HIDE_FROM_ABI explicit istrstream(char* __s) : istream(&__sb_), __sb_(__s, 0) {}
0244 _LIBCPP_HIDE_FROM_ABI istrstream(const char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}
0245 _LIBCPP_HIDE_FROM_ABI istrstream(char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}
0246
0247 # ifndef _LIBCPP_CXX03_LANG
0248 _LIBCPP_HIDE_FROM_ABI istrstream(istrstream&& __rhs) // extension
0249 : istream(std::move(static_cast<istream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
0250 istream::set_rdbuf(&__sb_);
0251 }
0252
0253 _LIBCPP_HIDE_FROM_ABI istrstream& operator=(istrstream&& __rhs) {
0254 __sb_ = std::move(__rhs.__sb_);
0255 istream::operator=(std::move(__rhs));
0256 return *this;
0257 }
0258 # endif // _LIBCPP_CXX03_LANG
0259
0260 ~istrstream() override;
0261
0262 _LIBCPP_HIDE_FROM_ABI void swap(istrstream& __rhs) {
0263 istream::swap(__rhs);
0264 __sb_.swap(__rhs.__sb_);
0265 }
0266
0267 _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }
0268 _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }
0269
0270 private:
0271 strstreambuf __sb_;
0272 };
0273
0274 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI ostrstream : public ostream {
0275 public:
0276 _LIBCPP_HIDE_FROM_ABI ostrstream() : ostream(&__sb_) {}
0277 _LIBCPP_HIDE_FROM_ABI ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
0278 : ostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}
0279
0280 # ifndef _LIBCPP_CXX03_LANG
0281 _LIBCPP_HIDE_FROM_ABI ostrstream(ostrstream&& __rhs) // extension
0282 : ostream(std::move(static_cast<ostream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
0283 ostream::set_rdbuf(&__sb_);
0284 }
0285
0286 _LIBCPP_HIDE_FROM_ABI ostrstream& operator=(ostrstream&& __rhs) {
0287 __sb_ = std::move(__rhs.__sb_);
0288 ostream::operator=(std::move(__rhs));
0289 return *this;
0290 }
0291 # endif // _LIBCPP_CXX03_LANG
0292
0293 ~ostrstream() override;
0294
0295 _LIBCPP_HIDE_FROM_ABI void swap(ostrstream& __rhs) {
0296 ostream::swap(__rhs);
0297 __sb_.swap(__rhs.__sb_);
0298 }
0299
0300 _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }
0301 _LIBCPP_HIDE_FROM_ABI void freeze(bool __freezefl = true) { __sb_.freeze(__freezefl); }
0302 _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }
0303 _LIBCPP_HIDE_FROM_ABI int pcount() const { return __sb_.pcount(); }
0304
0305 private:
0306 strstreambuf __sb_; // exposition only
0307 };
0308
0309 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstream : public iostream {
0310 public:
0311 // Types
0312 typedef char char_type;
0313 typedef char_traits<char>::int_type int_type;
0314 typedef char_traits<char>::pos_type pos_type;
0315 typedef char_traits<char>::off_type off_type;
0316
0317 // constructors/destructor
0318 _LIBCPP_HIDE_FROM_ABI strstream() : iostream(&__sb_) {}
0319 _LIBCPP_HIDE_FROM_ABI strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
0320 : iostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}
0321
0322 # ifndef _LIBCPP_CXX03_LANG
0323 _LIBCPP_HIDE_FROM_ABI strstream(strstream&& __rhs) // extension
0324 : iostream(std::move(static_cast<iostream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
0325 iostream::set_rdbuf(&__sb_);
0326 }
0327
0328 _LIBCPP_HIDE_FROM_ABI strstream& operator=(strstream&& __rhs) {
0329 __sb_ = std::move(__rhs.__sb_);
0330 iostream::operator=(std::move(__rhs));
0331 return *this;
0332 }
0333 # endif // _LIBCPP_CXX03_LANG
0334
0335 ~strstream() override;
0336
0337 _LIBCPP_HIDE_FROM_ABI void swap(strstream& __rhs) {
0338 iostream::swap(__rhs);
0339 __sb_.swap(__rhs.__sb_);
0340 }
0341
0342 // Members:
0343 _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }
0344 _LIBCPP_HIDE_FROM_ABI void freeze(bool __freezefl = true) { __sb_.freeze(__freezefl); }
0345 _LIBCPP_HIDE_FROM_ABI int pcount() const { return __sb_.pcount(); }
0346 _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }
0347
0348 private:
0349 strstreambuf __sb_; // exposition only
0350 };
0351
0352 _LIBCPP_END_NAMESPACE_STD
0353
0354 _LIBCPP_POP_MACROS
0355
0356 # endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM) ||
0357 // defined(_LIBCPP_BUILDING_LIBRARY)
0358
0359 # endif // _LIBCPP_HAS_LOCALIZATION
0360
0361 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0362
0363 #endif // _LIBCPP_STRSTREAM