DBC framework
tree_node.h
Go to the documentation of this file.
1/**
2 * @file tree_node.h
3 * @brief
4 *
5 * Created: 2026-03-13
6 * Author: Deeaitch (Dim. Himro)
7 *
8 * Licensed under the MIT License.
9 * See LICENSE file in the project root for full license text.
10 */
11
12#ifndef TREE_NODE_H
13#define TREE_NODE_H
14
15#include <string>
16#include <vector>
17#include <memory>
18#include <cstddef>
19
20#include "frame_info.h"
21#include "signal_info.h"
22
23/**
24 * @brief Type of a tree node.
25 */
26enum class NodeType {
27 Root,
28 Frame,
29 Signal
30};
31
32/**
33 * @brief Tree node for later use in model/view or other hierarchy consumers.
34 */
35class TreeNode {
36 public:
37 /**
38 * @brief Create root node.
39 */
40 TreeNode();
41
42 /**
43 * @brief Create frame node.
44 * @param frame Frame payload.
45 */
46 explicit TreeNode (const FrameInfo &frame);
47
48 /**
49 * @brief Create signal node.
50 * @param signal Signal payload.
51 */
52 explicit TreeNode (const SignalInfo &signal);
53
54 ~TreeNode() = default;
55
56 TreeNode (const TreeNode &) = delete;
57 TreeNode &operator= (const TreeNode &) = delete;
58
59 TreeNode (TreeNode &&) = default;
61
62 /**
63 * @brief Add child node.
64 * @param child Child node to add.
65 */
66 void AddChild (std::unique_ptr<TreeNode> child);
67
68 /**
69 * @brief Get child count.
70 * @return Number of children.
71 */
72 std::size_t GetChildCount() const;
73
74 /**
75 * @brief Get child by index.
76 * @param index Child index.
77 * @return Child pointer or nullptr if index is invalid.
78 */
79 const TreeNode *GetChild (std::size_t index) const;
80
81 /**
82 * @brief Get mutable child by index.
83 * @param index Child index.
84 * @return Child pointer or nullptr if index is invalid.
85 */
86 TreeNode *GetChild (std::size_t index);
87
88 /**
89 * @brief Get node type.
90 * @return Node type.
91 */
92 NodeType GetType() const;
93
94 /**
95 * @brief Get display name.
96 * @return Node name.
97 */
98 const std::string &GetName() const;
99
100 /**
101 * @brief Get frame payload if node is frame.
102 * @return Pointer to frame info or nullptr.
103 */
104 const FrameInfo *GetFrame() const;
105
106 /**
107 * @brief Get signal payload if node is signal.
108 * @return Pointer to signal info or nullptr.
109 */
110 const SignalInfo *GetSignal() const;
111
112 private:
114 std::string m_name;
115 std::vector<std::unique_ptr<TreeNode> > m_children;
116 std::unique_ptr<FrameInfo> m_frame;
117 std::unique_ptr<SignalInfo> m_signal;
118};
119
120#endif /* TREE_NODE_H */
Tree node for later use in model/view or other hierarchy consumers.
Definition: tree_node.h:35
NodeType m_type
Definition: tree_node.h:113
std::vector< std::unique_ptr< TreeNode > > m_children
Definition: tree_node.h:115
const SignalInfo * GetSignal() const
Get signal payload if node is signal.
Definition: tree_node.cpp:73
TreeNode(TreeNode &&)=default
const TreeNode * GetChild(std::size_t index) const
Get child by index.
Definition: tree_node.cpp:47
TreeNode(const TreeNode &)=delete
void AddChild(std::unique_ptr< TreeNode > child)
Add child node.
Definition: tree_node.cpp:38
std::unique_ptr< FrameInfo > m_frame
Definition: tree_node.h:116
~TreeNode()=default
TreeNode()
Create root node.
Definition: tree_node.cpp:14
const std::string & GetName() const
Get display name.
Definition: tree_node.cpp:65
std::size_t GetChildCount() const
Get child count.
Definition: tree_node.cpp:43
std::string m_name
Definition: tree_node.h:114
TreeNode & operator=(const TreeNode &)=delete
std::unique_ptr< SignalInfo > m_signal
Definition: tree_node.h:117
NodeType GetType() const
Get node type.
Definition: tree_node.cpp:61
const FrameInfo * GetFrame() const
Get frame payload if node is frame.
Definition: tree_node.cpp:69
Created: 2026-03-13 Author: Deeaitch (Dim. Himro)
Created: 2026-03-13 Author: Deeaitch (Dim. Himro)
Describes one CAN frame from a DBC file.
Definition: frame_info.h:24
Describes one signal inside a DBC frame.
Definition: signal_info.h:22
NodeType
Type of a tree node.
Definition: tree_node.h:26