| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | ||
| 3 | // Copyright (c) 2025 Mohammad Nejati | ||
| 4 | // | ||
| 5 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
| 6 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
| 7 | // | ||
| 8 | // Official repository: https://github.com/cppalliance/capy | ||
| 9 | // | ||
| 10 | |||
| 11 | #include <boost/capy/polystore.hpp> | ||
| 12 | #include <boost/capy/zlib/deflate.hpp> | ||
| 13 | |||
| 14 | #include "stream_cast.hpp" | ||
| 15 | |||
| 16 | #include <boost/core/detail/static_assert.hpp> | ||
| 17 | |||
| 18 | #include <zlib.h> | ||
| 19 | |||
| 20 | namespace boost { | ||
| 21 | namespace capy { | ||
| 22 | namespace zlib { | ||
| 23 | |||
| 24 | BOOST_CORE_STATIC_ASSERT(sizeof(stream) == sizeof(z_stream_s)); | ||
| 25 | BOOST_CORE_STATIC_ASSERT(is_layout_identical<stream, z_stream_s>()); | ||
| 26 | |||
| 27 | //------------------------------------------------ | ||
| 28 | |||
| 29 | class deflate_service_impl | ||
| 30 | : public deflate_service | ||
| 31 | { | ||
| 32 | public: | ||
| 33 | using key_type = deflate_service; | ||
| 34 | |||
| 35 | explicit | ||
| 36 | 1 | deflate_service_impl( | |
| 37 | capy::polystore&) noexcept | ||
| 38 | 1 | { | |
| 39 | 1 | } | |
| 40 | |||
| 41 | 1 | ~deflate_service_impl() | |
| 42 | 1 | { | |
| 43 | 1 | } | |
| 44 | |||
| 45 | char const* | ||
| 46 | ✗ | version() const noexcept override | |
| 47 | { | ||
| 48 | ✗ | return zlibVersion(); | |
| 49 | } | ||
| 50 | |||
| 51 | int | ||
| 52 | ✗ | init( | |
| 53 | stream& st, | ||
| 54 | int level) const override | ||
| 55 | { | ||
| 56 | ✗ | stream_cast sc(st); | |
| 57 | ✗ | return deflateInit(sc.get(), level); | |
| 58 | } | ||
| 59 | |||
| 60 | int | ||
| 61 | ✗ | init2( | |
| 62 | stream& st, | ||
| 63 | int level, | ||
| 64 | int method, | ||
| 65 | int windowBits, | ||
| 66 | int memLevel, | ||
| 67 | int strategy) const override | ||
| 68 | { | ||
| 69 | ✗ | stream_cast sc(st); | |
| 70 | ✗ | return deflateInit2(sc.get(), | |
| 71 | level, method, windowBits, | ||
| 72 | memLevel, strategy); | ||
| 73 | } | ||
| 74 | |||
| 75 | int | ||
| 76 | ✗ | set_dict( | |
| 77 | stream& st, | ||
| 78 | unsigned char const* dict, | ||
| 79 | unsigned len) const override | ||
| 80 | { | ||
| 81 | ✗ | stream_cast sc(st); | |
| 82 | ✗ | return deflateSetDictionary(sc.get(), dict, len); | |
| 83 | } | ||
| 84 | |||
| 85 | int | ||
| 86 | ✗ | get_dict( | |
| 87 | stream& st, | ||
| 88 | unsigned char* dest, | ||
| 89 | unsigned* len) const override | ||
| 90 | { | ||
| 91 | ✗ | stream_cast sc(st); | |
| 92 | ✗ | return deflateGetDictionary(sc.get(), dest, len); | |
| 93 | } | ||
| 94 | |||
| 95 | int | ||
| 96 | ✗ | dup( | |
| 97 | stream& dest, | ||
| 98 | stream& src) const override | ||
| 99 | { | ||
| 100 | ✗ | stream_cast sc0(dest); | |
| 101 | ✗ | stream_cast sc1(src); | |
| 102 | ✗ | return deflateCopy(sc0.get(), sc1.get()); | |
| 103 | } | ||
| 104 | |||
| 105 | int | ||
| 106 | ✗ | deflate( | |
| 107 | stream& st, | ||
| 108 | int flush) const override | ||
| 109 | { | ||
| 110 | ✗ | stream_cast sc(st); | |
| 111 | ✗ | return ::deflate(sc.get(), flush); | |
| 112 | } | ||
| 113 | |||
| 114 | int | ||
| 115 | ✗ | deflate_end( | |
| 116 | stream& st) const override | ||
| 117 | { | ||
| 118 | ✗ | stream_cast sc(st); | |
| 119 | ✗ | return deflateEnd(sc.get()); | |
| 120 | } | ||
| 121 | |||
| 122 | int | ||
| 123 | ✗ | reset( | |
| 124 | stream& st) const override | ||
| 125 | { | ||
| 126 | ✗ | stream_cast sc(st); | |
| 127 | ✗ | return deflateReset(sc.get()); | |
| 128 | } | ||
| 129 | |||
| 130 | int | ||
| 131 | ✗ | params( | |
| 132 | stream& st, | ||
| 133 | int level, | ||
| 134 | int strategy) const override | ||
| 135 | { | ||
| 136 | ✗ | stream_cast sc(st); | |
| 137 | ✗ | return deflateParams(sc.get(), level, strategy); | |
| 138 | } | ||
| 139 | |||
| 140 | std::size_t | ||
| 141 | ✗ | bound( | |
| 142 | stream& st, | ||
| 143 | unsigned long sourceLen) const override | ||
| 144 | { | ||
| 145 | ✗ | stream_cast sc(st); | |
| 146 | ✗ | return deflateBound(sc.get(), sourceLen); | |
| 147 | } | ||
| 148 | |||
| 149 | int | ||
| 150 | ✗ | pending( | |
| 151 | stream& st, | ||
| 152 | unsigned* pending, | ||
| 153 | int* bits) const override | ||
| 154 | { | ||
| 155 | ✗ | stream_cast sc(st); | |
| 156 | ✗ | return deflatePending(sc.get(), pending, bits); | |
| 157 | } | ||
| 158 | |||
| 159 | int | ||
| 160 | ✗ | prime( | |
| 161 | stream& st, | ||
| 162 | int bits, | ||
| 163 | int value) const override | ||
| 164 | { | ||
| 165 | ✗ | stream_cast sc(st); | |
| 166 | ✗ | return deflatePrime(sc.get(), bits, value); | |
| 167 | } | ||
| 168 | |||
| 169 | int | ||
| 170 | ✗ | set_header( | |
| 171 | stream& st, | ||
| 172 | void* header) const override | ||
| 173 | { | ||
| 174 | ✗ | stream_cast sc(st); | |
| 175 | ✗ | return deflateSetHeader(sc.get(), | |
| 176 | ✗ | reinterpret_cast<gz_header*>(header)); | |
| 177 | } | ||
| 178 | }; | ||
| 179 | |||
| 180 | deflate_service& | ||
| 181 | 1 | install_deflate_service(polystore& ctx) | |
| 182 | { | ||
| 183 | 1 | return ctx.emplace<deflate_service_impl>(ctx); | |
| 184 | } | ||
| 185 | |||
| 186 | } // zlib | ||
| 187 | } // capy | ||
| 188 | } // boost | ||
| 189 |