brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.6 KiB · 22b223b Raw
268 lines · plain
1// -*- C++ -*-2//===----------------------------------------------------------------------===//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 _LIBCPP___CXX03_STRSTREAM11#define _LIBCPP___CXX03_STRSTREAM12 13/*14    strstream synopsis15 16class strstreambuf                                    // Removed in C++2617    : public basic_streambuf<char>18{19public:20    explicit strstreambuf(streamsize alsize_arg = 0); // before C++2021    strstreambuf() : strstreambuf(0) {}               // C++2022    explicit strstreambuf(streamsize alsize_arg);     // C++2023 24    strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));25    strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = nullptr);26    strstreambuf(const char* gnext_arg, streamsize n);27 28    strstreambuf(signed char* gnext_arg, streamsize n, signed char* pbeg_arg = nullptr);29    strstreambuf(const signed char* gnext_arg, streamsize n);30    strstreambuf(unsigned char* gnext_arg, streamsize n, unsigned char* pbeg_arg = nullptr);31    strstreambuf(const unsigned char* gnext_arg, streamsize n);32 33    strstreambuf(strstreambuf&& rhs);34    strstreambuf& operator=(strstreambuf&& rhs);35 36    virtual ~strstreambuf();37 38    void swap(strstreambuf& rhs);39 40    void freeze(bool freezefl = true);41    char* str();42    int pcount() const;43 44protected:45    virtual int_type overflow (int_type c = EOF);46    virtual int_type pbackfail(int_type c = EOF);47    virtual int_type underflow();48    virtual pos_type seekoff(off_type off, ios_base::seekdir way,49                             ios_base::openmode which = ios_base::in | ios_base::out);50    virtual pos_type seekpos(pos_type sp,51                             ios_base::openmode which = ios_base::in | ios_base::out);52    virtual streambuf* setbuf(char* s, streamsize n);53 54private:55    typedef T1 strstate;                // exposition only56    static const strstate allocated;    // exposition only57    static const strstate constant;     // exposition only58    static const strstate dynamic;      // exposition only59    static const strstate frozen;       // exposition only60    strstate strmode;                   // exposition only61    streamsize alsize;                  // exposition only62    void* (*palloc)(size_t);            // exposition only63    void (*pfree)(void*);               // exposition only64};65 66class istrstream                                      // Removed in C++2667    : public basic_istream<char>68{69public:70    explicit istrstream(const char* s);71    explicit istrstream(char* s);72    istrstream(const char* s, streamsize n);73    istrstream(char* s, streamsize n);74 75    virtual ~istrstream();76 77    strstreambuf* rdbuf() const;78    char *str();79 80private:81    strstreambuf sb; // exposition only82};83 84class ostrstream                                      // Removed in C++2685    : public basic_ostream<char>86{87public:88    ostrstream();89    ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);90 91    virtual ~ostrstream();92 93    strstreambuf* rdbuf() const;94    void freeze(bool freezefl = true);95    char* str();96    int pcount() const;97 98private:99    strstreambuf sb; // exposition only100};101 102class strstream                                       // Removed in C++26103    : public basic_iostream<char>104{105public:106    // Types107    typedef char                        char_type;108    typedef char_traits<char>::int_type int_type;109    typedef char_traits<char>::pos_type pos_type;110    typedef char_traits<char>::off_type off_type;111 112    // constructors/destructor113    strstream();114    strstream(char* s, int n, ios_base::openmode mode = ios_base::in | ios_base::out);115 116    virtual ~strstream();117 118    // Members:119    strstreambuf* rdbuf() const;120    void freeze(bool freezefl = true);121    int pcount() const;122    char* str();123 124private:125    strstreambuf sb; // exposition only126};127 128}  // std129 130*/131 132#include <__cxx03/__config>133#include <__cxx03/istream>134#include <__cxx03/ostream>135#include <__cxx03/version>136 137#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)138#  pragma GCC system_header139#endif140 141_LIBCPP_PUSH_MACROS142#  include <__cxx03/__undef_macros>143 144_LIBCPP_BEGIN_NAMESPACE_STD145 146class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstreambuf : public streambuf {147public:148  explicit strstreambuf(streamsize __alsize = 0);149  strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*));150  strstreambuf(char* __gnext, streamsize __n, char* __pbeg = nullptr);151  strstreambuf(const char* __gnext, streamsize __n);152 153  strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = nullptr);154  strstreambuf(const signed char* __gnext, streamsize __n);155  strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = nullptr);156  strstreambuf(const unsigned char* __gnext, streamsize __n);157 158  ~strstreambuf() override;159 160  void swap(strstreambuf& __rhs);161 162  void freeze(bool __freezefl = true);163  char* str();164  int pcount() const;165 166protected:167  int_type overflow(int_type __c = EOF) override;168  int_type pbackfail(int_type __c = EOF) override;169  int_type underflow() override;170  pos_type171  seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out) override;172  pos_type seekpos(pos_type __sp, ios_base::openmode __which = ios_base::in | ios_base::out) override;173 174private:175  typedef unsigned __mode_type;176  static const __mode_type __allocated     = 0x01;177  static const __mode_type __constant      = 0x02;178  static const __mode_type __dynamic       = 0x04;179  static const __mode_type __frozen        = 0x08;180  static const streamsize __default_alsize = 4096;181 182  __mode_type __strmode_;183  streamsize __alsize_;184  void* (*__palloc_)(size_t);185  void (*__pfree_)(void*);186 187  void __init(char* __gnext, streamsize __n, char* __pbeg);188};189 190class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI istrstream : public istream {191public:192  _LIBCPP_HIDE_FROM_ABI explicit istrstream(const char* __s) : istream(&__sb_), __sb_(__s, 0) {}193  _LIBCPP_HIDE_FROM_ABI explicit istrstream(char* __s) : istream(&__sb_), __sb_(__s, 0) {}194  _LIBCPP_HIDE_FROM_ABI istrstream(const char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}195  _LIBCPP_HIDE_FROM_ABI istrstream(char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}196 197  ~istrstream() override;198 199  _LIBCPP_HIDE_FROM_ABI void swap(istrstream& __rhs) {200    istream::swap(__rhs);201    __sb_.swap(__rhs.__sb_);202  }203 204  _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }205  _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }206 207private:208  strstreambuf __sb_;209};210 211class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI ostrstream : public ostream {212public:213  _LIBCPP_HIDE_FROM_ABI ostrstream() : ostream(&__sb_) {}214  _LIBCPP_HIDE_FROM_ABI ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)215      : ostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}216 217  ~ostrstream() override;218 219  _LIBCPP_HIDE_FROM_ABI void swap(ostrstream& __rhs) {220    ostream::swap(__rhs);221    __sb_.swap(__rhs.__sb_);222  }223 224  _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }225  _LIBCPP_HIDE_FROM_ABI void freeze(bool __freezefl = true) { __sb_.freeze(__freezefl); }226  _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }227  _LIBCPP_HIDE_FROM_ABI int pcount() const { return __sb_.pcount(); }228 229private:230  strstreambuf __sb_; // exposition only231};232 233class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstream : public iostream {234public:235  // Types236  typedef char char_type;237  typedef char_traits<char>::int_type int_type;238  typedef char_traits<char>::pos_type pos_type;239  typedef char_traits<char>::off_type off_type;240 241  // constructors/destructor242  _LIBCPP_HIDE_FROM_ABI strstream() : iostream(&__sb_) {}243  _LIBCPP_HIDE_FROM_ABI strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)244      : iostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}245 246  ~strstream() override;247 248  _LIBCPP_HIDE_FROM_ABI void swap(strstream& __rhs) {249    iostream::swap(__rhs);250    __sb_.swap(__rhs.__sb_);251  }252 253  // Members:254  _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }255  _LIBCPP_HIDE_FROM_ABI void freeze(bool __freezefl = true) { __sb_.freeze(__freezefl); }256  _LIBCPP_HIDE_FROM_ABI int pcount() const { return __sb_.pcount(); }257  _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }258 259private:260  strstreambuf __sb_; // exposition only261};262 263_LIBCPP_END_NAMESPACE_STD264 265_LIBCPP_POP_MACROS266 267#endif // _LIBCPP___CXX03_STRSTREAM268