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::SgfcGame Class Reference

The SgfcGame class provides an implementation of the ISgfcGame interface. See the interface header file for documentation. More...

#include <SgfcGame.h>

Inheritance diagram for LibSgfcPlusPlus::SgfcGame:
LibSgfcPlusPlus::ISgfcGame

Public Member Functions

 SgfcGame ()
 Initializes a newly constructed SgfcGame object. The game has no root node.
 
 SgfcGame (std::shared_ptr< ISgfcNode > rootNode)
 Initializes a newly constructed SgfcGame object. The game has the specified root node rootNode.
 
virtual ~SgfcGame ()
 Destroys and cleans up the SgfcGame object.
 
virtual SgfcGameType GetGameType () const override
 Returns the property value(s) found in the root node property of type SgfcPropertyType::GM, interpreted as an SgfcGameType value.
 
virtual SgfcNumber GetGameTypeAsNumber () const override
 Returns the property value(s) found in the root node property of type SgfcPropertyType::GM, as an SgfcNumber value.
 
virtual bool HasBoardSize () const override
 Returns true if the game has a board size. Returns false if the game has no board size.
 
virtual SgfcBoardSize GetBoardSize () const override
 Returns the board size found in the root node property of type SgfcPropertyType::SZ, as an SgfcBoardSize value.
 
virtual bool HasRootNode () const override
 Returns true if the game has a root node. Returns false if the game has no root node.
 
virtual std::shared_ptr< ISgfcNodeGetRootNode () const override
 Returns the game tree's root node. Returns nullptr if HasRootNode() returns false.
 
virtual void SetRootNode (std::shared_ptr< ISgfcNode > rootNode) override
 Sets the game tree's root node to rootNode. The previous root node, and with it the entire previous game tree, is discarded.
 
virtual std::vector< std::shared_ptr< ISgfcNode > > GetGameInfoNodes () const override
 Returns the game tree's game info nodes. Returns an empty list if the game tree has no game info nodes.
 
virtual std::shared_ptr< ISgfcGameInfoCreateGameInfo () const override
 Returns a newly constructed ISgfcGameInfo object with values taken from the properties in the root node that GetRootNode() returns and the first game info node in the list of game info nodes returned by GetGameInfoNodes().
 
virtual void WriteGameInfo (std::shared_ptr< ISgfcGameInfo > gameInfo) override
 Writes all root property values in gameInfo to the corresponding properties in the root node that GetRootNode() returns, and all game info property values in gameInfo to the first game info node in the list of game info nodes returned by GetGameInfoNodes().
 
virtual std::shared_ptr< ISgfcTreeBuilderGetTreeBuilder () const override
 Returns an ISgfcTreeBuilder object that can be used to manipulate the game tree.
 
void SetTreeBuilder (std::shared_ptr< ISgfcTreeBuilder > treeBuilder)
 Configures the SgfcGame object with treeBuilder, an object that can be used to manipulate the game tree.
 
- Public Member Functions inherited from LibSgfcPlusPlus::ISgfcGame
 ISgfcGame ()
 Initializes a newly constructed ISgfcGame object.
 
virtual ~ISgfcGame ()
 Destroys and cleans up the ISgfcGame object.
 

Detailed Description

The SgfcGame class provides an implementation of the ISgfcGame interface. See the interface header file for documentation.

Constructor & Destructor Documentation

◆ SgfcGame()

LibSgfcPlusPlus::SgfcGame::SgfcGame ( std::shared_ptr< ISgfcNode > rootNode)

Initializes a newly constructed SgfcGame object. The game has the specified root node rootNode.

Exceptions
std::invalid_argumentIs thrown if rootNode is nullptr.

Member Function Documentation

◆ CreateGameInfo()

std::shared_ptr< ISgfcGameInfo > LibSgfcPlusPlus::SgfcGame::CreateGameInfo ( ) const
overridevirtual

Returns a newly constructed ISgfcGameInfo object with values taken from the properties in the root node that GetRootNode() returns and the first game info node in the list of game info nodes returned by GetGameInfoNodes().

This is a convenience method that is useful if a game contains only one game tree (GetGameInfoNodes() returns only one game info node). If the game contains more than one game tree, an ISgfcGameInfo object that describes the second, third, etc. game tree can be obtained by invoking ISgfcNode::CreateGameInfo() on the second, third, etc. game info nodes returned by GetGameInfoNodes().

If the game has no game trees (GetGameInfoNodes() returns an empty list) then the ISgfcGameInfo object returned by this method contains only values taken from the properties in the root node, but all values that would normally be taken from the properties in the game info node have default values.

If the game has no root node (HasRootNode() returns false) then the ISgfcGameInfo object contains default values.

If GetGameType() returns SgfcGameType::Go then the returned object is an ISgfcGoGameInfo object.

See also
ISgfcNode::CreateGameInfo()

Implements LibSgfcPlusPlus::ISgfcGame.

◆ GetBoardSize()

SgfcBoardSize LibSgfcPlusPlus::SgfcGame::GetBoardSize ( ) const
overridevirtual

Returns the board size found in the root node property of type SgfcPropertyType::SZ, as an SgfcBoardSize value.

Return values
SgfcBoardSizeIf the property is present and has a valid value. The value is guaranteed not to be SgfcConstants::BoardSizeNone nor SgfcConstants::BoardSizeInvalid.
SgfcConstants::BoardSizeDefaultGoIf GetGameType() returns SgfcGameType::Go and one of the following is true: The game has no root node, or the game has a root node but the property is not present, or the game has a root node and the property is present but has no value (e.g. while the game tree is being set up programmatically).
SgfcConstants::BoardSizeDefaultChessIf GetGameType() returns SgfcGameType::Chess and one of the following is true: The game has a root node but the property is not present, or the game has a root node and the property is present but has no value (e.g. while the game tree is being set up programmatically).
SgfcConstants::BoardSizeNoneIf GetGameType() returns neither SgfcGameType::Go nor SgfcGameType::Chess (these are the two game types for which the SGF standard defines a default board size) and one of the following is true: The game has a root node but the property is not present, or the game has a root node and the property is present but has no value (e.g. while the game tree is being set up programmatically).
SgfcConstants::BoardSizeInvalidIf the property is present but either its property value(s) cannot be converted to an SgfcBoardSize value (the property has more than one value, or it has a single value that is neither a Number nor a composed value consisting of two Number values), or if conversion is possible but the SgfcBoardSize value violates the constraints defined by the SGF standard. See the documentation of SgfcConstants::BoardSizeInvalid for details.

Implements LibSgfcPlusPlus::ISgfcGame.

◆ GetGameInfoNodes()

std::vector< std::shared_ptr< ISgfcNode > > LibSgfcPlusPlus::SgfcGame::GetGameInfoNodes ( ) const
overridevirtual

Returns the game tree's game info nodes. Returns an empty list if the game tree has no game info nodes.

This is a convenience method that searches the game tree's nodes on behalf of the caller and returns the result. The search logic is this:

  • Starting with the root node every node is examined whether it contains one or more game info properties. These are properties that are classified as SgfcPropertyCategory::GameInfo.
  • When a node contains at least one game info property it is considered to be a game info node and included in the search result returned by the method.
  • The search does not continue below a game info node. This is because the SGF standard mandates that there may be only one game info node on any path within a tree of nodes. If the root node contains at least one game info property, the search result will therefore contain only the root node. Since game info properties are usually stored in the root node this is actually the expected outcome for most of the SGF content out there.
  • The search is performed depth-first.
See also
SgfcNodeTraits::GameInfo

Implements LibSgfcPlusPlus::ISgfcGame.

◆ GetGameType()

SgfcGameType LibSgfcPlusPlus::SgfcGame::GetGameType ( ) const
overridevirtual

Returns the property value(s) found in the root node property of type SgfcPropertyType::GM, interpreted as an SgfcGameType value.

Return values
SgfcGameTypeIf the property is present and has a single Number value, and that value is defined in the SGF standard, then the SgfcGameType value that corresponds to the Number value is returned. The value is guaranteed not to be SgfcGameType::Unknown.
SgfcConstants::DefaultGameTypeIf the property is not present, or if the game has no root node, or if the property is present but has no value. The value is guaranteed not to be SgfcGameType::Unknown.
SgfcGameType::UnknownIf the property is present but its value(s) cannot be converted to a Number value (the property has more than one value, or the single value is not a Number value), or if conversion is possible but the Number value is not defined in the SGF standard. Invoke GetGameTypeAsNumber() to obtain the game type as Number value.

Implements LibSgfcPlusPlus::ISgfcGame.

◆ GetGameTypeAsNumber()

SgfcNumber LibSgfcPlusPlus::SgfcGame::GetGameTypeAsNumber ( ) const
overridevirtual

Returns the property value(s) found in the root node property of type SgfcPropertyType::GM, as an SgfcNumber value.

This is useful if GetGameType() returns SgfcGameType::Unknown because the Number value is not defined in the SGF standard and cannot be mapped to a member of the enumeration SgfcGameType.

Return values
SgfcNumberIf the property is present and contains a single Number value, then that Number value is returned. If the property is not present, or if the game has no root node, or if the property is present but has no value, then this method returns the Number value that corresponds to SgfcConstants::DefaultGameType.
SgfcConstants::GameTypeNaNIf the property is present but its value(s) cannot be converted to a Number value, either because the property has more than one value, or its single value is not a Number value.

Implements LibSgfcPlusPlus::ISgfcGame.

◆ GetRootNode()

std::shared_ptr< ISgfcNode > LibSgfcPlusPlus::SgfcGame::GetRootNode ( ) const
overridevirtual

Returns the game tree's root node. Returns nullptr if HasRootNode() returns false.

Implements LibSgfcPlusPlus::ISgfcGame.

◆ GetTreeBuilder()

std::shared_ptr< ISgfcTreeBuilder > LibSgfcPlusPlus::SgfcGame::GetTreeBuilder ( ) const
overridevirtual

Returns an ISgfcTreeBuilder object that can be used to manipulate the game tree.

Implements LibSgfcPlusPlus::ISgfcGame.

◆ HasBoardSize()

bool LibSgfcPlusPlus::SgfcGame::HasBoardSize ( ) const
overridevirtual

Returns true if the game has a board size. Returns false if the game has no board size.

The game has no board size if GetBoardSize() returns SgfcConstants::BoardSizeNone or SgfcConstants::BoardSizeInvalid.

Implements LibSgfcPlusPlus::ISgfcGame.

◆ HasRootNode()

bool LibSgfcPlusPlus::SgfcGame::HasRootNode ( ) const
overridevirtual

Returns true if the game has a root node. Returns false if the game has no root node.

Implements LibSgfcPlusPlus::ISgfcGame.

◆ SetRootNode()

void LibSgfcPlusPlus::SgfcGame::SetRootNode ( std::shared_ptr< ISgfcNode > rootNode)
overridevirtual

Sets the game tree's root node to rootNode. The previous root node, and with it the entire previous game tree, is discarded.

Implements LibSgfcPlusPlus::ISgfcGame.

◆ WriteGameInfo()

void LibSgfcPlusPlus::SgfcGame::WriteGameInfo ( std::shared_ptr< ISgfcGameInfo > gameInfo)
overridevirtual

Writes all root property values in gameInfo to the corresponding properties in the root node that GetRootNode() returns, and all game info property values in gameInfo to the first game info node in the list of game info nodes returned by GetGameInfoNodes().

This is a convenience method that is useful if a game contains only one game tree (GetGameInfoNodes() returns only one game info node). If the game contains more than one game tree, then ISgfcNode::WriteGameInfo() can be invoked to write the content of gameInfo to the second, third, etc. game info nodes returned by GetGameInfoNodes().

If the game has no game trees (GetGameInfoNodes() returns an empty list) then the game info property values in gameInfo are written to the root node that GetRootNode() returns.

If the game has no root node (HasRootNode() returns false) then a new root node is created and all property values in gameInfo are written to the new node.

Game info property values are written only if they are not equal to their default values (already existing property values are overwritten). Game info property values that are equal to their default value cause the property to be removed, if it exists, from the game info node.

Root property values are always written, regardless of whether they are equal to their default values.

Exceptions
std::invalid_argumentIs thrown if gameInfo is nullptr.

Implements LibSgfcPlusPlus::ISgfcGame.


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