Skip to content

Commit

Permalink
Improved Integer Handling with CSVField::get<>() (#40)
Browse files Browse the repository at this point in the history
 * Integrated Hedley library
   * Possible performance increase on older compilers due to use of `restrict`, `pure`, etc.
 * Updated Catch to latest version
   * Refactored unit tests
* Better handling of integer types with `get()`
  * `get<>()` is now supported for all signed integer types
  • Loading branch information
vincentlaucsb committed May 26, 2019
1 parent a1e1343 commit fad938f
Show file tree
Hide file tree
Showing 28 changed files with 16,083 additions and 9,360 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ If your CSV has lots of numeric values, you can also have this parser (lazily)
convert them to the proper data type. Type checking is performed on conversions
to prevent undefined behavior.
**Note:** Conversions to floating point types are not currently checked for loss of precision.
```cpp
# include "csv.hpp"
Expand All @@ -133,6 +135,7 @@ CSVReader reader("very_big_file.csv");
for (auto& row: reader) {
if (row["timestamp"].is_int()) {
// Can use get<>() with any signed integer type
row["timestamp"].get<int>();
// ..
Expand All @@ -158,9 +161,6 @@ format.delimiter('\t')
// Alternatively, we can use format.delimiter({ '\t', ',', ... })
// to tell the CSV guesser which delimiters to try out

// Alternatively, we can use format.delimiter({ '\t', ',', ... })
// to tell the CSV guesser which delimiters to try out

CSVReader reader("wierd_csv_dialect.csv", format);

for (auto& row: reader) {
Expand Down Expand Up @@ -208,16 +208,15 @@ for (auto& r: rows) {
# include ...

using namespace csv;
using vector;
using string;
using namespace std;

...

std::stringstream ss; // Can also use ifstream, etc.
stringstream ss; // Can also use ifstream, etc.
auto writer = make_csv_writer(ss);
writer << vector<string>({ "A", "B", "C" })
<< vector<string>({ "I'm", "too", "tired" })
<< vector<string>({ "to", "write", "documentation" });
<< deque<string>({ "I'm", "too", "tired" })
<< list<string>({ "to", "write", "documentation" });

...

Expand Down
20 changes: 11 additions & 9 deletions docs/source/Doxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ CSVReader reader("very_big_file.csv");
for (CSVRow& row: reader) { // Input iterator
for (CSVField& field: row) {
// By default, get<>() produces a std::string.
// A more efficient get<string_view>() is also available, where the resulting
// string_view is valid as long as the parent CSVRow is alive
// A more efficient get<string_view>() is also available, where the resulting
// string_view is valid as long as the parent CSVRow is alive
std::cout << field.get<>() << ...
}
}
Expand Down Expand Up @@ -68,6 +68,8 @@ If your CSV has lots of numeric values, you can also have this parser (lazily)
convert them to the proper data type. Type checking is performed on conversions
to prevent undefined behavior.
**Note:** Conversions to floating point types are not currently checked for loss of precision.
```cpp
# include "csv.hpp"
Expand All @@ -79,6 +81,7 @@ CSVReader reader("very_big_file.csv");
for (auto& row: reader) {
if (row["timestamp"].is_int()) {
// Can use get<>() with any signed integer type
row["timestamp"].get<int>();
// ..
Expand All @@ -98,8 +101,8 @@ using namespace csv;

CSVFormat format;
format.delimiter('\t')
.quote('~')
.header_row(2); // Header is on 3rd row (zero-indexed)
.quote('~')
.header_row(2); // Header is on 3rd row (zero-indexed)

// Alternatively, we can use format.delimiter({ '\t', ',', ... })
// to tell the CSV guesser which delimiters to try out
Expand Down Expand Up @@ -151,16 +154,15 @@ for (auto& r: rows) {
# include ...

using namespace csv;
using vector;
using string;
using namespace std;

...

std::stringstream ss; // Can also use ifstream, etc.
stringstream ss; // Can also use ifstream, etc.
auto writer = make_csv_writer(ss);
writer << vector<string>({ "A", "B", "C" })
<< vector<string>({ "I'm", "too", "tired" })
<< vector<string>({ "to", "write", "documentation" });
<< deque<string>({ "I'm", "too", "tired" })
<< list<string>({ "to", "write", "documentation" });

...

Expand Down
Loading

0 comments on commit fad938f

Please sign in to comment.