5#ifndef RADARELAB_UTILS_H
6#define RADARELAB_UTILS_H
24 log4c_category_t* logging_category;
31 File(log4c_category_t* logging_category);
32 File(
const File&) =
delete;
36 File& operator=(
const File*) =
delete;
43 bool open_from_env(
const char* varname,
const char* mode,
const char* desc=
nullptr);
50 bool open(
const std::string& fname,
const char* mode,
const char* desc=
nullptr);
52 const char* name()
const {
return fname.c_str(); }
53 const char* desc()
const {
return fdesc.c_str(); }
56 operator FILE*() {
return fd; }
62 operator bool()
const {
return fd; }
71 bool fread(
void* buf,
size_t size);
73 void fseek(
size_t seek_par,
int origin);
78 void read_lines(std::function<
void (
char*,
size_t)> line_cb);
84void str_split(
char* str,
const char* sep, std::function<
void (
const char* tok)> val_cb);
90const char*
getenv_default(
const char* envname,
const char* default_value);
100FILE*
fopen_checked(
const char* fname,
const char* mode,
const char* description=0);
bool open_from_env(const char *varname, const char *mode, const char *desc=nullptr)
Opens a file taking its name from the environment variable envname.
void read_lines(std::function< void(char *, size_t)> line_cb)
Read the file line by line, calling line_cb on each line read.
bool open(const std::string &fname, const char *mode, const char *desc=nullptr)
Opens a file by its pathname.
bool fread(void *buf, size_t size)
Performs a fread on the file, throwing an exception if anything goes wrong.
FILE * fopen_checked(const char *fname, const char *mode, const char *description)
A wrapper of fopen that throws an exception if it cannot open the file.
void str_split(char *str, const char *sep, std::function< void(const char *tok)> val_cb)
Split a string in tokens, skipping the given separator characters.
const char * getenv_default(const char *envname, const char *default_value)
A wrapper of getenv, that returns 'default_value' if the given environment name is not defined.