]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/asio/detail/winrt_utils.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / asio / detail / winrt_utils.hpp
CommitLineData
7c673cae
FG
1//
2// detail/winrt_utils.hpp
3// ~~~~~~~~~~~~~~~~~~~~~~
4//
92f5a8d4 5// Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7c673cae
FG
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 BOOST_ASIO_DETAIL_WINRT_UTILS_HPP
12#define BOOST_ASIO_DETAIL_WINRT_UTILS_HPP
13
14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15# pragma once
16#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18#include <boost/asio/detail/config.hpp>
19
20#if defined(BOOST_ASIO_WINDOWS_RUNTIME)
21
22#include <codecvt>
23#include <cstdlib>
24#include <future>
25#include <locale>
7c673cae
FG
26#include <robuffer.h>
27#include <windows.storage.streams.h>
28#include <wrl/implements.h>
29#include <boost/asio/buffer.hpp>
30#include <boost/system/error_code.hpp>
b32b8144 31#include <boost/asio/detail/memory.hpp>
7c673cae
FG
32#include <boost/asio/detail/socket_ops.hpp>
33
34#include <boost/asio/detail/push_options.hpp>
35
36namespace boost {
37namespace asio {
38namespace detail {
39namespace winrt_utils {
40
41inline Platform::String^ string(const char* from)
42{
43 std::wstring tmp(from, from + std::strlen(from));
44 return ref new Platform::String(tmp.c_str());
45}
46
47inline Platform::String^ string(const std::string& from)
48{
49 std::wstring tmp(from.begin(), from.end());
50 return ref new Platform::String(tmp.c_str());
51}
52
53inline std::string string(Platform::String^ from)
54{
55 std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
56 return converter.to_bytes(from->Data());
57}
58
59inline Platform::String^ string(unsigned short from)
60{
61 return string(std::to_string(from));
62}
63
64template <typename T>
65inline Platform::String^ string(const T& from)
66{
67 return string(from.to_string());
68}
69
70inline int integer(Platform::String^ from)
71{
72 return _wtoi(from->Data());
73}
74
75template <typename T>
76inline Windows::Networking::HostName^ host_name(const T& from)
77{
78 return ref new Windows::Networking::HostName((string)(from));
79}
80
81template <typename ConstBufferSequence>
82inline Windows::Storage::Streams::IBuffer^ buffer_dup(
83 const ConstBufferSequence& buffers)
84{
85 using Microsoft::WRL::ComPtr;
b32b8144
FG
86 using boost::asio::buffer_size;
87 std::size_t size = buffer_size(buffers);
7c673cae
FG
88 auto b = ref new Windows::Storage::Streams::Buffer(size);
89 ComPtr<IInspectable> insp = reinterpret_cast<IInspectable*>(b);
90 ComPtr<Windows::Storage::Streams::IBufferByteAccess> bacc;
91 insp.As(&bacc);
92 byte* bytes = nullptr;
93 bacc->Buffer(&bytes);
94 boost::asio::buffer_copy(boost::asio::buffer(bytes, size), buffers);
95 b->Length = size;
96 return b;
97}
98
99} // namespace winrt_utils
100} // namespace detail
101} // namespace asio
102} // namespace boost
103
104#include <boost/asio/detail/pop_options.hpp>
105
106#endif // defined(BOOST_ASIO_WINDOWS_RUNTIME)
107
108#endif // BOOST_ASIO_DETAIL_WINRT_UTILS_HPP