codekingpro/portable-devtools
114k
1// -*- C++ -*-2//===--------------------------- strstream --------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCUDACXX_STRSTREAM11#define _LIBCUDACXX_STRSTREAM12 13/*14 strstream synopsis15 16class strstreambuf17 : public basic_streambuf<char>18{19public:20 explicit strstreambuf(streamsize alsize_arg = 0);21 strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));22 strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = 0);23 strstreambuf(const char* gnext_arg, streamsize n);24 25 strstreambuf(signed char* gnext_arg, streamsize n, signed char* pbeg_arg = 0);26 strstreambuf(const signed char* gnext_arg, streamsize n);27 strstreambuf(unsigned char* gnext_arg, streamsize n, unsigned char* pbeg_arg = 0);28 strstreambuf(const unsigned char* gnext_arg, streamsize n);29 30 strstreambuf(strstreambuf&& rhs);31 strstreambuf& operator=(strstreambuf&& rhs);32 33 virtual ~strstreambuf();34 35 void swap(strstreambuf& rhs);36 37 void freeze(bool freezefl = true);38 char* str();39 int pcount() const;40 41protected:42 virtual int_type overflow (int_type c = EOF);43 virtual int_type pbackfail(int_type c = EOF);44 virtual int_type underflow();45 virtual pos_type seekoff(off_type off, ios_base::seekdir way,46 ios_base::openmode which = ios_base::in | ios_base::out);47 virtual pos_type seekpos(pos_type sp,48 ios_base::openmode which = ios_base::in | ios_base::out);49 virtual streambuf* setbuf(char* s, streamsize n);50 51private:52 typedef T1 strstate; // exposition only53 static const strstate allocated; // exposition only54 static const strstate constant; // exposition only55 static const strstate dynamic; // exposition only56 static const strstate frozen; // exposition only57 strstate strmode; // exposition only58 streamsize alsize; // exposition only59 void* (*palloc)(size_t); // exposition only60 void (*pfree)(void*); // exposition only61};62 63class istrstream64 : public basic_istream<char>65{66public:67 explicit istrstream(const char* s);68 explicit istrstream(char* s);69 istrstream(const char* s, streamsize n);70 istrstream(char* s, streamsize n);71 72 virtual ~istrstream();73 74 strstreambuf* rdbuf() const;75 char *str();76 77private:78 strstreambuf sb; // exposition only79};80 81class ostrstream82 : public basic_ostream<char>83{84public:85 ostrstream();86 ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);87 88 virtual ~ostrstream();89 90 strstreambuf* rdbuf() const;91 void freeze(bool freezefl = true);92 char* str();93 int pcount() const;94 95private:96 strstreambuf sb; // exposition only97};98 99class strstream100 : public basic_iostream<char>101{102public:103 // Types104 typedef char char_type;105 typedef char_traits<char>::int_type int_type;106 typedef char_traits<char>::pos_type pos_type;107 typedef char_traits<char>::off_type off_type;108 109 // constructors/destructor110 strstream();111 strstream(char* s, int n, ios_base::openmode mode = ios_base::in | ios_base::out);112 113 virtual ~strstream();114 115 // Members:116 strstreambuf* rdbuf() const;117 void freeze(bool freezefl = true);118 int pcount() const;119 char* str();120 121private:122 strstreambuf sb; // exposition only123};124 125} // std126 127*/128 129#include <__config>130#include <ostream>131#include <istream>132 133#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)134# pragma GCC system_header135#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)136# pragma clang system_header137#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)138# pragma system_header139#endif // no system header140 141_LIBCUDACXX_BEGIN_NAMESPACE_STD142 143class _LIBCUDACXX_TYPE_VIS strstreambuf144 : public streambuf145{146public:147 explicit strstreambuf(streamsize __alsize = 0);148 strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*));149 strstreambuf(char* __gnext, streamsize __n, char* __pbeg = 0);150 strstreambuf(const char* __gnext, streamsize __n);151 152 strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = 0);153 strstreambuf(const signed char* __gnext, streamsize __n);154 strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = 0);155 strstreambuf(const unsigned char* __gnext, streamsize __n);156 157 _LIBCUDACXX_INLINE_VISIBILITY158 strstreambuf(strstreambuf&& __rhs);159 _LIBCUDACXX_INLINE_VISIBILITY160 strstreambuf& operator=(strstreambuf&& __rhs);161 162 virtual ~strstreambuf();163 164 void swap(strstreambuf& __rhs);165 166 void freeze(bool __freezefl = true);167 char* str();168 int pcount() const;169 170protected:171 virtual int_type overflow (int_type __c = EOF);172 virtual int_type pbackfail(int_type __c = EOF);173 virtual int_type underflow();174 virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,175 ios_base::openmode __which = ios_base::in | ios_base::out);176 virtual pos_type seekpos(pos_type __sp,177 ios_base::openmode __which = ios_base::in | ios_base::out);178 179private:180 typedef unsigned __mode_type;181 static const __mode_type __allocated = 0x01;182 static const __mode_type __constant = 0x02;183 static const __mode_type __dynamic = 0x04;184 static const __mode_type __frozen = 0x08;185 static const streamsize __default_alsize = 4096;186 187 __mode_type __strmode_;188 streamsize __alsize_;189 void* (*__palloc_)(size_t);190 void (*__pfree_)(void*);191 192 void __init(char* __gnext, streamsize __n, char* __pbeg);193};194 195inline _LIBCUDACXX_INLINE_VISIBILITY196strstreambuf::strstreambuf(strstreambuf&& __rhs)197 : streambuf(__rhs),198 __strmode_(__rhs.__strmode_),199 __alsize_(__rhs.__alsize_),200 __palloc_(__rhs.__palloc_),201 __pfree_(__rhs.__pfree_)202{203 __rhs.setg(nullptr, nullptr, nullptr);204 __rhs.setp(nullptr, nullptr);205}206 207inline _LIBCUDACXX_INLINE_VISIBILITY208strstreambuf&209strstreambuf::operator=(strstreambuf&& __rhs)210{211 if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0)212 {213 if (__pfree_)214 __pfree_(eback());215 else216 delete [] eback();217 }218 streambuf::operator=(__rhs);219 __strmode_ = __rhs.__strmode_;220 __alsize_ = __rhs.__alsize_;221 __palloc_ = __rhs.__palloc_;222 __pfree_ = __rhs.__pfree_;223 __rhs.setg(nullptr, nullptr, nullptr);224 __rhs.setp(nullptr, nullptr);225 return *this;226}227 228class _LIBCUDACXX_TYPE_VIS istrstream229 : public istream230{231public:232 _LIBCUDACXX_INLINE_VISIBILITY233 explicit istrstream(const char* __s)234 : istream(&__sb_), __sb_(__s, 0) {}235 _LIBCUDACXX_INLINE_VISIBILITY236 explicit istrstream(char* __s)237 : istream(&__sb_), __sb_(__s, 0) {}238 _LIBCUDACXX_INLINE_VISIBILITY239 istrstream(const char* __s, streamsize __n)240 : istream(&__sb_), __sb_(__s, __n) {}241 _LIBCUDACXX_INLINE_VISIBILITY242 istrstream(char* __s, streamsize __n)243 : istream(&__sb_), __sb_(__s, __n) {}244 245 _LIBCUDACXX_INLINE_VISIBILITY246 istrstream(istrstream&& __rhs)247 : istream(_CUDA_VSTD::move(__rhs)),248 __sb_(_CUDA_VSTD::move(__rhs.__sb_))249 {250 istream::set_rdbuf(&__sb_);251 }252 253 _LIBCUDACXX_INLINE_VISIBILITY254 istrstream& operator=(istrstream&& __rhs)255 {256 istream::operator=(_CUDA_VSTD::move(__rhs));257 __sb_ = _CUDA_VSTD::move(__rhs.__sb_);258 return *this;259 }260 261 virtual ~istrstream();262 263 _LIBCUDACXX_INLINE_VISIBILITY264 void swap(istrstream& __rhs)265 {266 istream::swap(__rhs);267 __sb_.swap(__rhs.__sb_);268 }269 270 _LIBCUDACXX_INLINE_VISIBILITY271 strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}272 _LIBCUDACXX_INLINE_VISIBILITY273 char *str() {return __sb_.str();}274 275private:276 strstreambuf __sb_;277};278 279class _LIBCUDACXX_TYPE_VIS ostrstream280 : public ostream281{282public:283 _LIBCUDACXX_INLINE_VISIBILITY284 ostrstream()285 : ostream(&__sb_) {}286 _LIBCUDACXX_INLINE_VISIBILITY287 ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)288 : ostream(&__sb_),289 __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0))290 {}291 292 _LIBCUDACXX_INLINE_VISIBILITY293 ostrstream(ostrstream&& __rhs)294 : ostream(_CUDA_VSTD::move(__rhs)),295 __sb_(_CUDA_VSTD::move(__rhs.__sb_))296 {297 ostream::set_rdbuf(&__sb_);298 }299 300 _LIBCUDACXX_INLINE_VISIBILITY301 ostrstream& operator=(ostrstream&& __rhs)302 {303 ostream::operator=(_CUDA_VSTD::move(__rhs));304 __sb_ = _CUDA_VSTD::move(__rhs.__sb_);305 return *this;306 }307 308 virtual ~ostrstream();309 310 _LIBCUDACXX_INLINE_VISIBILITY311 void swap(ostrstream& __rhs)312 {313 ostream::swap(__rhs);314 __sb_.swap(__rhs.__sb_);315 }316 317 _LIBCUDACXX_INLINE_VISIBILITY318 strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}319 _LIBCUDACXX_INLINE_VISIBILITY320 void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}321 _LIBCUDACXX_INLINE_VISIBILITY322 char* str() {return __sb_.str();}323 _LIBCUDACXX_INLINE_VISIBILITY324 int pcount() const {return __sb_.pcount();}325 326private:327 strstreambuf __sb_; // exposition only328};329 330class _LIBCUDACXX_TYPE_VIS strstream331 : public iostream332{333public:334 // Types335 typedef char char_type;336 typedef char_traits<char>::int_type int_type;337 typedef char_traits<char>::pos_type pos_type;338 typedef char_traits<char>::off_type off_type;339 340 // constructors/destructor341 _LIBCUDACXX_INLINE_VISIBILITY342 strstream()343 : iostream(&__sb_) {}344 _LIBCUDACXX_INLINE_VISIBILITY345 strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)346 : iostream(&__sb_),347 __sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0))348 {}349 350 _LIBCUDACXX_INLINE_VISIBILITY351 strstream(strstream&& __rhs)352 : iostream(_CUDA_VSTD::move(__rhs)),353 __sb_(_CUDA_VSTD::move(__rhs.__sb_))354 {355 iostream::set_rdbuf(&__sb_);356 }357 358 _LIBCUDACXX_INLINE_VISIBILITY359 strstream& operator=(strstream&& __rhs)360 {361 iostream::operator=(_CUDA_VSTD::move(__rhs));362 __sb_ = _CUDA_VSTD::move(__rhs.__sb_);363 return *this;364 }365 366 virtual ~strstream();367 368 _LIBCUDACXX_INLINE_VISIBILITY369 void swap(strstream& __rhs)370 {371 iostream::swap(__rhs);372 __sb_.swap(__rhs.__sb_);373 }374 375 // Members:376 _LIBCUDACXX_INLINE_VISIBILITY377 strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}378 _LIBCUDACXX_INLINE_VISIBILITY379 void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}380 _LIBCUDACXX_INLINE_VISIBILITY381 int pcount() const {return __sb_.pcount();}382 _LIBCUDACXX_INLINE_VISIBILITY383 char* str() {return __sb_.str();}384 385private:386 strstreambuf __sb_; // exposition only387};388 389_LIBCUDACXX_END_NAMESPACE_STD390 391#endif // _LIBCUDACXX_STRSTREAM392 