Update of /cvsroot/boost/boost/boost/interprocess/streams
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv22035/streams
Modified Files:
vectorstream.hpp
Log Message:
New Interprocess version
Index: vectorstream.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/interprocess/streams/vectorstream.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- vectorstream.hpp 12 May 2007 12:51:20 -0000 1.5
+++ vectorstream.hpp 22 Jul 2007 14:06:08 -0000 1.6
@@ -26,13 +26,12 @@
* purpose. It is provided "as is" without express or implied warranty.
*/
-/*!\file
- This file defines basic_vectorbuf, basic_ivectorstream,
- basic_ovectorstream, and basic_vectorstreamclasses. These classes
- represent streamsbufs and streams whose sources or destinations are
- STL-like vectors that can be swapped with external vectors to avoid
- unnecessary allocations/copies.
-*/
+//!\file
+//!This file defines basic_vectorbuf, basic_ivectorstream,
+//!basic_ovectorstream, and basic_vectorstreamclasses. These classes
+//!represent streamsbufs and streams whose sources or destinations are
+//!STL-like vectors that can be swapped with external vectors to avoid
+//!unnecessary allocations/copies.
#ifndef BOOST_INTERPROCESS_VECTORSTREAM_HPP
#define BOOST_INTERPROCESS_VECTORSTREAM_HPP
@@ -51,11 +50,11 @@
namespace boost { namespace interprocess {
-/*!A streambuf class that controls the transmission of elements to and from
- a basic_ivectorstream, basic_ovectorstream or basic_vectorstream.
- It holds a character vector specified by CharVector template parameter
- as its formatting buffer. The vector must have contiguous storage, like
- std::vector, boost::interprocess::vector or
boost::interprocess::basic_string*/
+//!A streambuf class that controls the transmission of elements to and from
+//!a basic_ivectorstream, basic_ovectorstream or basic_vectorstream.
+//!It holds a character vector specified by CharVector template parameter
+//!as its formatting buffer. The vector must have contiguous storage, like
+//!std::vector, boost::interprocess::vector or
boost::interprocess::basic_string
template <class CharVector, class CharTraits>
class basic_vectorbuf
: public std::basic_streambuf<typename CharVector::value_type, CharTraits>
@@ -77,52 +76,59 @@
/// @endcond
public:
- /*!Constructor. Throws if vector_type default constructor throws.*/
+ //!Constructor. Throws if vector_type default
+ //!constructor throws.
explicit basic_vectorbuf(std::ios_base::openmode mode
= std::ios_base::in | std::ios_base::out)
: base_t(), m_mode(mode)
- { this->set_pointers(); }
+ { this->initialize_pointers(); }
- /*!Constructor. Throws if vector_type(const VectorParameter ¶m)
throws.*/
+ //!Constructor. Throws if
+ //!vector_type(const VectorParameter ¶m) throws.
template<class VectorParameter>
explicit basic_vectorbuf(const VectorParameter ¶m,
std::ios_base::openmode mode
= std::ios_base::in | std::ios_base::out)
: base_t(), m_mode(mode), m_vect(param)
- { this->set_pointers(); }
+ { this->initialize_pointers(); }
virtual ~basic_vectorbuf(){}
public:
- /*!Swaps the underlying vector with the passed vector.
- This function resets the read/write position in the stream.
- Does not throw.*/
+ //!Swaps the underlying vector with the passed vector.
+ //!This function resets the read/write position in the stream.
+ //!Does not throw.
void swap_vector(vector_type &vect)
{
- //Update high water if necessary
- //And resize vector to remove extra size
if (this->m_mode & std::ios_base::out){
+ //Update high water if necessary
+ //And resize vector to remove extra size
if (mp_high_water < base_t::pptr()){
//Restore the vector's size if necessary
mp_high_water = base_t::pptr();
}
-
m_vect.resize(mp_high_water - (m_vect.size() ? &m_vect[0] : 0));
- }
- //Now swap vector
- m_vect.swap(vect);
+ //Now swap vector
+ m_vect.swap(vect);
- //Now update pointer data
- typename vector_type::size_type old_size = m_vect.size();
- m_vect.resize(m_vect.capacity());
- this->set_pointers();
- mp_high_water = old_size ? &m_vect[0] + old_size : 0;
+ //If the stream is writable put the high water mark
+ //and maximize the size.
+ typename vector_type::size_type old_size = m_vect.size();
+ m_vect.resize(m_vect.capacity());
+ this->initialize_pointers();
+ mp_high_water = old_size ? &m_vect[0] + old_size : 0;
+ }
+ else{
+ //Now swap vector
+ m_vect.swap(vect);
+ this->initialize_pointers();
+ }
}
- /*!Returns a const reference to the internal vector.
- Does not throw.*/
+ //!Returns a const reference to the internal vector.
+ //!Does not throw.
const vector_type &vector() const
{
if (this->m_mode & std::ios_base::out){
@@ -131,32 +137,32 @@
mp_high_water = base_t::pptr();
}
m_vect.resize(mp_high_water - (m_vect.size() ? &m_vect[0] : 0));
- const_cast<basic_vectorbuf * const>(this)->set_pointers();
+ const_cast<basic_vectorbuf * const>(this)->initialize_pointers();
}
return m_vect;
}
- /*!Preallocates memory from the internal vector.
- Resets the stream to the first position.
- Throws if the internals vector's memory allocation throws.*/
+ //!Preallocates memory from the internal vector.
+ //!Resets the stream to the first position.
+ //!Throws if the internals vector's memory allocation throws.
void reserve(typename vector_type::size_type size)
{
m_vect.reserve(size);
//Now update pointer data
typename vector_type::size_type old_size = m_vect.size();
m_vect.resize(m_vect.capacity());
- this->set_pointers();
+ this->initialize_pointers();
mp_high_water = old_size ? &m_vect[0] + old_size : 0;
}
- /*!Calls clear() method of the internal vector.
- Resets the stream to the first position.*/
+ //!Calls clear() method of the internal vector.
+ //!Resets the stream to the first position.
void clear()
- { m_vect.clear(); this->set_pointers(); }
+ { m_vect.clear(); this->initialize_pointers(); }
/// @cond
private:
- void set_pointers()
+ void initialize_pointers()
{
// The initial read position is the beginning of the vector.
if(m_mode & std::ios_base::in){
@@ -226,41 +232,48 @@
{
if(m_mode & std::ios_base::out) {
if(!CharTraits::eq_int_type(c, CharTraits::eof())) {
- if(!(m_mode & std::ios_base::in)) {
- if(this->pptr() < this->epptr()) {
- *this->pptr() = CharTraits::to_char_type(c);
- this->pbump(1);
- if (mp_high_water < base_t::pptr())
- mp_high_water = base_t::pptr();
- if ((m_mode & std::ios_base::in) && base_t::egptr() <
mp_high_water)
- base_t::setg(base_t::eback(), base_t::gptr(),
mp_high_water);
- return c;
- }
- else
- return CharTraits::eof();
- }
- else {
- try{
+// if(!(m_mode & std::ios_base::in)) {
+// if(this->pptr() < this->epptr()) {
+// *this->pptr() = CharTraits::to_char_type(c);
+// this->pbump(1);
+// if (mp_high_water < base_t::pptr())
+// mp_high_water = base_t::pptr();
+// if ((m_mode & std::ios_base::in) && base_t::egptr() <
mp_high_water)
+// base_t::setg(base_t::eback(), base_t::gptr(),
mp_high_water);
+// return c;
+// }
+// else
+// return CharTraits::eof();
+// }
+// else {
+// try{
typedef typename vector_type::difference_type dif_t;
dif_t inpos = base_t::gptr() - base_t::eback();
- dif_t outpos = base_t::pptr() - base_t::pbase() + 1;
+ //The new output position is the previous one plus one
+ //because 'overflow' requires putting 'c' on the buffer
+ dif_t new_outpos = base_t::pptr() - base_t::pbase() + 1;
+ //Adjust high water if necessary
dif_t hipos = mp_high_water - base_t::pbase();
- if (hipos < outpos)
- hipos = outpos;
+ if (hipos < new_outpos)
+ hipos = new_outpos;
+ //Insert the new data
m_vect.push_back(CharTraits::to_char_type(c));
m_vect.resize(m_vect.capacity());
char_type* p = const_cast<char_type*>(&m_vect[0]);
+ //A reallocation has happened, update pointers
if (m_mode & std::ios_base::in)
base_t::setg(p, p + inpos, p + hipos);
base_t::setp(p, p + (dif_t)m_vect.size());
- base_t::pbump((int)outpos);
+ //Update write position to the old position + 1
+ base_t::pbump((int)new_outpos);
+ //Update high water pointer, since the buffer has been
reallocated
mp_high_water = base_t::pbase() + hipos;
return c;
- }
- catch(...){
- return CharTraits::eof();
- }
- }
+// }
+// catch(...){
+// return CharTraits::eof();
+// }
+// }
}
else // c is EOF, so we don't have to do anything
return CharTraits::not_eof(c);
@@ -273,8 +286,7 @@
std::ios_base::openmode mode
= std::ios_base::in | std::ios_base::out)
{
- bool in = false;
- bool out = false;
+ bool in = false, out = false;
const std::ios_base::openmode inout =
std::ios_base::in | std::ios_base::out;
@@ -295,11 +307,11 @@
return pos_type(off_type(-1));
off_type newoff;
- off_type limit = static_cast<off_type>
- (mode & std::ios_base::out ?
- mp_high_water - base_t::pbase() :
- mp_high_water - base_t::eback()
- );
+ //Just calculate the end of the stream. If the stream is read-only
+ //the limit is the size of the vector. Otherwise, the high water mark
+ //will mark the real size.
+ off_type limit = static_cast<off_type> (mode & std::ios_base::out ?
+ mp_high_water - base_t::pbase() : m_vect.size()/*mp_high_water -
base_t::eback()*/);
switch(dir) {
case std::ios_base::beg:
@@ -326,7 +338,7 @@
base_t::setg(base_t::eback(), base_t::eback() + newoff,
base_t::egptr());
if (out){
base_t::setp(base_t::pbase(), base_t::epptr());
- base_t::pbump((int)newoff);
+ base_t::pbump(newoff);
}
return pos_type(newoff);
}
@@ -342,13 +354,13 @@
/// @endcond
};
-/*!A basic_istream class that holds a character vector specified by CharVector
- template parameter as its formatting buffer. The vector must have
- contiguous storage, like std::vector, boost::interprocess::vector or
- boost::interprocess::basic_string*/
+//!A basic_istream class that holds a character vector specified by CharVector
+//!template parameter as its formatting buffer. The vector must have
+//!contiguous storage, like std::vector, boost::interprocess::vector or
+//!boost::interprocess::basic_string
template <class CharVector, class CharTraits>
class basic_ivectorstream
-: public std::basic_istream<typename CharVector::value_type, CharTraits>
+ : public std::basic_istream<typename CharVector::value_type, CharTraits>
{
public:
typedef CharVector
vector_type;
@@ -366,12 +378,14 @@
/// @endcond
public:
- /*!Constructor. Throws if vector_type default constructor throws.*/
+ //!Constructor. Throws if vector_type default
+ //!constructor throws.
basic_ivectorstream(std::ios_base::openmode mode = std::ios_base::in)
: basic_ios_t(), base_t(0), m_buf(mode | std::ios_base::in)
{ basic_ios_t::init(&m_buf); }
- /*!Constructor. Throws if vector_type(const VectorParameter ¶m)
throws.*/
+ //!Constructor. Throws if vector_type(const VectorParameter ¶m)
+ //!throws.
template<class VectorParameter>
basic_ivectorstream(const VectorParameter ¶m,
std::ios_base::openmode mode = std::ios_base::in)
@@ -382,29 +396,30 @@
~basic_ivectorstream(){};
public:
- /*!Returns the address of the stored stream buffer.*/
+ //!Returns the address of the stored
+ //!stream buffer.
basic_vectorbuf<CharVector, CharTraits>* rdbuf() const
{ return const_cast<basic_vectorbuf<CharVector, CharTraits>*>(&m_buf); }
- /*!Swaps the underlying vector with the passed vector.
- This function resets the read position in the stream.
- Does not throw.*/
+ //!Swaps the underlying vector with the passed vector.
+ //!This function resets the read position in the stream.
+ //!Does not throw.
void swap_vector(vector_type &vect)
{ m_buf.swap_vector(vect); }
- /*!Returns a const reference to the internal vector.
- Does not throw.*/
+ //!Returns a const reference to the internal vector.
+ //!Does not throw.
const vector_type &vector() const
{ return m_buf.vector(); }
- /*!Calls reserve() method of the internal vector.
- Resets the stream to the first position.
- Throws if the internals vector's reserve throws.*/
+ //!Calls reserve() method of the internal vector.
+ //!Resets the stream to the first position.
+ //!Throws if the internals vector's reserve throws.
void reserve(typename vector_type::size_type size)
{ m_buf.reserve(size); }
- /*!Calls clear() method of the internal vector.
- Resets the stream to the first position.*/
+ //!Calls clear() method of the internal vector.
+ //!Resets the stream to the first position.
void clear()
{ m_buf.clear(); }
@@ -414,10 +429,10 @@
/// @endcond
};
-/*!A basic_ostream class that holds a character vector specified by CharVector
- template parameter as its formatting buffer. The vector must have
- contiguous storage, like std::vector, boost::interprocess::vector or
- boost::interprocess::basic_string*/
+//!A basic_ostream class that holds a character vector specified by CharVector
+//!template parameter as its formatting buffer. The vector must have
+//!contiguous storage, like std::vector, boost::interprocess::vector or
+//!boost::interprocess::basic_string
template <class CharVector, class CharTraits>
class basic_ovectorstream
: public std::basic_ostream<typename CharVector::value_type, CharTraits>
@@ -438,12 +453,14 @@
/// @endcond
public:
- /*!Constructor. Throws if vector_type default constructor throws.*/
+ //!Constructor. Throws if vector_type default
+ //!constructor throws.
basic_ovectorstream(std::ios_base::openmode mode = std::ios_base::out)
: basic_ios_t(), base_t(0), m_buf(mode | std::ios_base::out)
{ basic_ios_t::init(&m_buf); }
- /*!Constructor. Throws if vector_type(const VectorParameter ¶m)
throws.*/
+ //!Constructor. Throws if vector_type(const VectorParameter ¶m)
+ //!throws.
template<class VectorParameter>
basic_ovectorstream(const VectorParameter ¶m,
std::ios_base::openmode mode = std::ios_base::out)
@@ -453,24 +470,25 @@
~basic_ovectorstream(){}
public:
- /*!Returns the address of the stored stream buffer.*/
+ //!Returns the address of the stored
+ //!stream buffer.
basic_vectorbuf<CharVector, CharTraits>* rdbuf() const
{ return const_cast<basic_vectorbuf<CharVector, CharTraits>*>(&m_buf); }
- /*!Swaps the underlying vector with the passed vector.
- This function resets the write position in the stream.
- Does not throw.*/
+ //!Swaps the underlying vector with the passed vector.
+ //!This function resets the write position in the stream.
+ //!Does not throw.
void swap_vector(vector_type &vect)
{ m_buf.swap_vector(vect); }
- /*!Returns a const reference to the internal vector.
- Does not throw.*/
+ //!Returns a const reference to the internal vector.
+ //!Does not throw.
const vector_type &vector() const
{ return m_buf.vector(); }
- /*!Calls reserve() method of the internal vector.
- Resets the stream to the first position.
- Throws if the internals vector's reserve throws.*/
+ //!Calls reserve() method of the internal vector.
+ //!Resets the stream to the first position.
+ //!Throws if the internals vector's reserve throws.
void reserve(typename vector_type::size_type size)
{ m_buf.reserve(size); }
@@ -481,13 +499,13 @@
};
-/*!A basic_iostream class that holds a character vector specified by CharVector
- template parameter as its formatting buffer. The vector must have
- contiguous storage, like std::vector, boost::interprocess::vector or
- boost::interprocess::basic_string*/
+//!A basic_iostream class that holds a character vector specified by CharVector
+//!template parameter as its formatting buffer. The vector must have
+//!contiguous storage, like std::vector, boost::interprocess::vector or
+//!boost::interprocess::basic_string
template <class CharVector, class CharTraits>
class basic_vectorstream
-: public std::basic_iostream<typename CharVector::value_type, CharTraits>
+ : public std::basic_iostream<typename CharVector::value_type, CharTraits>
{
public:
@@ -506,13 +524,15 @@
/// @endcond
public:
- /*!Constructor. Throws if vector_type default constructor throws.*/
+ //!Constructor. Throws if vector_type default
+ //!constructor throws.
basic_vectorstream(std::ios_base::openmode mode
= std::ios_base::in | std::ios_base::out)
: basic_ios_t(), base_t(0), m_buf(mode)
{ basic_ios_t::init(&m_buf); }
- /*!Constructor. Throws if vector_type(const VectorParameter ¶m)
throws.*/
+ //!Constructor. Throws if vector_type(const VectorParameter ¶m)
+ //!throws.
template<class VectorParameter>
basic_vectorstream(const VectorParameter ¶m, std::ios_base::openmode
mode
= std::ios_base::in | std::ios_base::out)
@@ -526,25 +546,25 @@
basic_vectorbuf<CharVector, CharTraits>* rdbuf() const
{ return const_cast<basic_vectorbuf<CharVector, CharTraits>*>(&m_buf); }
- /*!Swaps the underlying vector with the passed vector.
- This function resets the read/write position in the stream.
- Does not throw.*/
+ //!Swaps the underlying vector with the passed vector.
+ //!This function resets the read/write position in the stream.
+ //!Does not throw.
void swap_vector(vector_type &vect)
{ m_buf.swap_vector(vect); }
- /*!Returns a const reference to the internal vector.
- Does not throw.*/
+ //!Returns a const reference to the internal vector.
+ //!Does not throw.
const vector_type &vector() const
{ return m_buf.vector(); }
- /*!Calls reserve() method of the internal vector.
- Resets the stream to the first position.
- Throws if the internals vector's reserve throws.*/
+ //!Calls reserve() method of the internal vector.
+ //!Resets the stream to the first position.
+ //!Throws if the internals vector's reserve throws.
void reserve(typename vector_type::size_type size)
{ m_buf.reserve(size); }
- /*!Calls clear() method of the internal vector.
- Resets the stream to the first position.*/
+ //!Calls clear() method of the internal vector.
+ //!Resets the stream to the first position.
void clear()
{ m_buf.clear(); }
@@ -555,17 +575,17 @@
};
//Some typedefs to simplify usage
-/*
-typedef basic_vectorbuf<std::vector<char> > vectorbuf;
-typedef basic_vectorstream<std::vector<char> > vectorstream;
-typedef basic_ivectorstream<std::vector<char> > ivectorstream;
-typedef basic_ovectorstream<std::vector<char> > ovectorstream;
+//!
+//!typedef basic_vectorbuf<std::vector<char> > vectorbuf;
+//!typedef basic_vectorstream<std::vector<char> > vectorstream;
+//!typedef basic_ivectorstream<std::vector<char> > ivectorstream;
+//!typedef basic_ovectorstream<std::vector<char> > ovectorstream;
+//!
+//!typedef basic_vectorbuf<std::vector<wchar_t> > wvectorbuf;
+//!typedef basic_vectorstream<std::vector<wchar_t> > wvectorstream;
+//!typedef basic_ivectorstream<std::vector<wchar_t> > wivectorstream;
+//!typedef basic_ovectorstream<std::vector<wchar_t> > wovectorstream;
-typedef basic_vectorbuf<std::vector<wchar_t> > wvectorbuf;
-typedef basic_vectorstream<std::vector<wchar_t> > wvectorstream;
-typedef basic_ivectorstream<std::vector<wchar_t> > wivectorstream;
-typedef basic_ovectorstream<std::vector<wchar_t> > wovectorstream;
-*/
}} //namespace boost { namespace interprocess {
#include <boost/interprocess/detail/config_end.hpp>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs