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)
15 : buffer_position_(buffer_.end()), file_(filename) {
16 if (file_.fail()) throw std::runtime_error("Error opening shapes file");
17 }
18
20 if (buffer_position_ == buffer_.end()) FillCache();
21 size_t size = *buffer_position_;
23 IPosition result(size);
24 for (ssize_t& value : result) {
25 if (buffer_position_ == buffer_.end()) FillCache();
28 }
29 return result;
30 }
31
32 bool Eof() const { return file_.eof(); }
33
34 private:
35 void FillCache() {
36 uint32_t uncompressed_size;
37 if (!file_.eof()) {
38 file_.read(reinterpret_cast<char*>(&uncompressed_size), sizeof(uint32_t));
39 }
40 if (file_.eof()) {
41 buffer_.assign(1, 0);
42 } else {
43 uint32_t compressed_size;
44 file_.read(reinterpret_cast<char*>(&compressed_size), sizeof(uint32_t));
45 compressed_buffer_.resize(compressed_size);
46 file_.read(reinterpret_cast<char*>(compressed_buffer_.data()),
47 compressed_size);
48 buffer_.resize(uncompressed_size / sizeof(uint64_t));
49 std::span output(reinterpret_cast<std::byte*>(buffer_.data()),
50 uncompressed_size);
51 decompressor_.Decompress(compressed_buffer_, output);
52 if (file_.fail())
53 throw std::runtime_error("Error reading from shapes file");
54 }
55 buffer_position_ = buffer_.begin();
56 }
57
58 std::vector<uint64_t> buffer_;
59 std::vector<uint64_t>::const_iterator buffer_position_;
60 std::vector<std::byte> compressed_buffer_;
62 std::ifstream file_;
63};
64
65} // namespace casacore
66
67#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_
this file contains all the compiler specific defines
Definition mainpage.dox:28
uInt size() const
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:368