Skip to content

Commit

Permalink
tuple-conversion : parameter start idx for vector<string>, now idx is…
Browse files Browse the repository at this point in the history
… alwas zero based
  • Loading branch information
panchaBhuta committed Dec 12, 2023
1 parent c44938f commit 1c7b838
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 22 deletions.
8 changes: 4 additions & 4 deletions cmake/converter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,10 @@ macro(converter_build)
endif()
#message(STATUS "_DEBUG_LOG=${_DEBUG_LOG}")
# for _DEBUG_LOG can't use generator-expression as its computed during build-stage, but we need it during config-stage
option(CONVERTER_DEBUG_LOG "Set to ON for debugging logs" ${_DEBUG_LOG})
message(STATUS "CONVERTER_DEBUG_LOG=${CONVERTER_DEBUG_LOG}")
option(OPTION_CONVERTER_DEBUG_LOG "Set to ON for debugging logs" ${_DEBUG_LOG})
message(STATUS "OPTION_CONVERTER_DEBUG_LOG=${OPTION_CONVERTER_DEBUG_LOG}")
#[===========[ donot use generator-expressions in option() functions
# option(CONVERTER_DEBUG_LOG "Set to ON for debugging logs" "$<AND:$<CONFIG:Debug>,$<CONVERTER_STANDALONE_PROJECT>>")
# option(OPTION_CONVERTER_DEBUG_LOG "Set to ON for debugging logs" "$<AND:$<CONFIG:Debug>,$<CONVERTER_STANDALONE_PROJECT>>")
#]===========]

#[==================================================================================[
Expand Down Expand Up @@ -475,7 +475,7 @@ macro(converter_build)
target_compile_definitions(converter INTERFACE
$<$<CONFIG:Debug>:DEBUG_BUILD>
$<$<CONFIG:Release>:RELEASE_BUILD>
ENABLE_CONVERTER_DEBUG_LOG=$<BOOL:${CONVERTER_DEBUG_LOG}>)
FLAG_CONVERTER_DEBUG_LOG=$<BOOL:${OPTION_CONVERTER_DEBUG_LOG}>)
#[==================================================================================[
# refer https://cmake.org/cmake/help/v3.27/manual/cmake-generator-expressions.7.html#genex:COMPILE_LANG_AND_ID
# This specifies the use of different compile definitions based on both the compiler id and compilation language.
Expand Down
4 changes: 0 additions & 4 deletions doc/converter/converter_Tuple_helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ Converts variable holding 'tuple' value to string. The output string has the for
```c++
template <c_S2Tconverter ... S2Tconv>
inline void GetTuple(const std::vector<std::string>& dataVec,
size_t colIdx,
std::tuple<typename S2Tconv::return_type ...>& dataTuple)
```
populate a tuple from a vector of string.
Expand All @@ -75,7 +74,6 @@ populate a tuple from a vector of string.
**Parameters**
- `dataVec` vector of string, having string representation of numeric values.
- `colIdx` start id of dataVec in case vector starts with the column-name.
- `dataTuple` values stored in the tuple after performing string-to-value conversion.
---
Expand All @@ -87,7 +85,6 @@ populate a tuple from a vector of string.
```c++
template <c_T2Sconverter ... T2Sconv>
inline void SetTuple(const std::tuple<typename T2Sconv::input_type ...>& dataTuple,
size_t colIdx,
std::vector<std::string>& dataVec)
```

Expand All @@ -98,5 +95,4 @@ populate a vector of string from a tuple.

**Parameters**
- `dataTuple` values stored in the tuple after performing string-to-value conversion.
- `colIdx` start id of dataVec in case vector starts with the column-name.
- `dataVec` vector of string, having string representation of numeric values.
2 changes: 1 addition & 1 deletion include/converter/_convertDate.h
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ namespace converter

if (oss.fail() || oss.bad()) // || oss.eof())
{
#if ENABLE_CONVERTER_DEBUG_LOG == 1
#if FLAG_CONVERTER_DEBUG_LOG == 1
std::ostringstream eoss;
eoss << _errMsg << " ::: ";
try {
Expand Down
2 changes: 1 addition & 1 deletion include/converter/_convertT2S.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ namespace converter
oss << val;
if (oss.fail() || oss.bad()) // || oss.eof())
{
#if ENABLE_CONVERTER_DEBUG_LOG == 1
#if FLAG_CONVERTER_DEBUG_LOG == 1
std::ostringstream eoss;
try {
eoss << "val='" << val << "'";
Expand Down
12 changes: 4 additions & 8 deletions include/converter/_convertTuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ namespace converter
* @brief populate a tuple from a vector of string.
* @tparam S2Tconv converter types that satisfies concept 'c_S2Tconverter'.
* @param dataVec vector of string, having string representation of numeric values.
* @param colIdx start id of dataVec in case vector starts with the column-name.
* @param dataTuple values stored in the tuple after performing string-to-value conversion.
*/
template <c_S2Tconverter ... S2Tconv>
inline void GetTuple(const std::vector<std::string>& dataVec,
size_t colIdx,
std::tuple<typename S2Tconv::return_type ...>& dataTuple)
{
size_t colIdx = 0;
//auto write_tuple = [&dataVec,&colIdx] (auto&& ... wrt_result) -> void # doesnot work for msvc
auto write_tuple = [&dataVec,&colIdx] (typename S2Tconv::return_type & ... wrt_result) -> void
{
Expand All @@ -86,21 +85,19 @@ namespace converter
* @tparam IDX The tuple/vector index being processed by the template instance.
* @tparam T2Sconv converter types that satisfies concept 'c_T2Sconverter'.
* @param dataTuple values stored in the tuple after performing string-to-value conversion.
* @param colIdx start id of dataVec in case vector starts with the column-name.
* @param dataVec vector of string, having string representation of numeric values.
*/
template <size_t IDX,c_T2Sconverter ... T2Sconv>
inline static void setTupleElements(const std::tuple<typename T2Sconv::input_type ...>& dataTuple,
const size_t colIdx,
std::vector<std::string>& dataVec)
{
using _t_tuple_convertors = std::tuple< T2Sconv ...>;
dataVec.at(IDX+colIdx) = std::tuple_element_t<IDX, _t_tuple_convertors>::ToStr(std::get<IDX>(dataTuple));
dataVec.at(IDX) = std::tuple_element_t<IDX, _t_tuple_convertors>::ToStr(std::get<IDX>(dataTuple));
if constexpr(IDX>0)
{
// "((IDX>0)?(IDX-1):0)" eliminates infinite compile time looping,
// and we don't have to define function specialization for setTupleElements<0>()
setTupleElements< ((IDX>0)?(IDX-1):0), T2Sconv ... >(dataTuple,colIdx,dataVec);
setTupleElements< ((IDX>0)?(IDX-1):0), T2Sconv ... >(dataTuple,dataVec);
}
}
// ]===========] workarounds in case std::apply() doesn't work as expected for a given compiler(MSVC)
Expand All @@ -109,14 +106,13 @@ namespace converter
* @brief populate a vector of string from a tuple.
* @tparam T2Sconv converter types that satisfies concept 'c_T2Sconverter'.
* @param dataTuple values stored in the tuple after performing string-to-value conversion.
* @param colIdx start id of dataVec in case vector starts with the column-name.
* @param dataVec vector of string, having string representation of numeric values.
*/
template <c_T2Sconverter ... T2Sconv>
inline void SetTuple(const std::tuple<typename T2Sconv::input_type ...>& dataTuple,
size_t colIdx,
std::vector<std::string>& dataVec)
{
size_t colIdx = 0;
constexpr size_t eleSize = std::tuple_size_v< std::tuple<typename T2Sconv::input_type ...> >;
if(dataVec.size() < eleSize )
{
Expand Down
4 changes: 2 additions & 2 deletions include/converter/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

#define CONVERTER_VERSION_MAJOR 1
#define CONVERTER_VERSION_MINOR 2
#define CONVERTER_VERSION_PATCH 11
#define CONVERTER_VERSION_PATCH 12



Expand All @@ -58,7 +58,7 @@
#define CONVERTER_PREFERRED_PATH std::filesystem::path(CONVERTER_FILE).make_preferred().string()


#if ENABLE_CONVERTER_DEBUG_LOG == 1
#if FLAG_CONVERTER_DEBUG_LOG == 1
#define CONVERTER_DEBUG_LOG(aMessage) { std::cout << aMessage << " :: file:" << CONVERTER_PREFERRED_PATH << ":" << __LINE__ << std::endl; }
#define CONVERTER_DEBUG_TRY_START try {
#define CONVERTER_DEBUG_TRY_END }
Expand Down
4 changes: 2 additions & 2 deletions tests/testTupleConversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ void conversionVectorEqualCheck(const std::vector<std::string>& rowVecInput, con
std::cout << "###### rowVecInput" << /*rowVecInput <<*/ std::endl;
using t_tupleRow = std::tuple<T...>;
t_tupleRow convTuple;
converter::GetTuple<converter::t_S2Tconv_c<T>...>(rowVecInput, 0, convTuple);
converter::GetTuple<converter::t_S2Tconv_c<T>...>(rowVecInput, convTuple);
if(chkTuple != convTuple)
{
throw std::runtime_error("vector->tuple row mismatch");
}

std::vector<std::string> rowOutput;
converter::SetTuple<converter::t_T2Sconv_c<T>...>(convTuple, 0, rowOutput);
converter::SetTuple<converter::t_T2Sconv_c<T>...>(convTuple, rowOutput);
if(expectedOutputVector == nullptr)
{
if(rowVecInput != rowOutput)
Expand Down

0 comments on commit 1c7b838

Please sign in to comment.