Stroika Library
3.0d20
Help-Home
Loading...
Searching...
No Matches
TextToBinary.h
1
/*
2
* Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3
*/
4
#ifndef _Stroika_Foundation_Streams_TextToBinary_h_
5
#define _Stroika_Foundation_Streams_TextToBinary_h_ 1
6
7
#include "Stroika/Foundation/StroikaPreComp.h"
8
9
#include "
Stroika/Foundation/Characters/CodeCvt.h
"
10
#include "
Stroika/Foundation/Characters/TextConvert.h
"
11
#include "
Stroika/Foundation/Execution/Synchronized.h
"
12
#include "
Stroika/Foundation/Streams/OutputStream.h
"
13
14
namespace
Stroika::Foundation::Streams {
15
using
Characters::ByteOrderMark
;
16
using
Characters::Character;
17
using
Characters::UnicodeExternalEncodings
;
18
}
19
20
namespace
Stroika::Foundation::Streams::TextToBinary {
21
22
/**
23
* \brief Take some binary output stream, and make it look like an output stream of (UNICODE) characters (using New - argument - encoding).
24
*
25
* Obviously todo this, there may be some character set mapping/conversion needed. The object
26
* takes constructor arguments to decide how this will he handled.
27
*
28
* TextToBinary::Writer is not seekable. It's possible to implement, but complicated, and performance costly. Very unlikely
29
* to ever be useful.
30
*
31
* \note This API was called TextOutputStreamAdapter
32
*
33
* \note TextToBinary::Writer aggregates its owned sub-stream, so that a Close () on TextToBinary::Writer
34
* will Close that sub-stream.
35
*
36
* Ptr is a copyable smart pointer to a TextToBinary::Writer stream.
37
*
38
* \par Example Usage
39
* \code
40
* Streams::TextToBinary::Writer::Ptr textOut = Streams::TextToBinary::Writer::New (out, UnicodeExternalEncodings::eUTF8, ByteOrderMark::eDoneInclude);
41
* textOut.Write ("{}\r\n"_f (headLine));
42
* ...
43
* \endcode
44
*
45
* \par Example Usage
46
* \code
47
* Streams::TextToBinary::Writer::Ptr textOut = Streams::TextToBinary::Writer::New (binOut);
48
* textOut.Write ("Hello World\n");
49
* \endcode
50
*
51
* \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety-For-Envelope-Plus-Must-Externally-Synchronize-Letter">C++-Standard-Thread-Safety-For-Envelope-Plus-Must-Externally-Synchronize-Letter</a>
52
*
53
* If TextToBinary::Writer given an OutStream<Bytes>, it maps the characters according to the given code page info (@todo improve so generic code page support).
54
* If handled an OutputStream<Character> - it just passes through characters.
55
*
56
* \par Example Usage
57
* \code
58
* Streams::TextToBinary::Writer::Ptr textOut = Streams::TextToBinary::Writer::New (out, UnicodeExternalEncodings::eUTF8, ByteOrderMark::eInclude);
59
* textOut.Write ("{}\r\n"_f (headLine));
60
* ...
61
* \endcode
62
*
63
* \par Example Usage
64
* \code
65
* Streams::TextToBinary::Writer::Ptr textOut = Streams::TextToBinary::Writer::New (binOut);
66
* textOut.Write ("Hello World\n");
67
* \endcode
68
*/
69
namespace
Writer {
70
71
/**
72
* \brief TextToBinary::Writer wrap some sink (typically a binary stream), and produce a text sink you can Write() text to
73
*/
74
using
Ptr
=
Streams::OutputStream::Ptr<Character>
;
75
76
/**
77
* \note Warning: the OutputStream objects returned are not seekable.
78
*/
79
Ptr
New
(
const
Streams::OutputStream::Ptr<byte>
& src,
const
Characters::CodeCvt<>
& char2OutputConverter);
80
Ptr
New
(
const
Streams::OutputStream::Ptr<byte>
& src, UnicodeExternalEncodings e = UnicodeExternalEncodings::eDEFAULT,
81
ByteOrderMark bom = ByteOrderMark::eDontInclude);
82
Ptr
New
(
const
Streams::OutputStream::Ptr<Character>
& src);
83
template
<
typename
... ARGS>
84
Ptr
New
(
Execution::InternallySynchronized
internallySynchronized, ARGS... args);
85
86
}
87
88
namespace
Reader {
89
90
/**
91
* \brief TextToBinary::Reader wrap some source of text, and produce an binary input stream you can read (converted) bytes from.
92
*/
93
using
Ptr
=
InputStream::Ptr<byte>
;
94
95
/**
96
* \brief Stream wrapper that takes an InputStream<Character> and transforms it into an
97
* InputStream<byte> (like TextToBinary::Writer does, but pull rather than push based).
98
*
99
* Draft implementation (not very performant, but doesn't seem used much and easy to tweak)
100
*
101
* DOC CONNECTION TO TextToBinary::Writer and maybe share output/format flags?
102
*
103
* @todo NOTE - this CURRENTLY HARDWIRES converting to UTF-8
104
*
105
* @todo take optional CodeCvt argument, or things you would pass to CodeCvt (character coding) for what binary rep to create!
106
*
107
* WONT change this part of the API - just adding overloads, so OK to release as-is - 2023-07-10
108
*
109
* Ptr New (const InputStream::Ptr<Character>& srcStream, optional<SeekableFlag> seekable...) overload:
110
* if seekable argument seekable, then \ens result.IsSeekable ()
111
* Ptr New (const Traversal::Iterable<Character>& srcText) overload:
112
* \ens result.IsSeekable ()
113
*/
114
Ptr
New (
const
InputStream::Ptr<Character>
& srcStream, optional<SeekableFlag> seekable = {});
115
Ptr
New (
const
Traversal::Iterable<Character>
& srcText);
116
117
}
118
119
}
120
121
/*
122
********************************************************************************
123
***************************** Implementation Details ***************************
124
********************************************************************************
125
*/
126
#include "TextToBinary.inl"
127
128
#endif
/*_Stroika_Foundation_Streams_TextToBinary_h_*/
CodeCvt.h
OutputStream.h
Synchronized.h
TextConvert.h
Stroika::Foundation::Characters::CodeCvt
CodeCvt unifies byte <-> unicode conversions, vaguely inspired by (and wraps) std::codecvt,...
Definition
CodeCvt.h:118
Stroika::Foundation::Streams::InputStream::Ptr
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...
Definition
InputStream.h:165
Stroika::Foundation::Streams::OutputStream::Ptr
OutputStream<>::Ptr is Smart pointer to a stream-based sink of data.
Definition
OutputStream.h:92
Stroika::Foundation::Streams::Ptr
A Streams::Ptr<ELEMENT_TYPE> is a smart-pointer to a stream of elements of type T.
Definition
Stream.h:170
Stroika::Foundation::Traversal::Iterable
Iterable<T> is a base class for containers which easily produce an Iterator<T> to traverse them.
Definition
Iterable.h:237
Stroika::Foundation::Characters::ByteOrderMark
ByteOrderMark
Definition
TextConvert.h:29
Stroika::Foundation::Characters::UnicodeExternalEncodings
UnicodeExternalEncodings
list of external UNICODE character encodings, for file IO (eDEFAULT = eUTF8)
Definition
UTFConvert.h:31
Stroika::Foundation::Execution::InternallySynchronized
InternallySynchronized
Definition
Synchronized.h:54
Stroika::Foundation::Streams::TextToBinary::Writer::New
Ptr New(const Streams::OutputStream::Ptr< byte > &src, const Characters::CodeCvt<> &char2OutputConverter)
Definition
TextToBinary.inl:151
Library
Sources
Stroika
Foundation
Streams
TextToBinary.h
Generated by
1.9.8