eminem
Parse Matrix Market files in C++
Loading...
Searching...
No Matches
from_gzip.hpp
Go to the documentation of this file.
1#ifndef EMINEM_FROM_GZIP_HPP
2#define EMINEM_FROM_GZIP_HPP
3
4#include <memory>
5#include <cstddef>
6
7#include "Parser.hpp"
8#include "byteme/byteme.hpp"
9
15namespace eminem {
16
20// For back-compatibility.
21// If people want to parametrize the Reader construction, they should just directly create the Parser themselves.
22typedef ParserOptions ParseGzipFileOptions;
23typedef ParserOptions ParseZlibBufferOptions;
24typedef ParserOptions ParseSomeFileOptions;
25typedef ParserOptions ParseSomeBufferOptions;
41template<typename Index_ = unsigned long long>
42auto parse_gzip_file(const char* path, const ParserOptions& options) {
43 auto reader = std::make_unique<byteme::GzipFileReader>(path, byteme::GzipFileReaderOptions());
44 return Parser<decltype(reader), Index_>(std::move(reader), options);
45}
46
59template<typename Index_ = unsigned long long>
60auto parse_zlib_buffer(const unsigned char* buffer, std::size_t len, const ParserOptions& options) {
61 auto reader = std::make_unique<byteme::ZlibBufferReader>(buffer, len, byteme::ZlibBufferReaderOptions());
62 return Parser<decltype(reader), Index_>(std::move(reader), options);
63}
64
76template<typename Index_ = unsigned long long>
77auto parse_some_file(const char* path, const ParserOptions& options) {
78 std::unique_ptr<byteme::Reader> ptr;
79 if (byteme::is_gzip(path)) {
80 ptr.reset(new byteme::GzipFileReader(path, {}));
81 } else {
82 ptr.reset(new byteme::RawFileReader(path, {}));
83 }
84 return Parser<std::unique_ptr<byteme::Reader>, Index_>(std::move(ptr), options);
85}
86
99template<typename Index_ = unsigned long long>
100auto parse_some_buffer(const unsigned char* buffer, std::size_t len, const ParserOptions& options) {
101 std::unique_ptr<byteme::Reader> ptr;
102 if (byteme::is_zlib_or_gzip(buffer, len)) {
103 ptr.reset(new byteme::ZlibBufferReader(buffer, len, {}));
104 } else {
105 ptr.reset(new byteme::RawBufferReader(buffer, len));
106 }
107 return Parser<std::unique_ptr<byteme::Reader>, Index_>(std::move(ptr), options);
108}
109
110}
111
112#endif
Parse a matrix from a Matrix Market file.
Parse a matrix from a Matrix Market file.
Definition Parser.hpp:304
bool is_zlib_or_gzip(const unsigned char *buffer, std::size_t n)
bool is_gzip(const unsigned char *buffer, std::size_t n)
Classes and methods for parsing Matrix Market files.
auto parse_some_file(const char *path, const ParserOptions &options)
Definition from_gzip.hpp:77
auto parse_gzip_file(const char *path, const ParserOptions &options)
Definition from_gzip.hpp:42
auto parse_zlib_buffer(const unsigned char *buffer, std::size_t len, const ParserOptions &options)
Definition from_gzip.hpp:60
auto parse_some_buffer(const unsigned char *buffer, std::size_t len, const ParserOptions &options)
Definition from_gzip.hpp:100
Options for the Parser constructor.
Definition Parser.hpp:32