Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
OutputStreamFromStdOStream.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_OutputStreamFromStdOStream_h_
5#define _Stroika_Foundation_Streams_iostream_OutputStreamFromStdOStream_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <ostream>
10
11#include "Stroika/Foundation/Common/Common.h"
13
14/**
15 * \file
16 *
17 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
18 *
19 * TODO:
20 * @todo http://stroika-bugs.sophists.com/browse/STK-606 - Implement StdIStreamFromInputStream and StdOStreamFromOutputStream classes
21 */
22
23namespace Stroika::Foundation::Streams::iostream::OutputStreamFromStdOStream {
24
25 template <typename ELEMENT_TYPE>
27
28 /**
29 * OutputStreamFromStdOStream wraps an argument std::ostream or std::wostream or std::basic_ostream<> as a Stroika OutputStream object
30 *
31 * \note OutputStreamFromStdOStream ::Close () does not call close on the owned basic_ostream, because there is no such stdC++ method (though filestream has one)
32 *
33 * Default seekability should be determined automatically, but for now, I cannot figure out how...
34 *
35 * \par Example Usage
36 * \code
37 * stringstream s;
38 * OutputStreamFromStdOStream<byte>::Ptr so = OutputStreamFromStdOStream<byte>::New (s);
39 * const char kData_[] = "ddasdf3294234";
40 * so.Write (reinterpret_cast<const byte*> (std::begin (kData_)), reinterpret_cast<const byte*> (std::begin (kData_)) + strlen (kData_));
41 * EXPECT_TRUE (s.str () == kData_);
42 * \endcode
43 *
44 * \note The lifetime of the underlying created (shared_ptr) Stream must be <= the lifetime of the argument std::ostream
45 *
46 * \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>
47 * It is also up to the caller to assure no references to or calls to that ostream
48 * be made from another thread. However, no data is cached in this class - it just
49 * delegates, so calls CAN be made the the underlying ostream - so long as not
50 * concurrently.
51 *
52 * If you pass in eInternallySynchronized, the internal rep is internally synchronized, but you still must assure
53 * no other threads access the OStreamType object.
54 */
55 template <typename ELEMENT_TYPE, typename BASIC_OSTREAM_ELEMENT_TYPE, typename BASIC_OSTREAM_TRAITS_TYPE>
56 Ptr<ELEMENT_TYPE> New (basic_ostream<BASIC_OSTREAM_ELEMENT_TYPE, BASIC_OSTREAM_TRAITS_TYPE>& originalStream)
57 requires ((same_as<ELEMENT_TYPE, byte> and same_as<BASIC_OSTREAM_ELEMENT_TYPE, char>) or
58 (same_as<ELEMENT_TYPE, Characters::Character> and same_as<BASIC_OSTREAM_ELEMENT_TYPE, wchar_t>));
59 template <typename ELEMENT_TYPE, typename BASIC_OSTREAM_ELEMENT_TYPE, typename BASIC_OSTREAM_TRAITS_TYPE>
60 Ptr<ELEMENT_TYPE> New (Execution::InternallySynchronized internallySynchronized,
61 basic_ostream<BASIC_OSTREAM_ELEMENT_TYPE, BASIC_OSTREAM_TRAITS_TYPE>& originalStream)
62 requires ((same_as<ELEMENT_TYPE, byte> and same_as<BASIC_OSTREAM_ELEMENT_TYPE, char>) or
63 (same_as<ELEMENT_TYPE, Characters::Character> and same_as<BASIC_OSTREAM_ELEMENT_TYPE, wchar_t>));
64
65}
66
67/*
68 ********************************************************************************
69 ***************************** Implementation Details ***************************
70 ********************************************************************************
71 */
72
73#include "OutputStreamFromStdOStream.inl"
74
75#endif /*_Stroika_Foundation_Streams_iostream_OutputStreamFromStdOStream_h_*/
OutputStream<>::Ptr is Smart pointer to a stream-based sink of data.