diff options
Diffstat (limited to 'core/src/Model')
-rw-r--r-- | core/src/Model/Template/TableTemplate.cpp | 25 | ||||
-rw-r--r-- | core/src/Model/Template/TableTemplate.hpp | 19 | ||||
-rw-r--r-- | core/src/Model/Template/TableTemplateIterator.cpp | 52 | ||||
-rw-r--r-- | core/src/Model/Template/TableTemplateIterator.hpp | 35 | ||||
-rw-r--r-- | core/src/Model/Template/fwd.hpp | 2 |
5 files changed, 112 insertions, 21 deletions
diff --git a/core/src/Model/Template/TableTemplate.cpp b/core/src/Model/Template/TableTemplate.cpp index e01af02..6c3d86b 100644 --- a/core/src/Model/Template/TableTemplate.cpp +++ b/core/src/Model/Template/TableTemplate.cpp @@ -20,22 +20,22 @@ bool TableCell::IsMergedCell() const return PrimaryCellLocation.x == -1 || PrimaryCellLocation.y == -1; } -Vec2i TableCellArrayGroup::GetLeftCell() const +Vec2i TableArrayGroup::GetLeftCell() const { return { Row, LeftCell }; } -Vec2i TableCellArrayGroup::GetRightCell() const +Vec2i TableArrayGroup::GetRightCell() const { return { Row, RightCell }; } -int TableCellArrayGroup::GetCount() const +int TableArrayGroup::GetCount() const { return RightCell - LeftCell + 1; } -Vec2i TableCellArrayGroup::FindCell(std::string_view name) +Vec2i TableArrayGroup::FindCell(std::string_view name) { } @@ -165,10 +165,11 @@ void TableTemplate::SetCellType(Vec2i pos, TableCell::CellType type) case TableCell::ArrayParametricCell: { auto& ag = mArrayGroups[cell.DataId]; if (cell.Location.x == ag.LeftCell) { - + ag.LeftCell++; } else if (cell.Location.x == ag.RightCell) { - + ag.RightCell--; } else { + } } break; } @@ -205,17 +206,17 @@ int TableTemplate::GetArrayGroupCount() const return mArrayGroups.size(); } -const TableCellArrayGroup& TableTemplate::GetArrayGroup(int id) const +const TableArrayGroup& TableTemplate::GetArrayGroup(int id) const { return mArrayGroups[id]; } -TableCellArrayGroup& TableTemplate::GetArrayGroup(int id) +TableArrayGroup& TableTemplate::GetArrayGroup(int id) { return mArrayGroups[id]; } -TableCellArrayGroup* TableTemplate::AddArrayGroup(int row, int left, int right) +TableArrayGroup* TableTemplate::AddArrayGroup(int row, int left, int right) { // size_t max value: 18446744073709551615 // ^~~~~~~~~~~~~~~~~~~~ 20 chars @@ -226,7 +227,7 @@ TableCellArrayGroup* TableTemplate::AddArrayGroup(int row, int left, int right) return AddArrayGroup(nameStr, row, left, right); } -TableCellArrayGroup* TableTemplate::AddArrayGroup(std::string_view name, int row, int left, int right) +TableArrayGroup* TableTemplate::AddArrayGroup(std::string_view name, int row, int left, int right) { assert(row >= 0 && row < GetTableHeight()); assert(left >= 0 && left < GetTableWidth()); @@ -243,7 +244,7 @@ TableCellArrayGroup* TableTemplate::AddArrayGroup(std::string_view name, int row return nullptr; } - mArrayGroups.push_back(TableCellArrayGroup{ + mArrayGroups.push_back(TableArrayGroup{ .Row = row, .LeftCell = left, .RightCell = right, @@ -281,7 +282,7 @@ TableCell* TableTemplate::FindCell(std::string_view name) } } -TableCellArrayGroup* TableTemplate::FindArrayGroup(std::string_view name) +TableArrayGroup* TableTemplate::FindArrayGroup(std::string_view name) { auto iter = mName2ArrayGroups.find(name); if (iter != mName2ArrayGroups.end()) { diff --git a/core/src/Model/Template/TableTemplate.hpp b/core/src/Model/Template/TableTemplate.hpp index 7f331fa..a9a89d4 100644 --- a/core/src/Model/Template/TableTemplate.hpp +++ b/core/src/Model/Template/TableTemplate.hpp @@ -84,7 +84,7 @@ public: /// \see TableCell /// \see TableInstantiationParameters /// \see TableTemplate -class TableCellArrayGroup +class TableArrayGroup { public: /// Parameter name mapped to cell location (index from LeftCell). @@ -108,7 +108,7 @@ public: struct lxw_workbook; struct lxw_worksheet; -/// An object containing the necessary information to instanciate a table template. +/// An object containing the necessary information to instantiate a table template. /// \see TableTemplate class TableInstantiationParameters { @@ -137,13 +137,16 @@ public: /// This current supports exporting to xlsx files. class TableTemplate : public Template { + friend class TableSingleParamsIter; + friend class TableArrayGroupsIter; + private: /// Map from parameter name to index of the parameter cell (stored in mCells). tsl::array_map<char, int> mName2Parameters; /// Map from array group name to the index of the array group (stored in mArrayGroups). tsl::array_map<char, int> mName2ArrayGroups; std::vector<TableCell> mCells; - std::vector<TableCellArrayGroup> mArrayGroups; + std::vector<TableArrayGroup> mArrayGroups; std::vector<int> mRowHeights; std::vector<int> mColumnWidths; @@ -165,10 +168,10 @@ public: void SetCellType(Vec2i pos, TableCell::CellType type); int GetArrayGroupCount() const; - const TableCellArrayGroup& GetArrayGroup(int id) const; - TableCellArrayGroup& GetArrayGroup(int id); - TableCellArrayGroup* AddArrayGroup(int row, int left, int right); - TableCellArrayGroup* AddArrayGroup(std::string_view name, int row, int left, int right); + const TableArrayGroup& GetArrayGroup(int id) const; + TableArrayGroup& GetArrayGroup(int id); + TableArrayGroup* AddArrayGroup(int row, int left, int right); + TableArrayGroup* AddArrayGroup(std::string_view name, int row, int left, int right); bool ExtendArrayGroupLeft(int id, int n); bool ExtendArrayGroupRight(int id, int n); @@ -176,7 +179,7 @@ public: TableCell* FindCell(std::string_view name); /// Find an array group by its name. - TableCellArrayGroup* FindArrayGroup(std::string_view name); + TableArrayGroup* FindArrayGroup(std::string_view name); enum MergeCellsResult { diff --git a/core/src/Model/Template/TableTemplateIterator.cpp b/core/src/Model/Template/TableTemplateIterator.cpp new file mode 100644 index 0000000..19e30b9 --- /dev/null +++ b/core/src/Model/Template/TableTemplateIterator.cpp @@ -0,0 +1,52 @@ +#include "TableTemplateIterator.hpp" + +TableSingleParamsIter::TableSingleParamsIter(TableTemplate& tmpl) + : mTemplate{ &tmpl } + , mIter{ tmpl.mName2Parameters.begin() } +{ +} + +bool TableSingleParamsIter::HasNext() const +{ + return mIter != mTemplate->mName2Parameters.end(); +} + +TableCell& TableSingleParamsIter::Next() +{ + int id = mIter.value(); + ++mIter; + + return mTemplate->mCells[id]; +} + +TableArrayGroupsIter::TableArrayGroupsIter(TableTemplate& tmpl) + : mTemplate{ &tmpl } + , mIter{ tmpl.mName2ArrayGroups.begin() } +{ +} + +bool TableArrayGroupsIter::HasNext() const +{ + return mIter != mTemplate->mName2ArrayGroups.end(); +} + +TableArrayGroup& TableArrayGroupsIter::Peek() const +{ + int id = mIter.value(); + return mTemplate->mArrayGroups[id]; +} + +std::string_view TableArrayGroupsIter::PeekName() const +{ + return mIter.key_sv(); +} + +const char* TableArrayGroupsIter::PeekNameCStr() const +{ + return mIter.key(); +} + +void TableArrayGroupsIter::Next() +{ + ++mIter; +} diff --git a/core/src/Model/Template/TableTemplateIterator.hpp b/core/src/Model/Template/TableTemplateIterator.hpp new file mode 100644 index 0000000..bf7f517 --- /dev/null +++ b/core/src/Model/Template/TableTemplateIterator.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include "Model/Template/TableTemplate.hpp" +#include "Model/Template/Template.hpp" + +#include <string_view> + +class TableSingleParamsIter +{ +private: + TableTemplate* mTemplate; + tsl::array_map<char, int>::iterator mIter; + +public: + TableSingleParamsIter(TableTemplate& tmpl); + + bool HasNext() const; + TableCell& Next(); +}; + +class TableArrayGroupsIter +{ +private: + TableTemplate* mTemplate; + tsl::array_map<char, int>::iterator mIter; + +public: + TableArrayGroupsIter(TableTemplate& tmpl); + + bool HasNext() const; + TableArrayGroup& Peek() const; + std::string_view PeekName() const; + const char* PeekNameCStr() const; + void Next(); +}; diff --git a/core/src/Model/Template/fwd.hpp b/core/src/Model/Template/fwd.hpp index b918755..8378871 100644 --- a/core/src/Model/Template/fwd.hpp +++ b/core/src/Model/Template/fwd.hpp @@ -2,7 +2,7 @@ // TableTemplate.hpp class TableCell; -class TableCellArrayGroup; +class TableArrayGroup; class TableInstantiationParameters; class TableTemplate; |