2
// buffer_resize_guard.hpp
3
// ~~~~~~~~~~~~~~~~~~~~~~~
5
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11
#ifndef ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP
12
#define ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP
14
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18
#include "asio/detail/push_options.hpp"
20
#include "asio/detail/push_options.hpp"
22
#include <boost/config.hpp>
23
#include "asio/detail/pop_options.hpp"
28
// Helper class to manage buffer resizing in an exception safe way.
29
template <typename Buffer>
30
class buffer_resize_guard
34
buffer_resize_guard(Buffer& buffer)
36
old_size_(buffer.size())
40
// Destructor rolls back the buffer resize unless commit was called.
41
~buffer_resize_guard()
44
!= std::numeric_limits<size_t>::max BOOST_PREVENT_MACRO_SUBSTITUTION())
46
buffer_.resize(old_size_);
50
// Commit the resize transaction.
54
= std::numeric_limits<size_t>::max BOOST_PREVENT_MACRO_SUBSTITUTION();
58
// The buffer being managed.
61
// The size of the buffer at the time the guard was constructed.
68
#include "asio/detail/pop_options.hpp"
70
#endif // ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP