Program Listing for File input_reader.h
↰ Return to documentation for file (include/input_reader.h
)
#pragma once
#define DOMAIN_NAME_MAX_SIZE 256
#include <liburing.h>
#include <stdlib.h>
#include <array>
#include <memory>
#include <string>
template <size_t val>
struct IsPowerOfTwoStatic {
static const bool res = !(val & 0x01) && IsPowerOfTwoStatic<(val >> 1)>::res;
};
// Skip documentation of template specialisations
template <>
struct IsPowerOfTwoStatic<1> {
static const bool res = true;
};
template <>
struct IsPowerOfTwoStatic<0> {
static const bool res = false;
};
enum struct ReadDomainResult {
Success,
NotAvailable,
FileEnd,
NotValid
};
enum struct GetBufferResult {
Success,
NotAvailable
};
struct DomainInputInfo {
char* buf;
size_t len;
};
class InputReader {
public:
InputReader(FILE* read_file);
InputReader(FILE* read_file, const size_t block_size);
ReadDomainResult GetDomain(DomainInputInfo& domain_info);
~InputReader();
private:
static_assert(IsPowerOfTwoStatic<DOMAIN_NAME_MAX_SIZE>::res,
"DOMAIN_NAME_MAX_SIZE must be a power of two");
GetBufferResult RefreshBuffers();
const size_t block_size;
char* process_buf_curr_ptr;
char* process_buf_end_ptr;
char* simd_buf_curr_ptr;
char* simd_buf_end_ptr;
unsigned long long simd_invalid_chars;
unsigned long long simd_newlines;
const FILE* read_file;
int read_file_fd;
size_t offset_tracker;
io_uring ring;
std::unique_ptr<char[], decltype(&::free)> process_buf;
std::unique_ptr<char[], decltype(&::free)> read_buf;
char* domain_begin_ptr;
bool current_domain_valid;
std::array<char, DOMAIN_NAME_MAX_SIZE> curr_domain;
int curr_domain_written;
};