Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
InputStreamFromStdIStream.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Streams_iostream_InputStreamFromStdIStream_h_
5#define _Stroika_Foundation_Streams_iostream_InputStreamFromStdIStream_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <istream>
10
11#include "Stroika/Foundation/Common/Common.h"
13#include "Stroika/Foundation/Streams/InternallySynchronizedInputStream.h"
14
15/**
16 * \file
17 *
18 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha/a>
19 *
20 * TODO:
21 * @todo http://stroika-bugs.sophists.com/browse/STK-606 - Implement StdIStreamFromInputStream and StdOStreamFromOutputStream classes
22 *
23 * @todo Better handle failbit / eofbit etc. Not correct, but maybe OK for now... Not sure right answer.
24 *
25 */
26
27namespace Stroika::Foundation::Streams::iostream::InputStreamFromStdIStream {
28
29 using InputStream::Ptr;
30
31 /**
32 * InputStreamFromStdIStream wraps an argument std::istream or std::wistream or std::basic_istream<> as a Stroika InputStream object
33 *
34 * \par Example Usage
35 * \code
36 * stringstream tmpStrm;
37 * tmpStrm << "some xml";
38 * XML::SAXParse (InputStreamFromStdIStream::New<byte> (tmpStrm), MyCallback{});
39 * \endcode
40 *
41 * \note InputStreamFromStdIStream ::Close () does not call close on the owned basic_istream, because there is no such stdC++ method (though filestream has one)
42 *
43 *
44 * Default seekability should be determined automatically, but for now, I cannot figure out how...
45 * \par Example Usage
46 * \code
47 * stringstream tmpStrm;
48 * WriteTextStream_ (newDocXML, tmpStrm);
49 * return InputStreamFromStdIStream::New<byte>(tmpStrm).ReadAll ();
50 * \endcode
51 *
52 * \par Example Usage
53 * \code
54 * stringstream tmpStrm;
55 * WriteTextStream_ (newDocXML, tmpStrm);
56 * MyCallback myCallback;
57 * XML::SAXParse (InputStreamFromStdIStream::New<byte> (tmpStrm), myCallback);
58 * \endcode
59 *
60 * \note The lifetime of the underlying created (shared_ptr) Stream must be >= the lifetime of the argument std::istream
61 *
62 * \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>
63 * It is also up to the caller to assure no references to or calls to that istream
64 * be made from another thread. However, no data is cached in this class - it just
65 * delegates, so calls CAN be made the the underlying istream - so long as not
66 * concurrently.
67 *
68 * If you pass in eInternallySynchronized, the internal rep is internally synchronized, but you still must assure
69 * no other threads access the IStreamType object.
70 */
71 template <typename ELEMENT_TYPE, typename BASIC_ISTREAM_ELEMENT_TYPE, typename BASIC_ISTREAM_TRAITS_TYPE>
72 Ptr<ELEMENT_TYPE> New (basic_istream<BASIC_ISTREAM_ELEMENT_TYPE, BASIC_ISTREAM_TRAITS_TYPE>& originalStream)
73 requires ((same_as<ELEMENT_TYPE, byte> and same_as<BASIC_ISTREAM_ELEMENT_TYPE, char>) or
74 (same_as<ELEMENT_TYPE, Characters::Character> and same_as<BASIC_ISTREAM_ELEMENT_TYPE, wchar_t>));
75 template <typename ELEMENT_TYPE, typename BASIC_ISTREAM_ELEMENT_TYPE, typename BASIC_ISTREAM_TRAITS_TYPE>
76 Ptr<ELEMENT_TYPE> New (basic_istream<BASIC_ISTREAM_ELEMENT_TYPE, BASIC_ISTREAM_TRAITS_TYPE>& originalStream, SeekableFlag seekable)
77 requires ((same_as<ELEMENT_TYPE, byte> and same_as<BASIC_ISTREAM_ELEMENT_TYPE, char>) or
78 (same_as<ELEMENT_TYPE, Characters::Character> and same_as<BASIC_ISTREAM_ELEMENT_TYPE, wchar_t>));
79 template <typename ELEMENT_TYPE, typename BASIC_ISTREAM_ELEMENT_TYPE, typename BASIC_ISTREAM_TRAITS_TYPE>
80 Ptr<ELEMENT_TYPE> New (Execution::InternallySynchronized internallySynchronized,
81 basic_istream<BASIC_ISTREAM_ELEMENT_TYPE, BASIC_ISTREAM_TRAITS_TYPE>& originalStream)
82 requires ((same_as<ELEMENT_TYPE, byte> and same_as<BASIC_ISTREAM_ELEMENT_TYPE, char>) or
83 (same_as<ELEMENT_TYPE, Characters::Character> and same_as<BASIC_ISTREAM_ELEMENT_TYPE, wchar_t>));
84 template <typename ELEMENT_TYPE, typename BASIC_ISTREAM_ELEMENT_TYPE, typename BASIC_ISTREAM_TRAITS_TYPE>
85 Ptr<ELEMENT_TYPE> New (Execution::InternallySynchronized internallySynchronized,
86 basic_istream<BASIC_ISTREAM_ELEMENT_TYPE, BASIC_ISTREAM_TRAITS_TYPE>& originalStream, SeekableFlag seekable)
87 requires ((same_as<ELEMENT_TYPE, byte> and same_as<BASIC_ISTREAM_ELEMENT_TYPE, char>) or
88 (same_as<ELEMENT_TYPE, Characters::Character> and same_as<BASIC_ISTREAM_ELEMENT_TYPE, wchar_t>));
89
90}
91
92/*
93 ********************************************************************************
94 ***************************** Implementation Details ***************************
95 ********************************************************************************
96 */
97#include "InputStreamFromStdIStream.inl"
98
99#endif /*_Stroika_Foundation_Streams_iostream_InputStreamFromStdIStream_h_*/