From ac4e7fcb80bd09e8b38fcfdcc7e8cd09b7f0e448 Mon Sep 17 00:00:00 2001 From: Vincent La Date: Sat, 27 Apr 2019 17:10:20 -0700 Subject: [PATCH] Fix pollution of csv namespace (#26) Moved a lot of stuff users wouldn't really be interested in to the `csv::internals` namespace --- include/internal/compatibility.hpp | 2 -- include/internal/constants.hpp | 49 ++++++++++++++++-------------- include/internal/csv_reader.cpp | 4 +-- include/internal/csv_reader.hpp | 2 +- include/internal/csv_stat.cpp | 2 +- single_header.py | 5 +-- 6 files changed, 31 insertions(+), 33 deletions(-) diff --git a/include/internal/compatibility.hpp b/include/internal/compatibility.hpp index e77b632a..4ff1cc05 100644 --- a/include/internal/compatibility.hpp +++ b/include/internal/compatibility.hpp @@ -4,8 +4,6 @@ #define SUPPRESS_UNUSED_WARNING(x) (void)x namespace csv { - using namespace nonstd; - #if __cplusplus >= 201703L #include using string_view = std::string_view; diff --git a/include/internal/constants.hpp b/include/internal/constants.hpp index e1898d76..33a338d6 100644 --- a/include/internal/constants.hpp +++ b/include/internal/constants.hpp @@ -5,24 +5,32 @@ #include "csv_row.hpp" namespace csv { - // Get operating system specific details - #if defined(_WIN32) - #include - #undef max - #undef min - inline int getpagesize() { - _SYSTEM_INFO sys_info = {}; - GetSystemInfo(&sys_info); - return sys_info.dwPageSize; - } - - const int PAGE_SIZE = getpagesize(); - #elif defined(__linux__) - #include - const int PAGE_SIZE = getpagesize(); - #else - const int PAGE_SIZE = 4096; - #endif + namespace internals { + // Get operating system specific details + #if defined(_WIN32) + #include + #undef max + #undef min + + inline int getpagesize() { + _SYSTEM_INFO sys_info = {}; + GetSystemInfo(&sys_info); + return sys_info.dwPageSize; + } + + const int PAGE_SIZE = getpagesize(); + #elif defined(__linux__) + #include + const int PAGE_SIZE = getpagesize(); + #else + const int PAGE_SIZE = 4096; + #endif + + /** @brief For functions that lazy load a large CSV, this determines how + * many bytes are read at a time + */ + const size_t ITERATION_CHUNK_SIZE = 10000000; // 10MB + } /** @brief Used for counting number of rows */ using RowCount = long long int; @@ -31,11 +39,6 @@ namespace csv { /** @name Global Constants */ ///@{ - /** @brief For functions that lazy load a large CSV, this determines how - * many bytes are read at a time - */ - const size_t ITERATION_CHUNK_SIZE = 10000000; // 10MB - /** @brief A dummy variable used to indicate delimiter should be guessed */ const CSVFormat GUESS_CSV = { '\0', '"', 0, {}, false, true }; diff --git a/include/internal/csv_reader.cpp b/include/internal/csv_reader.cpp index 8f338cea..393de4d7 100644 --- a/include/internal/csv_reader.cpp +++ b/include/internal/csv_reader.cpp @@ -452,7 +452,7 @@ namespace csv { std::thread worker(&CSVReader::read_csv_worker, this); for (size_t processed = 0; processed < bytes; ) { - char * result = std::fgets(line_buffer, PAGE_SIZE, this->infile); + char * result = std::fgets(line_buffer, internals::PAGE_SIZE, this->infile); if (result == NULL) break; line_buffer += std::strlen(line_buffer); @@ -506,7 +506,7 @@ namespace csv { bool CSVReader::read_row(CSVRow &row) { if (this->records.empty()) { if (!this->eof()) { - this->read_csv("", ITERATION_CHUNK_SIZE); + this->read_csv("", internals::ITERATION_CHUNK_SIZE); } else return false; // Stop reading } diff --git a/include/internal/csv_reader.hpp b/include/internal/csv_reader.hpp index c145e9c7..b93d2607 100644 --- a/include/internal/csv_reader.hpp +++ b/include/internal/csv_reader.hpp @@ -198,7 +198,7 @@ namespace csv { void feed(std::unique_ptr&&); /**< @brief Helper for read_csv_worker() */ void read_csv( const std::string& filename, - const size_t& bytes = ITERATION_CHUNK_SIZE + const size_t& bytes = internals::ITERATION_CHUNK_SIZE ); void read_csv_worker(); ///@} diff --git a/include/internal/csv_stat.cpp b/include/internal/csv_stat.cpp index f75592cc..d0036ba3 100644 --- a/include/internal/csv_stat.cpp +++ b/include/internal/csv_stat.cpp @@ -13,7 +13,7 @@ namespace csv { * methods like get_mean(), get_counts(), etc... can be used to retrieve statistics. */ while (!this->eof()) { - this->read_csv("", ITERATION_CHUNK_SIZE); + this->read_csv("", internals::ITERATION_CHUNK_SIZE); this->calc(); } diff --git a/single_header.py b/single_header.py index aed1058d..c688fa1c 100644 --- a/single_header.py +++ b/single_header.py @@ -111,10 +111,7 @@ def get_dependencies(file: Path) -> dict: ''' Strip local include statements and #pragma once declarations from header files ''' def file_strip(file: Path) -> str: new_file = '' - strip_these = [ - '#include "(?P.*)"', - '#pragma once' - ] + strip_these = [ '#include "(?P.*)"', '#pragma once' ] with open(str(file), mode='r') as infile: for line in infile: