Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
InternallySynchronizedInputOutputStream.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Streams_InternallySynchronizedInputOutputStream_h_
5#define _Stroika_Foundation_Streams_InternallySynchronizedInputOutputStream_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include <mutex>
10
12
13/*
14 * \file
15 *
16 * \note Code-Status: <a href="Code-Status.md#Alpha">Alpha</a>
17 */
18
19namespace Stroika::Foundation::Streams::InternallySynchronizedInputOutputStream {
20
21 using InputOutputStream::Ptr;
22
23 /**
24 */
25 struct DefaultOptions {
26 /**
27 * Default to using recursive mutex since this is the safest, most flexible option, and callers can specify explcitly if its safe todo another way (e.g. mutex)
28 */
29 using MutexType = recursive_mutex;
30 };
31
32 /**
33 * Helper to wrap an existing stream in synchronized wrapper - like @see Execution::Synchronized - except this wrape
34 * the underlying pointed to stream, not the external smart-pointer wrapper.
35 *
36 * \par Example Usage
37 * \code
38 * Streams::InputOutputStream::Ptr<byte> syncStream = Streams::InternallySynchronizedInputOutputStream::New<UNSYNC_REP> (otherInputOutputStreamToBeSharedAcrossThread);
39 * \endcode
40 *
41 * \note BASE_REP overload more efficient, and ::Ptr overload more flexible/simple to use.
42 *
43 * \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety-For-Envelope-Letter-Internally-Synchronized">C++-Standard-Thread-Safety-For-Envelope-Letter-Internally-Synchronized</a>
44 */
45 template <typename BASE_REP_TYPE, typename OPTIONS = DefaultOptions, typename... ARGS>
46 Ptr<typename BASE_REP_TYPE::ElementType> New (const OPTIONS& o = {}, ARGS&&... args);
47 template <typename ELEMENT_TYPE, typename OPTIONS = DefaultOptions>
48 Ptr<ELEMENT_TYPE> New (const OPTIONS& o, const InputOutputStream::Ptr<ELEMENT_TYPE>& stream2Wrap);
49
50}
51
52/*
53 ********************************************************************************
54 ***************************** Implementation Details ***************************
55 ********************************************************************************
56 */
57#include "InternallySynchronizedInputOutputStream.inl"
58
59#endif /*_Stroika_Foundation_Streams_InternallySynchronizedInputOutputStream_h_*/