INSTINCT Code Coverage Report


Directory: src/
File: NodeData/NodeData.hpp
Date: 2025-02-07 16:54:41
Exec Total Coverage
Lines: 8 26 30.8%
Functions: 8 23 34.8%
Branches: 1 12 8.3%

Line Branch Exec Source
1 // This file is part of INSTINCT, the INS Toolkit for Integrated
2 // Navigation Concepts and Training by the Institute of Navigation of
3 // the University of Stuttgart, Germany.
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9 /// @file NodeData.hpp
10 /// @brief Abstract NodeData Class
11 /// @author T. Topp (topp@ins.uni-stuttgart.de)
12 /// @date 2020-04-16
13
14 #pragma once
15
16 #include <string>
17 #include <vector>
18 #include <optional>
19
20 #include "Navigation/Time/InsTime.hpp"
21 #include "util/Assert.h"
22 #include "util/Logger.hpp"
23
24 namespace NAV
25 {
26 /// @brief Parent class for all data transmitted over Flow pins
27 class NodeData
28 {
29 public:
30 /// @brief Default constructor
31 466505 NodeData() = default;
32 /// @brief Destructor
33 1061416 virtual ~NodeData() = default;
34 /// @brief Copy constructor
35 64197 NodeData(const NodeData&) = default;
36 /// @brief Move constructor
37 NodeData(NodeData&&) = default;
38 /// @brief Copy assignment operator
39 50782 NodeData& operator=(const NodeData&) = default;
40 /// @brief Move assignment operator
41 NodeData& operator=(NodeData&&) = default;
42
43 /// @brief Returns the type of the data class
44 /// @return The data type
45
1/2
✓ Branch 1 taken 3091 times.
✗ Branch 2 not taken.
9273 [[nodiscard]] static std::string type() { return "NodeData"; }
46
47 /// @brief Returns the type of the data class
48 /// @return The data type
49 [[nodiscard]] virtual std::string getType() const { return type(); };
50
51 /// @brief Returns the parent types of the data class
52 /// @return The parent data types
53 112 [[nodiscard]] static std::vector<std::string> parentTypes() { return {}; }
54
55 /// @brief Returns a vector of data descriptors
56 1 [[nodiscard]] static std::vector<std::string> GetStaticDataDescriptors() { return {}; }
57
58 /// @brief Get the amount of descriptors
59 [[nodiscard]] static constexpr size_t GetStaticDescriptorCount() { return 0; }
60
61 /// @brief Returns a vector of data descriptors
62 [[nodiscard]] virtual std::vector<std::string> staticDataDescriptors() const { return GetStaticDataDescriptors(); }
63
64 /// @brief Get the amount of descriptors
65 [[nodiscard]] virtual size_t staticDescriptorCount() const { return GetStaticDescriptorCount(); }
66
67 /// @brief Returns a vector of string events associated with this data
68 [[nodiscard]] const std::vector<std::string>& events() const { return _events; }
69
70 /// @brief Adds the event to the list
71 /// @param[in] text Event text
72 void addEvent(const std::string& text) { _events.push_back(text); }
73
74 /// @brief Get the value at the index
75 /// @return Value if in the observation
76 [[nodiscard]] virtual std::optional<double> getValueAt(size_t /* idx */) const { return std::nullopt; }
77
78 /// @brief Set the value at the index
79 /// @return True if the value was updated
80 [[nodiscard]] virtual bool setValueAt(size_t /* idx */, double /* value */)
81 {
82 LOG_CRITICAL("This function should never be called. Did you forget to override it?");
83 return false;
84 }
85
86 /// @brief Get the value at the index or NaN if not in the observation
87 /// @param idx Index corresponding to data descriptor order
88 /// @return Value or NaN if not in the observation
89 [[nodiscard]] double getValueAtOrNaN(size_t idx) const { return getValueAt(idx).value_or(std::nan("")); }
90
91 /// @brief Returns a vector of data descriptors for the dynamic data
92 48444 [[nodiscard]] virtual std::vector<std::string> dynamicDataDescriptors() const { return {}; }
93
94 /// @brief Get the value for the descriptor
95 /// @return Value if in the observation
96 [[nodiscard]] virtual std::optional<double> getDynamicDataAt(const std::string& /* descriptor */) const { return std::nullopt; }
97
98 /// @brief Set the value for the descriptor
99 /// @return True if the value was updated
100 [[nodiscard]] virtual bool setDynamicDataAt(const std::string& /* descriptor */, double /* value */)
101 {
102 LOG_CRITICAL("This function should never be called. Did you forget to override it?");
103 return false;
104 }
105
106 /// @brief Returns a vector of data descriptors and values for the dynamic data
107 [[nodiscard]] virtual std::vector<std::pair<std::string, double>> getDynamicData() const { return {}; }
108
109 /// @brief Shows a GUI tooltip to look into details of the observation
110 /// @param[in] detailView Flag to show the detailed view
111 /// @param[in] firstOpen Flag whether the tooltip is opened once
112 /// @param[in] displayName Data identifier, can be used in dynamic data to identify the correct data
113 /// @param[in] id Unique identifier
114 /// @param[in] rootWindow Pointer to the root window opening the tooltip
115 virtual void guiTooltip([[maybe_unused]] bool detailView, [[maybe_unused]] bool firstOpen,
116 [[maybe_unused]] const char* displayName, [[maybe_unused]] const char* id,
117 [[maybe_unused]] int* rootWindow) const {}
118
119 /// @brief Return whether this data has a tooltip
120 [[nodiscard]] virtual bool hasTooltip() const { return false; }
121
122 /// Time at which the message was received
123 InsTime insTime;
124
125 protected:
126 /// @brief List of events
127 std::vector<std::string> _events;
128 };
129
130 } // namespace NAV
131