Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix #140: add two setCell methods #141

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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