libsgfc++ 2.0.1
A C++ library that uses SGFC to read and write SGF (Smart Game Format) data.
Loading...
Searching...
No Matches
Public Member Functions | List of all members
LibSgfcPlusPlus::SgfcTreeBuilder Class Reference

The SgfcTreeBuilder class provides an implementation of the ISgfcTreeBuilder interface. See the interface header file for documentation. More...

#include <SgfcTreeBuilder.h>

Inheritance diagram for LibSgfcPlusPlus::SgfcTreeBuilder:
LibSgfcPlusPlus::ISgfcTreeBuilder

Public Member Functions

 SgfcTreeBuilder (std::weak_ptr< ISgfcGame > game)
 Initializes a newly constructed SgfcTreeBuilder object. The tree builder operates on the game tree represented by game.
 
virtual ~SgfcTreeBuilder ()
 Destroys and cleans up the SgfcTreeBuilder object.
 
virtual std::weak_ptr< ISgfcGameGetGame () const override
 Returns the ISgfcGame object whose game tree the methods in the ISgfcTreeBuilder operate on.
 
virtual void SetFirstChild (std::shared_ptr< ISgfcNode > node, std::shared_ptr< ISgfcNode > child) const override
 Sets the first child node of node to child, replacing everything below node with child (which may be nullptr). Use InsertChild() if you want to keep the existing nodes below node.
 
virtual void AppendChild (std::shared_ptr< ISgfcNode > node, std::shared_ptr< ISgfcNode > child) const override
 Adds child as the last child to node. child may not be nullptr.
 
virtual void InsertChild (std::shared_ptr< ISgfcNode > node, std::shared_ptr< ISgfcNode > child, std::shared_ptr< ISgfcNode > referenceChild) const override
 Inserts child as a child to node, before the reference child node referenceChild. child may not be nullptr. referenceChild may be nullptr, but if it's not then it must be a child of node.
 
virtual void RemoveChild (std::shared_ptr< ISgfcNode > node, std::shared_ptr< ISgfcNode > child) const override
 Removes child from node. child may not be nullptr. child must be a child of the node.
 
virtual void ReplaceChild (std::shared_ptr< ISgfcNode > node, std::shared_ptr< ISgfcNode > newChild, std::shared_ptr< ISgfcNode > oldChild) const override
 Replaces oldChild with newChild. oldChild and newChild may not be nullptr. oldChild must be a child of node.
 
virtual void SetNextSibling (std::shared_ptr< ISgfcNode > node, std::shared_ptr< ISgfcNode > nextSibling) const override
 Sets the next sibling node of node to nextSibling, replacing the previous next sibling node, the siblings behind that, and the sub trees dangling from all of these siblings with nextSibling (which may be nullptr). Use InsertChild() if you want to keep the next sibling nodes.
 
virtual void SetParent (std::shared_ptr< ISgfcNode > node, std::shared_ptr< ISgfcNode > parent) const override
 Sets the parent node of node to parent. parent may be nullptr.
 
- Public Member Functions inherited from LibSgfcPlusPlus::ISgfcTreeBuilder
 ISgfcTreeBuilder ()
 Initializes a newly constructed ISgfcTreeBuilder object.
 
virtual ~ISgfcTreeBuilder ()
 Destroys and cleans up the ISgfcTreeBuilder object.
 

Detailed Description

The SgfcTreeBuilder class provides an implementation of the ISgfcTreeBuilder interface. See the interface header file for documentation.

Constructor & Destructor Documentation

◆ SgfcTreeBuilder()

LibSgfcPlusPlus::SgfcTreeBuilder::SgfcTreeBuilder ( std::weak_ptr< ISgfcGame > game)

Initializes a newly constructed SgfcTreeBuilder object. The tree builder operates on the game tree represented by game.

Exceptions
std::invalid_argumentIs thrown if game is nullptr.

Member Function Documentation

◆ AppendChild()

void LibSgfcPlusPlus::SgfcTreeBuilder::AppendChild ( std::shared_ptr< ISgfcNode > node,
std::shared_ptr< ISgfcNode > child ) const
overridevirtual

Adds child as the last child to node. child may not be nullptr.

If child is already part of the game tree in some other location, it is moved, together with the entire sub tree dangling from it, from its current location to the new location.

This method exists for convenience. The operations it performs can also be achieved by invoking Insertchild() and specifying nullptr as the referenceChild argument.

Exceptions
std::invalid_argumentIs thrown if node is nullptr, if child is nullptr, if child is an ancestor of node, or if child is equal to node.

Implements LibSgfcPlusPlus::ISgfcTreeBuilder.

◆ GetGame()

std::weak_ptr< ISgfcGame > LibSgfcPlusPlus::SgfcTreeBuilder::GetGame ( ) const
overridevirtual

Returns the ISgfcGame object whose game tree the methods in the ISgfcTreeBuilder operate on.

Implements LibSgfcPlusPlus::ISgfcTreeBuilder.

◆ InsertChild()

void LibSgfcPlusPlus::SgfcTreeBuilder::InsertChild ( std::shared_ptr< ISgfcNode > node,
std::shared_ptr< ISgfcNode > child,
std::shared_ptr< ISgfcNode > referenceChild ) const
overridevirtual

Inserts child as a child to node, before the reference child node referenceChild. child may not be nullptr. referenceChild may be nullptr, but if it's not then it must be a child of node.

If referenceChild is nullptr then child is inserted as the last child of node. The result is the same as if AppendChild() had been invoked on node.

If child is already part of the game tree in some other location, it is moved, together with the entire sub tree dangling from it, from its current location to the new location.

Exceptions
std::invalid_argumentIs thrown if node is nullptr, if child is nullptr, if referenceChild is not nullptr but it's not a child of the node, if child is an ancestor of node, or if child is equal to node.

Implements LibSgfcPlusPlus::ISgfcTreeBuilder.

◆ RemoveChild()

void LibSgfcPlusPlus::SgfcTreeBuilder::RemoveChild ( std::shared_ptr< ISgfcNode > node,
std::shared_ptr< ISgfcNode > child ) const
overridevirtual

Removes child from node. child may not be nullptr. child must be a child of the node.

The game tree is relinked to close the gap.

child and the entire sub tree dangling from it, is discarded once no one holds a reference to it anymore.

Exceptions
std::invalid_argumentIs thrown if node is nullptr, if child is nullptr, or if child is not a child of node.

Implements LibSgfcPlusPlus::ISgfcTreeBuilder.

◆ ReplaceChild()

void LibSgfcPlusPlus::SgfcTreeBuilder::ReplaceChild ( std::shared_ptr< ISgfcNode > node,
std::shared_ptr< ISgfcNode > newChild,
std::shared_ptr< ISgfcNode > oldChild ) const
overridevirtual

Replaces oldChild with newChild. oldChild and newChild may not be nullptr. oldChild must be a child of node.

If newChild is already part of the game tree in some other location, it is moved, together with the entire sub tree dangling from it, from its current location to the new location.

oldChild and the entire sub tree dangling from it, is discarded once no one holds a reference to it anymore.

Exceptions
std::invalid_argumentIs thrown if node is nullptr, if oldChild or newChild are nullptr, if oldChild is not a child of node, if newChild is an ancestor of node, or if newChild is equal to node.

Implements LibSgfcPlusPlus::ISgfcTreeBuilder.

◆ SetFirstChild()

void LibSgfcPlusPlus::SgfcTreeBuilder::SetFirstChild ( std::shared_ptr< ISgfcNode > node,
std::shared_ptr< ISgfcNode > child ) const
overridevirtual

Sets the first child node of node to child, replacing everything below node with child (which may be nullptr). Use InsertChild() if you want to keep the existing nodes below node.

If child is already part of the game tree in some other location, it is moved, together with the entire sub tree dangling from it, from its current location to the new location.

The previous first child node, the siblings behind that, and the sub trees dangling from all of these nodes, are discarded once no one holds a reference to them anymore.

Exceptions
std::invalid_argumentIs thrown if node is nullptr, if child is an ancestor of node, or if child is equal to node.

Implements LibSgfcPlusPlus::ISgfcTreeBuilder.

◆ SetNextSibling()

void LibSgfcPlusPlus::SgfcTreeBuilder::SetNextSibling ( std::shared_ptr< ISgfcNode > node,
std::shared_ptr< ISgfcNode > nextSibling ) const
overridevirtual

Sets the next sibling node of node to nextSibling, replacing the previous next sibling node, the siblings behind that, and the sub trees dangling from all of these siblings with nextSibling (which may be nullptr). Use InsertChild() if you want to keep the next sibling nodes.

node must not be the root node of a game tree because a root node by definition can't have siblings.

If nextSibling is already part of the game tree in some other location, it is moved, together with the entire sub tree dangling from it, from its current location to the new location.

The previous next sibling node, the siblings behind that, and the sub trees dangling from all of these siblings, are discarded once no one holds a reference to them anymore.

Exceptions
std::invalid_argumentIs thrown if node is nullptr, if node is the root node of a game tree, if nextSibling is not nullptr and an ancestor of node, or if nextSibling is equal to node.

Implements LibSgfcPlusPlus::ISgfcTreeBuilder.

◆ SetParent()

void LibSgfcPlusPlus::SgfcTreeBuilder::SetParent ( std::shared_ptr< ISgfcNode > node,
std::shared_ptr< ISgfcNode > parent ) const
overridevirtual

Sets the parent node of node to parent. parent may be nullptr.

If parent is not nullptr and node is already a child of parent, then this method has no effect.

If parent is not nullptr and node is not yet a child of parent, then node is added as the last child of parent. The result is the same as if AppendChild() had been invoked on parent with node as the argument.

If parent is not nullptr and if node is already part of the game tree in some other location, node is moved, together with the entire sub tree dangling from it, from its current location to the new location.

If parent is nullptr then node and the entire sub tree dangling from it, is discarded once no one holds a reference to it anymore. The game tree is relinked to close the gap. The result is the same as if RemoveChild() had been invoked on the node's parent with node as the argument.

Exceptions
std::invalid_argumentIs thrown if node is nullptr, if parent is a descendant of node, or if parent is equal to node.

Implements LibSgfcPlusPlus::ISgfcTreeBuilder.


The documentation for this class was generated from the following files: