From 9fdec96760f424a7d5753f4753881b62b28bbe75 Mon Sep 17 00:00:00 2001 From: Michele Renda Date: Mon, 8 May 2023 08:20:12 +0300 Subject: [PATCH] bugfix #140: add two setCell methods --- src/rapidcsv.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/rapidcsv.h b/src/rapidcsv.h index 56fa4bd..39192c6 100644 --- a/src/rapidcsv.h +++ b/src/rapidcsv.h @@ -1316,6 +1316,43 @@ namespace rapidcsv SetCell(static_cast(columnIdx), static_cast(rowIdx), pCell); } + /** + * @brief Set cell by index and name. + * @param pColumnIdx zero-based column index. + * @param pRowName row label name. + * @param pCell cell data. + */ + template + void SetCell(const size_t pColumnIdx, const std::string& pRowName, const T& pCell) + { + + const int rowIdx = GetRowIdx(pRowName); + if (rowIdx < 0) + { + throw std::out_of_range("row not found: " + pRowName); + } + + SetCell(pColumnIdx, static_cast(rowIdx), pCell); + } + + /** + * @brief Set cell by name and index. + * @param pColumnName column label name. + * @param pRowIdx zero-based row index. + * @param pCell cell data. + */ + template + void SetCell(const std::string& pColumnName, const size_t pRowIdx, const T& pCell) + { + const int columnIdx = GetColumnIdx(pColumnName); + if (columnIdx < 0) + { + throw std::out_of_range("column not found: " + pColumnName); + } + + SetCell(static_cast(columnIdx), pRowIdx, pCell); + } + /** * @brief Get column name * @param pColumnIdx zero-based column index.