Commit 0984c85a authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[3555] CSVRow.append() implemented.

parent 8f112316
......@@ -178,6 +178,20 @@ public:
writeAt(at, value.c_str());
}
/// @brief Appends the value as a new column.
///
/// @param value Value to be written.
/// @tparam T Type of the value being written.
template<typename T>
void append(const T value) {
try {
values_.push_back(boost::lexical_cast<std::string>(value));
} catch (const boost::bad_lexical_cast& ex) {
isc_throw(CSVFileError, "unable to stringify the value to be "
"appended to the CSV file row.");
}
}
/// @brief Replaces the value at specified index.
///
/// This function is used to set values to be rendered using
......
......@@ -90,6 +90,25 @@ TEST(CSVRow, writeAt) {
EXPECT_THROW(row.writeAt(3, "foo"), CSVFileError);
}
// Checks whether writeAt() and append() can be mixed together.
TEST(CSVRow, append) {
CSVRow row(3);
EXPECT_EQ(3, row.getValuesCount());
row.writeAt(0, "alpha");
ASSERT_NO_THROW(row.append("delta"));
EXPECT_EQ(4, row.getValuesCount());
row.writeAt(1, "beta");
row.writeAt(2, "gamma");
ASSERT_NO_THROW(row.append("epsilon"));
EXPECT_EQ(5, row.getValuesCount());
std::string text;
ASSERT_NO_THROW(text = row.render());
EXPECT_EQ("alpha,beta,gamma,delta,epsilon", text);
}
/// @brief Test fixture class for testing operations on CSV file.
///
/// It implements basic operations on files, such as reading writing
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment