TreeNode.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_DATASTRUCTURES_TREENODE_H
#define SURGSIM_DATASTRUCTURES_TREENODE_H
#include <vector>
#include <memory>
#include "SurgSim/DataStructures/TreeVisitor.h"
namespace SurgSim
{
namespace DataStructures
{
class TreeData;
class TreeNode
{
public:
TreeNode();
virtual ~TreeNode();
void setData(std::shared_ptr<TreeData> data);
std::shared_ptr<TreeData> getData() const;
size_t getNumChildren() const;
std::shared_ptr<TreeNode> getChild(size_t index) const;
void accept(TreeVisitor* visitor);
bool operator==(const TreeNode& node) const;
bool operator!=(const TreeNode& node) const;
protected:
virtual bool isEqual(const TreeNode& node) const;
virtual bool doAccept(TreeVisitor* visitor) = 0;
void setNumChildren(size_t numChildren);
void addChild(const std::shared_ptr<TreeNode>& node);
void addChild(const std::shared_ptr<TreeNode>&& node);
void setChild(size_t index, const std::shared_ptr<TreeNode>& node);
private:
std::vector<std::shared_ptr<TreeNode>> m_children;
std::shared_ptr<TreeData> m_data;
};
}; // namespace DataStructures
}; // namespace SurgSim
#endif // SURGSIM_DATASTRUCTURES_TREENODE_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::DataStructures::TreeNode::isEqual
virtual bool isEqual(const TreeNode &node) const
Returns true if the nodes are equal; otherwise, returns false.
Definition: TreeNode.cpp:44
SurgSim::DataStructures::TreeNode::getChild
std::shared_ptr< TreeNode > getChild(size_t index) const
Returns the specified child of this node.
Definition: TreeNode.cpp:93
SurgSim::DataStructures::TreeNode::m_data
std::shared_ptr< TreeData > m_data
Data of this node.
Definition: TreeNode.h:117
SurgSim::DataStructures::TreeVisitor
Abstract Class for visitors, this needs to be extended for other tree nodes when necessary return fal...
Definition: TreeVisitor.h:31
SurgSim::DataStructures::TreeNode
Basic tree node structure.
Definition: TreeNode.h:36
SurgSim::DataStructures::TreeNode::doAccept
virtual bool doAccept(TreeVisitor *visitor)=0
Private function for use with the visitor pattern, this needs to be implemented to make the correct d...
SurgSim::DataStructures::TreeNode::setNumChildren
void setNumChildren(size_t numChildren)
Sets the number of children of this node.
Definition: TreeNode.cpp:67
SurgSim::DataStructures::TreeNode::accept
void accept(TreeVisitor *visitor)
Public entry point for visitor, currently this performs pre-order traversal of the tree...
Definition: TreeNode.cpp:99
SurgSim::DataStructures::TreeNode::TreeNode
TreeNode()
Constructor. After construction, the node has no children, and the data is null.
Definition: TreeNode.cpp:27
SurgSim::DataStructures::TreeNode::getNumChildren
size_t getNumChildren() const
Definition: TreeNode.cpp:72
SurgSim::DataStructures::TreeNode::operator==
bool operator==(const TreeNode &node) const
Returns true if the nodes are equal; otherwise, returns false.
Definition: TreeNode.cpp:34
SurgSim::DataStructures::TreeNode::m_children
std::vector< std::shared_ptr< TreeNode > > m_children
Children of this node.
Definition: TreeNode.h:114
SurgSim::DataStructures::TreeNode::setData
void setData(std::shared_ptr< TreeData > data)
Sets the data of this node.
Definition: TreeNode.cpp:57
SurgSim::DataStructures::TreeNode::setChild
void setChild(size_t index, const std::shared_ptr< TreeNode > &node)
Set a specific child of this node.
Definition: TreeNode.cpp:87
SurgSim::DataStructures::TreeNode::addChild
void addChild(const std::shared_ptr< TreeNode > &node)
Add a child to this node.
Definition: TreeNode.cpp:77
SurgSim::DataStructures::TreeNode::operator!=
bool operator!=(const TreeNode &node) const
Returns true if the nodes are not equal; otherwise, returns false.
Definition: TreeNode.cpp:39
SurgSim::DataStructures::TreeNode::getData
std::shared_ptr< TreeData > getData() const
Definition: TreeNode.cpp:62
SurgSim::DataStructures::TreeNode::~TreeNode
virtual ~TreeNode()
Destructor.
Definition: TreeNode.cpp:30
TreeVisitor.h