Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / detail / impl / buffer_sequence_adapter.ipp @ 2486

History | View | Annotate | Download (3.1 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// detail/impl/buffer_sequence_adapter.ipp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_DETAIL_IMPL_BUFFER_SEQUENCE_ADAPTER_IPP
12 2486 sjacqu01
#define BOOST_ASIO_DETAIL_IMPL_BUFFER_SEQUENCE_ADAPTER_IPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
19 2486 sjacqu01
20 2486 sjacqu01
#if defined(BOOST_ASIO_WINDOWS_RUNTIME)
21 2486 sjacqu01
22 2486 sjacqu01
#include <robuffer.h>
23 2486 sjacqu01
#include <windows.storage.streams.h>
24 2486 sjacqu01
#include <wrl/implements.h>
25 2486 sjacqu01
#include <boost/asio/detail/buffer_sequence_adapter.hpp>
26 2486 sjacqu01
27 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
28 2486 sjacqu01
29 2486 sjacqu01
namespace boost {
30 2486 sjacqu01
namespace asio {
31 2486 sjacqu01
namespace detail {
32 2486 sjacqu01
33 2486 sjacqu01
class winrt_buffer_impl :
34 2486 sjacqu01
  public Microsoft::WRL::RuntimeClass<
35 2486 sjacqu01
    Microsoft::WRL::RuntimeClassFlags<
36 2486 sjacqu01
      Microsoft::WRL::RuntimeClassType::WinRtClassicComMix>,
37 2486 sjacqu01
    ABI::Windows::Storage::Streams::IBuffer,
38 2486 sjacqu01
    Windows::Storage::Streams::IBufferByteAccess>
39 2486 sjacqu01
{
40 2486 sjacqu01
public:
41 2486 sjacqu01
  explicit winrt_buffer_impl(const boost::asio::const_buffer& b)
42 2486 sjacqu01
  {
43 2486 sjacqu01
    bytes_ = const_cast<byte*>(boost::asio::buffer_cast<const byte*>(b));
44 2486 sjacqu01
    length_ = boost::asio::buffer_size(b);
45 2486 sjacqu01
    capacity_ = boost::asio::buffer_size(b);
46 2486 sjacqu01
  }
47 2486 sjacqu01
48 2486 sjacqu01
  explicit winrt_buffer_impl(const boost::asio::mutable_buffer& b)
49 2486 sjacqu01
  {
50 2486 sjacqu01
    bytes_ = const_cast<byte*>(boost::asio::buffer_cast<const byte*>(b));
51 2486 sjacqu01
    length_ = 0;
52 2486 sjacqu01
    capacity_ = boost::asio::buffer_size(b);
53 2486 sjacqu01
  }
54 2486 sjacqu01
55 2486 sjacqu01
  ~winrt_buffer_impl()
56 2486 sjacqu01
  {
57 2486 sjacqu01
  }
58 2486 sjacqu01
59 2486 sjacqu01
  STDMETHODIMP Buffer(byte** value)
60 2486 sjacqu01
  {
61 2486 sjacqu01
    *value = bytes_;
62 2486 sjacqu01
    return S_OK;
63 2486 sjacqu01
  }
64 2486 sjacqu01
65 2486 sjacqu01
  STDMETHODIMP get_Capacity(UINT32* value)
66 2486 sjacqu01
  {
67 2486 sjacqu01
    *value = capacity_;
68 2486 sjacqu01
    return S_OK;
69 2486 sjacqu01
  }
70 2486 sjacqu01
71 2486 sjacqu01
  STDMETHODIMP get_Length(UINT32 *value)
72 2486 sjacqu01
  {
73 2486 sjacqu01
    *value = length_;
74 2486 sjacqu01
    return S_OK;
75 2486 sjacqu01
  }
76 2486 sjacqu01
77 2486 sjacqu01
  STDMETHODIMP put_Length(UINT32 value)
78 2486 sjacqu01
  {
79 2486 sjacqu01
    if (value > capacity_)
80 2486 sjacqu01
      return E_INVALIDARG;
81 2486 sjacqu01
    length_ = value;
82 2486 sjacqu01
    return S_OK;
83 2486 sjacqu01
  }
84 2486 sjacqu01
85 2486 sjacqu01
private:
86 2486 sjacqu01
  byte* bytes_;
87 2486 sjacqu01
  UINT32 length_;
88 2486 sjacqu01
  UINT32 capacity_;
89 2486 sjacqu01
};
90 2486 sjacqu01
91 2486 sjacqu01
void buffer_sequence_adapter_base::init_native_buffer(
92 2486 sjacqu01
    buffer_sequence_adapter_base::native_buffer_type& buf,
93 2486 sjacqu01
    const boost::asio::mutable_buffer& buffer)
94 2486 sjacqu01
{
95 2486 sjacqu01
  std::memset(&buf, 0, sizeof(native_buffer_type));
96 2486 sjacqu01
  Microsoft::WRL::ComPtr<IInspectable> insp
97 2486 sjacqu01
    = Microsoft::WRL::Make<winrt_buffer_impl>(buffer);
98 2486 sjacqu01
  buf = reinterpret_cast<Windows::Storage::Streams::IBuffer^>(insp.Get());
99 2486 sjacqu01
}
100 2486 sjacqu01
101 2486 sjacqu01
void buffer_sequence_adapter_base::init_native_buffer(
102 2486 sjacqu01
    buffer_sequence_adapter_base::native_buffer_type& buf,
103 2486 sjacqu01
    const boost::asio::const_buffer& buffer)
104 2486 sjacqu01
{
105 2486 sjacqu01
  std::memset(&buf, 0, sizeof(native_buffer_type));
106 2486 sjacqu01
  Microsoft::WRL::ComPtr<IInspectable> insp
107 2486 sjacqu01
    = Microsoft::WRL::Make<winrt_buffer_impl>(buffer);
108 2486 sjacqu01
  Platform::Object^ buf_obj = reinterpret_cast<Platform::Object^>(insp.Get());
109 2486 sjacqu01
  buf = reinterpret_cast<Windows::Storage::Streams::IBuffer^>(insp.Get());
110 2486 sjacqu01
}
111 2486 sjacqu01
112 2486 sjacqu01
} // namespace detail
113 2486 sjacqu01
} // namespace asio
114 2486 sjacqu01
} // namespace boost
115 2486 sjacqu01
116 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
117 2486 sjacqu01
118 2486 sjacqu01
#endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
119 2486 sjacqu01
120 2486 sjacqu01
#endif // BOOST_ASIO_DETAIL_IMPL_BUFFER_SEQUENCE_ADAPTER_IPP