idol
A C++ Framework for Optimization
Loading...
Searching...
No Matches
Node.h
1//
2// Created by henri on 21/03/23.
3//
4
5#ifndef IDOL_NODE_H
6#define IDOL_NODE_H
7
8#include <memory>
9
10namespace idol {
11 class Model;
12 template<class NodeInfoT> class Node;
13}
14
15template<class NodeInfoT>
17
18 static_assert(std::is_default_constructible_v<NodeInfoT>);
19
20 unsigned int m_id;
21 unsigned int m_level;
22 std::shared_ptr<NodeInfoT> m_info;
23 std::shared_ptr<Node<NodeInfoT>> m_parent;
24
25 Node() : m_level(0), m_id(0), m_info(std::make_shared<NodeInfoT>()) {}
26 Node(NodeInfoT* t_ptr_to_info, unsigned int t_id) : m_id(t_id), m_level(0), m_info(t_ptr_to_info) {}
27public:
28 Node(NodeInfoT* t_ptr_to_info, unsigned int t_id, const Node<NodeInfoT>& t_parent)
29 : m_id(t_id),
30 m_level(t_parent.level() + 1),
31 m_info(t_ptr_to_info),
32 m_parent(std::make_shared<Node<NodeInfoT>>(t_parent))
33 {}
34
35 Node(const Node&) = default;
36 Node(Node&&) noexcept = default;
37
38 Node& operator=(const Node&) = default;
39 Node& operator=(Node&&) noexcept = default;
40
41 static Node<NodeInfoT> create_root_node() { return Node<NodeInfoT>(); }
42
43 static Node<NodeInfoT> create_detached_node(NodeInfoT* t_ptr_to_info) { return Node<NodeInfoT>(t_ptr_to_info, -1); }
44
45 [[nodiscard]] unsigned int id() const { return m_id; }
46
47 [[nodiscard]] unsigned int level() const { return m_level; }
48
49 [[nodiscard]] const NodeInfoT& info() const { return *m_info; }
50
51 NodeInfoT& info() { return *m_info; }
52
53 [[nodiscard]] const Node<NodeInfoT>& parent() const { return *m_parent; }
54};
55
56#endif //IDOL_NODE_H