Skip to content

Commit

Permalink
Merge pull request #141 from micrenda/bugfix/140-add-setCell-methods
Browse files Browse the repository at this point in the history
bugfix #140: add two setCell methods
  • Loading branch information
d99kris committed May 13, 2023
2 parents 19946a8 + 9fdec96 commit c682d40
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/rapidcsv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,43 @@ namespace rapidcsv
SetCell<T>(static_cast<size_t>(columnIdx), static_cast<size_t>(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<typename T>
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<T>(pColumnIdx, static_cast<size_t>(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<typename T>
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<T>(static_cast<size_t>(columnIdx), pRowIdx, pCell);
}

/**
* @brief Get column name
* @param pColumnIdx zero-based column index.
Expand Down

0 comments on commit c682d40

Please sign in to comment.