GCC Code Coverage Report


Directory: ./
File: pdcom5/src/Variable.h
Date: 2024-11-17 04:08:36
Exec Total Coverage
Lines: 13 14 92.9%
Branches: 3 8 37.5%

Line Branch Exec Source
1 /*****************************************************************************
2 * vim:tw=78
3 *
4 * Copyright (C) 2021 Richard Hacker (lerichi at gmx dot net),
5 * Florian Pose (fp at igh dot de),
6 * Bjarne von Horn (vh at igh dot de).
7 *
8 * This file is part of the PdCom library.
9 *
10 * The PdCom library is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or (at your
13 * option) any later version.
14 *
15 * The PdCom library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the PdCom library. If not, see <http://www.gnu.org/licenses/>.
22 *
23 *****************************************************************************/
24
25
26 #ifndef PDCOM5_VARIABLE_IMPL_H
27 #define PDCOM5_VARIABLE_IMPL_H
28
29 #include <memory>
30 #include <pdcom5/Exception.h>
31 #include <pdcom5/Variable.h>
32
33 namespace PdCom {
34 class Subscription;
35 class Subscriber;
36 struct Selector;
37
38 namespace impl {
39 class Process;
40
41 class Variable
42 {
43 public:
44 1287 static std::shared_ptr<const Variable> fromUApi(const PdCom::Variable &p)
45 {
46
2/4
✓ Branch 3 taken 1287 times.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1287 times.
1287 if (auto ans = p.pimpl_.lock())
47
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 1287 times.
2574 return ans;
48 throw EmptyVariable();
49 }
50 2812 static PdCom::Variable toUApi(std::weak_ptr<const Variable> var)
51 {
52 2812 return PdCom::Variable {var};
53 }
54
55 static std::shared_ptr<Subscription> subscribe(
56 PdCom::Subscription *subscription,
57 const PdCom::Variable &p,
58 PdCom::Subscriber &subscriber,
59 const PdCom::Selector &selector);
60
61 377 virtual ~Variable() = default;
62 377 Variable(
63 SizeInfo size_info,
64 const TypeInfo *type_info,
65 377 std::weak_ptr<PdCom::impl::Process> p) :
66 377 size_info(std::move(size_info)), type_info(type_info), process(p)
67 377 {}
68
69 Variable(Variable &&) noexcept;
70 Variable &operator=(Variable &&) noexcept;
71
72 virtual PdCom::Variable::SetValueFuture
73 setValue(const void *, TypeInfo::DataType t, size_t idx, size_t n)
74 const = 0;
75 virtual std::string getPath() const = 0;
76 virtual std::string getName() const = 0;
77 virtual std::string getAlias() const = 0;
78 virtual int getTaskId() const = 0;
79 virtual bool isWriteable() const = 0;
80
81 virtual std::chrono::duration<double> getSampleTime() const = 0;
82
83 4973 std::size_t totalSizeInBytes() const
84 {
85 4973 return numberOfElements() * type_info->element_size;
86 }
87 4973 std::size_t numberOfElements() const { return size_info.totalElements(); }
88
89 SizeInfo size_info;
90 const TypeInfo *type_info;
91 std::weak_ptr<PdCom::impl::Process> process;
92
93 protected:
94 void getValue(
95 char *dst,
96 const void *src,
97 TypeInfo::DataType UserTypeIdx,
98 size_t n) const
99 {
100 details::copyData(dst, type_info->type, src, UserTypeIdx, n);
101 }
102 };
103
104
105 } // namespace impl
106
107 } // namespace PdCom
108
109 #endif // PDCOM5_VARIABLE_H
110