Realistic 3D camera system
3D camera system components
buffer_resize_guard.hpp
Go to the documentation of this file.
1 //
2 // detail/buffer_resize_guard.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
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)
9 //
10 
11 #ifndef ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP
12 #define ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
19 #include "asio/detail/limits.hpp"
20 
22 
23 namespace asio {
24 namespace detail {
25 
26 // Helper class to manage buffer resizing in an exception safe way.
27 template <typename Buffer>
29 {
30 public:
31  // Constructor.
33  : buffer_(buffer),
34  old_size_(buffer.size())
35  {
36  }
37 
38  // Destructor rolls back the buffer resize unless commit was called.
40  {
41  if (old_size_ != (std::numeric_limits<size_t>::max)())
42  {
43  buffer_.resize(old_size_);
44  }
45  }
46 
47  // Commit the resize transaction.
48  void commit()
49  {
50  old_size_ = (std::numeric_limits<size_t>::max)();
51  }
52 
53 private:
54  // The buffer being managed.
55  Buffer& buffer_;
56 
57  // The size of the buffer at the time the guard was constructed.
58  size_t old_size_;
59 };
60 
61 } // namespace detail
62 } // namespace asio
63 
65 
66 #endif // ASIO_DETAIL_BUFFER_RESIZE_GUARD_HPP
mutable_buffers_1 buffer(const mutable_buffer &b)
Create a new modifiable buffer from an existing buffer.
Definition: buffer.hpp:706