2 // detail/impl/buffer_sequence_adapter.ipp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2017 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 BOOST_ASIO_DETAIL_IMPL_BUFFER_SEQUENCE_ADAPTER_IPP
12 #define BOOST_ASIO_DETAIL_IMPL_BUFFER_SEQUENCE_ADAPTER_IPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/config.hpp>
20 #if defined(BOOST_ASIO_WINDOWS_RUNTIME)
23 #include <windows.storage.streams.h>
24 #include <wrl/implements.h>
25 #include <boost/asio/detail/buffer_sequence_adapter.hpp>
27 #include <boost/asio/detail/push_options.hpp>
33 class winrt_buffer_impl :
34 public Microsoft::WRL::RuntimeClass<
35 Microsoft::WRL::RuntimeClassFlags<
36 Microsoft::WRL::RuntimeClassType::WinRtClassicComMix>,
37 ABI::Windows::Storage::Streams::IBuffer,
38 Windows::Storage::Streams::IBufferByteAccess>
41 explicit winrt_buffer_impl(const boost::asio::const_buffer& b)
43 bytes_ = const_cast<byte*>(static_cast<const byte*>(b.data()));
48 explicit winrt_buffer_impl(const boost::asio::mutable_buffer& b)
50 bytes_ = static_cast<byte*>(b.data());
59 STDMETHODIMP Buffer(byte** value)
65 STDMETHODIMP get_Capacity(UINT32* value)
71 STDMETHODIMP get_Length(UINT32 *value)
77 STDMETHODIMP put_Length(UINT32 value)
79 if (value > capacity_)
91 void buffer_sequence_adapter_base::init_native_buffer(
92 buffer_sequence_adapter_base::native_buffer_type& buf,
93 const boost::asio::mutable_buffer& buffer)
95 std::memset(&buf, 0, sizeof(native_buffer_type));
96 Microsoft::WRL::ComPtr<IInspectable> insp
97 = Microsoft::WRL::Make<winrt_buffer_impl>(buffer);
98 buf = reinterpret_cast<Windows::Storage::Streams::IBuffer^>(insp.Get());
101 void buffer_sequence_adapter_base::init_native_buffer(
102 buffer_sequence_adapter_base::native_buffer_type& buf,
103 const boost::asio::const_buffer& buffer)
105 std::memset(&buf, 0, sizeof(native_buffer_type));
106 Microsoft::WRL::ComPtr<IInspectable> insp
107 = Microsoft::WRL::Make<winrt_buffer_impl>(buffer);
108 Platform::Object^ buf_obj = reinterpret_cast<Platform::Object^>(insp.Get());
109 buf = reinterpret_cast<Windows::Storage::Streams::IBuffer^>(insp.Get());
112 } // namespace detail
116 #include <boost/asio/detail/pop_options.hpp>
118 #endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
120 #endif // BOOST_ASIO_DETAIL_IMPL_BUFFER_SEQUENCE_ADAPTER_IPP