StringUriUtf8To32ReadResource.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__STRING_URI_UTF8_TO_32_READ_RESOURCE
18 #define COM_BORA_SOFTWARE__BALAU_RESOURCE__STRING_URI_UTF8_TO_32_READ_RESOURCE
19 
21 
22 #include <boost/iostreams/code_converter.hpp>
23 #include <boost/iostreams/stream.hpp>
24 
25 #include <codecvt>
26 
27 namespace Balau::Resource {
28 
29 class StringUri;
30 class Uri;
31 
38  private: using idevice_utf8_utf32 = boost::iostreams::code_converter<std::istream, std::codecvt_utf8<char32_t, 0x10ffff, std::consume_header>>;
39  private: using istream_utf8_utf32 = boost::iostreams::stream<idevice_utf8_utf32>;
40 
44  public: explicit StringUriUtf8To32ReadResource(const StringUri & stringUri_);
45 
47  : stringUri(std::move(rhs.stringUri))
48  , utf8Stream(std::move(rhs.utf8Stream))
49  , ref(rhs.ref)
50  , utf32Stream(std::move(rhs.utf32Stream)) {}
51 
52  public: std::u32istream & readStream() override {
53  return *utf32Stream;
54  }
55 
56  public: const Uri & uri() const override;
57 
58  public: void close() override {}
59 
61 
62  private: std::unique_ptr<StringUri> stringUri;
63  private: std::unique_ptr<std::istringstream> utf8Stream;
64  private: std::istream & ref;
65  private: std::unique_ptr<istream_utf8_utf32> utf32Stream;
66 };
67 
68 } // namespace Balau::Resource
69 
70 #endif // COM_BORA_SOFTWARE__BALAU_RESOURCE__STRING_URI_UTF8_TO_32_READ_RESOURCE
void close() override
Close the stream(s) in the resource.
Definition: StringUriUtf8To32ReadResource.hpp:58
A read-only UTF-8 resource which is read as UTF-32 characters.
A read-only UTF-8 resource which is read in as UTF-32 characters.
Definition: Utf8To32ReadResource.hpp:28
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
An immediate string pseudo-URI.
Definition: StringUri.hpp:49
std::u32istream & readStream() override
Get the input stream of the UTF-8 to UTF-32 read resource.
Definition: StringUriUtf8To32ReadResource.hpp:52
A read-only String UTF-8 resource which is read as UTF-32 characters.
Definition: StringUriUtf8To32ReadResource.hpp:37
StringUriUtf8To32ReadResource(const StringUri &stringUri_)
Create a new String URI UTF-8 to UTF-32 read resource from the supplied String URI.