aboutsummaryrefslogtreecommitdiff
path: root/third_party/image_io/includes/image_io/base/data_line_map_builder_destination.h
blob: a6c01955cd013f8a4f0e06db51bcbc1915695ac5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef IMAGE_IO_BASE_DATA_LINE_MAP_BUILDER_DESTINATION_H_  // NOLINT
#define IMAGE_IO_BASE_DATA_LINE_MAP_BUILDER_DESTINATION_H_  // NOLINT

#include "image_io/base/data_destination.h"
#include "image_io/base/data_line_map.h"

namespace photos_editing_formats {
namespace image_io {

/// A class to build a data line map of the string implied by the transfer
/// range of a data segment before passing the transfer off to an optional
/// next data destination.
class DataLineMapBuilderDestination : public DataDestination {
 public:
  /// @param data_line_map The data line map to build.
  /// @param next_destination An optional next transfer data destination
  DataLineMapBuilderDestination(DataLineMap* data_line_map,
                                DataDestination* next_destination)
      : data_line_map_(data_line_map),
        next_destination_(next_destination),
        bytes_transferred_(0) {}
  void StartTransfer() override {
    if (next_destination_ != nullptr) {
      next_destination_->StartTransfer();
    }
  }
  void FinishTransfer() override {
    if (next_destination_ != nullptr) {
      next_destination_->FinishTransfer();
    }
  }
  TransferStatus Transfer(const DataRange& transfer_range,
                          const DataSegment& data_segment) override {
    bytes_transferred_ += transfer_range.GetLength();
    data_line_map_->FindDataLines(transfer_range, data_segment);
    return next_destination_ != nullptr
               ? next_destination_->Transfer(transfer_range, data_segment)
               : kTransferOk;
  }
  size_t GetBytesTransferred() const override { return bytes_transferred_; }

 private:
  DataLineMap* data_line_map_;
  DataDestination* next_destination_;
  size_t bytes_transferred_;
};

}  // namespace image_io
}  // namespace photos_editing_formats

#endif  // IMAGE_IO_BASE_DATA_LINE_MAP_BUILDER_DESTINATION_H_  // NOLINT