Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/c++/v1/__cxx03/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___CXX03_STRSTREAM
0011 #define _LIBCPP___CXX03_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 #include <__cxx03/__config>
0133 #include <__cxx03/istream>
0134 #include <__cxx03/ostream>
0135 #include <__cxx03/version>
0136 
0137 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0138 #  pragma GCC system_header
0139 #endif
0140 
0141 #if _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM) || defined(_LIBCPP_BUILDING_LIBRARY)
0142 
0143 _LIBCPP_PUSH_MACROS
0144 #  include <__cxx03/__undef_macros>
0145 
0146 _LIBCPP_BEGIN_NAMESPACE_STD
0147 
0148 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstreambuf : public streambuf {
0149 public:
0150 #  ifndef _LIBCPP_CXX03_LANG
0151   _LIBCPP_HIDE_FROM_ABI strstreambuf() : strstreambuf(0) {}
0152   explicit strstreambuf(streamsize __alsize);
0153 #  else
0154   explicit strstreambuf(streamsize __alsize = 0);
0155 #  endif
0156   strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*));
0157   strstreambuf(char* __gnext, streamsize __n, char* __pbeg = nullptr);
0158   strstreambuf(const char* __gnext, streamsize __n);
0159 
0160   strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = nullptr);
0161   strstreambuf(const signed char* __gnext, streamsize __n);
0162   strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = nullptr);
0163   strstreambuf(const unsigned char* __gnext, streamsize __n);
0164 
0165 #  ifndef _LIBCPP_CXX03_LANG
0166   _LIBCPP_HIDE_FROM_ABI strstreambuf(strstreambuf&& __rhs);
0167   _LIBCPP_HIDE_FROM_ABI strstreambuf& operator=(strstreambuf&& __rhs);
0168 #  endif // _LIBCPP_CXX03_LANG
0169 
0170   ~strstreambuf() override;
0171 
0172   void swap(strstreambuf& __rhs);
0173 
0174   void freeze(bool __freezefl = true);
0175   char* str();
0176   int pcount() const;
0177 
0178 protected:
0179   int_type overflow(int_type __c = EOF) override;
0180   int_type pbackfail(int_type __c = EOF) override;
0181   int_type underflow() override;
0182   pos_type
0183   seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which = ios_base::in | ios_base::out) override;
0184   pos_type seekpos(pos_type __sp, ios_base::openmode __which = ios_base::in | ios_base::out) override;
0185 
0186 private:
0187   typedef unsigned __mode_type;
0188   static const __mode_type __allocated     = 0x01;
0189   static const __mode_type __constant      = 0x02;
0190   static const __mode_type __dynamic       = 0x04;
0191   static const __mode_type __frozen        = 0x08;
0192   static const streamsize __default_alsize = 4096;
0193 
0194   __mode_type __strmode_;
0195   streamsize __alsize_;
0196   void* (*__palloc_)(size_t);
0197   void (*__pfree_)(void*);
0198 
0199   void __init(char* __gnext, streamsize __n, char* __pbeg);
0200 };
0201 
0202 #  ifndef _LIBCPP_CXX03_LANG
0203 
0204 inline _LIBCPP_HIDE_FROM_ABI strstreambuf::strstreambuf(strstreambuf&& __rhs)
0205     : streambuf(__rhs),
0206       __strmode_(__rhs.__strmode_),
0207       __alsize_(__rhs.__alsize_),
0208       __palloc_(__rhs.__palloc_),
0209       __pfree_(__rhs.__pfree_) {
0210   __rhs.setg(nullptr, nullptr, nullptr);
0211   __rhs.setp(nullptr, nullptr);
0212 }
0213 
0214 inline _LIBCPP_HIDE_FROM_ABI strstreambuf& strstreambuf::operator=(strstreambuf&& __rhs) {
0215   if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0) {
0216     if (__pfree_)
0217       __pfree_(eback());
0218     else
0219       delete[] eback();
0220   }
0221   streambuf::operator=(__rhs);
0222   __strmode_ = __rhs.__strmode_;
0223   __alsize_  = __rhs.__alsize_;
0224   __palloc_  = __rhs.__palloc_;
0225   __pfree_   = __rhs.__pfree_;
0226   __rhs.setg(nullptr, nullptr, nullptr);
0227   __rhs.setp(nullptr, nullptr);
0228   return *this;
0229 }
0230 
0231 #  endif // _LIBCPP_CXX03_LANG
0232 
0233 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI istrstream : public istream {
0234 public:
0235   _LIBCPP_HIDE_FROM_ABI explicit istrstream(const char* __s) : istream(&__sb_), __sb_(__s, 0) {}
0236   _LIBCPP_HIDE_FROM_ABI explicit istrstream(char* __s) : istream(&__sb_), __sb_(__s, 0) {}
0237   _LIBCPP_HIDE_FROM_ABI istrstream(const char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}
0238   _LIBCPP_HIDE_FROM_ABI istrstream(char* __s, streamsize __n) : istream(&__sb_), __sb_(__s, __n) {}
0239 
0240 #  ifndef _LIBCPP_CXX03_LANG
0241   _LIBCPP_HIDE_FROM_ABI istrstream(istrstream&& __rhs) // extension
0242       : istream(std::move(static_cast<istream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
0243     istream::set_rdbuf(&__sb_);
0244   }
0245 
0246   _LIBCPP_HIDE_FROM_ABI istrstream& operator=(istrstream&& __rhs) {
0247     __sb_ = std::move(__rhs.__sb_);
0248     istream::operator=(std::move(__rhs));
0249     return *this;
0250   }
0251 #  endif // _LIBCPP_CXX03_LANG
0252 
0253   ~istrstream() override;
0254 
0255   _LIBCPP_HIDE_FROM_ABI void swap(istrstream& __rhs) {
0256     istream::swap(__rhs);
0257     __sb_.swap(__rhs.__sb_);
0258   }
0259 
0260   _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }
0261   _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }
0262 
0263 private:
0264   strstreambuf __sb_;
0265 };
0266 
0267 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI ostrstream : public ostream {
0268 public:
0269   _LIBCPP_HIDE_FROM_ABI ostrstream() : ostream(&__sb_) {}
0270   _LIBCPP_HIDE_FROM_ABI ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
0271       : ostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}
0272 
0273 #  ifndef _LIBCPP_CXX03_LANG
0274   _LIBCPP_HIDE_FROM_ABI ostrstream(ostrstream&& __rhs) // extension
0275       : ostream(std::move(static_cast<ostream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
0276     ostream::set_rdbuf(&__sb_);
0277   }
0278 
0279   _LIBCPP_HIDE_FROM_ABI ostrstream& operator=(ostrstream&& __rhs) {
0280     __sb_ = std::move(__rhs.__sb_);
0281     ostream::operator=(std::move(__rhs));
0282     return *this;
0283   }
0284 #  endif // _LIBCPP_CXX03_LANG
0285 
0286   ~ostrstream() override;
0287 
0288   _LIBCPP_HIDE_FROM_ABI void swap(ostrstream& __rhs) {
0289     ostream::swap(__rhs);
0290     __sb_.swap(__rhs.__sb_);
0291   }
0292 
0293   _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }
0294   _LIBCPP_HIDE_FROM_ABI void freeze(bool __freezefl = true) { __sb_.freeze(__freezefl); }
0295   _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }
0296   _LIBCPP_HIDE_FROM_ABI int pcount() const { return __sb_.pcount(); }
0297 
0298 private:
0299   strstreambuf __sb_; // exposition only
0300 };
0301 
0302 class _LIBCPP_DEPRECATED _LIBCPP_EXPORTED_FROM_ABI strstream : public iostream {
0303 public:
0304   // Types
0305   typedef char char_type;
0306   typedef char_traits<char>::int_type int_type;
0307   typedef char_traits<char>::pos_type pos_type;
0308   typedef char_traits<char>::off_type off_type;
0309 
0310   // constructors/destructor
0311   _LIBCPP_HIDE_FROM_ABI strstream() : iostream(&__sb_) {}
0312   _LIBCPP_HIDE_FROM_ABI strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
0313       : iostream(&__sb_), __sb_(__s, __n, __s + (__mode & ios::app ? std::strlen(__s) : 0)) {}
0314 
0315 #  ifndef _LIBCPP_CXX03_LANG
0316   _LIBCPP_HIDE_FROM_ABI strstream(strstream&& __rhs) // extension
0317       : iostream(std::move(static_cast<iostream&>(__rhs))), __sb_(std::move(__rhs.__sb_)) {
0318     iostream::set_rdbuf(&__sb_);
0319   }
0320 
0321   _LIBCPP_HIDE_FROM_ABI strstream& operator=(strstream&& __rhs) {
0322     __sb_ = std::move(__rhs.__sb_);
0323     iostream::operator=(std::move(__rhs));
0324     return *this;
0325   }
0326 #  endif // _LIBCPP_CXX03_LANG
0327 
0328   ~strstream() override;
0329 
0330   _LIBCPP_HIDE_FROM_ABI void swap(strstream& __rhs) {
0331     iostream::swap(__rhs);
0332     __sb_.swap(__rhs.__sb_);
0333   }
0334 
0335   // Members:
0336   _LIBCPP_HIDE_FROM_ABI strstreambuf* rdbuf() const { return const_cast<strstreambuf*>(&__sb_); }
0337   _LIBCPP_HIDE_FROM_ABI void freeze(bool __freezefl = true) { __sb_.freeze(__freezefl); }
0338   _LIBCPP_HIDE_FROM_ABI int pcount() const { return __sb_.pcount(); }
0339   _LIBCPP_HIDE_FROM_ABI char* str() { return __sb_.str(); }
0340 
0341 private:
0342   strstreambuf __sb_; // exposition only
0343 };
0344 
0345 _LIBCPP_END_NAMESPACE_STD
0346 
0347 _LIBCPP_POP_MACROS
0348 
0349 #endif // _LIBCPP_STD_VER < 26 || defined(_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM) || defined(_LIBCPP_BUILDING_LIBRARY)
0350 
0351 #endif // _LIBCPP___CXX03_STRSTREAM