RawSpeed
fast raw decoding library
Loading...
Searching...
No Matches
PartitioningOutputIterator.h
Go to the documentation of this file.
1/*
2 RawSpeed - RAW file decoder.
3
4 Copyright (C) 2024 Roman Lebedev
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#pragma once
22
23#include "adt/Bit.h"
24#include <concepts>
25#include <cstddef>
26#include <cstdint>
27#include <iterator>
28#include <type_traits>
29
30namespace rawspeed {
31
32template <typename UnderlyingOutputIterator,
33 typename PartType =
34 typename UnderlyingOutputIterator::container_type::value_type>
35 requires(std::output_iterator<UnderlyingOutputIterator, uint8_t> &&
36 std::unsigned_integral<PartType>)
38 UnderlyingOutputIterator it;
39
40public:
41 using iterator_concept = std::output_iterator_tag;
42 using value_type = void;
43 using difference_type = ptrdiff_t;
44 using pointer = void;
45 using reference = void;
46
48
49 template <typename U>
50 requires std::same_as<UnderlyingOutputIterator, std::remove_reference_t<U>>
51 explicit PartitioningOutputIterator(U&& it_) : it(std::forward<U>(it_)) {}
52
53 [[nodiscard]] PartitioningOutputIterator& operator*() { return *this; }
54
56
57 // NOLINTNEXTLINE(cert-dcl21-cpp)
59
60 template <typename U>
61 requires(std::unsigned_integral<U> && sizeof(U) >= sizeof(PartType) &&
62 sizeof(U) % sizeof(PartType) == 0)
63 PartitioningOutputIterator& operator=(U coalesced) {
64 // NOLINTNEXTLINE(bugprone-sizeof-expression)
65 constexpr int NumParts = sizeof(U) / sizeof(PartType);
66 for (int i = 0; i != NumParts; ++i) {
67 const auto part = static_cast<PartType>(coalesced);
68 if constexpr (NumParts != 1)
69 coalesced >>= bitwidth<PartType>();
70 *it = part;
71 ++it;
72 }
73 return *this;
74 }
75};
76
77// CTAD deduction guide
78template <typename T>
80
81} // namespace rawspeed
PartitioningOutputIterator operator++(int)
throw T(buf.data())
constexpr unsigned RAWSPEED_READNONE bitwidth(T unused={})
Definition Bit.h:43
PartitioningOutputIterator(T) -> PartitioningOutputIterator< T >