openGPMP
Open Source Mathematics Package
Functions | Variables
datatable2.cpp File Reference
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <fcntl.h>
#include <iomanip>
#include <iostream>
#include <mutex>
#include <openGPMP/core/datatable_wip.hpp>
#include <openGPMP/core/utils.hpp>
#include <regex>
#include <string>
#include <sys/mman.h>
#include <sys/stat.h>
#include <thread>
#include <typeinfo>
#include <unistd.h>
#include <unordered_set>
#include <variant>
#include <vector>

Go to the source code of this file.

Functions

bool is_int (const std::string &str)
 
bool is_double (const std::string &str)
 
void handle_error (const char *msg)
 
const char * map_file (const char *fname, size_t &length)
 
std::string dt_to_str (gpmp::core::DataType type)
 

Variables

static gpmp::core::Logger _log_
 

Function Documentation

◆ dt_to_str()

std::string dt_to_str ( gpmp::core::DataType  type)

Definition at line 341 of file datatable2.cpp.

341  {
342  switch (type) {
344  return "int64";
346  return "long double";
348  return "std::string";
349  // TODO : Add more cases if needed
350  default:
351  return "Unknown";
352  }
353 }

References gpmp::core::dt_int64, gpmp::core::dt_ldouble, and gpmp::core::dt_str.

◆ handle_error()

void handle_error ( const char *  msg)

Definition at line 69 of file datatable2.cpp.

69  {
70  perror(msg);
71  exit(255);
72 }

Referenced by map_file().

◆ is_double()

bool is_double ( const std::string &  str)

Definition at line 65 of file datatable2.cpp.

65  {
66  return std::regex_match(str, std::regex(R"(-?\d+\.\d+)"));
67 }

◆ is_int()

bool is_int ( const std::string &  str)

Definition at line 59 of file datatable2.cpp.

59  {
60  // TODO : determine type of int based on length of largest val?
61  return std::regex_match(str, std::regex(R"(-?\d+)"));
62 }

◆ map_file()

const char* map_file ( const char *  fname,
size_t &  length 
)

Definition at line 74 of file datatable2.cpp.

74  {
75  int fd = open(fname, O_RDONLY);
76  if (fd == -1)
77  handle_error("open");
78 
79  // Obtain file size
80  struct stat sb;
81  if (fstat(fd, &sb) == -1)
82  handle_error("fstat");
83 
84  length = sb.st_size;
85 
86  const char *addr = static_cast<const char *>(
87  mmap(NULL, length, PROT_READ, MAP_PRIVATE, fd, 0u));
88  if (addr == MAP_FAILED)
89  handle_error("mmap");
90 
91  // TODO: Close fd at some point in time, call munmap(...)
92  return addr;
93 }
void handle_error(const char *msg)
Definition: datatable2.cpp:69
static GLfloat u

References handle_error(), and u.

Variable Documentation

◆ _log_

gpmp::core::Logger _log_
static

Logger class object

Definition at line 54 of file datatable2.cpp.