StringUriUtf32To8WriteResource.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_UTF32_TO_8_WRITE_RESOURCE
18 #define COM_BORA_SOFTWARE__BALAU_RESOURCE__STRING_URI_UTF32_TO_8_WRITE_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 
36  private: using odevice_utf32_utf8 = boost::iostreams::code_converter<std::ostream, std::codecvt_utf8<char32_t, 0x10ffff, std::consume_header>>;
37  private: using ostream_utf32_utf8 = boost::iostreams::stream<odevice_utf32_utf8>;
38 
44  public: explicit StringUriUtf32To8WriteResource(StringUri & stringUri_);
45 
47  : stringUri(rhs.stringUri)
48  , utf8Stream(std::move(rhs.utf8Stream))
49  , ref(rhs.ref)
50  , utf32Stream(std::move(rhs.utf32Stream)) {}
51 
52  public: ~StringUriUtf32To8WriteResource() override {
53  close();
54  }
55 
56  public: std::u32ostream & writeStream() override {
57  return *utf32Stream;
58  }
59 
60  public: const Uri & uri() const override;
61 
62  public: void close() override;
63 
65 
66  private: StringUri & stringUri;
67  private: std::unique_ptr<std::ostringstream> utf8Stream;
68  private: std::ostream & ref;
69  private: std::unique_ptr<ostream_utf32_utf8> utf32Stream;
70 };
71 
72 } // namespace Balau::Resource
73 
74 #endif // COM_BORA_SOFTWARE__BALAU_RESOURCE__STRING_URI_UTF32_TO_8_WRITE_RESOURCE
A write-only UTF-8 resource, which is written with UTF-32 characters.
Definition: Utf32To8WriteResource.hpp:28
An abstract universal resource identifier.
Definition: Uri.hpp:131
std::u32ostream & writeStream() override
Get the output stream of the UTF-32 to UTF-8 write resource.
Definition: StringUriUtf32To8WriteResource.hpp:56
The unified resource class hierarchy.
Definition: ByteReadResource.hpp:24
A write-only UTF-8 resource, which is written as UTF-32 characters.
A write-only UTF-8 resource in a standard file on a file system, which is written with UTF-32 charact...
Definition: StringUriUtf32To8WriteResource.hpp:35
An immediate string pseudo-URI.
Definition: StringUri.hpp:49
const Uri & uri() const override
Get the URI associated with this resource.
void close() override
Close the stream(s) in the resource.
StringUriUtf32To8WriteResource(StringUri &stringUri_)
Create a new file UTF-32 to UTF-8 write resource from the supplied file URI.