aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/marisa-trie/marisa/grimoire/io/reader.h
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@ydb.tech>2023-11-30 13:26:22 +0300
committervitalyisaev <vitalyisaev@ydb.tech>2023-11-30 15:44:45 +0300
commit0a98fece5a9b54f16afeb3a94b3eb3105e9c3962 (patch)
tree291d72dbd7e9865399f668c84d11ed86fb190bbf /contrib/python/marisa-trie/marisa/grimoire/io/reader.h
parentcb2c8d75065e5b3c47094067cb4aa407d4813298 (diff)
downloadydb-0a98fece5a9b54f16afeb3a94b3eb3105e9c3962.tar.gz
YQ Connector:Use docker-compose in integrational tests
Diffstat (limited to 'contrib/python/marisa-trie/marisa/grimoire/io/reader.h')
-rw-r--r--contrib/python/marisa-trie/marisa/grimoire/io/reader.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/contrib/python/marisa-trie/marisa/grimoire/io/reader.h b/contrib/python/marisa-trie/marisa/grimoire/io/reader.h
new file mode 100644
index 0000000000..fc1ba5eea7
--- /dev/null
+++ b/contrib/python/marisa-trie/marisa/grimoire/io/reader.h
@@ -0,0 +1,67 @@
+#pragma once
+#ifndef MARISA_GRIMOIRE_IO_READER_H_
+#define MARISA_GRIMOIRE_IO_READER_H_
+
+#include <cstdio>
+#include <iostream>
+
+#include "../../base.h"
+
+namespace marisa {
+namespace grimoire {
+namespace io {
+
+class Reader {
+ public:
+ Reader();
+ ~Reader();
+
+ void open(const char *filename);
+ void open(std::FILE *file);
+ void open(int fd);
+ void open(std::istream &stream);
+
+ template <typename T>
+ void read(T *obj) {
+ MARISA_THROW_IF(obj == NULL, MARISA_NULL_ERROR);
+ read_data(obj, sizeof(T));
+ }
+
+ template <typename T>
+ void read(T *objs, std::size_t num_objs) {
+ MARISA_THROW_IF((objs == NULL) && (num_objs != 0), MARISA_NULL_ERROR);
+ MARISA_THROW_IF(num_objs > (MARISA_SIZE_MAX / sizeof(T)),
+ MARISA_SIZE_ERROR);
+ read_data(objs, sizeof(T) * num_objs);
+ }
+
+ void seek(std::size_t size);
+
+ bool is_open() const;
+
+ void clear();
+ void swap(Reader &rhs);
+
+ private:
+ std::FILE *file_;
+ int fd_;
+ std::istream *stream_;
+ bool needs_fclose_;
+
+ void open_(const char *filename);
+ void open_(std::FILE *file);
+ void open_(int fd);
+ void open_(std::istream &stream);
+
+ void read_data(void *buf, std::size_t size);
+
+ // Disallows copy and assignment.
+ Reader(const Reader &);
+ Reader &operator=(const Reader &);
+};
+
+} // namespace io
+} // namespace grimoire
+} // namespace marisa
+
+#endif // MARISA_GRIMOIRE_IO_READER_H_