Skip to content

Commit

Permalink
Fix pollution of csv namespace (#26)
Browse files Browse the repository at this point in the history
Moved a lot of stuff users wouldn't really be interested in to the `csv::internals` namespace
  • Loading branch information
vincentlaucsb authored Apr 28, 2019
1 parent 576ccbd commit ac4e7fc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
2 changes: 0 additions & 2 deletions include/internal/compatibility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#define SUPPRESS_UNUSED_WARNING(x) (void)x

namespace csv {
using namespace nonstd;

#if __cplusplus >= 201703L
#include <string_view>
using string_view = std::string_view;
Expand Down
49 changes: 26 additions & 23 deletions include/internal/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,32 @@
#include "csv_row.hpp"

namespace csv {
// Get operating system specific details
#if defined(_WIN32)
#include <Windows.h>
#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 <unistd.h>
const int PAGE_SIZE = getpagesize();
#else
const int PAGE_SIZE = 4096;
#endif
namespace internals {
// Get operating system specific details
#if defined(_WIN32)
#include <Windows.h>
#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 <unistd.h>
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;
Expand All @@ -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 };

Expand Down
4 changes: 2 additions & 2 deletions include/internal/csv_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion include/internal/csv_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace csv {
void feed(std::unique_ptr<char[]>&&); /**< @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();
///@}
Expand Down
2 changes: 1 addition & 1 deletion include/internal/csv_stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
5 changes: 1 addition & 4 deletions single_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<file>.*)"',
'#pragma once'
]
strip_these = [ '#include "(?P<file>.*)"', '#pragma once' ]

with open(str(file), mode='r') as infile:
for line in infile:
Expand Down

0 comments on commit ac4e7fc

Please sign in to comment.