casacore
Loading...
Searching...
No Matches
ShapesFileReader.h
Go to the documentation of this file.
1#ifndef CASACORE_SHAPES_FILE_READER_H_
2#define CASACORE_SHAPES_FILE_READER_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 ShapesFileReader(const std::string& filename) : buffer_position_(buffer_.end()), file_(filename) {
15 if (file_.fail()) throw std::runtime_error("Error opening shapes file");
16 }
17
19 if (buffer_position_ == buffer_.end()) FillCache();
20 size_t size = *buffer_position_;
22 IPosition result(size);
23 for (ssize_t& value : result) {
24 if (buffer_position_ == buffer_.end()) FillCache();
27 }
28 return result;
29 }
30
31 bool Eof() const { return file_.eof(); }
32
33 private:
34 void FillCache() {
35 uint32_t uncompressed_size;
36 if (!file_.eof()) {
37 file_.read(reinterpret_cast<char*>(&uncompressed_size), sizeof(uint32_t));
38 }
39 if (file_.eof()) {
40 buffer_.assign(1, 0);
41 } else {
42 uint32_t compressed_size;
43 file_.read(reinterpret_cast<char*>(&compressed_size), sizeof(uint32_t));
44 compressed_buffer_.resize(compressed_size);
45 file_.read(reinterpret_cast<char*>(compressed_buffer_.data()), compressed_size);
46 buffer_.resize(uncompressed_size / sizeof(uint64_t));
47 std::span output(reinterpret_cast<std::byte*>(buffer_.data()), uncompressed_size);
48 decompressor_.Decompress(compressed_buffer_, output);
49 if (file_.fail()) throw std::runtime_error("Error reading from shapes file");
50 }
51 buffer_position_ = buffer_.begin();
52 }
53
54 std::vector<uint64_t> buffer_;
55 std::vector<uint64_t>::const_iterator buffer_position_;
56 std::vector<std::byte> compressed_buffer_;
58 std::ifstream file_;
59};
60
61} // namespace casacore
62
63#endif
std::vector< uint64_t > buffer_
std::vector< uint64_t >::const_iterator buffer_position_
ShapesFileReader(const std::string &filename)
deflate::Decompressor decompressor_
std::vector< std::byte > compressed_buffer_
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
size_t size() const
Definition Block.h:566
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360
iterator end()
Definition Block.h:601