| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-FileCopyrightText: 2023 Carl Zeiss Microscopy GmbH | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: MIT | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <utility> | ||
| 8 | #include <memory> | ||
| 9 | #include <imgdoc2.h> | ||
| 10 | #include "../db/IDbConnection.h" | ||
| 11 | #include "../db/database_configuration.h" | ||
| 12 | |||
| 13 | class Document : public imgdoc2::IDoc, public std::enable_shared_from_this<Document> | ||
| 14 | { | ||
| 15 | private: | ||
| 16 | std::shared_ptr<IDbConnection> database_connection_; | ||
| 17 | std::shared_ptr<DatabaseConfiguration2D> database_configuration_2d_; ///< The database configuration for a "tiles-2d-document". Note that this member is only valid if the document is a "tiles-2d-document", and it is mutually exclusive to 'database_configuration_3d_'. | ||
| 18 | std::shared_ptr<DatabaseConfiguration3D> database_configuration_3d_; ///< The database configuration for a "bricks-3d-document". Note that this member is only valid if the document is a "bricks-3d-document", and it is mutually exclusive to 'database_configuration_2d_'. | ||
| 19 | public: | ||
| 20 | 180 | Document(std::shared_ptr<IDbConnection> database_connection, std::shared_ptr<DatabaseConfiguration2D> database_configuration) : | |
| 21 | 180 | database_connection_(std::move(database_connection)), | |
| 22 | 360 | database_configuration_2d_(std::move(database_configuration)) | |
| 23 | 180 | {} | |
| 24 | |||
| 25 | 72 | Document(std::shared_ptr<IDbConnection> database_connection, std::shared_ptr<DatabaseConfiguration3D> database_configuration) : | |
| 26 | 72 | database_connection_(std::move(database_connection)), | |
| 27 | 144 | database_configuration_3d_(std::move(database_configuration)) | |
| 28 | 72 | {} | |
| 29 | |||
| 30 | /// Try to get a "write object" for a 2D-document. This method may return an empty shared_ptr | ||
| 31 | /// if such an object cannot be constructed. | ||
| 32 | /// \returns The writer-object (for 2D-document). | ||
| 33 | std::shared_ptr<imgdoc2::IDocWrite2d> GetWriter2d() override; | ||
| 34 | |||
| 35 | /// Try to get a "read object" for a 2D-document. This method may return an empty shared_ptr | ||
| 36 | /// if such an object cannot be constructed. | ||
| 37 | /// \returns The read-object (for 2D-document). | ||
| 38 | std::shared_ptr<imgdoc2::IDocRead2d> GetReader2d() override; | ||
| 39 | |||
| 40 | /// Try to get a "write object" for a 3D-document. This method may return an empty shared_ptr | ||
| 41 | /// if such an object cannot be constructed. | ||
| 42 | /// \returns The writer-object (for 3D-document). | ||
| 43 | std::shared_ptr<imgdoc2::IDocWrite3d> GetWriter3d() override; | ||
| 44 | |||
| 45 | /// Try to get a "read object" for a 3D-document. This method may return an empty shared_ptr | ||
| 46 | /// if such an object cannot be constructed. | ||
| 47 | /// \returns The read-object (for 3D-document). | ||
| 48 | std::shared_ptr<imgdoc2::IDocRead3d> GetReader3d() override; | ||
| 49 | |||
| 50 | std::shared_ptr<imgdoc2::IDocumentMetadataWrite> GetDocumentMetadataWriter() override; | ||
| 51 | std::shared_ptr<imgdoc2::IDocumentMetadataRead> GetDocumentMetadataReader() override; | ||
| 52 | |||
| 53 | 504 | ~Document() override = default; | |
| 54 | public: | ||
| 55 | 268924 | [[nodiscard]] const std::shared_ptr<IDbConnection>& GetDatabase_connection() const { return this->database_connection_; } | |
| 56 | 72754 | [[nodiscard]] const std::shared_ptr<DatabaseConfiguration2D>& GetDataBaseConfiguration2d() const { return this->database_configuration_2d_; } | |
| 57 | 906532 | [[nodiscard]] const std::shared_ptr<DatabaseConfiguration3D>& GetDataBaseConfiguration3d() const { return this->database_configuration_3d_; } | |
| 58 | 10972 | [[nodiscard]] const DatabaseConfigurationCommon* GetDataBaseConfigurationCommon() const | |
| 59 | { | ||
| 60 |
1/2✓ Branch 1 taken 10972 times.
✗ Branch 2 not taken.
|
10972 | if (this->IsDocument2d()) |
| 61 | { | ||
| 62 | 10972 | return this->GetDataBaseConfiguration2d().get(); | |
| 63 | } | ||
| 64 | ✗ | else if (this->IsDocument3d()) | |
| 65 | { | ||
| 66 | ✗ | return this->GetDataBaseConfiguration3d().get(); | |
| 67 | } | ||
| 68 | |||
| 69 | ✗ | return nullptr; | |
| 70 | } | ||
| 71 | |||
| 72 | ✗ | [[nodiscard]] const std::shared_ptr<imgdoc2::IHostingEnvironment>& GetHostingEnvironment() const { return this->database_connection_->GetHostingEnvironment(); } | |
| 73 | 11124 | [[nodiscard]] bool IsDocument2d() const { return this->database_configuration_2d_.operator bool(); } | |
| 74 | 136 | [[nodiscard]] bool IsDocument3d() const { return this->database_configuration_3d_.operator bool(); } | |
| 75 | }; | ||
| 76 |