add type to dsv_io

This commit is contained in:
张壹 2025-02-13 10:31:15 +08:00
parent fe46cc7aa0
commit 12e15b869b
3 changed files with 28 additions and 1 deletions

View File

@ -389,6 +389,28 @@ void statistic(const std::vector<std::string> &cmd_units)
return; return;
} }
void set_type(const std::vector<std::string> &cmd_units)
{
// type row|col int|float|string <name>
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<std::string> &cmd_units) void set_titles(const std::vector<std::string> &cmd_units)
{ {
// title <row|col> <t1>,<t2>,<t3>,... [<id1>,<id2>,<id3>,...] // title <row|col> <t1>,<t2>,<t3>,... [<id1>,<id2>,<id3>,...]

View File

@ -53,12 +53,13 @@ void save_file(const std::vector<std::string> &cmd_units);
void statistic(const std::vector<std::string> &cmd_units); void statistic(const std::vector<std::string> &cmd_units);
void set_enable(const std::vector<std::string> &cmd_units); void set_enable(const std::vector<std::string> &cmd_units);
void set_disable(const std::vector<std::string> &cmd_units); void set_disable(const std::vector<std::string> &cmd_units);
void set_type(const std::vector<std::string> &cmd_units);
void set_titles(const std::vector<std::string> &cmd_units); void set_titles(const std::vector<std::string> &cmd_units);
void math_func(const std::vector<std::string> &cmd_units); void math_func(const std::vector<std::string> &cmd_units);
void rand_data(const std::vector<std::string> &cmd_units); void rand_data(const std::vector<std::string> &cmd_units);
void filt_data(const std::vector<std::string> &cmd_units); void filt_data(const std::vector<std::string> &cmd_units);
#define CMD_NUM 14 #define CMD_NUM 15
const cmd_pair commands[CMD_NUM] = { const cmd_pair commands[CMD_NUM] = {
{"quit", quit, "Quit the program."}, {"quit", quit, "Quit the program."},
{"info", info, "Show the table information."}, {"info", info, "Show the table information."},
@ -69,6 +70,7 @@ const cmd_pair commands[CMD_NUM] = {
{"stats", statistic, "Calculate statistics of the selected columns."}, {"stats", statistic, "Calculate statistics of the selected columns."},
{"enable", set_enable, "Enable column/row outputs by name or index."}, {"enable", set_enable, "Enable column/row outputs by name or index."},
{"disable", set_disable, "Disable 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."}, {"title", set_titles, "Set row and column titles."},
{"math", math_func, "Preform mathematic operations of column data."}, {"math", math_func, "Preform mathematic operations of column data."},
{"random", rand_data, "Generate random column data."}, {"random", rand_data, "Generate random column data."},

View File

@ -25,6 +25,9 @@ Enable table outputs. If the input file has no row or column names, use inbuild
#### disable column|row \<name1\> \<name2\> ... #### disable column|row \<name1\> \<name2\> ...
Disable table outputs. If the input file has no row or column names, use inbuild names `R<id>` and `C<id>` to select the rows and columns. Disable table outputs. If the input file has no row or column names, use inbuild names `R<id>` and `C<id>` to select the rows and columns.
#### type row|col int|float|string \<name\>
Set the data type of a row or column. If the input file has no row or column names, use inbuild names `R<id>` and `C<id>` to select the rows and columns.
#### title row|col \<t1\>,\<t2\>,\<t3\>,... [\<id1\>,\<id2\>,\<id3\>,...] #### title row|col \<t1\>,\<t2\>,\<t3\>,... [\<id1\>,\<id2\>,\<id3\>,...]
Set row and column titles. The titles will be assigned sequentially if no index is specified. Set row and column titles. The titles will be assigned sequentially if no index is specified.