aboutsummaryrefslogtreecommitdiff
path: root/core/src/Model
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-06-21 18:30:38 -0700
committerrtk0c <[email protected]>2021-06-21 18:30:38 -0700
commit43cd2bd879d529fcbd0a0f64eccd4ce1eb872ab4 (patch)
tree12e7bcbd08a30f76d83bd1bc8943133f3d5d51b9 /core/src/Model
parent4378dcd83d2387534f3b10276365d1003832fe81 (diff)
Implement array group conversion logic
Diffstat (limited to 'core/src/Model')
-rw-r--r--core/src/Model/Template/TableTemplate.cpp65
-rw-r--r--core/src/Model/Template/TableTemplate.hpp3
2 files changed, 59 insertions, 9 deletions
diff --git a/core/src/Model/Template/TableTemplate.cpp b/core/src/Model/Template/TableTemplate.cpp
index 88980ae..e01af02 100644
--- a/core/src/Model/Template/TableTemplate.cpp
+++ b/core/src/Model/Template/TableTemplate.cpp
@@ -1,6 +1,7 @@
#include "TableTemplate.hpp"
#include <xlsxwriter.h>
+#include <charconv>
#include <iostream>
#include <map>
@@ -153,18 +154,50 @@ void TableTemplate::SetCellType(Vec2i pos, TableCell::CellType type)
return;
}
- switch (type) {
- case TableCell::ConstantCell: {
- // TODO
+ switch (cell.Type) {
+ // Nothing to change
+ case TableCell::ConstantCell: break;
+
+ case TableCell::SingularParametricCell:
+ mName2Parameters.erase(cell.Content);
+ break;
+
+ case TableCell::ArrayParametricCell: {
+ auto& ag = mArrayGroups[cell.DataId];
+ if (cell.Location.x == ag.LeftCell) {
+
+ } else if (cell.Location.x == ag.RightCell) {
+
+ } else {
+ }
} break;
+ }
+
+ switch (type) {
+ // Nothing to do
+ case TableCell::ConstantCell: break;
case TableCell::SingularParametricCell: {
- cell.Type = type;
+ int idx = pos.y * GetTableWidth() + pos.x;
+ auto [DISCARD, inserted] = mName2Parameters.emplace(cell.Content, idx);
+
+ // Duplicate name
+ if (!inserted) {
+ return;
+ }
} break;
- // Setting the cell to be a part of a group requires calling the overload that supplies the group
- case TableCell::ArrayParametricCell: break;
+ case TableCell::ArrayParametricCell: {
+ auto ptr = AddArrayGroup(pos.y, pos.x, pos.x);
+
+ // Duplicate name
+ if (ptr == nullptr) {
+ return;
+ }
+ } break;
}
+
+ cell.Type = type;
}
int TableTemplate::GetArrayGroupCount() const
@@ -182,7 +215,18 @@ TableCellArrayGroup& TableTemplate::GetArrayGroup(int id)
return mArrayGroups[id];
}
-TableCellArrayGroup& TableTemplate::AddArrayGroup(int row, int left, int right)
+TableCellArrayGroup* TableTemplate::AddArrayGroup(int row, int left, int right)
+{
+ // size_t max value: 18446744073709551615
+ // ^~~~~~~~~~~~~~~~~~~~ 20 chars
+ char name[20];
+ auto res = std::to_chars(std::begin(name), std::end(name), mArrayGroups.size());
+ std::string_view nameStr(name, res.ptr - name);
+
+ return AddArrayGroup(nameStr, row, left, right);
+}
+
+TableCellArrayGroup* TableTemplate::AddArrayGroup(std::string_view name, int row, int left, int right)
{
assert(row >= 0 && row < GetTableHeight());
assert(left >= 0 && left < GetTableWidth());
@@ -194,12 +238,17 @@ TableCellArrayGroup& TableTemplate::AddArrayGroup(int row, int left, int right)
std::swap(left, right);
}
+ auto [DISCARD, inserted] = mName2ArrayGroups.emplace(name, (int)mArrayGroups.size());
+ if (!inserted) {
+ return nullptr;
+ }
+
mArrayGroups.push_back(TableCellArrayGroup{
.Row = row,
.LeftCell = left,
.RightCell = right,
});
- return mArrayGroups.back();
+ return &mArrayGroups.back();
}
bool TableTemplate::ExtendArrayGroupLeft(int id, int n)
diff --git a/core/src/Model/Template/TableTemplate.hpp b/core/src/Model/Template/TableTemplate.hpp
index 754ebe1..7f331fa 100644
--- a/core/src/Model/Template/TableTemplate.hpp
+++ b/core/src/Model/Template/TableTemplate.hpp
@@ -167,7 +167,8 @@ public:
int GetArrayGroupCount() const;
const TableCellArrayGroup& GetArrayGroup(int id) const;
TableCellArrayGroup& GetArrayGroup(int id);
- TableCellArrayGroup& AddArrayGroup(int row, int left, int right);
+ TableCellArrayGroup* AddArrayGroup(int row, int left, int right);
+ TableCellArrayGroup* AddArrayGroup(std::string_view name, int row, int left, int right);
bool ExtendArrayGroupLeft(int id, int n);
bool ExtendArrayGroupRight(int id, int n);