This commit is contained in:
deeaitch committed 2026-10-20 13:03:21 -04:00
1 parent a202ba12ba
commit 713276d34a
5 files changed
+120 -11

No files matched your search

+23 -1
View File
@@ -10,6 +10,7 @@
*/
#include "tree_node.h"
#include <stdexcept>
TreeNode::TreeNode()
: m_type(NodeType::Root), m_name("dbc") {
@@ -23,8 +24,14 @@ TreeNode::TreeNode(const SignalInfo &signal)
: m_type(NodeType::Signal), m_name(signal.name), m_signal(std::make_unique<SignalInfo>(signal)) {
}
void TreeNode::AddChild(std::unique_ptr<TreeNode> child) {
void TreeNode::AddChild(std::unique_ptr<TreeNode> &&child) {
if (child) {
for (const TreeNode *ancestor = this; ancestor; ancestor = ancestor->m_parent) {
if (ancestor == child.get())
throw std::invalid_argument("Cannot insert a node into its own subtree");
}
if (child->m_parent)
throw std::invalid_argument("Child is already attached");
m_children.push_back(std::move(child));
m_children.back()->m_parent = this;
m_children.back()->m_row = m_children.size() - 1U;
@@ -72,3 +79,18 @@ const TreeNode *TreeNode::GetParent() const {
std::size_t TreeNode::GetRow() const {
return m_row;
}
std::optional<FrameKey> TreeNode::GetFrameKey() const {
if (m_frame)
return FrameKey(m_frame->canId, m_frame->isExtended);
if (m_signal && m_parent && m_parent->GetType() == NodeType::Frame)
return m_parent->GetFrameKey();
return std::nullopt;
}
std::optional<SignalKey> TreeNode::GetSignalKey() const {
const std::optional<FrameKey> frame = GetFrameKey();
if (m_signal && frame)
return SignalKey(*frame, m_signal->name);
return std::nullopt;
}