Skip to content

Commit 3669d7c

Browse files
committed
column and row headers are stored in seperate vectors. Previously they were part of the data-vector. Introduced enums 'FlgColumnName' and 'FlgRowName'
1 parent b4f60dc commit 3669d7c

File tree

116 files changed

+763
-583
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+763
-583
lines changed

README.md

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,14 +595,44 @@ rapidcsv::FilterSortDocument
595595
When both filter and sorting is needed [rapidcsv::FilterSortDocument](doc/view/rapidcsv_FilterSortDocument.md). <br>
596596
Both the filter-function and sort-details are passed to [rapidcsv::FilterSortDocument](doc/view/rapidcsv_FilterSortDocument.md)
597597

598-
Refer [tests/testView001.cpp](tests/testView001.cpp) <br>
599-
```cpp
598+
Refer [tests/testView001.cpp](tests/testView001.cpp)
599+
```c++
600600
///// Filter + Sort
601601
const rapidcsv::SortParams<int, rapidcsv::e_SortOrder::DESCEND> spD(1);
602602
rapidcsv::FilterSortDocument<isFirstCellPositive, decltype(spD)> viewdoc2(doc, spD);
603603
```
604+
<br>
604605
605-
Similar to `rapidcsv::SortDocument`, multiple columns can vebew specified for sorting thru variadic-arguments.
606+
Similar to `rapidcsv::SortDocument`, multiple columns can be sorted thru variadic-arguments. Refer [tests/testViewB001.cpp](tests/testViewB001.cpp)
607+
```c++
608+
rapidcsv::Document doc(path, rapidcsv::LabelParams(rapidcsv::FlgColumnName::CN_PRESENT,
609+
rapidcsv::FlgRowName::RN_PRESENT));
610+
611+
///// Filter + Sort
612+
const rapidcsv::SortParams<int> spA(0);
613+
const rapidcsv::SortParams<int, rapidcsv::e_SortOrder::DESCEND> spD(1);
614+
rapidcsv::FilterSortDocument<isFirstCellPositive,
615+
rapidcsv::SortParams<int>,
616+
rapidcsv::SortParams<int, rapidcsv::e_SortOrder::DESCEND> > viewdoc1(doc, spA, spD);
617+
```
618+
<br>
619+
620+
If the sorted column has NaN (Not-A-Number) values, one can still sort using `converter::FailureS2Tprocess::VARIANT_NAN` template parameter. Refer [tests/testViewfNaN001.cpp](tests/testViewfNaN001.cpp)
621+
```c++
622+
template <typename T>
623+
using _ConvS2T_NAN =
624+
converter::ConvertFromStr
625+
< T,
626+
converter::S2T_Format_std_CtoT
627+
< T,
628+
converter::FailureS2Tprocess::VARIANT_NAN
629+
>
630+
>;
631+
...
632+
///// Filter + Sort
633+
const rapidcsv::SortParams<_ConvS2T_NAN<int>, rapidcsv::e_SortOrder::DESCEND> spD(0);
634+
rapidcsv::FilterSortDocument<isCellPositive, decltype(spD)> viewdoc2(doc, spD);
635+
```
606636
607637
<br>
608638
<br>
@@ -616,7 +646,8 @@ Architecture Components and Overview
616646
document.Get***<T>(...); // 1. T is 'data-type' such as int, long, float, double, ...
617647
document.Get***<C>(...); // 2. C is 'convertor-type' satisfying concept 'converter::c_S2Tconverter'
618648
// C can also be "a user defined Converter class"
619-
document.Get***<&CONV_S2T>(...); // 3. CONV_S2T is 'function-address' of signature 'R (*CONV_S2T)(const std::string&)'
649+
document.Get***<&CONV_S2T>(...); // 3. CONV_S2T is 'function-address' of signature
650+
// 'R (*CONV_S2T)(const std::string&)'.
620651
// R is either type 'T' or 'std::variant<T, std::string>'
621652
```
622653

@@ -625,7 +656,8 @@ Architecture Components and Overview
625656
document.Set***<T>(...); // 1. T is 'data-type' such as int, long, float, double, ...
626657
document.Set***<C>(...); // 2. C is 'convertor-type' satisfying concept 'converter::c_T2Sconverter'
627658
// C can also be "a user defined Converter class"
628-
document.Set***<&CONV_T2S>(...); // 3. CONV_T2S is 'function-address' of signature 'std::string (*CONV_T2S)(const R&)'
659+
document.Set***<&CONV_T2S>(...); // 3. CONV_T2S is 'function-address' of signature
660+
// 'std::string (*CONV_T2S)(const R&)'.
629661
// R is either type 'T' or 'std::variant<T, std::string>'
630662
```
631663

cmake/rapidcsv.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ macro(fetch_dependencies)
8686
include( FetchContent )
8787
FetchContent_Declare( ${CONVERTERLIB}
8888
GIT_REPOSITORY https://github.com/panchaBhuta/converter.git
89-
GIT_TAG v1.2.11) # adjust tag/branch/commit as needed
89+
GIT_TAG v1.2.12) # adjust tag/branch/commit as needed
9090
FetchContent_MakeAvailable(${CONVERTERLIB})
9191

9292
#[==================[

doc/UpstreamRepoChanges.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ void Converter<T>::ToStr(const T& pVal, std::string& pStr) const;
2020
AND
2121
void Converter<T>::ToVal(const std::string& pStr, T& pVal) const;
2222
```
23-
---
23+
24+
<br>
2425

2526
## Removed `struct ConverterParams`
2627
`struct ConverterParams`, which had several member variables to determine the run time conversion behavior has been done away with. <br> <br>
@@ -49,14 +50,33 @@ _T2S_Format_StreamAsIs_ &nbsp; , &nbsp; _T2S_Format_StreamUseClassicLocale_ &nbs
4950
<br> <br>
5051

5152
One can also provide their own implementations of _T2S_FORMAT_ or _S2T_FORMAT_. For implentation details, refer **exConv001.cpp, ex008.cpp, ex009.cpp**.
52-
<br> <br>
5353

54-
---
54+
<br>
55+
56+
5557
## Removed `class no_converter : public std::exception`
5658
For types which are not supported will generate compile-time error. This approach is better then getting a run-time exception.
5759

58-
---
59-
## Performance gains
60+
<br>
61+
62+
## Refactored constructor of `LabelParams`
63+
In the upstream repo, the labels-usage for row and column could be turned off by passing `-1`. Instead of `int` , enum's `FlgColumnName` and `FlgRowName` are passed to the constrcutor.
64+
65+
```c++
66+
enum FlgColumnName { CN_PRESENT, CN_MISSING };
67+
enum FlgRowName { RN_PRESENT, RN_MISSING };
68+
...
69+
explicit LabelParams(const FlgColumnName pColumnNameFlg = FlgColumnName::CN_PRESENT,
70+
const FlgRowName pRowNameFlg = FlgRowName::RN_MISSING)
71+
```
72+
73+
`FlgColumnName::CN_PRESENT` would imply that the column labels(headers) are available in the first row of the CSV file.
74+
`FlgRowName::RN_PRESENT` would imply that the row labels are available in the first column of the CSV file.
75+
76+
77+
<br>
78+
79+
# Performance gains
6080
Removed header `<typeinfo>` and calls to function `typeid(...)`.
6181
In template based code, calling any _RTTI_ functions such as `typeid(...)` is unnecessary, as templates are working with _types_ itself.
6282

doc/document/rapidcsv_LabelParams.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ Datastructure holding parameters controlling which row and column should be trea
55
---
66

77
```c++
8-
LabelParams (const ssize_t pColumnNameIdx = 0, const ssize_t pRowNameIdx = -1)
8+
explicit LabelParams(const FlgColumnName pColumnNameFlg = FlgColumnName::CN_PRESENT,
9+
const FlgRowName pRowNameFlg = FlgRowName::RN_MISSING)
910
```
1011
Constructor.
1112
1213
**Parameters**
13-
- `pColumnNameIdx` specifies the zero-based row index of the column labels, setting it to -1 prevents column lookup by label name, and gives access to all rows as document data. Default: 0
14-
- `pRowNameIdx` specifies the zero-based column index of the row labels, setting it to -1 prevents row lookup by label name, and gives access to all columns as document data. Default: -1
14+
- `pColumnNameFlg` specifies the zero-based row index of the column labels, setting it to _FlgColumnName::CN_MISSING_ prevents column lookup by label name, and gives access to all rows as document data. Default: _FlgColumnName::CN_PRESENT_
15+
- `pRowNameIdx` specifies the zero-based column index of the row labels, setting it to _FlgRowName::RN_MISSING_ prevents row lookup by label name, and gives access to all columns as document data. Default: _FlgRowName::RN_MISSING_
1516
1617
---
1718

examples/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ endmacro(add_example)
2121

2222

2323

24-
2524
# Examples
2625
add_example(ex001 ex001.cpp)
2726
add_example(ex002 ex002.cpp)

examples/ex002.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
int main()
77
{
8-
rapidcsv::Document doc("examples/colrowhdr.csv", rapidcsv::LabelParams(0, 0));
8+
rapidcsv::Document doc("examples/colrowhdr.csv", rapidcsv::LabelParams(rapidcsv::FlgColumnName::CN_PRESENT, rapidcsv::FlgRowName::RN_PRESENT));
99

1010
std::tuple<float, float, float, float, unsigned long, float>
1111
hlocVa = doc.GetRow<float, float, float, float, unsigned long, float>("2017-02-22");

examples/ex003.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
int main()
77
{
8-
rapidcsv::Document doc("examples/rowhdr.csv", rapidcsv::LabelParams(-1, 0));
8+
rapidcsv::Document doc("examples/rowhdr.csv", rapidcsv::LabelParams(rapidcsv::FlgColumnName::CN_MISSING, rapidcsv::FlgRowName::RN_PRESENT));
99

1010
std::tuple<float, float, float, float, unsigned long, float>
1111
hlocVa = doc.GetRow<float, float, float, float, unsigned long, float>("2017-02-22");

examples/ex004.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
int main()
77
{
8-
rapidcsv::Document doc("examples/nohdr.csv", rapidcsv::LabelParams(-1, -1));
8+
rapidcsv::Document doc("examples/nohdr.csv", rapidcsv::LabelParams(rapidcsv::FlgColumnName::CN_MISSING, rapidcsv::FlgRowName::RN_MISSING));
99

1010
std::vector<float> close = doc.GetColumn<float>(5);
1111
std::cout << "Read " << close.size() << " values." << std::endl;

examples/ex005.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
int main()
77
{
8-
rapidcsv::Document doc("examples/semi.csv", rapidcsv::LabelParams(0, 0),
8+
rapidcsv::Document doc("examples/semi.csv", rapidcsv::LabelParams(rapidcsv::FlgColumnName::CN_PRESENT, rapidcsv::FlgRowName::RN_PRESENT),
99
rapidcsv::SeparatorParams(';'));
1010

1111
std::vector<float> close = doc.GetColumn<float>("Close");

examples/ex006.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
int main()
77
{
8-
rapidcsv::Document doc("examples/colrowhdr.csv", rapidcsv::LabelParams(0, 0));
8+
rapidcsv::Document doc("examples/colrowhdr.csv", rapidcsv::LabelParams(rapidcsv::FlgColumnName::CN_PRESENT, rapidcsv::FlgRowName::RN_PRESENT));
99

1010
std::cout << doc.GetCell<std::string>("Volume", "2017-02-22") << std::endl;
1111
std::cout << doc.GetCell<int>("Volume", "2017-02-22") << std::endl;

0 commit comments

Comments
 (0)