GCC Code Coverage Report


Directory: libimgdoc2/
File: libimgdoc2/src/doc/documentReadBase.h
Date: 2025-02-03 12:41:04
Exec Total Coverage
Lines: 3 4 75.0%
Functions: 2 3 66.7%
Branches: 0 0 -%

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 <unordered_set>
8 #include <utility>
9 #include <map>
10 #include <functional>
11 #include <sstream>
12 #include <memory>
13 #include <vector>
14 #include <string>
15 #include "document.h"
16
17 /// This class contains common functionality and utilities for implementing the document-read-access classes.
18 class DocumentReadBase
19 {
20 private:
21 std::shared_ptr<Document> document_;
22 protected:
23 148 explicit DocumentReadBase(std::shared_ptr<Document> document) : document_(std::move(document))
24 148 {}
25
26 static void GetEntityDimensionsInternal(const std::unordered_set<imgdoc2::Dimension>& tile_dimensions, imgdoc2::Dimension* dimensions, std::uint32_t& count);
27
28 /// Gets minimum and maximum for the specified tile dimensions. This function will use the specified functor 'func_is_dimension_valid'
29 /// to determine if a dimension is valid, and the other functor 'func_add_dimension_table_name' is used to give the column name for a dimension.
30 /// The name of the table which is queried is specified by the parameter 'table_name'.
31 ///
32 /// \param dimensions_to_query_for The dimensions to query for.
33 /// \param func_is_dimension_valid A functor which determines if a dimension is valid.
34 /// \param func_add_dimension_table_name A functor which adds the column name for a dimension to the specified string stream.
35 /// \param table_name Name of the table to be queried.
36 ///
37 /// \returns A map containing the min/max-information for the requested dimensions.
38 std::map<imgdoc2::Dimension, imgdoc2::Int32Interval> GetMinMaxForTileDimensionInternal(
39 const std::vector<imgdoc2::Dimension>& dimensions_to_query_for,
40 const std::function<bool(imgdoc2::Dimension)>& func_is_dimension_valid,
41 const std::function<void(std::ostringstream&, imgdoc2::Dimension)>& func_add_dimension_table_name,
42 const std::string& table_name) const;
43
44 /// Information about columns for the position and the associated extent.
45 struct QueryMinMaxForXyzInfo
46 {
47 std::string column_name_coordinate; /// Name of the column for the coordinate.
48 std::string column_name_coordinate_extent; /// Name of the column for the coordinate extent.
49 };
50
51 /// Creates a statement which queries for the bounding box/cuboid of all tiles/bricks.
52 /// \param table_name Name of the table to query (the 'TILESINFO'-table).
53 /// \param query_info Information listing the columns for the position and the associated extent.
54 /// \returns A statement for retrieving the bounding box/cuboid of all tiles/bricks.
55 [[nodiscard]] std::shared_ptr<IDbStatement> CreateQueryMinMaxForXyz(const std::string& table_name, const std::vector<QueryMinMaxForXyzInfo>& query_info) const;
56
57 /// A utility which reads two doubles from the specified statement and sets the values in the specified interval. It uses the specified result index
58 /// for reading from the statement. If the pointer 'interval' is null, the function will not read from the statement and do nothing.
59 /// The returned integer is the next index to read from, or in other words - the argument 'result_index' plus two (if the pointer 'interval' is not null).
60 /// \param [in,out] interval If non-null, the interval which will be set.
61 /// \param [in,out] statement The database-result statement.
62 /// \param result_index The index where to start to read from the database-result statement.
63 /// \returns The index (into the database-result statement) where to read the next value from.
64 static int SetCoordinateBoundsValueIfNonNull(imgdoc2::DoubleInterval* interval, IDbStatement* statement, int result_index);
65
66 std::uint64_t GetTotalTileCount(const std::string& table_name);
67 std::map<int, std::uint64_t> GetTileCountPerLayer(const std::string& table_name, const std::string& pyramid_level_column_name);
68
69 50714 [[nodiscard]] const std::shared_ptr<Document>& GetDocument() const { return this->document_; }
70 [[nodiscard]] const std::shared_ptr<imgdoc2::IHostingEnvironment>& GetHostingEnvironment() const { return this->document_->GetHostingEnvironment(); }
71 private:
72 std::shared_ptr<IDbStatement> CreateQueryMinMaxStatement(const std::vector<imgdoc2::Dimension>& dimensions, const std::function<void(std::ostringstream&, imgdoc2::Dimension)>& func_add_dimension_table_name, const std::string& table_name) const;
73 };
74