| 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 <memory> | ||
| 8 | #include <utility> | ||
| 9 | #include <string> | ||
| 10 | #include "IDocumentMetadata.h" | ||
| 11 | #include "document.h" | ||
| 12 | #include "documentMetadataBase.h" | ||
| 13 | |||
| 14 | /// Implementation of the IDocumentMetadataRead interface. | ||
| 15 | class DocumentMetadataReader : public DocumentMetadataBase, public imgdoc2::IDocumentMetadataRead | ||
| 16 | { | ||
| 17 | public: | ||
| 18 | DocumentMetadataReader() = delete; | ||
| 19 | 80 | explicit DocumentMetadataReader(std::shared_ptr<Document> document) : DocumentMetadataBase(std::move(document)) {} | |
| 20 | 160 | ~DocumentMetadataReader() override = default; | |
| 21 | |||
| 22 | imgdoc2::DocumentMetadataItem GetItem(imgdoc2::dbIndex primary_key, imgdoc2::DocumentMetadataItemFlags flags) override; | ||
| 23 | imgdoc2::DocumentMetadataItem GetItemForPath(const std::string& path, imgdoc2::DocumentMetadataItemFlags flags) override; | ||
| 24 | void EnumerateItems( | ||
| 25 | std::optional<imgdoc2::dbIndex> parent, | ||
| 26 | bool recursive, | ||
| 27 | imgdoc2::DocumentMetadataItemFlags flags, | ||
| 28 | const std::function<bool(imgdoc2::dbIndex, const imgdoc2::DocumentMetadataItem& item)>& func) override; | ||
| 29 | void EnumerateItemsForPath( | ||
| 30 | const std::string& path, | ||
| 31 | bool recursive, | ||
| 32 | imgdoc2::DocumentMetadataItemFlags flags, | ||
| 33 | const std::function<bool(imgdoc2::dbIndex, const imgdoc2::DocumentMetadataItem& item)>& func) override; | ||
| 34 | |||
| 35 | private: | ||
| 36 | void InternalEnumerateItems( | ||
| 37 | std::optional<imgdoc2::dbIndex> parent, | ||
| 38 | const std::string& path_of_parent, | ||
| 39 | bool recursive, | ||
| 40 | imgdoc2::DocumentMetadataItemFlags flags, | ||
| 41 | const std::function<bool(imgdoc2::dbIndex, const imgdoc2::DocumentMetadataItem& item)>& func); | ||
| 42 | |||
| 43 | std::shared_ptr<IDbStatement> CreateStatementForRetrievingItem(imgdoc2::DocumentMetadataItemFlags flags); | ||
| 44 | |||
| 45 | /// Creates statement which gives the items for which the given item is an ancestor. If recursive is false, then | ||
| 46 | /// only items for which the given item is the direct parent are returned. If recursive is true, then all items | ||
| 47 | /// for which the given item is an ancestor are returned. | ||
| 48 | /// The result of this statements gives in column 0 the primary key of the item, in column 1 the name of the item, in column 2 the type discriminator, | ||
| 49 | /// in column 3 the value double, in column 4 the value integer and in column 5 the value string. | ||
| 50 | /// If the include_path flag is true, then the complete path of the item is included in the result as column 6. | ||
| 51 | /// | ||
| 52 | /// \param recursive True to query only items for the 'parent' is the direct ancestor, false to include all items (for which the 'parent' is direct or indirect ancestor). | ||
| 53 | /// \param include_path True to include a sixth column containing the complete path of the item; false otherwise. | ||
| 54 | /// \param parent The node to search for (being an ancestor). If nullopt, this means "root node". | ||
| 55 | /// | ||
| 56 | /// \returns The statement. | ||
| 57 | std::shared_ptr<IDbStatement> CreateStatementForEnumerateAllItemsWithAncestorAndDataBind(bool recursive, bool include_path, std::optional<imgdoc2::dbIndex> parent); | ||
| 58 | |||
| 59 | /// Retrieves a document-metadata-item object from a statement. The precondition is that the statement has been executed and the result is ready. | ||
| 60 | /// We expect at column 0 the primary key, column 1 the Name, at column 2 the TypeDiscriminator, at column 3 the ValueDouble, at column 4 the ValueInteger and | ||
| 61 | /// at column 5 the ValueString. | ||
| 62 | /// | ||
| 63 | /// \param statement The statement. | ||
| 64 | /// \param flags The flags. | ||
| 65 | /// \param path_to_prepend Used only in case where 'flags' includes 'DocumentMetadataItemFlags::kCompletePath' - a path to be prepended | ||
| 66 | /// (because the query gives only the path relative to the parent node). | ||
| 67 | /// | ||
| 68 | /// \returns The document-metadata-item object populated with the information from the statement, as indicated by the flags. | ||
| 69 | imgdoc2::DocumentMetadataItem RetrieveDocumentMetadataItemFromStatement(const std::shared_ptr<IDbStatement>& statement, imgdoc2::DocumentMetadataItemFlags flags, const string& path_to_prepend); | ||
| 70 | |||
| 71 | /// Retrieve the full path for the specified node. The returned boolean indicates whether the path could be retrieved. | ||
| 72 | /// If e.g. the node does not exist, the path is not set and the function returns false. | ||
| 73 | /// | ||
| 74 | /// \param node_id Primary key of the node for which the path should be retrieved. | ||
| 75 | /// \param [out] path If successful, the path for the specified node. | ||
| 76 | /// | ||
| 77 | /// \returns True if it succeeds, false if it fails. | ||
| 78 | bool GetPathForNode(imgdoc2::dbIndex node_id, std::string& path); | ||
| 79 | }; | ||
| 80 |