diff --git a/tool/dsviewer/dsviewer.cpp b/tool/dsviewer/dsviewer.cpp index d623767..1bd0917 100644 --- a/tool/dsviewer/dsviewer.cpp +++ b/tool/dsviewer/dsviewer.cpp @@ -389,6 +389,28 @@ void statistic(const std::vector &cmd_units) return; } +void set_type(const std::vector &cmd_units) +{ + // type row|col int|float|string + if (cmd_units.size() < 4) throw std::runtime_error("type: insufficient parameters."); + if (cmd_units[1] == "row") + { + if (cmd_units[2] == "int") tc.row_type(Int, cmd_units[3]); + else if (cmd_units[2] == "float") tc.row_type(Float, cmd_units[3]); + else if (cmd_units[2] == "string") tc.row_type(String, cmd_units[3]); + else throw std::runtime_error("type: invalid parameters."); + } + else if (cmd_units[1] == "col") + { + if (cmd_units[2] == "int") tc.column_type(Int, cmd_units[3]); + else if (cmd_units[2] == "float") tc.column_type(Float, cmd_units[3]); + else if (cmd_units[2] == "string") tc.column_type(String, cmd_units[3]); + else throw std::runtime_error("type: invalid parameters."); + } + else throw std::runtime_error("type: invalid parameters."); + return; +} + void set_titles(const std::vector &cmd_units) { // title ,,,... [,,,...] diff --git a/tool/dsviewer/dsviewer.h b/tool/dsviewer/dsviewer.h index 5528529..5354cfa 100644 --- a/tool/dsviewer/dsviewer.h +++ b/tool/dsviewer/dsviewer.h @@ -53,12 +53,13 @@ void save_file(const std::vector &cmd_units); void statistic(const std::vector &cmd_units); void set_enable(const std::vector &cmd_units); void set_disable(const std::vector &cmd_units); +void set_type(const std::vector &cmd_units); void set_titles(const std::vector &cmd_units); void math_func(const std::vector &cmd_units); void rand_data(const std::vector &cmd_units); void filt_data(const std::vector &cmd_units); -#define CMD_NUM 14 +#define CMD_NUM 15 const cmd_pair commands[CMD_NUM] = { {"quit", quit, "Quit the program."}, {"info", info, "Show the table information."}, @@ -69,6 +70,7 @@ const cmd_pair commands[CMD_NUM] = { {"stats", statistic, "Calculate statistics of the selected columns."}, {"enable", set_enable, "Enable column/row outputs by name or index."}, {"disable", set_disable, "Disable column/row outputs by name or index."}, + {"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."}, {"random", rand_data, "Generate random column data."}, diff --git a/tool/dsviewer/dsviewer.md b/tool/dsviewer/dsviewer.md index f76bc81..4f47c5c 100644 --- a/tool/dsviewer/dsviewer.md +++ b/tool/dsviewer/dsviewer.md @@ -25,6 +25,9 @@ Enable table outputs. If the input file has no row or column names, use inbuild #### disable 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. +#### 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. + #### title row|col \,\,\,... [\,\,\,...] Set row and column titles. The titles will be assigned sequentially if no index is specified.