Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Foundation/DataExchange/Compression/Common.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_DataExchange_Compression_Common_h_
5#define _Stroika_Foundation_DataExchange_Compression_Common_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
11
12/**
13 * \file
14 */
15
17
18 using namespace Streams;
19 using Memory::BLOB;
20
21 /**
22 */
23 struct Stats {
24 /**
25 * \brief compressed size / src data size
26 *
27 * 0 is complete compression, and 1.0 is same size as original (can possibly be > 1.0)
28 */
29 optional<float> fCompression;
30 };
31
32 /**
33 * API NOT internally synchronized - use one at a time
34 *
35 * Reason Transform API not re-entrant is so you can optionally accumulate state, and return it only at the end.
36 * Would need to hook that state into Stream - or into instance of compressor - and that's intrinsically non-re-entrant.
37 *
38 * Could have done API so that inputStream was passed into New(). Didn't see any strong reason one way or the other.
39 * Could have named 'Transform' operator()() or used std::function - but again - no strong reasons one way or the other.
40 *
41 * \note - this API properly respects Stream 'blocking' - so if its upstream 'src' is not at EOF, attempts to read the
42 * result input stream may block or throw, or return nullopt (depending on which input stream api is called on the
43 * transformed stream).
44 */
45 struct IRep {
46 virtual ~IRep () = default;
47 /**
48 * \pre not ongoing transform on this instance.
49 * If re-used, last transform must be completed, meaning EOF returned, or exception thrown.
50 */
52 /**
53 * return null (depends on implementation) or stats about current ongoing or last completed transformation.
54 */
55 virtual optional<Stats> GetStats () const = 0;
56 };
57
58 /**
59 */
60 struct Ptr : shared_ptr<IRep> {
61 Ptr () = default;
62 Ptr (const Ptr&) = default;
63 Ptr (Ptr&&) noexcept = default;
64 Ptr (const shared_ptr<IRep>& s);
65 Ptr (shared_ptr<IRep>&& s) noexcept;
66
67 Ptr& operator= (const Ptr&) = default;
68 Ptr& operator= (Ptr&&) = default;
69
70 /**
71 */
72 nonvirtual InputStream::Ptr<byte> Transform (const InputStream::Ptr<byte>& src);
73 nonvirtual BLOB Transform (const BLOB& src);
74
75 /**
76 */
77 nonvirtual optional<Stats> GetStats () const;
78 };
79
80 namespace Compress {
81 /**
82 */
83 struct Options {
84 /**
85 * 0 is least, and 1.0 is most compression/highest compression
86 */
87 optional<float> fCompressionLevel;
88 };
89 }
90 namespace Decompress {
91 /**
92 */
93 struct Options {};
94 }
95
96}
97
98/*
99 ********************************************************************************
100 ***************************** Implementation Details ***************************
101 ********************************************************************************
102 */
103#include "Common.inl"
104
105#endif /*_Stroika_Foundation_DataExchange_Compression_Common_h_*/
InputStream<>::Ptr is Smart pointer (with abstract Rep) class defining the interface to reading from ...
virtual InputStream::Ptr< byte > Transform(const InputStream::Ptr< byte > &src)=0
virtual optional< Stats > GetStats() const =0