channel_ptr.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // Copyright (c) 2019-2023 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. #ifndef BHO_MYSQL_DETAIL_CHANNEL_PTR_HPP
  8. #define BHO_MYSQL_DETAIL_CHANNEL_PTR_HPP
  9. #include <asio2/bho/mysql/diagnostics.hpp>
  10. #include <asio2/bho/mysql/field_view.hpp>
  11. #include <asio2/bho/mysql/metadata_mode.hpp>
  12. #include <asio2/bho/mysql/detail/any_stream.hpp>
  13. #include <asio2/bho/mysql/detail/config.hpp>
  14. #include <asio2/bho/assert.hpp>
  15. #include <memory>
  16. namespace bho {
  17. namespace mysql {
  18. namespace detail {
  19. class channel;
  20. class channel_ptr
  21. {
  22. std::unique_ptr<channel> chan_;
  23. BHO_MYSQL_DECL any_stream& get_stream() const;
  24. public:
  25. BHO_MYSQL_DECL channel_ptr(std::size_t read_buff_size, std::unique_ptr<any_stream>);
  26. channel_ptr(const channel_ptr&) = delete;
  27. BHO_MYSQL_DECL channel_ptr(channel_ptr&&) noexcept;
  28. channel_ptr& operator=(const channel_ptr&) = delete;
  29. BHO_MYSQL_DECL channel_ptr& operator=(channel_ptr&&) noexcept;
  30. BHO_MYSQL_DECL ~channel_ptr();
  31. any_stream& stream() noexcept { return get_stream(); }
  32. const any_stream& stream() const noexcept { return get_stream(); }
  33. channel& get() noexcept
  34. {
  35. BHO_ASSERT(chan_);
  36. return *chan_;
  37. }
  38. const channel& get() const noexcept
  39. {
  40. BHO_ASSERT(chan_);
  41. return *chan_;
  42. }
  43. BHO_MYSQL_DECL metadata_mode meta_mode() const noexcept;
  44. BHO_MYSQL_DECL void set_meta_mode(metadata_mode v) noexcept;
  45. BHO_MYSQL_DECL diagnostics& shared_diag() noexcept;
  46. };
  47. BHO_MYSQL_DECL std::vector<field_view>& get_shared_fields(channel&) noexcept;
  48. } // namespace detail
  49. } // namespace mysql
  50. } // namespace bho
  51. #ifdef BHO_MYSQL_HEADER_ONLY
  52. #include <asio2/bho/mysql/impl/channel_ptr.ipp>
  53. #endif
  54. #endif