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()); }
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;
142  { }
143  basic_oaltstringstream(::std::shared_ptr<stringbuf_t> buf)
144  : pbase_type(buf), stream_t(rdbuf())
145  { }
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 
boost::io::basic_oaltstringstream::basic_oaltstringstream
basic_oaltstringstream(::std::shared_ptr< stringbuf_t > buf)
Definition: alt_sstream.hpp:143
boost::io::basic_altstringbuf::compat_allocator_type
CompatAlloc< Alloc >::compatible_type compat_allocator_type
Definition: alt_sstream.hpp:42
boost::io::basic_altstringbuf::traits_type
Tr traits_type
Definition: alt_sstream.hpp:46
boost::io::basic_oaltstringstream::basic_oaltstringstream
basic_oaltstringstream(stringbuf_t *buf)
Definition: alt_sstream.hpp:146
boost::io::basic_altstringbuf::allocator_type
Alloc allocator_type
Definition: alt_sstream.hpp:50
boost::io::basic_oaltstringstream::size
size_type size() const
Definition: alt_sstream.hpp:157
boost::io::basic_oaltstringstream::clear_buffer
void clear_buffer()
Definition: alt_sstream.hpp:151
boost::io::basic_altstringbuf::size
size_type size() const
Definition: alt_sstream_impl.hpp:77
pos
float rs2_vector::* pos
Definition: rs-trajectory.cpp:252
boost::io::basic_altstringbuf::streambuf_t
::std::basic_streambuf< Ch, Tr > streambuf_t
Definition: alt_sstream.hpp:41
boost::io::basic_altstringbuf::char_type
Ch char_type
Definition: alt_sstream.hpp:45
boost::io::basic_altstringbuf::compat_traits_type
CompatTraits< Tr >::compatible_type compat_traits_type
Definition: alt_sstream.hpp:43
boost::io::CompatAlloc::compatible_type
Alloc compatible_type
Definition: compat_workarounds.hpp:81
boost::io::basic_altstringbuf::size_type
string_type::size_type size_type
Definition: alt_sstream.hpp:52
boost::io::basic_oaltstringstream::stringbuf_t
basic_altstringbuf< Ch, Tr, Alloc > stringbuf_t
Definition: alt_sstream.hpp:137
base_from_member.hpp
mode
GLenum mode
Definition: glad/glad/glad.h:1385
boost::io::basic_altstringbuf::alloc_min
@ alloc_min
Definition: alt_sstream.hpp:110
boost::io::basic_altstringbuf
Definition: alt_sstream.hpp:30
boost::io::basic_altstringbuf::begin
Ch * begin() const
Definition: alt_sstream_impl.hpp:66
boost::io::basic_altstringbuf::streamsize
::std::streamsize streamsize
Definition: alt_sstream.hpp:54
opencv_pointcloud_viewer.out
out
Definition: opencv_pointcloud_viewer.py:276
boost
BOOST_MOVE_USE_STANDARD_LIBRARY_MOVE.
Definition: core/addressof.hpp:19
boost::io::basic_altstringbuf::mode_
::std::ios_base::openmode mode_
Definition: alt_sstream.hpp:114
boost::io::basic_altstringbuf::basic_altstringbuf
basic_altstringbuf(const string_type &s, ::std::ios_base::openmode mode=::std::ios_base::in|::std::ios_base::out)
Definition: alt_sstream.hpp:61
boost::io::basic_altstringbuf::putend_
Ch * putend_
Definition: alt_sstream.hpp:112
boost::io::basic_altstringbuf::pcount
size_type pcount() const
Definition: alt_sstream.hpp:84
boost::io::basic_altstringbuf::is_allocated_
bool is_allocated_
Definition: alt_sstream.hpp:113
boost::io::basic_altstringbuf::seekoff
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)
Definition: alt_sstream_impl.hpp:101
boost::io::basic_oaltstringstream::No_Op
Definition: alt_sstream.hpp:125
boost::io::basic_altstringbuf::pbackfail
virtual int_type pbackfail(int_type meta=compat_traits_type::eof())
Definition: alt_sstream_impl.hpp:208
boost::io::basic_oaltstringstream::cur_size
size_type cur_size() const
Definition: alt_sstream.hpp:159
boost::io::basic_altstringbuf::cur_str
string_type cur_str() const
Definition: alt_sstream.hpp:90
boost::io::basic_oaltstringstream::allocator_type
Alloc allocator_type
Definition: alt_sstream.hpp:139
boost::io::basic_altstringbuf::off_type
compat_traits_type::off_type off_type
Definition: alt_sstream.hpp:49
boost::io::basic_oaltstringstream::cur_str
string_type cur_str() const
Definition: alt_sstream.hpp:165
boost::io::basic_oaltstringstream
Definition: alt_sstream.hpp:34
NULL
#define NULL
Definition: tinycthread.c:47
boost::io::basic_altstringbuf::pos_type
compat_traits_type::pos_type pos_type
Definition: alt_sstream.hpp:48
boost::io::basic_oaltstringstream::begin
Ch * begin() const
Definition: alt_sstream.hpp:155
alt_sstream_impl.hpp
arg
Definition: arg_fwd.hpp:23
boost::io::basic_altstringbuf::pend
Ch * pend() const
Definition: alt_sstream.hpp:82
assert.hpp
boost::io::basic_altstringbuf::dealloc
void dealloc()
Definition: alt_sstream_impl.hpp:300
t265_stereo.T
T
Definition: t265_stereo.py:157
boost::io::basic_oaltstringstream::stream_t
::std::basic_ostream< Ch, Tr > stream_t
Definition: alt_sstream.hpp:131
boost::io::basic_altstringbuf::basic_altstringbuf
basic_altstringbuf(std::ios_base::openmode mode=std::ios_base::in|std::ios_base::out)
Definition: alt_sstream.hpp:57
boost::io::basic_altstringbuf::overflow
virtual int_type overflow(int_type meta=compat_traits_type::eof())
Definition: alt_sstream_impl.hpp:228
boost::io::basic_oaltstringstream::string_type
::std::basic_string< Ch, Tr, Alloc > string_type
Definition: alt_sstream.hpp:135
boost::io::basic_altstringbuf::basic_altstringbuf
basic_altstringbuf(basic_altstringbuf *s, ::std::ios_base::openmode mode=::std::ios_base::in|::std::ios_base::out)
Definition: alt_sstream.hpp:93
boost::io::basic_oaltstringstream::str
string_type str() const
Definition: alt_sstream.hpp:163
boost::io::basic_oaltstringstream::pbase_type
boost::base_from_member< std::shared_ptr< basic_altstringbuf< Ch, Tr, Alloc > > > pbase_type
Definition: alt_sstream.hpp:134
boost::io::basic_altstringbuf::str
void str(const string_type &s)
Definition: alt_sstream_impl.hpp:37
boost::io::basic_oaltstringstream::No_Op::operator()
const T & operator()(const T &arg)
Definition: alt_sstream.hpp:129
boost::io::CompatTraits::compatible_type
Tr compatible_type
Definition: compat_workarounds.hpp:73
boost::io::basic_altstringbuf::cur_size
size_type cur_size() const
Definition: alt_sstream_impl.hpp:89
boost::base_from_member::member
MemberType member
Definition: base_from_member.hpp:127
boost::io::basic_oaltstringstream::basic_oaltstringstream
basic_oaltstringstream()
Definition: alt_sstream.hpp:140
boost::io::basic_oaltstringstream::str
void str(const string_type &s)
Definition: alt_sstream.hpp:167
boost::io::basic_altstringbuf::str
string_type str() const
Definition: alt_sstream.hpp:88
boost::io::basic_altstringbuf::~basic_altstringbuf
virtual ~basic_altstringbuf()
Definition: alt_sstream.hpp:66
boost::base_from_member
Definition: base_from_member.hpp:124
boost::io::basic_oaltstringstream::size_type
string_type::size_type size_type
Definition: alt_sstream.hpp:136
boost::io::basic_altstringbuf::underflow
virtual int_type underflow()
Definition: alt_sstream_impl.hpp:186
boost::io::basic_altstringbuf::string_type
::std::basic_string< Ch, Tr, Alloc > string_type
Definition: alt_sstream.hpp:51
boost::io::basic_altstringbuf::int_type
compat_traits_type::int_type int_type
Definition: alt_sstream.hpp:47
boost::io::basic_oaltstringstream::rdbuf
stringbuf_t * rdbuf() const
Definition: alt_sstream.hpp:149
s
GLdouble s
Definition: glad/glad/glad.h:2441
compat_workarounds.hpp
boost::io::basic_altstringbuf::seekpos
virtual pos_type seekpos(pos_type pos, ::std::ios_base::openmode which=::std::ios_base::in|::std::ios_base::out)
Definition: alt_sstream_impl.hpp:147
boost::io::basic_altstringbuf::alloc_
compat_allocator_type alloc_
Definition: alt_sstream.hpp:115
boost::io::basic_altstringbuf::clear_buffer
void clear_buffer()
Definition: alt_sstream_impl.hpp:22
buf
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glad/glad/glad.h:3610


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