This commit is contained in:
张壹 2024-12-30 22:09:39 +08:00
parent 5c726cf83a
commit 33e37c6b3e
3 changed files with 236 additions and 195 deletions

View File

@ -53,12 +53,12 @@ int main(int argc, char const *argv[]) try
geodsv_io tc; geodsv_io tc;
tc.load_text("tmp/topo", ".txt", ColumnHead); tc.load_text("tmp/topo", ".txt", ColumnHead);
tc.cell(0, 0, std::string("x (m)")); tc.cell(0, 1, std::string("x (m)"));
tc.cell(0, 1, std::string("y (m)")); tc.cell(0, 2, std::string("y (m)"));
tc.cell(0, 2, std::string("elevation (m)")); tc.cell(0, 3, std::string("elevation (m)"));
array<point3dc> topo; array<point3dc> topo;
tc.get_column_point3dc(0, 1, 2, topo); tc.get_column_point3dc(1, 2, 3, topo);
std::clog << std::setprecision(11) << topo.front().z << "\n"; std::clog << std::setprecision(11) << topo.front().z << "\n";
std::clog << topo.back().x << "," << topo.back().y << "," << topo.back().z << "\n"; std::clog << topo.back().x << "," << topo.back().y << "," << topo.back().z << "\n";
@ -66,7 +66,7 @@ int main(int argc, char const *argv[]) try
display_vector(tc.get_annotoations(), std::clog, '\n'); display_vector(tc.get_annotoations(), std::clog, '\n');
display_vector(tc.get_head_records(), std::clog, '\n'); display_vector(tc.get_head_records(), std::clog, '\n');
tc.column_output("elevation (m)", Disable); tc.column_output("C3", Disable);
_1s_vector s = tc.get_tags(); _1s_vector s = tc.get_tags();
s.push_back("Elev = 1000"); s.push_back("Elev = 1000");
@ -74,8 +74,8 @@ int main(int argc, char const *argv[]) try
tc.save_csv("out"); tc.save_csv("out");
double c = 4.25242153654; double c = 4.25242153654;
tc.cell(1, 0, c, 12); tc.cell(2, 1, c, 12);
std::clog << std::setprecision(12) << tc.cell<double>(1, 0) << "\n"; std::clog << std::setprecision(12) << tc.cell<double>(2, 1) << "\n";
tc.info(); tc.info();

View File

@ -36,7 +36,6 @@ gctl::dsv_io::dsv_io()
head_num_ = 0; head_num_ = 0;
row_num_ = 0; row_num_ = 0;
col_num_ = 0; col_num_ = 0;
thead_ = ColumnHead;
} }
gctl::dsv_io::~dsv_io() gctl::dsv_io::~dsv_io()
@ -53,7 +52,6 @@ gctl::dsv_io::dsv_io(std::string filename, std::string file_exten, table_headtyp
head_num_ = 0; head_num_ = 0;
row_num_ = 0; row_num_ = 0;
col_num_ = 0; col_num_ = 0;
thead_ = ColumnHead;
if (file_exten == ".csv") load_csv(filename, t); if (file_exten == ".csv") load_csv(filename, t);
else load_text(filename, file_exten, t); else load_text(filename, file_exten, t);
@ -68,13 +66,11 @@ void gctl::dsv_io::clear()
head_num_ = 0; head_num_ = 0;
row_num_ = 0; row_num_ = 0;
col_num_ = 0; col_num_ = 0;
thead_ = ColumnHead;
destroy_vector(heads_); destroy_vector(heads_);
destroy_vector(annotates_); destroy_vector(annotates_);
destroy_vector(tags_); destroy_vector(tags_);
destroy_vector(table_); destroy_vector(table_);
destroy_vector(bool_table_);
return; return;
} }
@ -83,6 +79,8 @@ void gctl::dsv_io::load_text(std::string filename, std::string file_exten, table
std::ifstream infile; std::ifstream infile;
open_infile(infile, filename, file_exten); open_infile(infile, filename, file_exten);
file_ = filename + file_exten;
int h = 0; int h = 0;
std::string tmp_line; std::string tmp_line;
std::vector<std::string> lines; std::vector<std::string> lines;
@ -115,20 +113,18 @@ void gctl::dsv_io::load_text(std::string filename, std::string file_exten, table
} }
infile.close(); infile.close();
// 首先初始化行数 table_.resize(lines.size());
row_num_ = lines.size();
table_.resize(row_num_);
int cn; int cn, cn_max = 0;
std::vector<std::string> tmp_cols; std::vector<std::string> tmp_cols;
for (size_t i = 0; i < row_num_; i++) for (size_t i = 0; i < lines.size(); i++)
{ {
tmp_cols.clear(); tmp_cols.clear();
parse_string_to_vector(lines[i], deli_sym_, tmp_cols); parse_string_to_vector(lines[i], deli_sym_, tmp_cols);
// 动态调整列数 // 动态调整列数
cn = tmp_cols.size(); cn = tmp_cols.size();
col_num_ = std::max(cn, col_num_); cn_max = std::max(cn, cn_max);
table_[i].resize(tmp_cols.size()); table_[i].resize(tmp_cols.size());
for (size_t j = 0; j < tmp_cols.size(); j++) for (size_t j = 0; j < tmp_cols.size(); j++)
@ -139,28 +135,56 @@ void gctl::dsv_io::load_text(std::string filename, std::string file_exten, table
// 补齐可能的空格 // 补齐可能的空格
table_cell empty_cell; table_cell empty_cell;
empty_cell.str_ = ""; for (size_t i = 0; i < table_.size(); i++)
for (size_t i = 0; i < row_num_; i++)
{ {
cn = table_[i].size(); cn = table_[i].size();
for (size_t j = cn; j < col_num_; j++) for (size_t j = cn; j < cn_max; j++)
{ {
table_[i].push_back(empty_cell); table_[i].push_back(empty_cell);
} }
} }
bool_table_.resize(row_num_); std::vector<table_cell> empty_line;
for (size_t i = 0; i < row_num_; i++) if (t == NoHead)
{ {
bool_table_[i].resize(col_num_); row_num_ = table_.size();
for (size_t j = 0; j < col_num_; j++) col_num_ = table_[0].size();
table_.emplace(table_.begin(), empty_line);
table_[0].resize(col_num_);
for (size_t i = 0; i < table_.size(); i++)
{ {
bool_table_[i][j] = true; table_[i].emplace(table_[i].begin(), empty_cell);
} }
} }
thead_ = t; if (t == ColumnHead)
file_ = filename + file_exten; {
row_num_ = table_.size() - 1;
col_num_ = table_[0].size();
for (size_t i = 0; i < table_.size(); i++)
{
table_[i].emplace(table_[i].begin(), empty_cell);
}
}
if (t == RowHead)
{
row_num_ = table_.size();
col_num_ = table_[0].size() - 1;
table_.emplace(table_.begin(), empty_line);
table_[0].resize(col_num_ + 1);
}
if (t == BothHead)
{
row_num_ = table_.size() - 1;
col_num_ = table_[0].size() - 1;
}
destroy_vector(lines); destroy_vector(lines);
return; return;
} }
@ -192,21 +216,39 @@ void gctl::dsv_io::save_text(std::string filename, std::string file_exten)
outfile << "# " << annotates_[i] << std::endl; outfile << "# " << annotates_[i] << std::endl;
} }
bool line_st; bool line_st = false;
for (int i = 0; i < row_num_; i++) 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; line_st = false;
if (bool_table_[i][0]) if (table_[i][0].out_ok_ && table_[i][0].str_ != "")
{ {
outfile << table_[i][0].str_; outfile << table_[i][0].str_;
line_st = true; line_st = true;
} }
for (size_t j = 1; j < col_num_; j++) for (int j = 1; j <= col_num_; j++)
{ {
if (line_st && bool_table_[i][j]) outfile << deli_sym_ << table_[i][j].str_; // line started if (line_st && table_[i][j].out_ok_) outfile << deli_sym_ << table_[i][j].str_; // line started
else if (bool_table_[i][j]) // line not started else if (table_[i][j].out_ok_) // line not started
{ {
outfile << table_[i][j].str_; outfile << table_[i][j].str_;
line_st = true; // start line line_st = true; // start line
@ -214,6 +256,7 @@ void gctl::dsv_io::save_text(std::string filename, std::string file_exten)
} }
outfile << std::endl; outfile << std::endl;
} }
outfile.close(); outfile.close();
return; return;
} }
@ -229,37 +272,11 @@ void gctl::dsv_io::init_table(int row, int col, table_headtype_e t)
{ {
row_num_ = row; row_num_ = row;
col_num_ = col; col_num_ = col;
thead_ = t;
table_.resize(row_num_); table_.resize(row_num_ + 1);
for (size_t i = 0; i < row_num_; i++) for (size_t i = 0; i < row_num_ + 1; i++)
{ {
table_[i].resize(col_num_); table_[i].resize(col_num_ + 1);
for (size_t j = 0; j < col_num_; j++)
{
table_[i][j].str_ = "";
}
}
if (t == RowHead || t == BothHead)
{
for (size_t i = 0; i < row_num_; i++)
{
table_[i][0].str_ = "row-" + std::to_string(i);
}
}
if (t == ColumnHead || t == BothHead)
{
for (size_t i = 0; i < col_num_; i++)
{
table_[0][i].str_ = "col-" + std::to_string(i);
}
}
if (t == BothHead)
{
table_[0][0].str_ = "row-idx";
} }
return; return;
} }
@ -283,6 +300,26 @@ void gctl::dsv_io::set_tags(const std::vector<std::string> &tags)
return; return;
} }
void gctl::dsv_io::set_row_names(const std::vector<std::string> &names)
{
for (size_t i = 1; i <= std::min(row_num_, (int) names.size()); i++)
{
table_[i][0].str_ = names[i];
}
table_[0][0].str_ = "row_name";
return;
}
void gctl::dsv_io::set_column_names(const std::vector<std::string> &names)
{
for (size_t i = 1; i <= std::min(col_num_, (int) names.size()); i++)
{
table_[0][i].str_ = names[i];
}
return;
}
void gctl::dsv_io::info() void gctl::dsv_io::info()
{ {
std::clog << "File: " << file_ << "\n------------\n"; std::clog << "File: " << file_ << "\n------------\n";
@ -291,18 +328,18 @@ void gctl::dsv_io::info()
std::clog << "Tag(s): " << tags_.size() << "\n"; std::clog << "Tag(s): " << tags_.size() << "\n";
std::clog << "------------\nColumns:\n"; std::clog << "------------\nColumns:\n";
for (size_t i = 0; i < col_num_; i++) for (size_t i = 1; i <= col_num_; i++)
{ {
if (thead_ == ColumnHead || thead_ == BothHead) if (table_[0][i].str_ != "")
{ {
std::clog << table_[0][i].str_ << ": " << table_[1][i].str_ << " -> " << table_[row_num_ - 1][i].str_; std::clog << table_[0][i].str_ << ": " << table_[1][i].str_ << " -> " << table_[row_num_][i].str_;
} }
else else
{ {
std::clog << table_[0][i].str_ << " -> " << table_[row_num_ - 1][i].str_; std::clog << "C" + std::to_string(i) << ": " << table_[1][i].str_ << " -> " << table_[row_num_][i].str_;
} }
if (!bool_table_[0][i]) std::clog << " (No output)"; if (!table_[0][i].out_ok_) std::clog << " (No output)";
std::clog << std::endl; std::clog << std::endl;
} }
std::clog << "============\n"; std::clog << "============\n";
@ -311,9 +348,25 @@ void gctl::dsv_io::info()
int gctl::dsv_io::name_index(std::string name, bool iter_row) int gctl::dsv_io::name_index(std::string name, bool iter_row)
{ {
std::smatch ret;
std::regex patr("R(\\d*)"), patc("C(\\d*)");
if (regex_search(name, ret, patr))
{
int r = atoi(std::string(ret[1]).c_str());
if (r >= 1 && r <= row_num_) return r;
else return -1;
}
if (regex_search(name, ret, patc))
{
int c = atoi(std::string(ret[1]).c_str());
if (c >= 1 && c <= col_num_) return c;
else return -1;
}
if (iter_row) if (iter_row)
{ {
for (size_t i = 0; i < row_num_; i++) for (size_t i = 1; i <= row_num_; i++)
{ {
if (table_[i][0].str_ == name) return i; if (table_[i][0].str_ == name) return i;
} }
@ -322,7 +375,7 @@ int gctl::dsv_io::name_index(std::string name, bool iter_row)
} }
else else
{ {
for (size_t i = 0; i < col_num_; i++) for (size_t i = 1; i <= col_num_; i++)
{ {
if (table_[0][i].str_ == name) return i; if (table_[0][i].str_ == name) return i;
} }
@ -333,15 +386,15 @@ int gctl::dsv_io::name_index(std::string name, bool iter_row)
void gctl::dsv_io::column_output(int idx, switch_type_e s) void gctl::dsv_io::column_output(int idx, switch_type_e s)
{ {
if (idx >= col_num_) if (idx > col_num_ || idx <= 0)
{ {
throw std::runtime_error("[gctl::dsv_io] Invalid column index."); throw std::runtime_error("[gctl::dsv_io] Invalid column index.");
} }
for (size_t i = 0; i < row_num_; i++) for (size_t i = 0; i <= row_num_; i++)
{ {
if (s == Enable) bool_table_[i][idx] = true; if (s == Enable) table_[i][idx].out_ok_ = true;
else bool_table_[i][idx] = false; else table_[i][idx].out_ok_ = false;
} }
return; return;
} }
@ -354,15 +407,15 @@ void gctl::dsv_io::column_output(std::string name, switch_type_e s)
void gctl::dsv_io::row_output(int idx, switch_type_e s) void gctl::dsv_io::row_output(int idx, switch_type_e s)
{ {
if (idx >= row_num_) if (idx > row_num_ || idx <= 0)
{ {
throw std::runtime_error("[gctl::dsv_io] Invalid row index."); throw std::runtime_error("[gctl::dsv_io] Invalid row index.");
} }
for (size_t i = 0; i < col_num_; i++) for (size_t i = 0; i <= col_num_; i++)
{ {
if (s == Enable) bool_table_[idx][i] = true; if (s == Enable) table_[idx][i].out_ok_ = true;
else bool_table_[idx][i] = false; else table_[idx][i].out_ok_ = false;
} }
return; return;
} }
@ -386,7 +439,6 @@ gctl::geodsv_io::geodsv_io(std::string filename, std::string file_exten, table_h
head_num_ = 0; head_num_ = 0;
row_num_ = 0; row_num_ = 0;
col_num_ = 0; col_num_ = 0;
thead_ = ColumnHead;
if (file_exten == ".csv") load_csv(filename, t); if (file_exten == ".csv") load_csv(filename, t);
else load_text(filename, file_exten, t); else load_text(filename, file_exten, t);
@ -394,27 +446,24 @@ gctl::geodsv_io::geodsv_io(std::string filename, std::string file_exten, table_h
void gctl::geodsv_io::fill_column_point2dc(int xid, int yid, const array<point2dc> &data, int p) void gctl::geodsv_io::fill_column_point2dc(int xid, int yid, const array<point2dc> &data, int p)
{ {
if (xid >= col_num_ || yid >= col_num_ || xid == yid) if (xid > col_num_ || yid > col_num_ || xid == yid || xid <= 0 || yid <= 0)
{ {
throw std::runtime_error("[gctl::geodsv_io] Invalid column index."); throw std::runtime_error("[gctl::geodsv_io] Invalid column index.");
} }
int st = 0;
if (thead_ == ColumnHead || thead_ == BothHead) st = 1;
std::stringstream ss; std::stringstream ss;
std::string s; std::string s;
for (size_t i = 0; i < std::min(row_num_ - st, (int) data.size()); i++) for (size_t i = 1; i <= std::min(row_num_, (int) data.size()); i++)
{ {
ss.clear(); ss.clear();
ss << data[i].x; ss << data[i - 1].x;
ss >> s; ss >> s;
table_[i + st][xid].str_ = s; table_[i][xid].str_ = s;
ss.clear(); ss.clear();
ss << data[i].y; ss << data[i - 1].y;
ss >> s; ss >> s;
table_[i + st][yid].str_ = s; table_[i][yid].str_ = s;
} }
return; return;
} }
@ -427,32 +476,30 @@ void gctl::geodsv_io::fill_column_point2dc(std::string xname, std::string yname,
void gctl::geodsv_io::fill_column_point3dc(int xid, int yid, int zid, const array<point3dc> &data, int p) void gctl::geodsv_io::fill_column_point3dc(int xid, int yid, int zid, const array<point3dc> &data, int p)
{ {
if (xid >= col_num_ || yid >= col_num_ || zid >= col_num_ || xid == yid || yid == zid || xid == zid) if (xid > col_num_ || yid > col_num_ || zid > col_num_ || xid == yid || yid == zid || xid == zid
|| xid <= 0 || yid <= 0 || zid <= 0)
{ {
throw std::runtime_error("[gctl::geodsv_io] Invalid column index."); throw std::runtime_error("[gctl::geodsv_io] Invalid column index.");
} }
int st = 0;
if (thead_ == ColumnHead || thead_ == BothHead) st = 1;
std::stringstream ss; std::stringstream ss;
std::string s; std::string s;
for (size_t i = 0; i < std::min(row_num_ - st, (int) data.size()); i++) for (size_t i = 1; i < std::min(row_num_, (int) data.size()); i++)
{ {
ss.clear(); ss.clear();
ss << data[i].x; ss << data[i - 1].x;
ss >> s; ss >> s;
table_[i + st][xid].str_ = s; table_[i][xid].str_ = s;
ss.clear(); ss.clear();
ss << data[i].y; ss << data[i - 1].y;
ss >> s; ss >> s;
table_[i + st][yid].str_ = s; table_[i][yid].str_ = s;
ss.clear(); ss.clear();
ss << data[i].z; ss << data[i - 1].z;
ss >> s; ss >> s;
table_[i + st][zid].str_ = s; table_[i][zid].str_ = s;
} }
return; return;
} }
@ -465,19 +512,16 @@ void gctl::geodsv_io::fill_column_point3dc(std::string xname, std::string yname,
void gctl::geodsv_io::get_column_point2dc(int xid, int yid, array<point2dc> &data) void gctl::geodsv_io::get_column_point2dc(int xid, int yid, array<point2dc> &data)
{ {
if (xid >= col_num_ || yid >= col_num_ || xid == yid) if (xid > col_num_ || yid > col_num_ || xid == yid || xid <= 0 || yid <= 0)
{ {
throw std::runtime_error("[gctl::geodsv_io] Invalid column index."); throw std::runtime_error("[gctl::geodsv_io] Invalid column index.");
} }
int st = 0; data.resize(row_num_);
if (thead_ == ColumnHead || thead_ == BothHead) st = 1; for (size_t i = 1; i <= row_num_; i++)
data.resize(row_num_ - st);
for (size_t i = st; i < row_num_; i++)
{ {
data[i - st].x = table_[i][xid].value<double>(); data[i - 1].x = table_[i][xid].value<double>();
data[i - st].y = table_[i][yid].value<double>(); data[i - 1].y = table_[i][yid].value<double>();
} }
return; return;
} }
@ -490,20 +534,18 @@ void gctl::geodsv_io::get_column_point2dc(std::string xname, std::string yname,
void gctl::geodsv_io::get_column_point3dc(int xid, int yid, int zid, array<point3dc> &data) void gctl::geodsv_io::get_column_point3dc(int xid, int yid, int zid, array<point3dc> &data)
{ {
if (xid >= col_num_ || yid >= col_num_ || zid >= col_num_ || xid == yid || yid == zid || xid == zid) if (xid > col_num_ || yid > col_num_ || zid > col_num_ || xid == yid || yid == zid || xid == zid
|| xid <= 0 || yid <= 0 || zid <= 0)
{ {
throw std::runtime_error("[gctl::geodsv_io] Invalid column index."); throw std::runtime_error("[gctl::geodsv_io] Invalid column index.");
} }
int st = 0; data.resize(row_num_);
if (thead_ == ColumnHead || thead_ == BothHead) st = 1; for (size_t i = 1; i <= row_num_; i++)
data.resize(row_num_ - st);
for (size_t i = st; i < row_num_; i++)
{ {
data[i - st].x = table_[i][xid].value<double>(); data[i - 1].x = table_[i][xid].value<double>();
data[i - st].y = table_[i][yid].value<double>(); data[i - 1].y = table_[i][yid].value<double>();
data[i - st].z = table_[i][zid].value<double>(); data[i - 1].z = table_[i][zid].value<double>();
} }
return; return;
} }

View File

@ -31,12 +31,20 @@
#include "../core.h" #include "../core.h"
#include "../utility.h" #include "../utility.h"
#include "../geometry.h" #include "../geometry.h"
#include "regex.h"
namespace gctl namespace gctl
{ {
struct table_cell struct table_cell
{ {
std::string str_; std::string str_; // 单元格的内容 统一保存为字符串
bool out_ok_; // 是否可输出到文件
table_cell()
{
str_ = "";
out_ok_ = true;
}
template <typename T> T value() template <typename T> T value()
{ {
@ -86,23 +94,22 @@ namespace gctl
* 2. '#!' * 2. '#!'
* 3. n行头信息 * 3. n行头信息
* 4. row*col大小的表格 * 4. row*col大小的表格
* 5. * 5.
* * 6. 使R<id>C<id>
*/ */
class dsv_io class dsv_io
{ {
protected: protected:
// 文件名
std::string file_; std::string file_;
table_headtype_e thead_; // 头信息行数 表格行数(不包括表头) 表格列数(不包括表头)
// 头信息行数 表格行数 表格列数
int head_num_, row_num_, col_num_; int head_num_, row_num_, col_num_;
// 注释行起始符 标记行起始符 分割符 // 注释行起始符 标记行起始符 分割符
char att_sym_, tag_sym_, deli_sym_; char att_sym_, tag_sym_, deli_sym_;
// 头信息行 注释行 标记行 // 头信息行 注释行 标记行
std::vector<std::string> heads_, annotates_, tags_; std::vector<std::string> heads_, annotates_, tags_;
// 内容表格 // 内容表格大小为row_num_+1 * col_num_+1
std::vector<std::vector<table_cell> > table_; std::vector<std::vector<table_cell> > table_;
std::vector<std::vector<bool> > bool_table_;
public: public:
/** /**
@ -122,6 +129,7 @@ namespace gctl
* *
* @param filename * @param filename
* @param file_exten * @param file_exten
* @param t
*/ */
dsv_io(std::string filename, std::string file_exten = ".txt", table_headtype_e t = NoHead); dsv_io(std::string filename, std::string file_exten = ".txt", table_headtype_e t = NoHead);
@ -161,14 +169,14 @@ namespace gctl
int head_number(){return head_num_;} int head_number(){return head_num_;}
/** /**
* @brief * @brief
* *
* @return * @return
*/ */
int row_number(){return row_num_;} int row_number(){return row_num_;}
/** /**
* @brief * @brief
* *
* @return * @return
*/ */
@ -216,6 +224,20 @@ namespace gctl
*/ */
void set_tags(const std::vector<std::string> &tags); void set_tags(const std::vector<std::string> &tags);
/**
* @brief
*
* @param names
*/
void set_row_names(const std::vector<std::string> &names);
/**
* @brief
*
* @param names
*/
void set_column_names(const std::vector<std::string> &names);
/** /**
* @brief * @brief
* *
@ -227,6 +249,7 @@ namespace gctl
* *
* @param filename * @param filename
* @param file_exten * @param file_exten
* @param t
*/ */
void load_text(std::string filename, std::string file_exten = ".txt", table_headtype_e t = NoHead); void load_text(std::string filename, std::string file_exten = ".txt", table_headtype_e t = NoHead);
@ -255,8 +278,8 @@ namespace gctl
/** /**
* @brief * @brief
* *
* @param row * @param row
* @param col * @param col
*/ */
void init_table(int row, int col, table_headtype_e t = ColumnHead); void init_table(int row, int col, table_headtype_e t = ColumnHead);
@ -269,16 +292,16 @@ namespace gctl
/** /**
* @brief name的行或列的索引 * @brief name的行或列的索引
* *
* @param name * @param name R<id>C<id>
* @param iter_row * @param iter_row
* @return * @return 1
*/ */
int name_index(std::string name, bool iter_row = false); int name_index(std::string name, bool iter_row = false);
/** /**
* @brief 使 * @brief 使
* *
* @param idx * @param idx 1
* @param s * @param s
*/ */
void column_output(int idx, switch_type_e s = Disable); void column_output(int idx, switch_type_e s = Disable);
@ -294,7 +317,7 @@ namespace gctl
/** /**
* @brief 使 * @brief 使
* *
* @param idx * @param idx 1
* @param s * @param s
*/ */
void row_output(int idx, switch_type_e s = Disable); void row_output(int idx, switch_type_e s = Disable);
@ -311,7 +334,7 @@ namespace gctl
* @brief * @brief
* *
* @tparam T * @tparam T
* @param data * @param data
* @param p * @param p
*/ */
template <typename T> void fill_table(const matrix<T> &data, int p = 6); template <typename T> void fill_table(const matrix<T> &data, int p = 6);
@ -328,7 +351,7 @@ namespace gctl
* @brief * @brief
* *
* @tparam T * @tparam T
* @param idx * @param idx 1
* @param data * @param data
* @param p * @param p
*/ */
@ -348,7 +371,7 @@ namespace gctl
* @brief * @brief
* *
* @tparam T * @tparam T
* @param idx * @param idx 1
* @param data * @param data
* @param p * @param p
*/ */
@ -368,7 +391,7 @@ namespace gctl
* @brief * @brief
* *
* @tparam T * @tparam T
* @param idx * @param idx 1
* @param data * @param data
*/ */
template <typename T> void get_column(int idx, array<T> &data); template <typename T> void get_column(int idx, array<T> &data);
@ -386,7 +409,7 @@ namespace gctl
* @brief * @brief
* *
* @tparam T * @tparam T
* @param idx * @param idx 1
* @param data * @param data
*/ */
template <typename T> void get_row(int idx, array<T> &data); template <typename T> void get_row(int idx, array<T> &data);
@ -404,8 +427,8 @@ namespace gctl
* @brief * @brief
* *
* @tparam T * @tparam T
* @param r * @param r 0
* @param c * @param c 0
* @return T * @return T
*/ */
template <typename T> T cell(int r, int c){return table_[r][c].value<T>();} template <typename T> T cell(int r, int c){return table_[r][c].value<T>();}
@ -414,8 +437,8 @@ namespace gctl
* @brief * @brief
* *
* @tparam T * @tparam T
* @param r * @param r 0
* @param c * @param c 0
* @param d * @param d
* @param p * @param p
*/ */
@ -425,17 +448,11 @@ namespace gctl
template <typename T> template <typename T>
void dsv_io::fill_table(const matrix<T> &data, int p) void dsv_io::fill_table(const matrix<T> &data, int p)
{ {
int st = 0; for (size_t i = 1; i <= std::min(row_num_, (int) data.row_size()); i++)
if (thead_ == ColumnHead || thead_ == BothHead) st = 1;
int ft = 0;
if (thead_ == RowHead || thead_ == BothHead) ft = 1;
for (size_t i = 0; i < std::min(row_num_ - st, (int) data.row_size()); i++)
{ {
for (size_t j = 0; j < std::min(col_num_ - ft, (int) data.col_size()); j++) for (size_t j = 1; j <= std::min(col_num_, (int) data.col_size()); j++)
{ {
table_[i + st][j + ft].value(data[i][j], p); table_[i][j].value(data[i - 1][j - 1], p);
} }
} }
return; return;
@ -444,18 +461,12 @@ namespace gctl
template <typename T> template <typename T>
void dsv_io::get_table(matrix<T> &data) void dsv_io::get_table(matrix<T> &data)
{ {
int st = 0; data.resize(row_num_, col_num_);
if (thead_ == ColumnHead || thead_ == BothHead) st = 1; for (size_t i = 1; i <= row_num_; i++)
int ft = 0;
if (thead_ == RowHead || thead_ == BothHead) ft = 1;
data.resize(row_num_ - st, col_num_ - ft);
for (size_t i = st; i < row_num_; i++)
{ {
for (size_t j = ft; j < col_num_; j++) for (size_t j = 1; j <= col_num_; j++)
{ {
data[i - st][j - ft] = table_[i][j].value<T>(); data[i -1][j - 1] = table_[i][j].value<T>();
} }
} }
return; return;
@ -464,17 +475,14 @@ namespace gctl
template <typename T> template <typename T>
void dsv_io::fill_column(int idx, const array<T> &data, int p) void dsv_io::fill_column(int idx, const array<T> &data, int p)
{ {
if (idx >= col_num_ || idx < 0) if (idx > col_num_ || idx <= 0)
{ {
throw std::runtime_error("[gctl::dsv_io] Invalid column index."); throw std::runtime_error("[gctl::dsv_io] Invalid column index.");
} }
int st = 0; for (size_t i = 1; i <= std::min(row_num_, (int) data.size()); i++)
if (thead_ == ColumnHead || thead_ == BothHead) st = 1;
for (size_t i = 0; i < std::min(row_num_ - st, (int) data.size()); i++)
{ {
table_[i + st][idx].value(data[i], p); table_[i][idx].value(data[i - 1], p);
} }
return; return;
} }
@ -489,17 +497,14 @@ namespace gctl
template <typename T> template <typename T>
void dsv_io::fill_row(int idx, const array<T> &data, int p) void dsv_io::fill_row(int idx, const array<T> &data, int p)
{ {
if (idx >= row_num_ || idx < 0) if (idx > row_num_ || idx <= 0)
{ {
throw std::runtime_error("[gctl::dsv_io] Invalid row index."); throw std::runtime_error("[gctl::dsv_io] Invalid row index.");
} }
int st = 0; for (size_t i = 1; i <= std::min(col_num_, (int) data.size()); i++)
if (thead_ == RowHead || thead_ == BothHead) st = 1;
for (size_t i = 0; i < std::min(col_num_ - st, (int) data.size()); i++)
{ {
table_[idx][i + st].value(data[i], p); table_[idx][i].value(data[i - 1], p);
} }
return; return;
} }
@ -514,18 +519,15 @@ namespace gctl
template <typename T> template <typename T>
void dsv_io::get_column(int idx, array<T> &data) void dsv_io::get_column(int idx, array<T> &data)
{ {
if (idx >= col_num_ || idx < 0) if (idx > col_num_ || idx <= 0)
{ {
throw std::runtime_error("[gctl::dsv_io] Invalid column index."); throw std::runtime_error("[gctl::dsv_io] Invalid column index.");
} }
int st = 0; data.resize(row_num_);
if (thead_ == ColumnHead || thead_ == BothHead) st = 1; for (size_t i = 1; i <= row_num_; i++)
data.resize(row_num_ - st);
for (size_t i = st; i < row_num_; i++)
{ {
data[i - st] = table_[i][idx].value<T>(); data[i - 1] = table_[i][idx].value<T>();
} }
return; return;
} }
@ -540,18 +542,15 @@ namespace gctl
template <typename T> template <typename T>
void dsv_io::get_row(int idx, array<T> &data) void dsv_io::get_row(int idx, array<T> &data)
{ {
if (idx >= row_num_ || idx < 0) if (idx > row_num_ || idx <= 0)
{ {
throw std::runtime_error("[gctl::dsv_io] Invalid row index."); throw std::runtime_error("[gctl::dsv_io] Invalid row index.");
} }
int st = 0; data.resize(col_num_);
if (thead_ == RowHead || thead_ == BothHead) st = 1; for (size_t i = 1; i <= col_num_; i++)
data.resize(col_num_ - st);
for (size_t i = st; i < col_num_; i++)
{ {
data[i - st] = table_[idx][i].value<T>(); data[i - 1] = table_[idx][i].value<T>();
} }
return; return;
} }
@ -593,8 +592,8 @@ namespace gctl
/** /**
* @brief * @brief
* *
* @param xid x坐标列索引 * @param xid x坐标列索引 1
* @param yid y坐标列索引 * @param yid y坐标列索引 1
* @param data * @param data
* @param p * @param p
*/ */
@ -613,9 +612,9 @@ namespace gctl
/** /**
* @brief * @brief
* *
* @param xid x坐标列索引 * @param xid x坐标列索引 1
* @param yid y坐标列索引 * @param yid y坐标列索引 1
* @param zid z坐标列索引 * @param zid z坐标列索引 1
* @param data * @param data
* @param p * @param p
*/ */
@ -635,8 +634,8 @@ namespace gctl
/** /**
* @brief * @brief
* *
* @param xid x坐标列索引 * @param xid x坐标列索引 1
* @param yid y坐标列索引 * @param yid y坐标列索引 1
* @param data * @param data
*/ */
void get_column_point2dc(int xid, int yid, array<point2dc> &data); void get_column_point2dc(int xid, int yid, array<point2dc> &data);
@ -653,9 +652,9 @@ namespace gctl
/** /**
* @brief * @brief
* *
* @param xid x坐标列索引 * @param xid x坐标列索引 1
* @param yid y坐标列索引 * @param yid y坐标列索引 1
* @param zid z坐标列索引 * @param zid z坐标列索引 1
* @param data * @param data
*/ */
void get_column_point3dc(int xid, int yid, int zid, array<point3dc> &data); void get_column_point3dc(int xid, int yid, int zid, array<point3dc> &data);