summaryrefslogtreecommitdiff
path: root/core/src/Model
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-09-04 17:58:56 -0700
committerrtk0c <[email protected]>2021-09-04 17:58:56 -0700
commit70e00f817e9596a746800ba4afec2b7c4ca25142 (patch)
tree52ca5f993034c6dcb7353805450e66cefc5a0481 /core/src/Model
parent500aa5130f3f5ad211749018d7be9b0ab46c12b4 (diff)
Migrate Template and TableTemplate to use DataStream
Diffstat (limited to 'core/src/Model')
-rw-r--r--core/src/Model/Assets.cpp4
-rw-r--r--core/src/Model/Template/TableTemplate.cpp56
-rw-r--r--core/src/Model/Template/TableTemplate.hpp14
-rw-r--r--core/src/Model/Template/Template.hpp9
4 files changed, 67 insertions, 16 deletions
diff --git a/core/src/Model/Assets.cpp b/core/src/Model/Assets.cpp
index 045a46f..80c2fa4 100644
--- a/core/src/Model/Assets.cpp
+++ b/core/src/Model/Assets.cpp
@@ -19,8 +19,8 @@ namespace fs = std::filesystem;
template <class TProxy>
void SavedAsset::OperateIOProxy(TProxy& proxy)
{
- proxy.ObjectAdapted(Name, DataStreamAdapters::String{});
- proxy.ObjectAdapted(Uuid, DataStreamAdapters::Uuid{});
+ proxy.template ObjectAdapted<DataStreamAdapters::String>(Name);
+ proxy.template ObjectAdapted<DataStreamAdapters::Uuid>(Uuid);
proxy.Value(Payload);
}
diff --git a/core/src/Model/Template/TableTemplate.cpp b/core/src/Model/Template/TableTemplate.cpp
index adf79fe..a5745c7 100644
--- a/core/src/Model/Template/TableTemplate.cpp
+++ b/core/src/Model/Template/TableTemplate.cpp
@@ -1,7 +1,14 @@
#include "TableTemplate.hpp"
+#include "Utils/IO/StringIntegration.hpp"
+#include "Utils/IO/TslArrayIntegration.hpp"
+#include "Utils/IO/VectorIntegration.hpp"
+
#include <xlsxwriter.h>
+#include <algorithm>
#include <charconv>
+#include <cstddef>
+#include <cstdint>
#include <iostream>
#include <map>
@@ -20,6 +27,23 @@ bool TableCell::IsMergedCell() const
return PrimaryCellLocation.x == -1 || PrimaryCellLocation.y == -1;
}
+template <class TProxy>
+void TableCell::OperateIOProxy(TProxy& proxy)
+{
+ proxy.template ObjectAdapted<DataStreamAdapters::String>(Content);
+ proxy.Object(Location);
+ proxy.Object(PrimaryCellLocation);
+ proxy.Value(SpanX);
+ proxy.Value(SpanY);
+ proxy.Value(HorizontalAlignment);
+ proxy.Value(VerticalAlignment);
+ proxy.Value(Type);
+ proxy.Value(DataId);
+}
+
+template void TableCell::OperateIOProxy(InputDataStream& adapter);
+template void TableCell::OperateIOProxy(OutputDataStream& adapter);
+
Vec2i TableArrayGroup::GetLeftCell() const
{
return { Row, LeftCell };
@@ -62,6 +86,17 @@ bool TableArrayGroup::UpdateCellName(std::string_view oldName, std::string_view
return ::UpdateElementName(mName2Cell, oldName, newName);
}
+template <class TProxy>
+void TableArrayGroup::OperateIOProxy(TProxy& proxy)
+{
+ proxy.Value(Row);
+ proxy.Value(LeftCell);
+ proxy.Value(RightCell);
+}
+
+template void TableArrayGroup::OperateIOProxy(InputDataStream& adapter);
+template void TableArrayGroup::OperateIOProxy(OutputDataStream& adapter);
+
TableInstantiationParameters::TableInstantiationParameters(const TableTemplate& table)
: mTable{ &table }
{
@@ -513,13 +548,24 @@ lxw_worksheet* TableTemplate::InstantiateToExcelWorksheet(lxw_workbook* workbook
return worksheet;
}
-Template::ReadResult TableTemplate::ReadFrom(std::istream& stream)
+
+void TableTemplate::ReadFromDataStream(InputDataStream& stream)
+{
+ OperateIOProxy(stream);
+}
+
+void TableTemplate::WriteToDataStream(OutputDataStream& stream)
{
- // TODO
- return ReadResult::RR_Success;
+ OperateIOProxy(stream);
}
-void TableTemplate::WriteTo(std::ostream& stream) const
+template <class TProxy>
+void TableTemplate::OperateIOProxy(TProxy& proxy)
{
- // TODO
+ proxy.template ObjectAdapted<DataStreamAdapters::Vector<>>(mColumnWidths);
+ proxy.template ObjectAdapted<DataStreamAdapters::Vector<>>(mRowHeights);
+ proxy.template ObjectAdapted<DataStreamAdapters::Vector<>>(mCells);
+ proxy.template ObjectAdapted<DataStreamAdapters::Vector<>>(mArrayGroups);
+ proxy.template ObjectAdapted<DataStreamAdapters::TslArrayMap<>>(mName2Parameters);
+ proxy.template ObjectAdapted<DataStreamAdapters::TslArrayMap<>>(mName2ArrayGroups);
}
diff --git a/core/src/Model/Template/TableTemplate.hpp b/core/src/Model/Template/TableTemplate.hpp
index c651ce1..c6617b0 100644
--- a/core/src/Model/Template/TableTemplate.hpp
+++ b/core/src/Model/Template/TableTemplate.hpp
@@ -53,6 +53,9 @@ public:
bool IsPrimaryCell() const;
/// Return whether this cell is a part of a merged range or not. Includes the primary cell.
bool IsMergedCell() const;
+
+ template <class TProxy>
+ void OperateIOProxy(TProxy& proxy);
};
// TODO support reverse (bottom to top) filling order
@@ -105,6 +108,9 @@ public:
/// Find the location of the cell within this array group that has the given name.
Vec2i FindCell(std::string_view name);
bool UpdateCellName(std::string_view oldName, std::string_view newName);
+
+ template <class TProxy>
+ void OperateIOProxy(TProxy& proxy);
};
// Forward declaration of libxlsxwriter structs
@@ -211,6 +217,10 @@ public:
lxw_workbook* InstantiateToExcelWorkbook(const TableInstantiationParameters& params) const;
lxw_worksheet* InstantiateToExcelWorksheet(lxw_workbook* workbook, const TableInstantiationParameters& params) const;
- ReadResult ReadFrom(std::istream& stream) override;
- void WriteTo(std::ostream& stream) const override;
+ void ReadFromDataStream(InputDataStream& stream) override;
+ void WriteToDataStream(OutputDataStream& stream) override;
+
+private:
+ template <class TProxy>
+ void OperateIOProxy(TProxy& proxy);
};
diff --git a/core/src/Model/Template/Template.hpp b/core/src/Model/Template/Template.hpp
index 30fdc75..c6b93e2 100644
--- a/core/src/Model/Template/Template.hpp
+++ b/core/src/Model/Template/Template.hpp
@@ -35,13 +35,8 @@ public:
Kind GetKind() const;
- enum ReadResult
- {
- RR_Success,
- RR_InvalidFormat,
- };
- virtual ReadResult ReadFrom(std::istream& stream) = 0;
- virtual void WriteTo(std::ostream& stream) const = 0;
+ virtual void ReadFromDataStream(InputDataStream& stream) = 0;
+ virtual void WriteToDataStream(OutputDataStream& stream) = 0;
};
class TemplateAssetList final : public AssetListTyped<Template>