From 2215a17d5f292a14a3a50991a63c2cc598fd8d66 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Wed, 5 Feb 2025 14:11:40 +0800 Subject: [PATCH] tmp --- CMakeLists.txt | 2 +- GCTLConfig.cmake.in | 2 +- example/text_io_ex.cpp | 5 +- lib/CMakeLists.txt | 7 +- lib/core/array.h | 13 ++- lib/io/dsv_io.cpp | 111 +++++++--------------- lib/io/dsv_io.h | 190 +++++++++++++++++++------------------ tool/dsviewer/dsviewer.cpp | 18 ++-- 8 files changed, 154 insertions(+), 194 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa01c46..a698620 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ if(GCTL_FFTW3) if(NOT FFTW3_FOUND) find_package(FFTW3 REQUIRED) message(STATUS "Found FFTW3") - include_directories(${FFTW3_INC_DIR}) + include_directories(${FFTW3_INCLUDE_DIRS}) endif() endif() diff --git a/GCTLConfig.cmake.in b/GCTLConfig.cmake.in index 8713ff0..7097cc1 100644 --- a/GCTLConfig.cmake.in +++ b/GCTLConfig.cmake.in @@ -45,7 +45,7 @@ endif() if(@PROJECT_NAME@_FFTW3) if(NOT FFTW3_FOUND) find_package(FFTW3 REQUIRED) - include_directories(${FFTW3_INC_DIR}) + include_directories(${FFTW3_INCLUDE_DIRS}) endif() endif() diff --git a/example/text_io_ex.cpp b/example/text_io_ex.cpp index 124dd56..f2fdbb2 100644 --- a/example/text_io_ex.cpp +++ b/example/text_io_ex.cpp @@ -25,7 +25,6 @@ * Also add information on how to contact you by electronic and paper mail. ******************************************************/ -#include "../lib/core.h" #include "../lib/io.h" using namespace gctl; @@ -34,7 +33,7 @@ int main(int argc, char const *argv[]) try { dsv_io tc, tout; - tc.set_delimeter('|'); + tc.delimeter('|'); tc.load_text("tmp/world_data", ".txt", BothHead); //tc.info(); @@ -51,7 +50,7 @@ int main(int argc, char const *argv[]) try int lr_id = tout.add_row(); tout.fill_row(array{"Asia", "China", "14000000", "1949"}, lr_id); - tout.set_delimeter('|'); + tout.delimeter('|'); tout.save_text("out"); /* diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 709de96..0d68666 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -51,10 +51,9 @@ endif() # 连接动态库与静态库 if(GCTL_FFTW3) - # 因为是手动设置的动态库地址 使用find_library更保险 - find_library(LIB_TAR ${FFTW3_LIB} HINTS ${FFTW3_LIB_DIR}) - target_link_libraries(gctl PUBLIC ${LIB_TAR}) - target_link_libraries(gctl_static ${LIB_TAR}) + find_library(FFTW_LIB ${FFTW3_LIBRARIES} HINTS ${FFTW3_LIBRARY_DIRS}) + target_link_libraries(gctl PUBLIC ${FFTW_LIB}) + target_link_libraries(gctl_static ${FFTW_LIB}) endif() if(GCTL_EEMD) diff --git a/lib/core/array.h b/lib/core/array.h index 30aacd7..95c3375 100644 --- a/lib/core/array.h +++ b/lib/core/array.h @@ -145,7 +145,7 @@ namespace gctl * * @param init_val Initial values */ - array(std::vector init_val); + array(std::initializer_list init_val); /** * @brief Construct a new array object as a sequence @@ -394,7 +394,7 @@ namespace gctl * * @param init_val Initial values */ - void resize(std::vector init_val); + void resize(std::initializer_list init_val); /** * @brief Resize a new array object as a sequence @@ -894,7 +894,7 @@ namespace gctl } template - array::array(std::vector init_val) + array::array(std::initializer_list init_val) { length_ = 0; val_ = nullptr; @@ -1244,12 +1244,15 @@ namespace gctl } template - void array::resize(std::vector init_val) + void array::resize(std::initializer_list init_val) { resize(init_val.size()); + + typename std::initializer_list::iterator iter = init_val.begin(); for (size_t i = 0; i < length_; i++) { - val_[i] = init_val[i]; + val_[i] = *iter; + iter++; } return; } diff --git a/lib/io/dsv_io.cpp b/lib/io/dsv_io.cpp index 986b679..91db8a1 100644 --- a/lib/io/dsv_io.cpp +++ b/lib/io/dsv_io.cpp @@ -74,27 +74,17 @@ void gctl::dsv_io::clear() return; } -void gctl::dsv_io::get_row_names(std::vector &names) +std::vector gctl::dsv_io::row_names() { - names.resize(row_num_); + _1s_vector names(row_num_); for (size_t i = 1; i <= row_num_; i++) { names[i - 1] = table_[i][0].str_; } - return; + return names; } -void gctl::dsv_io::get_column_names(std::vector &names) -{ - names.resize(col_num_); - for (size_t i = 1; i <= col_num_; i++) - { - names[i - 1] = table_[0][i].str_; - } - return; -} - -void gctl::dsv_io::set_row_names(const std::vector &names, const std::vector &idx, std::string corner_name) +void gctl::dsv_io::row_names(const std::vector &names, const std::vector &idx, std::string corner_name) { if (!idx.empty()) { @@ -117,7 +107,17 @@ void gctl::dsv_io::set_row_names(const std::vector &names, const st return; } -void gctl::dsv_io::set_column_names(const std::vector &names, const std::vector &idx) +std::vector gctl::dsv_io::column_names() +{ + _1s_vector names(col_num_); + for (size_t i = 1; i <= col_num_; i++) + { + names[i - 1] = table_[0][i].str_; + } + return names; +} + +void gctl::dsv_io::column_names(const std::vector &names, const std::vector &idx) { if (!idx.empty()) { @@ -138,7 +138,7 @@ void gctl::dsv_io::set_column_names(const std::vector &names, const return; } -void gctl::dsv_io::set_row_type(cell_type_e t, int idx) +void gctl::dsv_io::row_type(table_cell_type t, int idx) { if (idx > row_num_ || idx <= 0) { @@ -151,12 +151,12 @@ void gctl::dsv_io::set_row_type(cell_type_e t, int idx) } } -void gctl::dsv_io::set_row_type(cell_type_e t, std::string name) +void gctl::dsv_io::row_type(table_cell_type t, std::string name) { - set_row_type(t, name_index(name, true)); + row_type(t, name_index(name, true)); } -void gctl::dsv_io::set_column_type(cell_type_e t, int idx) +void gctl::dsv_io::column_type(table_cell_type t, int idx) { if (idx > col_num_ || idx <= 0) { @@ -170,9 +170,9 @@ void gctl::dsv_io::set_column_type(cell_type_e t, int idx) return; } -void gctl::dsv_io::set_column_type(cell_type_e t, std::string name) +void gctl::dsv_io::column_type(table_cell_type t, std::string name) { - set_column_type(t, name_index(name, false)); + column_type(t, name_index(name, false)); } void gctl::dsv_io::load_text(std::string filename, std::string file_exten, table_headtype_e t) @@ -225,7 +225,7 @@ void gctl::dsv_io::load_text(std::string filename, std::string file_exten, table // 动态调整列数 cn = tmp_cols.size(); - cn_max = std::max(cn, cn_max); + cn_max = GCTL_MAX(cn, cn_max); table_[i].resize(tmp_cols.size()); for (size_t j = 0; j < tmp_cols.size(); j++) @@ -292,7 +292,7 @@ void gctl::dsv_io::load_text(std::string filename, std::string file_exten, table void gctl::dsv_io::load_csv(std::string filename, table_headtype_e t) { - set_delimeter(','); + delimeter(','); load_text(filename, ".csv", t); return; } @@ -338,59 +338,14 @@ void gctl::dsv_io::save_text(std::string filename, std::string file_exten) } outfile << std::endl; } - -/* - // 单独处理第一行 即列头 - bool line_st = false; - if (table_[0][0].out_ok_ && table_[0][0].str_ != "") - { - outfile << table_[0][0].str_; - line_st = true; - } - for (int j = 1; j <= col_num_; j++) - { - if (line_st && table_[0][j].out_ok_ && table_[0][j].str_ != "") outfile << deli_sym_ << table_[0][j].str_; // line started - else if (table_[0][j].out_ok_ && table_[0][j].str_ != "") // line not started - { - outfile << table_[0][j].str_; - line_st = true; // start line - } - } - - if (line_st) outfile << std::endl; - - // 处理余下的行 - for (int i = 1; i <= row_num_; i++) - { - line_st = false; - - // 单独处理第一列 即行头 - if (table_[i][0].out_ok_ && table_[i][0].str_ != "") - { - outfile << table_[i][0].str_; - line_st = true; - } - - for (int j = 1; j <= col_num_; j++) - { - if (line_st && table_[i][j].out_ok_) outfile << deli_sym_ << table_[i][j].str_; // line started - else if (table_[i][j].out_ok_) // line not started - { - outfile << table_[i][j].str_; - line_st = true; // start line - } - } - outfile << std::endl; - } -*/ outfile.close(); return; } void gctl::dsv_io::save_csv(std::string filename) { - set_delimeter(','); + delimeter(','); save_text(filename, ".csv"); return; } @@ -684,7 +639,7 @@ void gctl::dsv_io::filt_column(std::string cnd_str, std::string cnd_col, std::vector io_col; if (out_row) { - get_column_names(io_col); + column_names(io_col); out_table.cell(table_[0][0].str_, 0, 0); } else @@ -697,8 +652,8 @@ 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.column_names(io_col); + out_table.row_names(row_names, {}, table_[0][0].str_); destroy_vector(row_names); destroy_vector(io_col); @@ -761,7 +716,7 @@ void gctl::dsv_io::filt_column(rowbool_func_t func, const std::vector io_col; if (out_row) { - get_column_names(io_col); + column_names(io_col); out_table.cell(table_[0][0].str_, 0, 0); } else @@ -772,8 +727,8 @@ void gctl::dsv_io::filt_column(rowbool_func_t func, const std::vector io_col; if (out_row) { - get_column_names(io_col); + column_names(io_col); out_table.cell(table_[0][0].str_, 0, 0); } else @@ -940,8 +895,8 @@ void gctl::dsv_io::filt_column(std::string cnd_str, const std::vector& get_head_records(){return heads_;} - - /** - * @brief 返回注释行 - * - * @return 注释行 - */ - const std::vector& get_annotoations(){return annotates_;} - - /** - * @brief 返回标记行 - * - * @return 标记 - */ - const std::vector& get_tags(){return tags_;} - - /** - * @brief 获取行名称 - * - * @param names 名称 - */ - void get_row_names(std::vector &names); - - /** - * @brief 获取列名称 - * - * @param names 名称 - */ - void get_column_names(std::vector &names); - - /** - * @brief 设置列分隔符 - * - * @param deli_sym 分隔符 - */ - void set_delimeter(char deli_sym){deli_sym_ = deli_sym;} - - /** - * @brief 获取列分隔符 - * - * @return 分隔符 - */ - char get_delimeter(){return deli_sym_;} + int head_number(){return head_num_;} /** * @brief 设置头信息行数 * * @param num 行数 */ - void set_head_number(char num){head_num_ = num;} + void head_number(char num){head_num_ = num;} /** - * @brief 获取头信息行数 - * - * @return 行数 - */ - int get_head_number(){return head_num_;} - - /** - * @brief 设置注释行符号 + * @brief 返回头信息 * - * @param att_sym 注释符号 + * @return 头信息 */ - void set_annotation_symbol(char att_sym){att_sym_ = att_sym;} - - /** - * @brief 获取注释行符号 - * - * @return 注释符号 - */ - char get_annotation_symbol(){return att_sym_;} - - /** - * @brief 设置标记行符号 - * - * @param tag_sym 标记符号 - */ - void set_tag_symbol(char tag_sym){tag_sym_ = tag_sym;} + const std::vector &head_records(){return heads_;} /** * @brief 设置头信息 * * @param heads 头信息 */ - void set_head_records(const std::vector &heads){heads_ = heads; head_num_ = heads_.size();} + void head_records(const std::vector &heads){heads_ = heads; head_num_ = heads_.size();} + + /** + * @brief 设置列分隔符 + * + * @param deli_sym 分隔符 + */ + void delimeter(char deli_sym){deli_sym_ = deli_sym;} + + /** + * @brief 获取列分隔符 + * + * @return 分隔符 + */ + char delimeter(){return deli_sym_;} + + /** + * @brief 设置注释行符号 + * + * @param att_sym 注释符号 + */ + void annotation_symbol(char att_sym){att_sym_ = att_sym;} + + /** + * @brief 获取注释行符号 + * + * @return 注释符号 + */ + char annotation_symbol(){return att_sym_;} /** * @brief 设置注释 * * @param att 注释 */ - void set_annotoations(const std::vector &att){annotates_ = att;} + void annotoations(const std::vector &att){annotates_ = att;} + + /** + * @brief 返回注释行 + * + * @return 注释行 + */ + const std::vector &annotoations(){return annotates_;} + + /** + * @brief 设置标记行符号 + * + * @param tag_sym 标记符号 + */ + void tag_symbol(char tag_sym){tag_sym_ = tag_sym;} + + /** + * @brief 获取标记行符号 + * + * @return 标记符号 + */ + char tag_symbol(){return tag_sym_;} /** * @brief 设置标记 * * @param tags 标记 */ - void set_tags(const std::vector &tags){tags_ = tags;} + void tags(const std::vector &tags){tags_ = tags;} + + /** + * @brief 返回标记行 + * + * @return 标记 + */ + const std::vector &tags(){return tags_;} /** * @brief 设置行名称 @@ -298,7 +288,14 @@ namespace gctl * @param idx 索引数组(若为空则依次设置行名称) * @param corner_name 表格左上角位置名称(默认为RowNames) */ - void set_row_names(const std::vector &names, const std::vector &idx = {}, std::string corner_name = "RowNames"); + void row_names(const std::vector &names, const std::vector &idx = {}, std::string corner_name = "RowNames"); + + /** + * @brief 获取行名称 + * + * @return 行名称 + */ + std::vector row_names(); /** * @brief 设置列名称 @@ -306,7 +303,14 @@ namespace gctl * @param names 名称数组 * @param idx 索引数组(若为空则依次设置行名称) */ - void set_column_names(const std::vector &names, const std::vector &idx = {}); + void column_names(const std::vector &names, const std::vector &idx = {}); + + /** + * @brief 获取列名称 + * + * @return 列名称 + */ + std::vector column_names(); /** * @brief 设置行类型 @@ -314,7 +318,7 @@ namespace gctl * @param t 类型名称 String|Float|Int * @param idx 行索引 */ - void set_row_type(cell_type_e t, int idx); + void row_type(table_cell_type t, int idx); /** * @brief 设置行类型 @@ -322,7 +326,7 @@ namespace gctl * @param t 类型名称 String|Float|Int * @param name 行名称 */ - void set_row_type(cell_type_e t, std::string name); + void row_type(table_cell_type t, std::string name); /** * @brief 设置列类型 @@ -330,7 +334,7 @@ namespace gctl * @param t 类型名称 String|Float|Int * @param idx 列索引 */ - void set_column_type(cell_type_e t, int idx); + void column_type(table_cell_type t, int idx); /** * @brief 设置列类型 @@ -338,7 +342,7 @@ namespace gctl * @param t 类型名称 String|Float|Int * @param name 列名称 */ - void set_column_type(cell_type_e t, std::string name); + void column_type(table_cell_type t, std::string name); /** * @brief 读入文本文件 diff --git a/tool/dsviewer/dsviewer.cpp b/tool/dsviewer/dsviewer.cpp index eb7c5d9..22769ed 100644 --- a/tool/dsviewer/dsviewer.cpp +++ b/tool/dsviewer/dsviewer.cpp @@ -238,7 +238,7 @@ void head(const std::vector &cmd_units) for (size_t i = 1; i <= h; i++) { tc.get_row(line, i); - line.show(std::cout, tc.get_delimeter()); + line.show(std::cout, tc.delimeter()); } return; } @@ -254,7 +254,7 @@ void tail(const std::vector &cmd_units) for (size_t i = tc.row_number() - h + 1; i <= tc.row_number(); i++) { tc.get_row(line, i); - line.show(std::cout, tc.get_delimeter()); + line.show(std::cout, tc.delimeter()); } return; } @@ -328,11 +328,11 @@ void load_file(const std::vector &cmd_units) int hnum = 0; if (copy_str[1] != "null") hnum = atoi(copy_str[1].c_str()); - if (hnum != 0) tc.set_head_number(hnum); + if (hnum != 0) tc.head_number(hnum); - if (copy_str[2] != "null") tc.set_delimeter(copy_str[2][0]); - if (copy_str[3] != "null") tc.set_annotation_symbol(copy_str[3][0]); - if (copy_str[4] != "null") tc.set_tag_symbol(copy_str[4][0]); + if (copy_str[2] != "null") tc.delimeter(copy_str[2][0]); + if (copy_str[3] != "null") tc.annotation_symbol(copy_str[3][0]); + if (copy_str[4] != "null") tc.tag_symbol(copy_str[4][0]); std::string naked_name, exten_name; parse_filename(cmd_units[1], naked_name, exten_name); @@ -353,9 +353,9 @@ void save_file(const std::vector &cmd_units) copy_str[i] = cmd_units[i + 2]; } - if (copy_str[0] != "null") tc.set_delimeter(copy_str[0][0]); - if (copy_str[1] != "null") tc.set_annotation_symbol(copy_str[1][0]); - if (copy_str[2] != "null") tc.set_tag_symbol(copy_str[2][0]); + if (copy_str[0] != "null") tc.delimeter(copy_str[0][0]); + if (copy_str[1] != "null") tc.annotation_symbol(copy_str[1][0]); + if (copy_str[2] != "null") tc.tag_symbol(copy_str[2][0]); std::string naked_name, exten_name; parse_filename(cmd_units[1], naked_name, exten_name);