GCC Code Coverage Report


Directory: ./
File: src/Selector.h
Date: 2024-03-27 13:09:52
Exec Total Coverage
Lines: 3 3 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * Copyright (C) 2021 Bjarne von Horn (vh at igh dot de).
4 *
5 * This file is part of the PdCom library.
6 *
7 * The PdCom library is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * The PdCom library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with the PdCom library. If not, see <http://www.gnu.org/licenses/>.
19 *
20 *****************************************************************************/
21
22 #ifndef PDCOM_IMPL_SELECTOR_H
23 #define PDCOM_IMPL_SELECTOR_H
24
25 #include <functional>
26 #include <pdcom5/SizeTypeInfo.h>
27 #include <pdcom5/Variable.h>
28 #include <vector>
29
30 namespace PdCom { namespace impl {
31 class Variable;
32
33 /** Selector base class for creating views on multidimensional data.
34 *
35 * Developers have to override clone(), getRequiredSize() and getCopyFunction()
36 * in their derived class.
37 *
38 */
39 181 struct Selector
40 {
41 using CopyFunctionType = std::function<
42 void(void * /* destination */, const void * /* src */)>;
43
44 181 virtual ~Selector() = default;
45 /** Required size of the view, in bytes.
46 *
47 * \return The required memory space for the view, in bytes.
48 */
49 virtual std::size_t getRequiredSize(const Variable &variable) const;
50 /** Smart memcpy().
51 *
52 * \returns A functor which will copy arriving variable data to the provided
53 * view memory.
54 */
55 virtual CopyFunctionType getCopyFunction(const Variable &variable) const;
56
57 virtual PdCom::Variable::SetValueFuture applySetValue(
58 const Variable &variable,
59 const void *src_data,
60 TypeInfo::DataType src_type,
61 size_t src_count) const;
62
63 virtual SizeInfo getViewSizeInfo(const Variable &variable) const;
64 };
65
66 /** Selects one scalar out of a vector or matrix.
67 *
68 * The index is in Row major format, ((layer, )row, column).
69 */
70 63 class ScalarSelector : public Selector
71 {
72 std::vector<int> indices_;
73
74 public:
75 std::size_t getRequiredSize(const Variable &) const override;
76 CopyFunctionType getCopyFunction(const Variable &) const override;
77
78 ScalarSelector(std::vector<int> indices);
79
80 size_t getOffset(const Variable &variable) const;
81
82 SizeInfo getViewSizeInfo(const Variable &variable) const override;
83
84 PdCom::Variable::SetValueFuture applySetValue(
85 const Variable &variable,
86 const void *src_data,
87 TypeInfo::DataType src_type,
88 size_t src_count) const override;
89 };
90 }} // namespace PdCom::impl
91
92
93 #endif // PDCOM_IMPL_SELECTOR_H
94