vectorstream.hpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. // This file comes from SGI's sstream file. Modified by Ion Gaztanaga 2005-2012.
  12. // Changed internal SGI string to a generic, templatized vector. Added efficient
  13. // internal buffer get/set/swap functions, so that we can obtain/establish the
  14. // internal buffer without any reallocation or copy. Kill those temporaries!
  15. ///////////////////////////////////////////////////////////////////////////////
  16. /*
  17. * Copyright (c) 1998
  18. * Silicon Graphics Computer Systems, Inc.
  19. *
  20. * Permission to use, copy, modify, distribute and sell this software
  21. * and its documentation for any purpose is hereby granted without fee,
  22. * provided that the above copyright notice appear in all copies and
  23. * that both that copyright notice and this permission notice appear
  24. * in supporting documentation. Silicon Graphics makes no
  25. * representations about the suitability of this software for any
  26. * purpose. It is provided "as is" without express or implied warranty.
  27. */
  28. //!\file
  29. //!This file defines basic_vectorbuf, basic_ivectorstream,
  30. //!basic_ovectorstream, and basic_vectorstreamclasses. These classes
  31. //!represent streamsbufs and streams whose sources or destinations are
  32. //!STL-like vectors that can be swapped with external vectors to avoid
  33. //!unnecessary allocations/copies.
  34. #ifndef BOOST_INTERPROCESS_VECTORSTREAM_HPP
  35. #define BOOST_INTERPROCESS_VECTORSTREAM_HPP
  36. #include <boost/interprocess/detail/config_begin.hpp>
  37. #include <boost/interprocess/detail/workaround.hpp>
  38. #include <iosfwd>
  39. #include <ios>
  40. #include <istream>
  41. #include <ostream>
  42. #include <string> // char traits
  43. #include <cstddef> // ptrdiff_t
  44. #include <boost/interprocess/interprocess_fwd.hpp>
  45. #include <boost/assert.hpp>
  46. namespace boost { namespace interprocess {
  47. //!A streambuf class that controls the transmission of elements to and from
  48. //!a basic_ivectorstream, basic_ovectorstream or basic_vectorstream.
  49. //!It holds a character vector specified by CharVector template parameter
  50. //!as its formatting buffer. The vector must have contiguous storage, like
  51. //!std::vector, boost::interprocess::vector or boost::interprocess::basic_string
  52. template <class CharVector, class CharTraits>
  53. class basic_vectorbuf
  54. : public std::basic_streambuf<typename CharVector::value_type, CharTraits>
  55. {
  56. public:
  57. typedef CharVector vector_type;
  58. typedef typename CharVector::value_type char_type;
  59. typedef typename CharTraits::int_type int_type;
  60. typedef typename CharTraits::pos_type pos_type;
  61. typedef typename CharTraits::off_type off_type;
  62. typedef CharTraits traits_type;
  63. /// @cond
  64. private:
  65. typedef std::basic_streambuf<char_type, traits_type> base_t;
  66. basic_vectorbuf(const basic_vectorbuf&);
  67. basic_vectorbuf & operator =(const basic_vectorbuf&);
  68. /// @endcond
  69. public:
  70. //!Constructor. Throws if vector_type default
  71. //!constructor throws.
  72. explicit basic_vectorbuf(std::ios_base::openmode mode
  73. = std::ios_base::in | std::ios_base::out)
  74. : base_t(), m_mode(mode)
  75. { this->initialize_pointers(); }
  76. //!Constructor. Throws if
  77. //!vector_type(const VectorParameter &param) throws.
  78. template<class VectorParameter>
  79. explicit basic_vectorbuf(const VectorParameter &param,
  80. std::ios_base::openmode mode
  81. = std::ios_base::in | std::ios_base::out)
  82. : base_t(), m_mode(mode), m_vect(param)
  83. { this->initialize_pointers(); }
  84. virtual ~basic_vectorbuf(){}
  85. public:
  86. //!Swaps the underlying vector with the passed vector.
  87. //!This function resets the read/write position in the stream.
  88. //!Does not throw.
  89. void swap_vector(vector_type &vect)
  90. {
  91. if (this->m_mode & std::ios_base::out){
  92. //Update high water if necessary
  93. //And resize vector to remove extra size
  94. if (mp_high_water < base_t::pptr()){
  95. //Restore the vector's size if necessary
  96. mp_high_water = base_t::pptr();
  97. }
  98. //This does not reallocate
  99. m_vect.resize(mp_high_water - (m_vect.size() ? &m_vect[0] : 0));
  100. }
  101. //Now swap vector
  102. m_vect.swap(vect);
  103. this->initialize_pointers();
  104. }
  105. //!Returns a const reference to the internal vector.
  106. //!Does not throw.
  107. const vector_type &vector() const
  108. {
  109. if (this->m_mode & std::ios_base::out){
  110. if (mp_high_water < base_t::pptr()){
  111. //Restore the vector's size if necessary
  112. mp_high_water = base_t::pptr();
  113. }
  114. //This shouldn't reallocate
  115. typedef typename vector_type::size_type size_type;
  116. char_type *old_ptr = base_t::pbase();
  117. size_type high_pos = size_type(mp_high_water-old_ptr);
  118. if(m_vect.size() > high_pos){
  119. m_vect.resize(high_pos);
  120. //But we must update end write pointer because vector size is now shorter
  121. int old_pos = base_t::pptr() - base_t::pbase();
  122. const_cast<basic_vectorbuf*>(this)->base_t::setp(old_ptr, old_ptr + high_pos);
  123. const_cast<basic_vectorbuf*>(this)->base_t::pbump(old_pos);
  124. }
  125. }
  126. return m_vect;
  127. }
  128. //!Preallocates memory from the internal vector.
  129. //!Resets the stream to the first position.
  130. //!Throws if the internals vector's memory allocation throws.
  131. void reserve(typename vector_type::size_type size)
  132. {
  133. if (this->m_mode & std::ios_base::out && size > m_vect.size()){
  134. typename vector_type::difference_type write_pos = base_t::pptr() - base_t::pbase();
  135. typename vector_type::difference_type read_pos = base_t::gptr() - base_t::eback();
  136. //Now update pointer data
  137. m_vect.reserve(size);
  138. this->initialize_pointers();
  139. base_t::pbump((int)write_pos);
  140. if(this->m_mode & std::ios_base::in){
  141. base_t::gbump((int)read_pos);
  142. }
  143. }
  144. }
  145. //!Calls clear() method of the internal vector.
  146. //!Resets the stream to the first position.
  147. void clear()
  148. { m_vect.clear(); this->initialize_pointers(); }
  149. /// @cond
  150. private:
  151. //Maximizes high watermark to the initial vector size,
  152. //initializes read and write iostream buffers to the capacity
  153. //and resets stream positions
  154. void initialize_pointers()
  155. {
  156. // The initial read position is the beginning of the vector.
  157. if(!(m_mode & std::ios_base::out)){
  158. if(m_vect.empty()){
  159. this->setg(0, 0, 0);
  160. }
  161. else{
  162. this->setg(&m_vect[0], &m_vect[0], &m_vect[0] + m_vect.size());
  163. }
  164. }
  165. // The initial write position is the beginning of the vector.
  166. if(m_mode & std::ios_base::out){
  167. //First get real size
  168. int real_size = (int)m_vect.size();
  169. //Then maximize size for high watermarking
  170. m_vect.resize(m_vect.capacity());
  171. BOOST_ASSERT(m_vect.size() == m_vect.capacity());
  172. //Set high watermarking with the expanded size
  173. mp_high_water = m_vect.size() ? (&m_vect[0] + real_size) : 0;
  174. //Now set formatting pointers
  175. if(m_vect.empty()){
  176. this->setp(0, 0);
  177. if(m_mode & std::ios_base::in)
  178. this->setg(0, 0, 0);
  179. }
  180. else{
  181. char_type *p = &m_vect[0];
  182. this->setp(p, p + m_vect.size());
  183. if(m_mode & std::ios_base::in)
  184. this->setg(p, p, p + real_size);
  185. }
  186. if (m_mode & (std::ios_base::app | std::ios_base::ate)){
  187. base_t::pbump((int)real_size);
  188. }
  189. }
  190. }
  191. protected:
  192. virtual int_type underflow()
  193. {
  194. if (base_t::gptr() == 0)
  195. return CharTraits::eof();
  196. if(m_mode & std::ios_base::out){
  197. if (mp_high_water < base_t::pptr())
  198. mp_high_water = base_t::pptr();
  199. if (base_t::egptr() < mp_high_water)
  200. base_t::setg(base_t::eback(), base_t::gptr(), mp_high_water);
  201. }
  202. if (base_t::gptr() < base_t::egptr())
  203. return CharTraits::to_int_type(*base_t::gptr());
  204. return CharTraits::eof();
  205. }
  206. virtual int_type pbackfail(int_type c = CharTraits::eof())
  207. {
  208. if(this->gptr() != this->eback()) {
  209. if(!CharTraits::eq_int_type(c, CharTraits::eof())) {
  210. if(CharTraits::eq(CharTraits::to_char_type(c), this->gptr()[-1])) {
  211. this->gbump(-1);
  212. return c;
  213. }
  214. else if(m_mode & std::ios_base::out) {
  215. this->gbump(-1);
  216. *this->gptr() = c;
  217. return c;
  218. }
  219. else
  220. return CharTraits::eof();
  221. }
  222. else {
  223. this->gbump(-1);
  224. return CharTraits::not_eof(c);
  225. }
  226. }
  227. else
  228. return CharTraits::eof();
  229. }
  230. virtual int_type overflow(int_type c = CharTraits::eof())
  231. {
  232. if(m_mode & std::ios_base::out) {
  233. if(!CharTraits::eq_int_type(c, CharTraits::eof())) {
  234. typedef typename vector_type::difference_type dif_t;
  235. //The new output position is the previous one plus one
  236. //because 'overflow' requires putting 'c' on the buffer
  237. dif_t new_outpos = base_t::pptr() - base_t::pbase() + 1;
  238. //Adjust high water if necessary
  239. dif_t hipos = mp_high_water - base_t::pbase();
  240. if (hipos < new_outpos)
  241. hipos = new_outpos;
  242. //Insert the new data
  243. m_vect.push_back(CharTraits::to_char_type(c));
  244. m_vect.resize(m_vect.capacity());
  245. BOOST_ASSERT(m_vect.size() == m_vect.capacity());
  246. char_type* p = const_cast<char_type*>(&m_vect[0]);
  247. //A reallocation might have happened, update pointers
  248. base_t::setp(p, p + (dif_t)m_vect.size());
  249. mp_high_water = p + hipos;
  250. if (m_mode & std::ios_base::in)
  251. base_t::setg(p, p + (base_t::gptr() - base_t::eback()), mp_high_water);
  252. //Update write position to the old position + 1
  253. base_t::pbump((int)new_outpos);
  254. return c;
  255. }
  256. else // c is EOF, so we don't have to do anything
  257. return CharTraits::not_eof(c);
  258. }
  259. else // Overflow always fails if it's read-only.
  260. return CharTraits::eof();
  261. }
  262. virtual pos_type seekoff(off_type off, std::ios_base::seekdir dir,
  263. std::ios_base::openmode mode
  264. = std::ios_base::in | std::ios_base::out)
  265. {
  266. //Get seek mode
  267. bool in(0 != (mode & std::ios_base::in)), out(0 != (mode & std::ios_base::out));
  268. //Test for logic errors
  269. if(!in & !out)
  270. return pos_type(off_type(-1));
  271. else if((in && out) && (dir == std::ios_base::cur))
  272. return pos_type(off_type(-1));
  273. else if((in && (!(m_mode & std::ios_base::in) || this->gptr() == 0)) ||
  274. (out && (!(m_mode & std::ios_base::out) || this->pptr() == 0)))
  275. return pos_type(off_type(-1));
  276. off_type newoff;
  277. //Just calculate the end of the stream. If the stream is read-only
  278. //the limit is the size of the vector. Otherwise, the high water mark
  279. //will mark the real size.
  280. off_type limit;
  281. if(m_mode & std::ios_base::out){
  282. //Update high water marking because pptr() is going to change and it might
  283. //have been updated since last overflow()
  284. if(mp_high_water < base_t::pptr())
  285. mp_high_water = base_t::pptr();
  286. //Update read limits in case high water mark was changed
  287. if(m_mode & std::ios_base::in){
  288. if (base_t::egptr() < mp_high_water)
  289. base_t::setg(base_t::eback(), base_t::gptr(), mp_high_water);
  290. }
  291. limit = static_cast<off_type>(mp_high_water - base_t::pbase());
  292. }
  293. else{
  294. limit = static_cast<off_type>(m_vect.size());
  295. }
  296. switch(dir) {
  297. case std::ios_base::beg:
  298. newoff = 0;
  299. break;
  300. case std::ios_base::end:
  301. newoff = limit;
  302. break;
  303. case std::ios_base::cur:
  304. newoff = in ? static_cast<std::streamoff>(this->gptr() - this->eback())
  305. : static_cast<std::streamoff>(this->pptr() - this->pbase());
  306. break;
  307. default:
  308. return pos_type(off_type(-1));
  309. }
  310. newoff += off;
  311. if (newoff < 0 || newoff > limit)
  312. return pos_type(-1);
  313. if (m_mode & std::ios_base::app && mode & std::ios_base::out && newoff != limit)
  314. return pos_type(-1);
  315. //This can reassign pointers
  316. //if(m_vect.size() != m_vect.capacity())
  317. //this->initialize_pointers();
  318. if (in)
  319. base_t::setg(base_t::eback(), base_t::eback() + newoff, base_t::egptr());
  320. if (out){
  321. base_t::setp(base_t::pbase(), base_t::epptr());
  322. base_t::pbump(newoff);
  323. }
  324. return pos_type(newoff);
  325. }
  326. virtual pos_type seekpos(pos_type pos, std::ios_base::openmode mode
  327. = std::ios_base::in | std::ios_base::out)
  328. { return seekoff(pos - pos_type(off_type(0)), std::ios_base::beg, mode); }
  329. private:
  330. std::ios_base::openmode m_mode;
  331. mutable vector_type m_vect;
  332. mutable char_type* mp_high_water;
  333. /// @endcond
  334. };
  335. //!A basic_istream class that holds a character vector specified by CharVector
  336. //!template parameter as its formatting buffer. The vector must have
  337. //!contiguous storage, like std::vector, boost::interprocess::vector or
  338. //!boost::interprocess::basic_string
  339. template <class CharVector, class CharTraits>
  340. class basic_ivectorstream
  341. /// @cond
  342. : private basic_vectorbuf<CharVector, CharTraits>
  343. /// @endcond
  344. , public std::basic_istream<typename CharVector::value_type, CharTraits>
  345. {
  346. public:
  347. typedef CharVector vector_type;
  348. typedef typename std::basic_ios
  349. <typename CharVector::value_type, CharTraits>::char_type char_type;
  350. typedef typename std::basic_ios<char_type, CharTraits>::int_type int_type;
  351. typedef typename std::basic_ios<char_type, CharTraits>::pos_type pos_type;
  352. typedef typename std::basic_ios<char_type, CharTraits>::off_type off_type;
  353. typedef typename std::basic_ios<char_type, CharTraits>::traits_type traits_type;
  354. /// @cond
  355. private:
  356. typedef basic_vectorbuf<CharVector, CharTraits> vectorbuf_t;
  357. typedef std::basic_istream<char_type, CharTraits> base_t;
  358. vectorbuf_t & m_buf() { return *this; }
  359. const vectorbuf_t & m_buf() const{ return *this; }
  360. /// @endcond
  361. public:
  362. //!Constructor. Throws if vector_type default
  363. //!constructor throws.
  364. basic_ivectorstream(std::ios_base::openmode mode = std::ios_base::in)
  365. : vectorbuf_t(mode | std::ios_base::in), base_t(&m_buf())
  366. {}
  367. //!Constructor. Throws if vector_type(const VectorParameter &param)
  368. //!throws.
  369. template<class VectorParameter>
  370. basic_ivectorstream(const VectorParameter &param,
  371. std::ios_base::openmode mode = std::ios_base::in)
  372. : vectorbuf_t(param, mode | std::ios_base::in), base_t(&m_buf())
  373. {}
  374. ~basic_ivectorstream(){};
  375. public:
  376. //!Returns the address of the stored
  377. //!stream buffer.
  378. basic_vectorbuf<CharVector, CharTraits>* rdbuf() const
  379. { return const_cast<basic_vectorbuf<CharVector, CharTraits>*>(&m_buf()); }
  380. //!Swaps the underlying vector with the passed vector.
  381. //!This function resets the read position in the stream.
  382. //!Does not throw.
  383. void swap_vector(vector_type &vect)
  384. { m_buf().swap_vector(vect); }
  385. //!Returns a const reference to the internal vector.
  386. //!Does not throw.
  387. const vector_type &vector() const
  388. { return m_buf().vector(); }
  389. //!Calls reserve() method of the internal vector.
  390. //!Resets the stream to the first position.
  391. //!Throws if the internals vector's reserve throws.
  392. void reserve(typename vector_type::size_type size)
  393. { m_buf().reserve(size); }
  394. //!Calls clear() method of the internal vector.
  395. //!Resets the stream to the first position.
  396. void clear()
  397. { m_buf().clear(); }
  398. };
  399. //!A basic_ostream class that holds a character vector specified by CharVector
  400. //!template parameter as its formatting buffer. The vector must have
  401. //!contiguous storage, like std::vector, boost::interprocess::vector or
  402. //!boost::interprocess::basic_string
  403. template <class CharVector, class CharTraits>
  404. class basic_ovectorstream
  405. /// @cond
  406. : private basic_vectorbuf<CharVector, CharTraits>
  407. /// @endcond
  408. , public std::basic_ostream<typename CharVector::value_type, CharTraits>
  409. {
  410. public:
  411. typedef CharVector vector_type;
  412. typedef typename std::basic_ios
  413. <typename CharVector::value_type, CharTraits>::char_type char_type;
  414. typedef typename std::basic_ios<char_type, CharTraits>::int_type int_type;
  415. typedef typename std::basic_ios<char_type, CharTraits>::pos_type pos_type;
  416. typedef typename std::basic_ios<char_type, CharTraits>::off_type off_type;
  417. typedef typename std::basic_ios<char_type, CharTraits>::traits_type traits_type;
  418. /// @cond
  419. private:
  420. typedef basic_vectorbuf<CharVector, CharTraits> vectorbuf_t;
  421. typedef std::basic_ostream<char_type, CharTraits> base_t;
  422. vectorbuf_t & m_buf() { return *this; }
  423. const vectorbuf_t & m_buf()const { return *this; }
  424. /// @endcond
  425. public:
  426. //!Constructor. Throws if vector_type default
  427. //!constructor throws.
  428. basic_ovectorstream(std::ios_base::openmode mode = std::ios_base::out)
  429. : vectorbuf_t(mode | std::ios_base::out), base_t(&m_buf())
  430. {}
  431. //!Constructor. Throws if vector_type(const VectorParameter &param)
  432. //!throws.
  433. template<class VectorParameter>
  434. basic_ovectorstream(const VectorParameter &param,
  435. std::ios_base::openmode mode = std::ios_base::out)
  436. : vectorbuf_t(param, mode | std::ios_base::out), base_t(&m_buf())
  437. {}
  438. ~basic_ovectorstream(){}
  439. public:
  440. //!Returns the address of the stored
  441. //!stream buffer.
  442. basic_vectorbuf<CharVector, CharTraits>* rdbuf() const
  443. { return const_cast<basic_vectorbuf<CharVector, CharTraits>*>(&m_buf()); }
  444. //!Swaps the underlying vector with the passed vector.
  445. //!This function resets the write position in the stream.
  446. //!Does not throw.
  447. void swap_vector(vector_type &vect)
  448. { m_buf().swap_vector(vect); }
  449. //!Returns a const reference to the internal vector.
  450. //!Does not throw.
  451. const vector_type &vector() const
  452. { return m_buf().vector(); }
  453. //!Calls reserve() method of the internal vector.
  454. //!Resets the stream to the first position.
  455. //!Throws if the internals vector's reserve throws.
  456. void reserve(typename vector_type::size_type size)
  457. { m_buf().reserve(size); }
  458. };
  459. //!A basic_iostream class that holds a character vector specified by CharVector
  460. //!template parameter as its formatting buffer. The vector must have
  461. //!contiguous storage, like std::vector, boost::interprocess::vector or
  462. //!boost::interprocess::basic_string
  463. template <class CharVector, class CharTraits>
  464. class basic_vectorstream
  465. : public std::basic_iostream<typename CharVector::value_type, CharTraits>
  466. {
  467. public:
  468. typedef CharVector vector_type;
  469. typedef typename std::basic_ios
  470. <typename CharVector::value_type, CharTraits>::char_type char_type;
  471. typedef typename std::basic_ios<char_type, CharTraits>::int_type int_type;
  472. typedef typename std::basic_ios<char_type, CharTraits>::pos_type pos_type;
  473. typedef typename std::basic_ios<char_type, CharTraits>::off_type off_type;
  474. typedef typename std::basic_ios<char_type, CharTraits>::traits_type traits_type;
  475. /// @cond
  476. private:
  477. typedef std::basic_ios<char_type, CharTraits> basic_ios_t;
  478. typedef std::basic_iostream<char_type, CharTraits> base_t;
  479. /// @endcond
  480. public:
  481. //!Constructor. Throws if vector_type default
  482. //!constructor throws.
  483. basic_vectorstream(std::ios_base::openmode mode
  484. = std::ios_base::in | std::ios_base::out)
  485. : basic_ios_t(), base_t(0), m_buf(mode)
  486. { basic_ios_t::init(&m_buf); }
  487. //!Constructor. Throws if vector_type(const VectorParameter &param)
  488. //!throws.
  489. template<class VectorParameter>
  490. basic_vectorstream(const VectorParameter &param, std::ios_base::openmode mode
  491. = std::ios_base::in | std::ios_base::out)
  492. : basic_ios_t(), base_t(0), m_buf(param, mode)
  493. { basic_ios_t::init(&m_buf); }
  494. ~basic_vectorstream(){}
  495. public:
  496. //Returns the address of the stored stream buffer.
  497. basic_vectorbuf<CharVector, CharTraits>* rdbuf() const
  498. { return const_cast<basic_vectorbuf<CharVector, CharTraits>*>(&m_buf); }
  499. //!Swaps the underlying vector with the passed vector.
  500. //!This function resets the read/write position in the stream.
  501. //!Does not throw.
  502. void swap_vector(vector_type &vect)
  503. { m_buf.swap_vector(vect); }
  504. //!Returns a const reference to the internal vector.
  505. //!Does not throw.
  506. const vector_type &vector() const
  507. { return m_buf.vector(); }
  508. //!Calls reserve() method of the internal vector.
  509. //!Resets the stream to the first position.
  510. //!Throws if the internals vector's reserve throws.
  511. void reserve(typename vector_type::size_type size)
  512. { m_buf.reserve(size); }
  513. //!Calls clear() method of the internal vector.
  514. //!Resets the stream to the first position.
  515. void clear()
  516. { m_buf.clear(); }
  517. /// @cond
  518. private:
  519. basic_vectorbuf<CharVector, CharTraits> m_buf;
  520. /// @endcond
  521. };
  522. //Some typedefs to simplify usage
  523. //!
  524. //!typedef basic_vectorbuf<std::vector<char> > vectorbuf;
  525. //!typedef basic_vectorstream<std::vector<char> > vectorstream;
  526. //!typedef basic_ivectorstream<std::vector<char> > ivectorstream;
  527. //!typedef basic_ovectorstream<std::vector<char> > ovectorstream;
  528. //!
  529. //!typedef basic_vectorbuf<std::vector<wchar_t> > wvectorbuf;
  530. //!typedef basic_vectorstream<std::vector<wchar_t> > wvectorstream;
  531. //!typedef basic_ivectorstream<std::vector<wchar_t> > wivectorstream;
  532. //!typedef basic_ovectorstream<std::vector<wchar_t> > wovectorstream;
  533. }} //namespace boost { namespace interprocess {
  534. #include <boost/interprocess/detail/config_end.hpp>
  535. #endif /* BOOST_INTERPROCESS_VECTORSTREAM_HPP */