Silicon
A realtime platform for creating interactive media.
Node.hpp
Go to the documentation of this file.
1// BSD 2-Clause License
2//
3// Copyright (c) 2022, Matthew McCall
4// All rights reserved.
5//
6// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are met:
8//
9// 1. Redistributions of source code must retain the above copyright notice, this
10// list of conditions and the following disclaimer.
11//
12// 2. Redistributions in binary form must reproduce the above copyright notice,
13// this list of conditions and the following disclaimer in the documentation
14// and/or other materials provided with the distribution.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27//
28// Created by Matthew McCall on 10/9/22.
29//
30
31#ifndef SILICON_NODE_HPP
32#define SILICON_NODE_HPP
33
34#include <initializer_list>
35
36#include "Types.hpp"
37
38namespace Si {
39
40class Node;
41
43
44/*
45 * A Node is a base class for all objects that can be added to a NodeGraph.
46 */
47class Node
48{
49public:
50
52 {
53 public:
54 explicit ChildIterator(NodeGraph::adjacency_iterator);
55
56 Node& operator*();
58
61 const ChildIterator operator++(int);
62 const ChildIterator operator--(int);
63
64 bool operator==(const ChildIterator &other);
65 bool operator!=(const ChildIterator &other);
66
67 private:
68 NodeGraph::adjacency_iterator m_itr;
69 };
70
74 Node();
75 Node(const Node &) = delete;
76 Node(Node &&) = delete;
77
82
89
95 void addChild(Node &);
96
103
108 [[nodiscard]] ChildIterator begin() const;
109
114 [[nodiscard]] ChildIterator end() const;
115
119 virtual ~Node();
120
121protected:
122 unsigned m_id = 0;
123 NodeGraph::vertex_descriptor m_graphDescriptor;
124
125 static unsigned s_currentID;
127};
128
129}
130
131#endif //SILICON_NODE_HPP
ChildIterator & operator--()
Definition: Node.cpp:103
bool operator==(const ChildIterator &other)
Definition: Node.cpp:120
bool operator!=(const ChildIterator &other)
Definition: Node.cpp:124
Node * operator->()
Definition: Node.cpp:94
ChildIterator(NodeGraph::adjacency_iterator)
Definition: Node.cpp:86
ChildIterator & operator++()
Definition: Node.cpp:98
Node & operator*()
Definition: Node.cpp:89
static unsigned s_currentID
Definition: Node.hpp:125
static NodeGraph s_graph
Definition: Node.hpp:126
NodeGraph::vertex_descriptor m_graphDescriptor
Definition: Node.hpp:123
Node(const Node &)=delete
ChildIterator end() const
Gets the end iterator for the children of this node.
Definition: Node.cpp:72
unsigned m_id
Definition: Node.hpp:122
Node & addChildren(std::initializer_list< Node * > children)
Add a list of children to this node.
Definition: Node.cpp:77
Node(Node &&)=delete
Node()
Construct a new Node object.
Definition: Node.cpp:39
ChildIterator begin() const
Gets the begin iterator for the children of this node.
Definition: Node.cpp:67
void addChild(NotNull< Node * >)
Add a child to this node.
Definition: Node.cpp:51
virtual ~Node()
Destroys this node.
Definition: Node.cpp:61
Definition: Allocator.hpp:36
Graph< NotNull< Node * >, GraphList > NodeGraph
Definition: Node.hpp:42
boost::adjacency_list< ContainerT, ContainerT, boost::bidirectionalS, T > Graph
Container for representing relationships between objects.
Definition: Types.hpp:117
gsl::strict_not_null< T > NotNull
Definition: Types.hpp:48
List for use in Graphs.
Definition: Types.hpp:78