MCPcopy Create free account
hub / github.com/d99kris/rapidcsv / SetRowName

Method SetRowName

src/rapidcsv.h:1509–1539  ·  view source on GitHub ↗

* @brief Set row name * @param pRowIdx zero-based row index. * @param pRowName row name. */

Source from the content-addressed store, hash-verified

1507 * @param pRowName row name.
1508 */
1509 void SetRowName(size_t pRowIdx, const std::string& pRowName)
1510 {
1511 const size_t dataRowIdx = GetDataRowIndex(pRowIdx);
1512
1513 // remove old name from map before adding new one
1514 if ((mLabelParams.mRowNameIdx >= 0) && (dataRowIdx < mData.size()) &&
1515 (static_cast<size_t>(mLabelParams.mRowNameIdx) < mData.at(dataRowIdx).size()))
1516 {
1517 const std::string oldName = mData.at(dataRowIdx).at(static_cast<size_t>(mLabelParams.mRowNameIdx));
1518 mRowNames.erase(oldName);
1519 }
1520 mRowNames[pRowName] = dataRowIdx;
1521 if (mLabelParams.mRowNameIdx < 0)
1522 {
1523 throw std::out_of_range("row name column index < 0: " + std::to_string(mLabelParams.mRowNameIdx));
1524 }
1525
1526 // increase table size if necessary:
1527 if (dataRowIdx >= mData.size())
1528 {
1529 mData.resize(dataRowIdx + 1);
1530 }
1531
1532 std::vector<std::string>& row = mData[dataRowIdx];
1533 if (mLabelParams.mRowNameIdx >= static_cast<int>(row.size()))
1534 {
1535 row.resize(static_cast<size_t>(mLabelParams.mRowNameIdx) + 1);
1536 }
1537
1538 mData.at(dataRowIdx).at(static_cast<size_t>(mLabelParams.mRowNameIdx)) = pRowName;
1539 }
1540
1541 /**
1542 * @brief Get row names

Callers 6

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
test082.cppFile · 0.80

Calls

no outgoing calls

Tested by 5

mainFunction · 0.64
mainFunction · 0.64
mainFunction · 0.64
mainFunction · 0.64
mainFunction · 0.64