casacore
Loading...
Searching...
No Matches
ShapesFileWriter.h
Go to the documentation of this file.
1#ifndef CASACORE_SHAPES_FILE_WRITER_H_
2#define CASACORE_SHAPES_FILE_WRITER_H_
3
4#include <fstream>
5
6#include <casacore/casa/Arrays/IPosition.h>
7
8#include "Deflate.h"
9
10namespace casacore {
11
13 public:
14 ShapesFileWriter(const std::string& filename)
15 : compressor_(9), file_(filename) {}
16
18 if (!buffer_.empty()) Flush();
19 }
20
21 void Write(const IPosition& position) {
22 buffer_.emplace_back(position.size());
23 if (buffer_.size() == kMaxBufferSize) Flush();
24 for (ssize_t value : position) {
25 buffer_.emplace_back(value);
26 if (buffer_.size() == kMaxBufferSize) Flush();
27 }
28 }
29
30 private:
31 void Flush() {
32 const uint32_t uncompressed_size = buffer_.size() * sizeof(uint64_t);
33 compressed_buffer_.resize(compressor_.CompressBound(uncompressed_size));
34 std::span input(reinterpret_cast<const std::byte*>(buffer_.data()),
35 uncompressed_size);
36 const uint32_t compressed_size =
37 compressor_.Compress(input, compressed_buffer_);
38 file_.write(reinterpret_cast<const char*>(&uncompressed_size),
39 sizeof(uint32_t));
40 file_.write(reinterpret_cast<const char*>(&compressed_size),
41 sizeof(uint32_t));
42 file_.write(reinterpret_cast<const char*>(compressed_buffer_.data()),
43 compressed_size);
44 buffer_.clear();
45 }
46
47 static constexpr size_t kMaxBufferSize = 1024 * 10 * 128;
48 std::vector<uint64_t> buffer_;
49 std::vector<std::byte> compressed_buffer_;
51 std::ofstream file_;
52};
53
54} // namespace casacore
55
56#endif
size_t size() const
Definition IPosition.h:570
static constexpr size_t kMaxBufferSize
deflate::Compressor compressor_
std::vector< uint64_t > buffer_
void Write(const IPosition &position)
ShapesFileWriter(const std::string &filename)
std::vector< std::byte > compressed_buffer_
this file contains all the compiler specific defines
Definition mainpage.dox:28
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:368