Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

winrt_utils.hpp 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // detail/winrt_utils.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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. #ifndef ASIO_DETAIL_WINRT_UTILS_HPP
  11. #define ASIO_DETAIL_WINRT_UTILS_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include "asio/detail/config.hpp"
  16. #if defined(ASIO_WINDOWS_RUNTIME)
  17. #include <codecvt>
  18. #include <cstdlib>
  19. #include <future>
  20. #include <locale>
  21. #include <robuffer.h>
  22. #include <windows.storage.streams.h>
  23. #include <wrl/implements.h>
  24. #include "asio/buffer.hpp"
  25. #include "asio/error_code.hpp"
  26. #include "asio/detail/memory.hpp"
  27. #include "asio/detail/socket_ops.hpp"
  28. #include "asio/detail/push_options.hpp"
  29. namespace asio {
  30. namespace detail {
  31. namespace winrt_utils {
  32. inline Platform::String^ string(const char* from)
  33. {
  34. std::wstring tmp(from, from + std::strlen(from));
  35. return ref new Platform::String(tmp.c_str());
  36. }
  37. inline Platform::String^ string(const std::string& from)
  38. {
  39. std::wstring tmp(from.begin(), from.end());
  40. return ref new Platform::String(tmp.c_str());
  41. }
  42. inline std::string string(Platform::String^ from)
  43. {
  44. std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
  45. return converter.to_bytes(from->Data());
  46. }
  47. inline Platform::String^ string(unsigned short from)
  48. {
  49. return string(std::to_string(from));
  50. }
  51. template <typename T>
  52. inline Platform::String^ string(const T& from)
  53. {
  54. return string(from.to_string());
  55. }
  56. inline int integer(Platform::String^ from)
  57. {
  58. return _wtoi(from->Data());
  59. }
  60. template <typename T>
  61. inline Windows::Networking::HostName^ host_name(const T& from)
  62. {
  63. return ref new Windows::Networking::HostName((string)(from));
  64. }
  65. template <typename ConstBufferSequence>
  66. inline Windows::Storage::Streams::IBuffer^ buffer_dup(
  67. const ConstBufferSequence& buffers)
  68. {
  69. using Microsoft::WRL::ComPtr;
  70. using asio::buffer_size;
  71. std::size_t size = buffer_size(buffers);
  72. auto b = ref new Windows::Storage::Streams::Buffer(size);
  73. ComPtr<IInspectable> insp = reinterpret_cast<IInspectable*>(b);
  74. ComPtr<Windows::Storage::Streams::IBufferByteAccess> bacc;
  75. insp.As(&bacc);
  76. byte* bytes = nullptr;
  77. bacc->Buffer(&bytes);
  78. asio::buffer_copy(asio::buffer(bytes, size), buffers);
  79. b->Length = size;
  80. return b;
  81. }
  82. } // namespace winrt_utils
  83. } // namespace detail
  84. } // namespace asio
  85. #include "asio/detail/pop_options.hpp"
  86. #endif // defined(ASIO_WINDOWS_RUNTIME)
  87. #endif // ASIO_DETAIL_WINRT_UTILS_HPP