|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85555 - in trunk: boost/interprocess/streams libs/interprocess/doc libs/interprocess/test
From: igaztanaga_at_[hidden]
Date: 2013-09-03 18:03:10
Author: igaztanaga
Date: 2013-09-03 18:03:10 EDT (Tue, 03 Sep 2013)
New Revision: 85555
URL: http://svn.boost.org/trac/boost/changeset/85555
Log:
Fixes #7156
Text files modified:
trunk/boost/interprocess/streams/bufferstream.hpp | 137 +++++++++++++++++++++++++--------------
trunk/boost/interprocess/streams/vectorstream.hpp | 113 ++++++++++++++++++--------------
trunk/libs/interprocess/doc/interprocess.qbk | 3
trunk/libs/interprocess/test/bufferstream_test.cpp | 2
4 files changed, 154 insertions(+), 101 deletions(-)
Modified: trunk/boost/interprocess/streams/bufferstream.hpp
==============================================================================
--- trunk/boost/interprocess/streams/bufferstream.hpp Tue Sep 3 16:08:30 2013 (r85554)
+++ trunk/boost/interprocess/streams/bufferstream.hpp 2013-09-03 18:03:10 EDT (Tue, 03 Sep 2013) (r85555)
@@ -251,8 +251,11 @@
//!A basic_istream class that uses a fixed size character buffer
//!as its formatting buffer.
template <class CharT, class CharTraits>
-class basic_ibufferstream
- : public std::basic_istream<CharT, CharTraits>
+class basic_ibufferstream :
+ /// @cond
+ private basic_bufferbuf<CharT, CharTraits>,
+ /// @endcond
+ public std::basic_istream<CharT, CharTraits>
{
public: // Typedefs
typedef typename std::basic_ios
@@ -262,24 +265,40 @@
typedef typename std::basic_ios<char_type, CharTraits>::off_type off_type;
typedef typename std::basic_ios<char_type, CharTraits>::traits_type traits_type;
+ /// @cond
private:
- typedef std::basic_ios<char_type, CharTraits> basic_ios_t;
- typedef std::basic_istream<char_type, CharTraits> base_t;
+ typedef basic_bufferbuf<CharT, CharTraits> bufferbuf_t;
+ typedef std::basic_ios<char_type, CharTraits> basic_ios_t;
+ typedef std::basic_istream<char_type, CharTraits> base_t;
+ bufferbuf_t & get_buf() { return *this; }
+ const bufferbuf_t & get_buf() const{ return *this; }
+ /// @endcond
public:
//!Constructor.
//!Does not throw.
basic_ibufferstream(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); }
+ : //basic_ios_t() is called first (lefting it uninitialized) as it's a
+ //virtual base of basic_istream. The class will be initialized when
+ //basic_istream is constructed calling basic_ios_t::init().
+ //As bufferbuf_t's constructor does not throw there is no risk of
+ //calling the basic_ios_t's destructor without calling basic_ios_t::init()
+ bufferbuf_t(mode | std::ios_base::in)
+ , base_t(&get_buf())
+ {}
//!Constructor. Assigns formatting buffer.
//!Does not throw.
basic_ibufferstream(const CharT *buf, std::size_t length,
std::ios_base::openmode mode = std::ios_base::in)
- : basic_ios_t(), base_t(0),
- m_buf(const_cast<CharT*>(buf), length, mode | std::ios_base::in)
- { basic_ios_t::init(&m_buf); }
+ : //basic_ios_t() is called first (lefting it uninitialized) as it's a
+ //virtual base of basic_istream. The class will be initialized when
+ //basic_istream is constructed calling basic_ios_t::init().
+ //As bufferbuf_t's constructor does not throw there is no risk of
+ //calling the basic_ios_t's destructor without calling basic_ios_t::init()
+ bufferbuf_t(const_cast<CharT*>(buf), length, mode | std::ios_base::in)
+ , base_t(&get_buf())
+ {}
~basic_ibufferstream(){};
@@ -287,29 +306,27 @@
//!Returns the address of the stored
//!stream buffer.
basic_bufferbuf<CharT, CharTraits>* rdbuf() const
- { return const_cast<basic_bufferbuf<CharT, CharTraits>*>(&m_buf); }
+ { return const_cast<basic_bufferbuf<CharT, CharTraits>*>(&get_buf()); }
//!Returns the pointer and size of the internal buffer.
//!Does not throw.
std::pair<const CharT *, std::size_t> buffer() const
- { return m_buf.buffer(); }
+ { return get_buf().buffer(); }
//!Sets the underlying buffer to a new value. Resets
//!stream position. Does not throw.
void buffer(const CharT *buf, std::size_t length)
- { m_buf.buffer(const_cast<CharT*>(buf), length); }
-
- /// @cond
- private:
- basic_bufferbuf<CharT, CharTraits> m_buf;
- /// @endcond
+ { get_buf().buffer(const_cast<CharT*>(buf), length); }
};
//!A basic_ostream class that uses a fixed size character buffer
//!as its formatting buffer.
template <class CharT, class CharTraits>
-class basic_obufferstream
- : public std::basic_ostream<CharT, CharTraits>
+class basic_obufferstream :
+ /// @cond
+ private basic_bufferbuf<CharT, CharTraits>,
+ /// @endcond
+ public std::basic_ostream<CharT, CharTraits>
{
public:
typedef typename std::basic_ios
@@ -321,23 +338,38 @@
/// @cond
private:
+ typedef basic_bufferbuf<CharT, CharTraits> bufferbuf_t;
typedef std::basic_ios<char_type, CharTraits> basic_ios_t;
typedef std::basic_ostream<char_type, CharTraits> base_t;
+ bufferbuf_t & get_buf() { return *this; }
+ const bufferbuf_t & get_buf() const{ return *this; }
/// @endcond
+
public:
//!Constructor.
//!Does not throw.
basic_obufferstream(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); }
+ : //basic_ios_t() is called first (lefting it uninitialized) as it's a
+ //virtual base of basic_istream. The class will be initialized when
+ //basic_istream is constructed calling basic_ios_t::init().
+ //As bufferbuf_t's constructor does not throw there is no risk of
+ //calling the basic_ios_t's destructor without calling basic_ios_t::init()
+ bufferbuf_t(mode | std::ios_base::out)
+ , base_t(&get_buf())
+ {}
//!Constructor. Assigns formatting buffer.
//!Does not throw.
basic_obufferstream(CharT *buf, std::size_t length,
std::ios_base::openmode mode = std::ios_base::out)
- : basic_ios_t(), base_t(0),
- m_buf(buf, length, mode | std::ios_base::out)
- { basic_ios_t::init(&m_buf); }
+ : //basic_ios_t() is called first (lefting it uninitialized) as it's a
+ //virtual base of basic_istream. The class will be initialized when
+ //basic_istream is constructed calling basic_ios_t::init().
+ //As bufferbuf_t's constructor does not throw there is no risk of
+ //calling the basic_ios_t's destructor without calling basic_ios_t::init()
+ bufferbuf_t(buf, length, mode | std::ios_base::out)
+ , base_t(&get_buf())
+ {}
~basic_obufferstream(){}
@@ -345,31 +377,28 @@
//!Returns the address of the stored
//!stream buffer.
basic_bufferbuf<CharT, CharTraits>* rdbuf() const
- { return const_cast<basic_bufferbuf<CharT, CharTraits>*>(&m_buf); }
+ { return const_cast<basic_bufferbuf<CharT, CharTraits>*>(&get_buf()); }
//!Returns the pointer and size of the internal buffer.
//!Does not throw.
std::pair<CharT *, std::size_t> buffer() const
- { return m_buf.buffer(); }
+ { return get_buf().buffer(); }
//!Sets the underlying buffer to a new value. Resets
//!stream position. Does not throw.
void buffer(CharT *buf, std::size_t length)
- { m_buf.buffer(buf, length); }
-
- /// @cond
- private:
- basic_bufferbuf<CharT, CharTraits> m_buf;
- /// @endcond
+ { get_buf().buffer(buf, length); }
};
//!A basic_iostream class that uses a fixed size character buffer
//!as its formatting buffer.
template <class CharT, class CharTraits>
-class basic_bufferstream
- : public std::basic_iostream<CharT, CharTraits>
-
+class basic_bufferstream :
+ /// @cond
+ private basic_bufferbuf<CharT, CharTraits>,
+ /// @endcond
+ public std::basic_iostream<CharT, CharTraits>
{
public: // Typedefs
typedef typename std::basic_ios
@@ -381,8 +410,11 @@
/// @cond
private:
- typedef std::basic_ios<char_type, CharTraits> basic_ios_t;
- typedef std::basic_iostream<char_type, CharTraits> base_t;
+ typedef basic_bufferbuf<CharT, CharTraits> bufferbuf_t;
+ typedef std::basic_ios<char_type, CharTraits> basic_ios_t;
+ typedef std::basic_iostream<char_type, CharTraits> base_t;
+ bufferbuf_t & get_buf() { return *this; }
+ const bufferbuf_t & get_buf() const{ return *this; }
/// @endcond
public:
@@ -390,16 +422,28 @@
//!Does not throw.
basic_bufferstream(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); }
+ : //basic_ios_t() is called first (lefting it uninitialized) as it's a
+ //virtual base of basic_istream. The class will be initialized when
+ //basic_istream is constructed calling basic_ios_t::init().
+ //As bufferbuf_t's constructor does not throw there is no risk of
+ //calling the basic_ios_t's destructor without calling basic_ios_t::init()
+ bufferbuf_t(mode)
+ , base_t(&get_buf())
+ {}
//!Constructor. Assigns formatting buffer.
//!Does not throw.
basic_bufferstream(CharT *buf, std::size_t length,
std::ios_base::openmode mode
= std::ios_base::in | std::ios_base::out)
- : basic_ios_t(), base_t(0), m_buf(buf, length, mode)
- { basic_ios_t::init(&m_buf); }
+ : //basic_ios_t() is called first (lefting it uninitialized) as it's a
+ //virtual base of basic_istream. The class will be initialized when
+ //basic_istream is constructed calling basic_ios_t::init().
+ //As bufferbuf_t's constructor does not throw there is no risk of
+ //calling the basic_ios_t's destructor without calling basic_ios_t::init()
+ bufferbuf_t(buf, length, mode)
+ , base_t(&get_buf())
+ {}
~basic_bufferstream(){}
@@ -407,22 +451,17 @@
//!Returns the address of the stored
//!stream buffer.
basic_bufferbuf<CharT, CharTraits>* rdbuf() const
- { return const_cast<basic_bufferbuf<CharT, CharTraits>*>(&m_buf); }
+ { return const_cast<basic_bufferbuf<CharT, CharTraits>*>(&get_buf()); }
//!Returns the pointer and size of the internal buffer.
//!Does not throw.
std::pair<CharT *, std::size_t> buffer() const
- { return m_buf.buffer(); }
+ { return get_buf().buffer(); }
//!Sets the underlying buffer to a new value. Resets
//!stream position. Does not throw.
void buffer(CharT *buf, std::size_t length)
- { m_buf.buffer(buf, length); }
-
- /// @cond
- private:
- basic_bufferbuf<CharT, CharTraits> m_buf;
- /// @endcond
+ { get_buf().buffer(buf, length); }
};
//Some typedefs to simplify usage
Modified: trunk/boost/interprocess/streams/vectorstream.hpp
==============================================================================
--- trunk/boost/interprocess/streams/vectorstream.hpp Tue Sep 3 16:08:30 2013 (r85554)
+++ trunk/boost/interprocess/streams/vectorstream.hpp 2013-09-03 18:03:10 EDT (Tue, 03 Sep 2013) (r85555)
@@ -92,8 +92,6 @@
: base_t(), m_mode(mode), m_vect(param)
{ this->initialize_pointers(); }
- virtual ~basic_vectorbuf(){}
-
public:
//!Swaps the underlying vector with the passed vector.
@@ -367,10 +365,10 @@
//!boost::interprocess::basic_string
template <class CharVector, class CharTraits>
class basic_ivectorstream
+ : public std::basic_istream<typename CharVector::value_type, CharTraits>
/// @cond
- : private basic_vectorbuf<CharVector, CharTraits>
+ , private basic_vectorbuf<CharVector, CharTraits>
/// @endcond
- , public std::basic_istream<typename CharVector::value_type, CharTraits>
{
public:
typedef CharVector vector_type;
@@ -384,56 +382,62 @@
/// @cond
private:
typedef basic_vectorbuf<CharVector, CharTraits> vectorbuf_t;
+ typedef std::basic_ios<char_type, CharTraits> basic_ios_t;
typedef std::basic_istream<char_type, CharTraits> base_t;
- vectorbuf_t & m_buf() { return *this; }
- const vectorbuf_t & m_buf() const{ return *this; }
+ vectorbuf_t & get_buf() { return *this; }
+ const vectorbuf_t & get_buf() const{ return *this; }
/// @endcond
public:
+
//!Constructor. Throws if vector_type default
//!constructor throws.
basic_ivectorstream(std::ios_base::openmode mode = std::ios_base::in)
- : vectorbuf_t(mode | std::ios_base::in), base_t(&m_buf())
- {}
+ : base_t(0) //Initializes first the base class to safely init the virtual basic_ios base
+ //(via basic_ios::init() call in base_t's constructor) without the risk of a
+ //previous throwing vectorbuf constructor. Set the streambuf after risk has gone.
+ , vectorbuf_t(mode | std::ios_base::in)
+ { this->base_t::rdbuf(&get_buf()); }
//!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)
- : vectorbuf_t(param, mode | std::ios_base::in), base_t(&m_buf())
+ : vectorbuf_t(param, mode | std::ios_base::in)
+ //basic_ios_t() is constructed uninitialized as virtual base
+ //and initialized inside base_t calling basic_ios::init()
+ , base_t(&get_buf())
{}
- ~basic_ivectorstream(){};
-
public:
//!Returns the address of the stored
//!stream buffer.
basic_vectorbuf<CharVector, CharTraits>* rdbuf() const
- { return const_cast<basic_vectorbuf<CharVector, CharTraits>*>(&m_buf()); }
+ { return const_cast<basic_vectorbuf<CharVector, CharTraits>*>(&get_buf()); }
//!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); }
+ { get_buf().swap_vector(vect); }
//!Returns a const reference to the internal vector.
//!Does not throw.
const vector_type &vector() const
- { return m_buf().vector(); }
+ { return get_buf().vector(); }
//!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); }
+ { get_buf().reserve(size); }
//!Calls clear() method of the internal vector.
//!Resets the stream to the first position.
void clear()
- { m_buf().clear(); }
+ { get_buf().clear(); }
};
//!A basic_ostream class that holds a character vector specified by CharVector
@@ -442,10 +446,10 @@
//!boost::interprocess::basic_string
template <class CharVector, class CharTraits>
class basic_ovectorstream
+ : public std::basic_ostream<typename CharVector::value_type, CharTraits>
/// @cond
- : private basic_vectorbuf<CharVector, CharTraits>
+ , private basic_vectorbuf<CharVector, CharTraits>
/// @endcond
- , public std::basic_ostream<typename CharVector::value_type, CharTraits>
{
public:
typedef CharVector vector_type;
@@ -459,54 +463,58 @@
/// @cond
private:
typedef basic_vectorbuf<CharVector, CharTraits> vectorbuf_t;
+ typedef std::basic_ios<char_type, CharTraits> basic_ios_t;
typedef std::basic_ostream<char_type, CharTraits> base_t;
- vectorbuf_t & m_buf() { return *this; }
- const vectorbuf_t & m_buf()const { return *this; }
+ vectorbuf_t & get_buf() { return *this; }
+ const vectorbuf_t & get_buf()const { return *this; }
/// @endcond
public:
//!Constructor. Throws if vector_type default
//!constructor throws.
basic_ovectorstream(std::ios_base::openmode mode = std::ios_base::out)
- : vectorbuf_t(mode | std::ios_base::out), base_t(&m_buf())
- {}
+ : base_t(0) //Initializes first the base class to safely init the virtual basic_ios base
+ //(via basic_ios::init() call in base_t's constructor) without the risk of a
+ //previous throwing vectorbuf constructor. Set the streambuf after risk has gone.
+ , vectorbuf_t(mode | std::ios_base::out)
+ { this->base_t::rdbuf(&get_buf()); }
//!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)
- : vectorbuf_t(param, mode | std::ios_base::out), base_t(&m_buf())
- {}
-
- ~basic_ovectorstream(){}
+ : base_t(0) //Initializes first the base class to safely init the virtual basic_ios base
+ //(via basic_ios::init() call in base_t's constructor) without the risk of a
+ //previous throwing vectorbuf constructor. Set the streambuf after risk has gone.
+ , vectorbuf_t(param, mode | std::ios_base::out)
+ { this->base_t::rdbuf(&get_buf()); }
public:
//!Returns the address of the stored
//!stream buffer.
basic_vectorbuf<CharVector, CharTraits>* rdbuf() const
- { return const_cast<basic_vectorbuf<CharVector, CharTraits>*>(&m_buf()); }
+ { return const_cast<basic_vectorbuf<CharVector, CharTraits>*>(&get_buf()); }
//!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); }
+ { get_buf().swap_vector(vect); }
//!Returns a const reference to the internal vector.
//!Does not throw.
const vector_type &vector() const
- { return m_buf().vector(); }
+ { return get_buf().vector(); }
//!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); }
+ { get_buf().reserve(size); }
};
-
//!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
@@ -514,7 +522,9 @@
template <class CharVector, class CharTraits>
class basic_vectorstream
: public std::basic_iostream<typename CharVector::value_type, CharTraits>
-
+ /// @cond
+ , private basic_vectorbuf<CharVector, CharTraits>
+ /// @endcond
{
public:
typedef CharVector vector_type;
@@ -527,8 +537,12 @@
/// @cond
private:
- typedef std::basic_ios<char_type, CharTraits> basic_ios_t;
- typedef std::basic_iostream<char_type, CharTraits> base_t;
+ typedef basic_vectorbuf<CharVector, CharTraits> vectorbuf_t;
+ typedef std::basic_ios<char_type, CharTraits> basic_ios_t;
+ typedef std::basic_iostream<char_type, CharTraits> base_t;
+
+ vectorbuf_t & get_buf() { return *this; }
+ const vectorbuf_t & get_buf() const{ return *this; }
/// @endcond
public:
@@ -536,50 +550,49 @@
//!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); }
+ : base_t(0) //Initializes first the base class to safely init the virtual basic_ios base
+ //(via basic_ios::init() call in base_t's constructor) without the risk of a
+ //previous throwing vectorbuf constructor. Set the streambuf after risk has gone.
+ , vectorbuf_t(mode)
+ { this->base_t::rdbuf(&get_buf()); }
//!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)
- : basic_ios_t(), base_t(0), m_buf(param, mode)
- { basic_ios_t::init(&m_buf); }
-
- ~basic_vectorstream(){}
+ : base_t(0) //Initializes first the base class to safely init the virtual basic_ios base
+ //(via basic_ios::init() call in base_t's constructor) without the risk of a
+ //previous throwing vectorbuf constructor. Set the streambuf after risk has gone.
+ , vectorbuf_t(param, mode)
+ { this->base_t::rdbuf(&get_buf()); }
public:
//Returns the address of the stored stream buffer.
basic_vectorbuf<CharVector, CharTraits>* rdbuf() const
- { return const_cast<basic_vectorbuf<CharVector, CharTraits>*>(&m_buf); }
+ { return const_cast<basic_vectorbuf<CharVector, CharTraits>*>(&get_buf()); }
//!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); }
+ { get_buf().swap_vector(vect); }
//!Returns a const reference to the internal vector.
//!Does not throw.
const vector_type &vector() const
- { return m_buf.vector(); }
+ { return get_buf().vector(); }
//!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); }
+ { get_buf().reserve(size); }
//!Calls clear() method of the internal vector.
//!Resets the stream to the first position.
void clear()
- { m_buf.clear(); }
-
- /// @cond
- private:
- basic_vectorbuf<CharVector, CharTraits> m_buf;
- /// @endcond
+ { get_buf().clear(); }
};
//Some typedefs to simplify usage
Modified: trunk/libs/interprocess/doc/interprocess.qbk
==============================================================================
--- trunk/libs/interprocess/doc/interprocess.qbk Tue Sep 3 16:08:30 2013 (r85554)
+++ trunk/libs/interprocess/doc/interprocess.qbk 2013-09-03 18:03:10 EDT (Tue, 03 Sep 2013) (r85555)
@@ -6715,7 +6715,8 @@
[section:release_notes_boost_1_55_00 Boost 1.55 Release]
-* Fixed bugs [@https://svn.boost.org/trac/boost/ticket/7164 #7164],
+* Fixed bugs [@https://svn.boost.org/trac/boost/ticket/7156 #7156],
+ [@https://svn.boost.org/trac/boost/ticket/7164 #7164],
[@https://svn.boost.org/trac/boost/ticket/8277 #8277],
[@https://svn.boost.org/trac/boost/ticket/8277 #9908],
[@https://svn.boost.org/trac/boost/ticket/9065 #9065].
Modified: trunk/libs/interprocess/test/bufferstream_test.cpp
==============================================================================
--- trunk/libs/interprocess/test/bufferstream_test.cpp Tue Sep 3 16:08:30 2013 (r85554)
+++ trunk/libs/interprocess/test/bufferstream_test.cpp 2013-09-03 18:03:10 EDT (Tue, 03 Sep 2013) (r85555)
@@ -33,7 +33,7 @@
const int BufSize = 10001;
//This will be zero-initialized
static char buffer [BufSize];
- bufferstream bufstream;;
+ bufferstream bufstream;
std::stringstream std_stringstream;
std::string str1, str2, str3("testline:");
int number1, number2;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk