update dsv_io
This commit is contained in:
parent
a927a93997
commit
ad55ba233a
@ -94,22 +94,46 @@ void gctl::dsv_io::get_column_names(std::vector<std::string> &names)
|
|||||||
return;
|
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;
|
table_[0][0].str_ = corner_name;
|
||||||
return;
|
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;
|
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_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(row_names);
|
||||||
destroy_vector(io_col);
|
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_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(row_names);
|
||||||
destroy_vector(io_col);
|
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_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(row_names);
|
||||||
destroy_vector(io_col);
|
destroy_vector(io_col);
|
||||||
|
@ -113,15 +113,15 @@ namespace gctl
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DSV文本读写类
|
* @brief DSV文本读写类型可以读写并处理一定格式保存的文本数据,具体的格式如下:
|
||||||
*
|
* 1. 所有以注释符(默认为#号)开始的行均会保存至注释变量内,可由用户提取;
|
||||||
* 可以处理的文本数据应该符合下述要求:
|
* 2. 所有以标记符(默认为#!号)开始的行均会保存至标记变量内,可由用户提取;
|
||||||
* 1. 以'#'开始的行均为注释行,标识符可由用户指定;
|
* 3. 文件内可以包含n(默认为0)行不以注释或标记符开始头信息行,保存为头信息变量内,可由用户提取;
|
||||||
* 2. 以'#!'开始的行均为标记行,标识符可由用户指定;
|
* 4. 注释、标记和头信息可出现在文本数据的任意行,且只有在头信息读入结束后才会开始读入数据;
|
||||||
* 3. 文本开始可以包含n行头信息;
|
* 5. 读入的表格保存为一个二维字符串数组,可由用户提取。浮点类型在读入/保存时可设置有效数字位数;
|
||||||
* 4. 数据体为一个row*col大小的表格;
|
* 6. 若制定读入的数据表格存在行或列表头,则读入表格的第一列或第一行将被初始化为对应的行名称或列名称;
|
||||||
* 5. 数据表格文件可以额外包含一列行名称与列名称;
|
* 7. 表格的行与列数据可通过数字索引访问(从1开始计数),也可由具体的行或列名称指定;
|
||||||
* 6. 如论文件内是否包含行头或列头,均可使用内置的行名称R<id>或列名称C<id>指定相应的行或列
|
* 8. 表格可识别内置的行与列名称(格式为为R<id>和C<id>),但不能用于输出文件。
|
||||||
*/
|
*/
|
||||||
class dsv_io
|
class dsv_io
|
||||||
{
|
{
|
||||||
@ -273,16 +273,19 @@ namespace gctl
|
|||||||
/**
|
/**
|
||||||
* @brief 设置行名称
|
* @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 设置列名称
|
* @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 设置行类型
|
* @brief 设置行类型
|
||||||
|
Loading…
Reference in New Issue
Block a user