]> jfr.im git - irc/gameservirc.git/blob - gameserv-2.0/asio/asio/detail/handler_alloc_helpers.hpp
Added the asio framework to start developing a GameServ server
[irc/gameservirc.git] / gameserv-2.0 / asio / asio / detail / handler_alloc_helpers.hpp
1 //
2 // detail/handler_alloc_helpers.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2011 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_HANDLER_ALLOC_HELPERS_HPP
12 #define ASIO_DETAIL_HANDLER_ALLOC_HELPERS_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 <boost/detail/workaround.hpp>
20 #include <boost/utility/addressof.hpp>
21 #include "asio/detail/noncopyable.hpp"
22 #include "asio/handler_alloc_hook.hpp"
23
24 #include "asio/detail/push_options.hpp"
25
26 // Calls to asio_handler_allocate and asio_handler_deallocate must be made from
27 // a namespace that does not contain any overloads of these functions. The
28 // asio_handler_alloc_helpers namespace is defined here for that purpose.
29 namespace asio_handler_alloc_helpers {
30
31 template <typename Handler>
32 inline void* allocate(std::size_t s, Handler& h)
33 {
34 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) \
35 || BOOST_WORKAROUND(__GNUC__, < 3)
36 return ::operator new(s);
37 #else
38 using namespace asio;
39 return asio_handler_allocate(s, boost::addressof(h));
40 #endif
41 }
42
43 template <typename Handler>
44 inline void deallocate(void* p, std::size_t s, Handler& h)
45 {
46 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) \
47 || BOOST_WORKAROUND(__GNUC__, < 3)
48 ::operator delete(p);
49 #else
50 using namespace asio;
51 asio_handler_deallocate(p, s, boost::addressof(h));
52 #endif
53 }
54
55 } // namespace asio_handler_alloc_helpers
56
57 #define ASIO_DEFINE_HANDLER_PTR(op) \
58 struct ptr \
59 { \
60 Handler* h; \
61 void* v; \
62 op* p; \
63 ~ptr() \
64 { \
65 reset(); \
66 } \
67 void reset() \
68 { \
69 if (p) \
70 { \
71 p->~op(); \
72 p = 0; \
73 } \
74 if (v) \
75 { \
76 asio_handler_alloc_helpers::deallocate(v, sizeof(op), *h); \
77 v = 0; \
78 } \
79 } \
80 } \
81 /**/
82
83 #include "asio/detail/pop_options.hpp"
84
85 #endif // ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP