update dsv_io

This commit is contained in:
张壹 2025-01-26 12:03:46 +08:00
parent a927a93997
commit ad55ba233a
2 changed files with 49 additions and 22 deletions

View File

@ -94,22 +94,46 @@ void gctl::dsv_io::get_column_names(std::vector<std::string> &names)
return;
}
void gctl::dsv_io::set_row_names(const std::vector<std::string> &names, std::string corner_name)
void gctl::dsv_io::set_row_names(const std::vector<std::string> &names, const std::vector<int> &idx, std::string corner_name)
{
for (size_t i = 1; i <= std::min(row_num_, (int) names.size()); i++)
if (!idx.empty())
{
table_[i][0].str_ = names[i - 1];
if (idx.size() != names.size()) throw std::runtime_error("[gctl::dsv_io] The size of idx and names must be the same.");
for (size_t i = 0; i < names.size(); i++)
{
table_[idx[i]][0].str_ = names[i];
}
}
else
{
for (size_t i = 1; i <= std::min(row_num_, (int) names.size()); i++)
{
table_[i][0].str_ = names[i - 1];
}
}
table_[0][0].str_ = corner_name;
return;
}
void gctl::dsv_io::set_column_names(const std::vector<std::string> &names)
void gctl::dsv_io::set_column_names(const std::vector<std::string> &names, const std::vector<int> &idx)
{
for (size_t i = 1; i <= std::min(col_num_, (int) names.size()); i++)
if (!idx.empty())
{
table_[0][i].str_ = names[i - 1];
if (idx.size() != names.size()) throw std::runtime_error("[gctl::dsv_io] The size of idx and names must be the same.");
for (size_t i = 0; i < names.size(); i++)
{
table_[0][idx[i]].str_ = names[i];
}
}
else
{
for (size_t i = 1; i <= std::min(col_num_, (int) names.size()); i++)
{
table_[0][i].str_ = names[i - 1];
}
}
return;
}
@ -674,7 +698,7 @@ void gctl::dsv_io::filt_column(std::string cnd_str, std::string cnd_col,
}
out_table.set_column_names(io_col);
out_table.set_row_names(row_names, table_[0][0].str_);
out_table.set_row_names(row_names, {}, table_[0][0].str_);
destroy_vector(row_names);
destroy_vector(io_col);
@ -749,7 +773,7 @@ void gctl::dsv_io::filt_column(rowbool_func_t func, const std::vector<std::strin
}
out_table.set_column_names(io_col);
out_table.set_row_names(row_names, table_[0][0].str_);
out_table.set_row_names(row_names, {}, table_[0][0].str_);
destroy_vector(row_names);
destroy_vector(io_col);
@ -917,7 +941,7 @@ void gctl::dsv_io::filt_column(std::string cnd_str, const std::vector<std::strin
}
out_table.set_column_names(io_col);
out_table.set_row_names(row_names, table_[0][0].str_);
out_table.set_row_names(row_names, {}, table_[0][0].str_);
destroy_vector(row_names);
destroy_vector(io_col);

View File

@ -113,15 +113,15 @@ namespace gctl
};
/**
* @brief DSV文本读写类
*
*
* 1. '#'
* 2. '#!'
* 3. n行头信息
* 4. row*col大小的表格
* 5.
* 6. 使R<id>C<id>
* @brief DSV文本读写类型可以读写并处理一定格式保存的文本数据
* 1. #
* 2. #!
* 3. n0
* 4.
* 5. /
* 6.
* 7. 访1
* 8. R<id>C<id>
*/
class dsv_io
{
@ -273,16 +273,19 @@ namespace gctl
/**
* @brief
*
* @param names
* @param names
* @param idx
* @param corner_name RowNames
*/
void set_row_names(const std::vector<std::string> &names, std::string corner_name = "row-idx");
void set_row_names(const std::vector<std::string> &names, const std::vector<int> &idx = {}, std::string corner_name = "RowNames");
/**
* @brief
*
* @param names
* @param names
* @param idx
*/
void set_column_names(const std::vector<std::string> &names);
void set_column_names(const std::vector<std::string> &names, const std::vector<int> &idx = {});
/**
* @brief