DBC parser initial commit.
This commit is contained in:
109
tree_node.h
Normal file
109
tree_node.h
Normal file
@@ -0,0 +1,109 @@
|
||||
#ifndef TREE_NODE_H
|
||||
#define TREE_NODE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <cstddef>
|
||||
|
||||
#include "frame_info.h"
|
||||
#include "signal_info.h"
|
||||
|
||||
/**
|
||||
* @brief Type of a tree node.
|
||||
*/
|
||||
enum class NodeType {
|
||||
Root,
|
||||
Frame,
|
||||
Signal
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Tree node for later use in model/view or other hierarchy consumers.
|
||||
*/
|
||||
class TreeNode {
|
||||
public:
|
||||
/**
|
||||
* @brief Create root node.
|
||||
*/
|
||||
TreeNode();
|
||||
|
||||
/**
|
||||
* @brief Create frame node.
|
||||
* @param frame Frame payload.
|
||||
*/
|
||||
explicit TreeNode (const FrameInfo &frame);
|
||||
|
||||
/**
|
||||
* @brief Create signal node.
|
||||
* @param signal Signal payload.
|
||||
*/
|
||||
explicit TreeNode (const SignalInfo &signal);
|
||||
|
||||
~TreeNode() = default;
|
||||
|
||||
TreeNode (const TreeNode &) = delete;
|
||||
TreeNode &operator= (const TreeNode &) = delete;
|
||||
|
||||
TreeNode (TreeNode &&) = default;
|
||||
TreeNode &operator= (TreeNode &&) = default;
|
||||
|
||||
/**
|
||||
* @brief Add child node.
|
||||
* @param child Child node to add.
|
||||
*/
|
||||
void AddChild (std::unique_ptr<TreeNode> child);
|
||||
|
||||
/**
|
||||
* @brief Get child count.
|
||||
* @return Number of children.
|
||||
*/
|
||||
std::size_t GetChildCount() const;
|
||||
|
||||
/**
|
||||
* @brief Get child by index.
|
||||
* @param index Child index.
|
||||
* @return Child pointer or nullptr if index is invalid.
|
||||
*/
|
||||
const TreeNode *GetChild (std::size_t index) const;
|
||||
|
||||
/**
|
||||
* @brief Get mutable child by index.
|
||||
* @param index Child index.
|
||||
* @return Child pointer or nullptr if index is invalid.
|
||||
*/
|
||||
TreeNode *GetChild (std::size_t index);
|
||||
|
||||
/**
|
||||
* @brief Get node type.
|
||||
* @return Node type.
|
||||
*/
|
||||
NodeType GetType() const;
|
||||
|
||||
/**
|
||||
* @brief Get display name.
|
||||
* @return Node name.
|
||||
*/
|
||||
const std::string &GetName() const;
|
||||
|
||||
/**
|
||||
* @brief Get frame payload if node is frame.
|
||||
* @return Pointer to frame info or nullptr.
|
||||
*/
|
||||
const FrameInfo *GetFrame() const;
|
||||
|
||||
/**
|
||||
* @brief Get signal payload if node is signal.
|
||||
* @return Pointer to signal info or nullptr.
|
||||
*/
|
||||
const SignalInfo *GetSignal() const;
|
||||
|
||||
private:
|
||||
NodeType m_type;
|
||||
std::string m_name;
|
||||
std::vector<std::unique_ptr<TreeNode> > m_children;
|
||||
std::unique_ptr<FrameInfo> m_frame;
|
||||
std::unique_ptr<SignalInfo> m_signal;
|
||||
};
|
||||
|
||||
#endif /* TREE_NODE_H */
|
||||
Reference in New Issue
Block a user