From 1c7b838f86ea717dc5c4271b7e0b8695438ef329 Mon Sep 17 00:00:00 2001 From: Gautam Dhar <27485331+panchaBhuta@users.noreply.github.com> Date: Tue, 12 Dec 2023 19:14:06 +0530 Subject: [PATCH] tuple-conversion : parameter start idx for vector, now idx is alwas zero based --- cmake/converter.cmake | 8 ++++---- doc/converter/converter_Tuple_helpers.md | 4 ---- include/converter/_convertDate.h | 2 +- include/converter/_convertT2S.h | 2 +- include/converter/_convertTuple.h | 12 ++++-------- include/converter/converter.h | 4 ++-- tests/testTupleConversions.cpp | 4 ++-- 7 files changed, 14 insertions(+), 22 deletions(-) diff --git a/cmake/converter.cmake b/cmake/converter.cmake index 4651b5b..bdb8ccb 100644 --- a/cmake/converter.cmake +++ b/cmake/converter.cmake @@ -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" "$,$>") + # option(OPTION_CONVERTER_DEBUG_LOG "Set to ON for debugging logs" "$,$>") #]===========] #[==================================================================================[ @@ -475,7 +475,7 @@ macro(converter_build) target_compile_definitions(converter INTERFACE $<$:DEBUG_BUILD> $<$:RELEASE_BUILD> - ENABLE_CONVERTER_DEBUG_LOG=$) + FLAG_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. diff --git a/doc/converter/converter_Tuple_helpers.md b/doc/converter/converter_Tuple_helpers.md index bf24824..1641748 100644 --- a/doc/converter/converter_Tuple_helpers.md +++ b/doc/converter/converter_Tuple_helpers.md @@ -65,7 +65,6 @@ Converts variable holding 'tuple' value to string. The output string has the for ```c++ template inline void GetTuple(const std::vector& dataVec, - size_t colIdx, std::tuple& dataTuple) ``` populate a tuple from a vector of string. @@ -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. --- @@ -87,7 +85,6 @@ populate a tuple from a vector of string. ```c++ template inline void SetTuple(const std::tuple& dataTuple, - size_t colIdx, std::vector& dataVec) ``` @@ -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. \ No newline at end of file diff --git a/include/converter/_convertDate.h b/include/converter/_convertDate.h index 11417eb..79a18af 100644 --- a/include/converter/_convertDate.h +++ b/include/converter/_convertDate.h @@ -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 { diff --git a/include/converter/_convertT2S.h b/include/converter/_convertT2S.h index d753f96..e92f553 100644 --- a/include/converter/_convertT2S.h +++ b/include/converter/_convertT2S.h @@ -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 << "'"; diff --git a/include/converter/_convertTuple.h b/include/converter/_convertTuple.h index a5a7c67..5607e20 100644 --- a/include/converter/_convertTuple.h +++ b/include/converter/_convertTuple.h @@ -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 inline void GetTuple(const std::vector& dataVec, - size_t colIdx, std::tuple& 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 { @@ -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 inline static void setTupleElements(const std::tuple& dataTuple, - const size_t colIdx, std::vector& dataVec) { using _t_tuple_convertors = std::tuple< T2Sconv ...>; - dataVec.at(IDX+colIdx) = std::tuple_element_t::ToStr(std::get(dataTuple)); + dataVec.at(IDX) = std::tuple_element_t::ToStr(std::get(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) @@ -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 inline void SetTuple(const std::tuple& dataTuple, - size_t colIdx, std::vector& dataVec) { + size_t colIdx = 0; constexpr size_t eleSize = std::tuple_size_v< std::tuple >; if(dataVec.size() < eleSize ) { diff --git a/include/converter/converter.h b/include/converter/converter.h index 6e10c21..a34a4ff 100644 --- a/include/converter/converter.h +++ b/include/converter/converter.h @@ -32,7 +32,7 @@ #define CONVERTER_VERSION_MAJOR 1 #define CONVERTER_VERSION_MINOR 2 -#define CONVERTER_VERSION_PATCH 11 +#define CONVERTER_VERSION_PATCH 12 @@ -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 } diff --git a/tests/testTupleConversions.cpp b/tests/testTupleConversions.cpp index b003b3d..e7021e6 100644 --- a/tests/testTupleConversions.cpp +++ b/tests/testTupleConversions.cpp @@ -19,14 +19,14 @@ void conversionVectorEqualCheck(const std::vector& rowVecInput, con std::cout << "###### rowVecInput" << /*rowVecInput <<*/ std::endl; using t_tupleRow = std::tuple; t_tupleRow convTuple; - converter::GetTuple...>(rowVecInput, 0, convTuple); + converter::GetTuple...>(rowVecInput, convTuple); if(chkTuple != convTuple) { throw std::runtime_error("vector->tuple row mismatch"); } std::vector rowOutput; - converter::SetTuple...>(convTuple, 0, rowOutput); + converter::SetTuple...>(convTuple, rowOutput); if(expectedOutputVector == nullptr) { if(rowVecInput != rowOutput)