This commit is contained in:
张壹 2025-02-14 09:45:57 +08:00
parent 908fa45d1b
commit 10c884b155
4 changed files with 89 additions and 46 deletions

View File

@ -427,96 +427,117 @@ gctl::dsv_io gctl::dsv_io::export_table(bool ignore_disabled)
return out_table;
}
void gctl::dsv_io::info(int t)
void gctl::dsv_io::info(int t, std::ostream &os)
{
if (t & HeadInfo)
{
std::clog << "Head(s): " << head_num_ << "\n";
os << "Head(s): " << head_num_ << "\n";
for (size_t i = 0; i < heads_.size(); i++)
{
std::clog << heads_[i] << "\n";
os << heads_[i] << "\n";
}
std::clog << "------------\n";
os << "------------\n";
}
if (t & AttInfo)
{
std::clog << "Annotation(s): " << annotates_.size() << "\n";
os << "Annotation(s): " << annotates_.size() << "\n";
for (size_t i = 0; i < annotates_.size(); i++)
{
std::clog << annotates_[i] << "\n";
os << annotates_[i] << "\n";
}
std::clog << "------------\n";
os << "------------\n";
}
if (t & TagInfo)
{
std::clog << "Tag(s): " << tags_.size() << "\n";
os << "Tag(s): " << tags_.size() << "\n";
for (size_t i = 0; i < tags_.size(); i++)
{
std::clog << tags_[i] << "\n";
os << tags_[i] << "\n";
}
std::clog << "------------\n";
os << "------------\n";
}
if (t & ColInfo)
{
std::clog << "Columns:\n";
os << "Columns:\n";
for (size_t i = 1; i <= col_num_; i++)
{
if (table_[0][i].str_ != "")
{
std::clog << table_[0][i].str_ << " | ";
if (table_[0][i].out_ok_) std::clog << "Enabled | ";
else std::clog << "Disabled | ";
if (table_[1][i].type_ == String) std::clog << "String | ";
if (table_[1][i].type_ == Int) std::clog << "Int | ";
if (table_[1][i].type_ == Float) std::clog << "Float | ";
std::clog << table_[1][i].str_ << " -> " << table_[row_num_][i].str_;
os << table_[0][i].str_ << " | ";
if (table_[0][i].out_ok_) os << "Enabled | ";
else os << "Disabled | ";
if (table_[1][i].type_ == String) os << "String | ";
if (table_[1][i].type_ == Int) os << "Int | ";
if (table_[1][i].type_ == Float) os << "Float | ";
os << table_[1][i].str_ << " -> " << table_[row_num_][i].str_;
}
else
{
std::clog << "C" + std::to_string(i) << " | ";
if (table_[0][i].out_ok_) std::clog << "Enabled | ";
else std::clog << "Disabled | ";
if (table_[1][i].type_ == String) std::clog << "String | ";
if (table_[1][i].type_ == Int) std::clog << "Int | ";
if (table_[1][i].type_ == Float) std::clog << "Float | ";
std::clog << table_[1][i].str_ << " -> " << table_[row_num_][i].str_;
os << "C" + std::to_string(i) << " | ";
if (table_[0][i].out_ok_) os << "Enabled | ";
else os << "Disabled | ";
if (table_[1][i].type_ == String) os << "String | ";
if (table_[1][i].type_ == Int) os << "Int | ";
if (table_[1][i].type_ == Float) os << "Float | ";
os << table_[1][i].str_ << " -> " << table_[row_num_][i].str_;
}
std::clog << std::endl;
os << std::endl;
}
std::clog << "------------\n";
os << "------------\n";
}
if (t & RowInfo)
{
std::clog << "Rows:\n";
os << "Rows:\n";
for (size_t i = 1; i <= row_num_; i++)
{
if (table_[i][0].str_ != "")
{
std::clog << table_[i][0].str_ << " | ";
if (table_[i][0].out_ok_) std::clog << "Enabled | ";
else std::clog << "Disabled | ";
if (table_[i][1].type_ == String) std::clog << "String | ";
if (table_[i][1].type_ == Int) std::clog << "Int | ";
if (table_[i][1].type_ == Float) std::clog << "Float | ";
std::clog << table_[i][1].str_ << " -> " << table_[i][col_num_].str_;
os << table_[i][0].str_ << " | ";
if (table_[i][0].out_ok_) os << "Enabled | ";
else os << "Disabled | ";
if (table_[i][1].type_ == String) os << "String | ";
if (table_[i][1].type_ == Int) os << "Int | ";
if (table_[i][1].type_ == Float) os << "Float | ";
os << table_[i][1].str_ << " -> " << table_[i][col_num_].str_;
}
else
{
std::clog << "R" + std::to_string(i) << " | ";
if (table_[i][0].out_ok_) std::clog << "Enabled | ";
else std::clog << "Disabled | ";
if (table_[i][1].type_ == String) std::clog << "String | ";
if (table_[i][1].type_ == Int) std::clog << "Int | ";
if (table_[i][1].type_ == Float) std::clog << "Float | ";
std::clog << table_[i][1].str_ << " -> " << table_[i][col_num_].str_;
os << "R" + std::to_string(i) << " | ";
if (table_[i][0].out_ok_) os << "Enabled | ";
else os << "Disabled | ";
if (table_[i][1].type_ == String) os << "String | ";
if (table_[i][1].type_ == Int) os << "Int | ";
if (table_[i][1].type_ == Float) os << "Float | ";
os << table_[i][1].str_ << " -> " << table_[i][col_num_].str_;
}
os << std::endl;
}
os << "------------\n";
}
return;
}
void gctl::dsv_io::display(std::ostream &os)
{
for (int i = 0; i <= row_num_; i++)
{
for (size_t j = 0; j <= col_num_; j++)
{
if (table_[i][j].out_ok_ && table_[i][j].str_!= "")
{
os << table_[i][j].str_;
for (size_t k = j + 1; k <= col_num_; k++)
{
if (table_[i][k].out_ok_) os << deli_sym_ << table_[i][k].str_;
}
os << std::endl;
break;
}
std::clog << std::endl;
}
std::clog << "------------\n";
}
return;
}

View File

@ -435,7 +435,14 @@ namespace gctl
*
* @param t
*/
void info(int t);
void info(int t, std::ostream &os = std::cout);
/**
* @brief
*
* @param os
*/
void display(std::ostream &os = std::cout);
/**
* @brief name和R<id>C<id>

View File

@ -242,6 +242,9 @@ void head(const std::vector<std::string> &cmd_units)
if (cmd_units.size() > 1) h = atoi(cmd_units[1].c_str());
if (h <= 0) throw std::runtime_error("head: invalid number.");
_1s_vector cnames = tc.column_names();
display_vector(cnames, std::cout, tc.delimeter());
_1s_array line;
for (size_t i = 1; i <= h; i++)
{
@ -258,6 +261,9 @@ void tail(const std::vector<std::string> &cmd_units)
if (cmd_units.size() > 1) h = atoi(cmd_units[1].c_str());
if (h <= 0) throw std::runtime_error("tail: invalid number.");
_1s_vector cnames = tc.column_names();
display_vector(cnames, std::cout, tc.delimeter());
_1s_array line;
for (size_t i = tc.row_number() - h + 1; i <= tc.row_number(); i++)
{
@ -521,6 +527,13 @@ void insert_data(const std::vector<std::string> &cmd_units)
return;
}
void display_table(const std::vector<std::string> &cmd_units)
{
// view
tc.display();
return;
}
int main(int argc, char *argv[])
{
if (argc >= 2)

View File

@ -59,10 +59,12 @@ void math_func(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 insert_data(const std::vector<std::string> &cmd_units);
void display_table(const std::vector<std::string> &cmd_units);
#define CMD_NUM 16
#define CMD_NUM 17
const cmd_pair commands[CMD_NUM] = {
{"quit", quit, "Quit the program."},
{"view", display_table, "Display valid cells."},
{"info", info, "Show the table information."},
{"head", head, "Show head line(s) of the table."},
{"tail", tail, "Show tail line(s) of the table."},