本文整理汇总了C++中CSVRow::append方法的典型用法代码示例。如果您正苦于以下问题:C++ CSVRow::append方法的具体用法?C++ CSVRow::append怎么用?C++ CSVRow::append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSVRow
的用法示例。
在下文中一共展示了CSVRow::append方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: join
// Perform a join on two tables, using two provided strings representing the headers of the respective columns to join on
CSVTable CSVJoiner::join(CSVTable t1, CSVTable t2, std::string c1, std::string c2, Config &config) {
CSVTable t3;
CSVRow row;
row.append( t1.rows[0].begin(), t1.rows[0].end() );
row.append( t2.rows[0].begin(), t2.rows[0].end() );
t3.push_back(row);
int comp1 = t1.get_column_index(c1);
int comp2 = t2.get_column_index(c2);
// For left and right joins. Would be great if this was simply a vector of pointers.
std::vector<CSVRow> remaining_rows1 = t1.rows;
std::vector<CSVRow> remaining_rows2 = t2.rows;
for (int i = 1; i < t1.rows.size(); i++) {
for (int j = 1; j < t2.rows.size(); j++) {
if( t1.rows[i][comp1] == t2.rows[j][comp2] ) {
CSVRow row;
row.append( t1.rows[i].begin(), t1.rows[i].end() );
row.append( t2.rows[j].begin(), t2.rows[j].end() );
t3.push_back(row);
remaining_rows1[i].clear();
remaining_rows2[j].clear();
}
}
}
if( config.join_left == true ) {
for (int i = 1; i < remaining_rows1.size(); i++) {
if( !remaining_rows1[i].empty() ) {
CSVRow row = remaining_rows1[i];
for (int j = 0; j < t2.column_count; j++) {
row.push_back("");
}
t3.push_back(row);
}
}
}
if( config.join_right == true ) {
for (int i = 1; i < remaining_rows2.size(); i++) {
if( !remaining_rows2[i].empty() ) {
CSVRow row;
for (int j = 0; j<t1.column_count; j++) {
row.push_back("");
}
row.append( remaining_rows2[i].begin(), remaining_rows2[i].end() );
t3.push_back(row);
}
}
}
return t3;
}