This commit is contained in:
张壹 2025-01-02 23:19:59 +08:00
parent a8a80f0dc4
commit 2c41a0c898
3 changed files with 62 additions and 40 deletions

View File

@ -83,7 +83,7 @@ int main(int argc, char const *argv[]) try
tc.fill_row(array<double>{5.5, 4.4, 3.3, 2.2, 1.1}, 3);
geodsv_io out_table;
tc.filter("dist > 1000", {"dist"}, {"x (m)", "y (m)", "elev (m)"}, out_table);
tc.filt_column("dist > 1000", {"dist"}, {"x (m)", "y (m)", "elev (m)"}, out_table);
out_table.save_text("out2");
_1s_vector s = tc.get_tags();

View File

@ -348,8 +348,10 @@ void gctl::dsv_io::save_csv(std::string filename)
return;
}
void gctl::dsv_io::init_table(int row, int col, table_headtype_e t)
void gctl::dsv_io::init_table(int row, int col)
{
if (!table_.empty()) clear();
row_num_ = row;
col_num_ = col;
@ -362,28 +364,6 @@ void gctl::dsv_io::init_table(int row, int col, table_headtype_e t)
return;
}
void gctl::dsv_io::init_table(const std::vector<std::vector<std::string> > &str_table, table_headtype_e t)
{
row_num_ = str_table.size();
col_num_ = str_table[0].size();
// 初始的列头和行头均为空白
table_.resize(row_num_ + 1);
for (size_t i = 0; i < row_num_ + 1; i++)
{
table_[i].resize(col_num_ + 1);
}
for (size_t i = 1; i <= row_num_; i++)
{
for (size_t j = 1; j <= col_num_; j++)
{
table_[i][j].str_ = str_table[i - 1][j - 1];
}
}
return;
}
void gctl::dsv_io::info(table_headtype_e t)
{
std::clog << "File: " << file_ << "\n------------\n";
@ -659,13 +639,18 @@ void gctl::dsv_io::cal_column(std::string expr_str, const std::vector<std::strin
return;
}
void gctl::dsv_io::filter(std::string cnd_str, const std::vector<std::string> &cnd_col,
void gctl::dsv_io::filt_column(std::string cnd_str, const std::vector<std::string> &cnd_col,
const std::vector<std::string> &out_col, dsv_io& out_table)
{
array<int> idx(cnd_col.size());
for (size_t i = 0; i < cnd_col.size(); i++)
{
idx[i] = name_index(cnd_col[i]);
if (table_[0][idx[i]].type_ != Int && table_[0][idx[i]].type_ != Float)
{
throw std::runtime_error("[gctl::dsv_io] Invalid column type for numerical calculating.");
}
}
array<int> odx(out_col.size());

View File

@ -352,17 +352,8 @@ namespace gctl
*
* @param row
* @param col
* @param t
*/
void init_table(int row, int col, table_headtype_e t = ColumnHead);
/**
* @brief
*
* @param str_table
* @param t
*/
void init_table(const std::vector<std::vector<std::string> > &str_table, table_headtype_e t = ColumnHead);
void init_table(int row, int col);
/**
* @brief
@ -475,16 +466,25 @@ namespace gctl
/**
* @brief
*
* @note float和Int类型的列数据才能用于计算exprtk库完成
*
* @param cnd_str
* @param cnd_col
* @param out_col
* @param out_table
*/
void filter(std::string cnd_str, const std::vector<std::string> &cnd_col,
void filt_column(std::string cnd_str, const std::vector<std::string> &cnd_col,
const std::vector<std::string> &out_col, dsv_io &out_table);
#endif // GCTL_EXPRTK
/**
* @brief
*
* @param data
*/
template <typename T> void init_table(const std::vector<std::vector<T> > &data, int p = 6);
/**
* @brief
*
@ -492,7 +492,7 @@ namespace gctl
* @param data
* @param p
*/
template <typename T> void fill_table(const matrix<T> &data, int p = 6);
template <typename T> void init_table(const matrix<T> &data, int p = 6);
/**
* @brief
@ -601,11 +601,48 @@ namespace gctl
};
template <typename T>
void dsv_io::fill_table(const matrix<T> &data, int p)
void dsv_io::init_table(const std::vector<std::vector<T> > &data, int p)
{
for (size_t i = 1; i <= std::min(row_num_, (int) data.row_size()); i++)
if (!table_.empty()) clear();
row_num_ = data.size();
col_num_ = data[0].size();
// 初始的列头和行头均为空白
table_.resize(row_num_ + 1);
for (size_t i = 0; i < row_num_ + 1; i++)
{
for (size_t j = 1; j <= std::min(col_num_, (int) data.col_size()); j++)
table_[i].resize(col_num_ + 1);
}
for (size_t i = 1; i <= row_num_; i++)
{
for (size_t j = 1; j <= col_num_; j++)
{
table_[i][j].value(data[i - 1][j - 1], p);
}
}
return;
}
template <typename T>
void dsv_io::init_table(const matrix<T> &data, int p)
{
if (!table_.empty()) clear();
row_num_ = data.row_size();
col_num_ = data.col_size();
// 初始的列头和行头均为空白
table_.resize(row_num_ + 1);
for (size_t i = 0; i < row_num_ + 1; i++)
{
table_[i].resize(col_num_ + 1);
}
for (size_t i = 1; i <= row_num_; i++)
{
for (size_t j = 1; j <= col_num_; j++)
{
table_[i][j].value(data[i - 1][j - 1], p);
}