|
1 | 1 | #include "resource/factory/MatrixFactory.h"
|
2 | 2 | #include "resource/type/Matrix.h"
|
| 3 | +#include "resource/readerbox/BinaryReaderBox.h" |
3 | 4 | #include "spdlog/spdlog.h"
|
4 | 5 |
|
5 | 6 | namespace LUS {
|
6 |
| -std::shared_ptr<IResource> MatrixFactory::ReadResource(std::shared_ptr<ResourceInitData> initData, |
7 |
| - std::shared_ptr<BinaryReader> reader) { |
8 |
| - auto resource = std::make_shared<Matrix>(initData); |
9 |
| - std::shared_ptr<ResourceVersionFactory> factory = nullptr; |
10 |
| - |
11 |
| - switch (resource->GetInitData()->ResourceVersion) { |
12 |
| - case 0: |
13 |
| - factory = std::make_shared<MatrixFactoryV0>(); |
14 |
| - break; |
| 7 | +std::shared_ptr<IResource> ResourceFactoryBinaryMatrixV0::ReadResource(std::shared_ptr<ResourceInitData> initData, |
| 8 | + std::shared_ptr<ReaderBox> readerBox) { |
| 9 | + auto binaryReaderBox = std::dynamic_pointer_cast<BinaryReaderBox>(readerBox); |
| 10 | + if (binaryReaderBox == nullptr) { |
| 11 | + SPDLOG_ERROR("ReaderBox must be a BinaryReaderBox."); |
| 12 | + return nullptr; |
15 | 13 | }
|
16 | 14 |
|
17 |
| - if (factory == nullptr) { |
18 |
| - SPDLOG_ERROR("Failed to load Matrix with version {}", resource->GetInitData()->ResourceVersion); |
| 15 | + auto reader = binaryReaderBox->GetReader(); |
| 16 | + if (reader == nullptr) { |
| 17 | + SPDLOG_ERROR("null reader in box."); |
19 | 18 | return nullptr;
|
20 | 19 | }
|
21 | 20 |
|
22 |
| - factory->ParseFileBinary(reader, resource); |
23 |
| - |
24 |
| - return resource; |
25 |
| -} |
26 |
| - |
27 |
| -void MatrixFactoryV0::ParseFileBinary(std::shared_ptr<BinaryReader> reader, std::shared_ptr<IResource> resource) { |
28 |
| - std::shared_ptr<Matrix> mtx = static_pointer_cast<Matrix>(resource); |
29 |
| - ResourceVersionFactory::ParseFileBinary(reader, resource); |
| 21 | + auto matrix = std::make_shared<Matrix>(initData); |
30 | 22 |
|
31 | 23 | for (size_t i = 0; i < 4; i++) {
|
32 | 24 | for (size_t j = 0; j < 4; j++) {
|
33 |
| - mtx->Matrx.m[i][j] = reader->ReadInt32(); |
| 25 | + matrix->Matrx.m[i][j] = reader->ReadInt32(); |
34 | 26 | }
|
35 | 27 | }
|
| 28 | + |
| 29 | + return matrix; |
36 | 30 | }
|
37 | 31 | } // namespace LUS
|
0 commit comments