From 71068038e8e59f18157bc843ab820cc1c6a1eb86 Mon Sep 17 00:00:00 2001 From: Yi Zhang Date: Mon, 3 Mar 2025 09:15:25 +0800 Subject: [PATCH] update dsviewer --- tool/dsviewer/dsviewer.cpp | 19 +++++++++++++++++++ tool/dsviewer/dsviewer.h | 4 +++- tool/dsviewer/dsviewer.md | 13 ++++++++----- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/tool/dsviewer/dsviewer.cpp b/tool/dsviewer/dsviewer.cpp index 35eeada..afdbb3e 100644 --- a/tool/dsviewer/dsviewer.cpp +++ b/tool/dsviewer/dsviewer.cpp @@ -525,6 +525,25 @@ void insert_data(const std::vector &cmd_units) return; } +void set_data(const std::vector &cmd_units) +{ + // set row|col \ \ + if (cmd_units.size() < 4) throw std::runtime_error("set: insufficient parameters."); + + if (cmd_units[1] == "row") + { + _1s_array row_data(tc.row_number(), cmd_units[3]); + tc.fill_row(row_data, cmd_units[2]); + } + else if (cmd_units[1] == "col") + { + _1s_array col_data(tc.col_number(), cmd_units[3]); + tc.fill_column(col_data, cmd_units[2]); + } + else throw std::runtime_error("set: invalid parameters."); + return; +} + void display_table(const std::vector &cmd_units) { // view diff --git a/tool/dsviewer/dsviewer.h b/tool/dsviewer/dsviewer.h index 036ddfc..1823866 100644 --- a/tool/dsviewer/dsviewer.h +++ b/tool/dsviewer/dsviewer.h @@ -59,9 +59,10 @@ void math_func(const std::vector &cmd_units); void rand_data(const std::vector &cmd_units); void filt_data(const std::vector &cmd_units); void insert_data(const std::vector &cmd_units); +void set_data(const std::vector &cmd_units); void display_table(const std::vector &cmd_units); -#define CMD_NUM 17 +#define CMD_NUM 18 const cmd_pair commands[CMD_NUM] = { {"quit", quit, "Quit the program."}, {"view", display_table, "Display valid cells."}, @@ -74,6 +75,7 @@ const cmd_pair commands[CMD_NUM] = { {"enable", set_enable, "Enable column/row outputs by name or index."}, {"disable", set_disable, "Disable column/row outputs by name or index."}, {"insert", insert_data, "Insert a new column/row data."}, + {"set", set_data, "Set a column/row data."}, {"type", set_type, "Set column/row data types."}, {"title", set_titles, "Set row and column titles."}, {"math", math_func, "Preform mathematic operations of column data."}, diff --git a/tool/dsviewer/dsviewer.md b/tool/dsviewer/dsviewer.md index 30b8953..4615d41 100644 --- a/tool/dsviewer/dsviewer.md +++ b/tool/dsviewer/dsviewer.md @@ -17,19 +17,22 @@ Open a dsv/csv file. The default setups are 'nohead', space for delimeter, '#' f Save table to a dsv/csv file. The default setups are space for delimeter, '#' for annotations, and '!' for tags. If the file name ends with '.csv', the default delimeter is ','. #### stats \ \ ... -Show statistics of a data column or columns. If the input file has no column names, use inbuild names `C` to select the columns. +Show statistics of a data column or columns. If the input file has no column names, use inbuilt names `C` to select the columns. #### enable table|column|row [\ \ ...] -Enable table outputs. If the input file has no row or column names, use inbuild names `R` and `C` to select the rows and columns. +Enable table outputs. If the input file has no row or column names, use inbuilt names `R` and `C` to select the rows and columns. #### disable table|column|row [\ \ ...] -Disable table outputs. If the input file has no row or column names, use inbuild names `R` and `C` to select the rows and columns. +Disable table outputs. If the input file has no row or column names, use inbuilt names `R` and `C` to select the rows and columns. #### insert row|col [\] [\] -Insert a new row or column. The new row or column will be attached to the end of the table by default. A `new-name` can be provided if the user wants to rename the new row or column. Provide the `insert-name` to insert the new row or column at the specified row or column. The remaining columns or rows will be moved one step right or down accordingly. If the input file has no row or column names, use inbuild names `R` and `C` to select the rows and columns. +Insert a new row or column. The new row or column will be attached to the end of the table by default. A `new-name` can be provided if the user wants to rename the new row or column. Provide the `insert-name` to insert the new row or column at the specified row or column. The remaining columns or rows will be moved one step right or down accordingly. If the input file has no row or column names, use inbuilt names `R` and `C` to select the rows and columns. + +#### set row|col \ \ +Set a row or column's value to the given one. If the input file has no row or column names, use inbuilt names `R` and `C` to select the rows and columns. #### type row|col int|float|string \ -Set the data type of a row or column. If the input file has no row or column names, use inbuild names `R` and `C` to select the rows and columns. +Set the data type of a row or column. If the input file has no row or column names, use inbuilt names `R` and `C` to select the rows and columns. #### title row|col \,\,\,... [\,\,\,...] Set row and column titles. The titles will be assigned sequentially if no index is specified.