alt_sstream.hpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // alt_sstream.hpp : alternative stringstream
3 // ----------------------------------------------------------------------------
4 
5 // Copyright Samuel Krempp 2003. Use, modification, and distribution are
6 // subject to the Boost Software License, Version 1.0. (See accompanying
7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 
9 // See http://www.boost.org/libs/format for library home page
10 
11 // ----------------------------------------------------------------------------
12 
13 
14 
15 #ifndef BOOST_SK_ALT_SSTREAM_HPP
16 #define BOOST_SK_ALT_SSTREAM_HPP
17 
18 #include <string>
21 //#include <boost/shared_ptr.hpp>
22 #include <boost/assert.hpp>
23 #include <memory.h>
24 
25 namespace boost {
26  namespace io {
27 
28  template<class Ch, class Tr=::std::char_traits<Ch>,
29  class Alloc=::std::allocator<Ch> >
31 
32  template<class Ch, class Tr =::std::char_traits<Ch>,
33  class Alloc=::std::allocator<Ch> >
35 
36 
37  template<class Ch, class Tr, class Alloc>
38  class basic_altstringbuf
39  : public ::std::basic_streambuf<Ch, Tr>
40  {
41  typedef ::std::basic_streambuf<Ch, Tr> streambuf_t;
44  public:
45  typedef Ch char_type;
46  typedef Tr traits_type;
47  typedef typename compat_traits_type::int_type int_type;
48  typedef typename compat_traits_type::pos_type pos_type;
49  typedef typename compat_traits_type::off_type off_type;
50  typedef Alloc allocator_type;
51  typedef ::std::basic_string<Ch, Tr, Alloc> string_type;
52  typedef typename string_type::size_type size_type;
53 
54  typedef ::std::streamsize streamsize;
55 
56 
57  explicit basic_altstringbuf(std::ios_base::openmode mode
58  = std::ios_base::in | std::ios_base::out)
59  : putend_(NULL), is_allocated_(false), mode_(mode)
60  {}
61  explicit basic_altstringbuf(const string_type& s,
62  ::std::ios_base::openmode mode
63  = ::std::ios_base::in | ::std::ios_base::out)
64  : putend_(NULL), is_allocated_(false), mode_(mode)
65  { dealloc(); str(s); }
67  { dealloc(); }
68  using streambuf_t::pbase;
69  using streambuf_t::pptr;
70  using streambuf_t::epptr;
71  using streambuf_t::eback;
72  using streambuf_t::gptr;
73  using streambuf_t::egptr;
74 
75  void clear_buffer();
76  void str(const string_type& s);
77 
78  // 0-copy access :
79  Ch * begin() const;
80  size_type size() const;
81  size_type cur_size() const; // stop at current pointer
82  Ch * pend() const // the highest position reached by pptr() since creation
83  { return ((putend_ < pptr()) ? pptr() : putend_); }
84  size_type pcount() const
85  { return static_cast<size_type>( pptr() - pbase()) ;}
86 
87  // copy buffer to string :
88  string_type str() const
89  { return string_type(begin(), size()); }
90  string_type cur_str() const
91  { return string_type(begin(), cur_size()); }
92  protected:
94  ::std::ios_base::openmode mode
95  = ::std::ios_base::in | ::std::ios_base::out)
96  : putend_(NULL), is_allocated_(false), mode_(mode)
97  { dealloc(); str(s); }
98 
99  virtual pos_type seekoff(off_type off, ::std::ios_base::seekdir way,
100  ::std::ios_base::openmode which
101  = ::std::ios_base::in | ::std::ios_base::out);
102  virtual pos_type seekpos (pos_type pos,
103  ::std::ios_base::openmode which
104  = ::std::ios_base::in | ::std::ios_base::out);
105  virtual int_type underflow();
106  virtual int_type pbackfail(int_type meta = compat_traits_type::eof());
107  virtual int_type overflow(int_type meta = compat_traits_type::eof());
108  void dealloc();
109  private:
110  enum { alloc_min = 256}; // minimum size of allocations
111 
112  Ch *putend_; // remembers (over seeks) the highest value of pptr()
114  ::std::ios_base::openmode mode_;
115  compat_allocator_type alloc_; // the allocator object
116  };
117 
118 
119 // --- class basic_oaltstringstream ----------------------------------------
120  template <class Ch, class Tr, class Alloc>
122  : private base_from_member< std::shared_ptr< basic_altstringbuf< Ch, Tr, Alloc> > >,
123  public ::std::basic_ostream<Ch, Tr>
124  {
125  class No_Op {
126  // used as no-op deleter for (not-owner) shared_pointers
127  public:
128  template<class T>
129  const T & operator()(const T & arg) { return arg; }
130  };
131  typedef ::std::basic_ostream<Ch, Tr> stream_t;
132  typedef boost::base_from_member<std::shared_ptr<
135  typedef ::std::basic_string<Ch, Tr, Alloc> string_type;
136  typedef typename string_type::size_type size_type;
138  public:
139  typedef Alloc allocator_type;
141  : pbase_type(new stringbuf_t), stream_t(rdbuf())
142  { }
143  basic_oaltstringstream(::std::shared_ptr<stringbuf_t> buf)
144  : pbase_type(buf), stream_t(rdbuf())
145  { }
146  basic_oaltstringstream(stringbuf_t * buf)
147  : pbase_type(buf, No_Op() ), stream_t(rdbuf())
148  { }
149  stringbuf_t * rdbuf() const
150  { return pbase_type::member.get(); }
151  void clear_buffer()
152  { rdbuf()->clear_buffer(); }
153 
154  // 0-copy access :
155  Ch * begin() const
156  { return rdbuf()->begin(); }
157  size_type size() const
158  { return rdbuf()->size(); }
159  size_type cur_size() const // stops at current position
160  { return rdbuf()->cur_size(); }
161 
162  // copy buffer to string :
163  string_type str() const // [pbase, epptr[
164  { return rdbuf()->str(); }
165  string_type cur_str() const // [pbase, pptr[
166  { return rdbuf()->cur_str(); }
167  void str(const string_type& s)
168  { rdbuf()->str(s); }
169  };
170 
171  } // N.S. io
172 } // N.S. boost
173 
175 
176 #endif // include guard
177 
basic_altstringbuf< Ch, Tr, Alloc > stringbuf_t
::std::basic_streambuf< Ch, Tr > streambuf_t
Definition: alt_sstream.hpp:41
::std::streamsize streamsize
Definition: alt_sstream.hpp:54
BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE.
GLdouble s
::std::ios_base::openmode mode_
compat_traits_type::pos_type pos_type
Definition: alt_sstream.hpp:48
compat_allocator_type alloc_
virtual pos_type seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which=::std::ios_base::in|::std::ios_base::out)
boost::base_from_member< std::shared_ptr< basic_altstringbuf< Ch, Tr, Alloc > > > pbase_type
string_type::size_type size_type
Definition: alt_sstream.hpp:52
string_type::size_type size_type
Definition: arg_fwd.hpp:23
compat_traits_type::off_type off_type
Definition: alt_sstream.hpp:49
basic_altstringbuf(const string_type &s, ::std::ios_base::openmode mode=::std::ios_base::in|::std::ios_base::out)
Definition: alt_sstream.hpp:61
virtual int_type overflow(int_type meta=compat_traits_type::eof())
GLenum GLuint GLenum GLsizei const GLchar * buf
GLenum mode
compat_traits_type::int_type int_type
Definition: alt_sstream.hpp:47
virtual int_type pbackfail(int_type meta=compat_traits_type::eof())
basic_altstringbuf(basic_altstringbuf *s, ::std::ios_base::openmode mode=::std::ios_base::in|::std::ios_base::out)
Definition: alt_sstream.hpp:93
CompatTraits< Tr >::compatible_type compat_traits_type
Definition: alt_sstream.hpp:43
string_type str() const
Definition: alt_sstream.hpp:88
basic_oaltstringstream(stringbuf_t *buf)
::std::basic_string< Ch, Tr, Alloc > string_type
basic_altstringbuf(std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
Definition: alt_sstream.hpp:57
void str(const string_type &s)
float rs2_vector::* pos
#define NULL
Definition: tinycthread.c:47
string_type cur_str() const
Definition: alt_sstream.hpp:90
basic_oaltstringstream(::std::shared_ptr< stringbuf_t > buf)
virtual pos_type seekpos(pos_type pos, ::std::ios_base::openmode which=::std::ios_base::in|::std::ios_base::out)
::std::basic_ostream< Ch, Tr > stream_t
::std::basic_string< Ch, Tr, Alloc > string_type
Definition: alt_sstream.hpp:51
CompatAlloc< Alloc >::compatible_type compat_allocator_type
Definition: alt_sstream.hpp:42


librealsense2
Author(s): LibRealSense ROS Team
autogenerated on Thu Dec 22 2022 03:41:41