Skip to content

Commit b7387bb

Browse files
committed
matrix
1 parent 6f7b32c commit b7387bb

File tree

2 files changed

+16
-27
lines changed

2 files changed

+16
-27
lines changed
+14-20
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
11
#include "resource/factory/MatrixFactory.h"
22
#include "resource/type/Matrix.h"
3+
#include "resource/readerbox/BinaryReaderBox.h"
34
#include "spdlog/spdlog.h"
45

56
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;
1513
}
1614

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.");
1918
return nullptr;
2019
}
2120

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);
3022

3123
for (size_t i = 0; i < 4; i++) {
3224
for (size_t j = 0; j < 4; j++) {
33-
mtx->Matrx.m[i][j] = reader->ReadInt32();
25+
matrix->Matrx.m[i][j] = reader->ReadInt32();
3426
}
3527
}
28+
29+
return matrix;
3630
}
3731
} // namespace LUS

src/resource/factory/MatrixFactory.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44
#include "resource/ResourceFactory.h"
55

66
namespace LUS {
7-
class MatrixFactory : public ResourceFactory {
7+
class ResourceFactoryBinaryMatrixV0 : public ResourceFactory {
88
public:
99
std::shared_ptr<IResource> ReadResource(std::shared_ptr<ResourceInitData> initData,
10-
std::shared_ptr<BinaryReader> reader) override;
11-
};
12-
13-
class MatrixFactoryV0 : public ResourceVersionFactory {
14-
public:
15-
void ParseFileBinary(std::shared_ptr<BinaryReader> reader, std::shared_ptr<IResource> resource) override;
10+
std::shared_ptr<ReaderBox> readerBox) override;
1611
};
1712
} // namespace LUS

0 commit comments

Comments
 (0)