Realistic 3D camera system
3D camera system components
winrt_utils.hpp
Go to the documentation of this file.
1 //
2 // detail/winrt_utils.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_WINRT_UTILS_HPP
12 #define 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 "asio/detail/config.hpp"
19 
20 #if defined(ASIO_WINDOWS_RUNTIME)
21 
22 #include <codecvt>
23 #include <cstdlib>
24 #include <future>
25 #include <locale>
26 #include <memory>
27 #include <robuffer.h>
28 #include <windows.storage.streams.h>
29 #include <wrl/implements.h>
30 #include "asio/buffer.hpp"
31 #include "asio/error_code.hpp"
34 
36 
37 namespace asio {
38 namespace detail {
39 namespace winrt_utils {
40 
41 inline 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 
47 inline 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 
53 inline 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 
59 inline Platform::String^ string(unsigned short from)
60 {
61  return string(std::to_string(from));
62 }
63 
64 template <typename T>
65 inline Platform::String^ string(const T& from)
66 {
67  return string(from.to_string());
68 }
69 
70 inline int integer(Platform::String^ from)
71 {
72  return _wtoi(from->Data());
73 }
74 
75 template <typename T>
76 inline Windows::Networking::HostName^ host_name(const T& from)
77 {
78  return ref new Windows::Networking::HostName((string)(from));
79 }
80 
81 template <typename ConstBufferSequence>
82 inline Windows::Storage::Streams::IBuffer^ buffer_dup(
83  const ConstBufferSequence& buffers)
84 {
85  using Microsoft::WRL::ComPtr;
86  std::size_t size = asio::buffer_size(buffers);
87  auto b = ref new Windows::Storage::Streams::Buffer(size);
88  ComPtr<IInspectable> insp = reinterpret_cast<IInspectable*>(b);
89  ComPtr<Windows::Storage::Streams::IBufferByteAccess> bacc;
90  insp.As(&bacc);
91  byte* bytes = nullptr;
92  bacc->Buffer(&bytes);
93  asio::buffer_copy(asio::buffer(bytes, size), buffers);
94  b->Length = size;
95  return b;
96 }
97 
98 } // namespace winrt_utils
99 } // namespace detail
100 } // namespace asio
101 
103 
104 #endif // defined(ASIO_WINDOWS_RUNTIME)
105 
106 #endif // ASIO_DETAIL_WINRT_UTILS_HPP
mutable_buffers_1 buffer(const mutable_buffer &b)
Create a new modifiable buffer from an existing buffer.
Definition: buffer.hpp:706
asio::basic_streambuf< Allocator > & b
Definition: read.hpp:702
std::string to_string(reply::status_type status)
Definition: reply.cpp:199
std::size_t buffer_size(const mutable_buffer &b)
Get the number of bytes in a modifiable buffer.
Definition: buffer.hpp:357
const MutableBufferSequence & buffers
Definition: read.hpp:521
ASIO_DECL std::string host_name()
Get the current host name.
Definition: host_name.ipp:29
std::size_t buffer_copy(const mutable_buffer &target, const const_buffer &source)
Copies bytes from a source buffer to a target buffer.
Definition: buffer.hpp:1295