HttpsUtf8To32ReadResource.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2008 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_RESOURCE__HTTPS_UTF8_TO_32_READ_RESOURCE
18 #define COM_BORA_SOFTWARE__BALAU_RESOURCE__HTTPS_UTF8_TO_32_READ_RESOURCE
19 
21 #include <Balau/Resource/Impl/HttpsSource.hpp>
22 
23 #include <boost/iostreams/code_converter.hpp>
24 #include <boost/iostreams/stream.hpp>
25 
26 #include <codecvt>
27 
28 namespace Balau::Resource {
29 
30 class Https;
31 
36  private: using idevice_utf8_utf32 = boost::iostreams::code_converter<std::istream, std::codecvt_utf8<char32_t, 0x10ffff, std::consume_header>>;
37  private: using istream_utf8_utf32 = boost::iostreams::stream<idevice_utf8_utf32>;
38 
44  public: explicit HttpsUtf8To32ReadResource(const Https & http_);
45 
47  : url(std::move(rhs.url))
48  , utf8Stream(std::move(rhs.utf8Stream))
49  , ref(rhs.ref)
50  , utf32Stream(std::move(rhs.utf32Stream)) {}
51 
52  public: ~HttpsUtf8To32ReadResource() override {
53  close();
54  }
55 
56  public: std::u32istream & readStream() override {
57  return *utf32Stream;
58  }
59 
60  public: const Uri & uri() const override;
61 
62  public: void close() override {
63  utf32Stream->close();
64  }
65 
67 
68  private: std::unique_ptr<Https> url;
69  private: std::unique_ptr<boost::iostreams::stream<Impl::HttpsSource>> utf8Stream;
70  private: std::istream & ref;
71  private: std::unique_ptr<istream_utf8_utf32> utf32Stream;
72 };
73 
74 } // namespace Balau::Resource
75 
76 #endif // COM_BORA_SOFTWARE__BALAU_RESOURCE__HTTPS_UTF8_TO_32_READ_RESOURCE
A read-only UTF-8 resource which is read as UTF-32 characters.
void close() override
Close the stream(s) in the resource.
Definition: HttpsUtf8To32ReadResource.hpp:62
A read-only UTF-8 resource which is read in as UTF-32 characters.
Definition: Utf8To32ReadResource.hpp:28
An HTTPS URL.
Definition: Https.hpp:30
const Uri & uri() const override
Get the URI associated with this resource.
An abstract universal resource identifier.
Definition: Uri.hpp:131
The unified resource class hierarchy.
Definition: ByteReadResource.hpp:24
A read-only HTTP UTF-8 resource which is read as UTF-32 characters.
Definition: HttpsUtf8To32ReadResource.hpp:35
HttpsUtf8To32ReadResource(const Https &http_)
Create a new HTTPS UTF-8 to UTF-32 read resource from the supplied HTTPS URI.
std::u32istream & readStream() override
Get the input stream of the UTF-8 to UTF-32 read resource.
Definition: HttpsUtf8To32ReadResource.hpp:56