libsgfc++ 2.0.1
A C++ library that uses SGFC to read and write SGF (Smart Game Format) data.
|
The SgfcGame class provides an implementation of the ISgfcGame interface. See the interface header file for documentation. More...
#include <SgfcGame.h>
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< ISgfcNode > | GetRootNode () 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< ISgfcGameInfo > | CreateGameInfo () 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< ISgfcTreeBuilder > | GetTreeBuilder () 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. | |
The SgfcGame class provides an implementation of the ISgfcGame interface. See the interface header file for documentation.
LibSgfcPlusPlus::SgfcGame::SgfcGame | ( | std::shared_ptr< ISgfcNode > | rootNode | ) |
Initializes a newly constructed SgfcGame object. The game has the specified root node rootNode.
std::invalid_argument | Is thrown if rootNode is nullptr. |
|
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.
Implements LibSgfcPlusPlus::ISgfcGame.
|
overridevirtual |
Returns the board size found in the root node property of type SgfcPropertyType::SZ, as an SgfcBoardSize value.
SgfcBoardSize | If the property is present and has a valid value. The value is guaranteed not to be SgfcConstants::BoardSizeNone nor SgfcConstants::BoardSizeInvalid. |
SgfcConstants::BoardSizeDefaultGo | If 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::BoardSizeDefaultChess | If 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::BoardSizeNone | If 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::BoardSizeInvalid | If 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.
|
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:
Implements LibSgfcPlusPlus::ISgfcGame.
|
overridevirtual |
Returns the property value(s) found in the root node property of type SgfcPropertyType::GM, interpreted as an SgfcGameType value.
SgfcGameType | If 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::DefaultGameType | If 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::Unknown | If 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.
|
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.
SgfcNumber | If 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::GameTypeNaN | If 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.
|
overridevirtual |
Returns the game tree's root node. Returns nullptr if HasRootNode() returns false.
Implements LibSgfcPlusPlus::ISgfcGame.
|
overridevirtual |
Returns an ISgfcTreeBuilder object that can be used to manipulate the game tree.
Implements LibSgfcPlusPlus::ISgfcGame.
|
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.
|
overridevirtual |
Returns true if the game has a root node. Returns false if the game has no root node.
Implements LibSgfcPlusPlus::ISgfcGame.
|
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.
|
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.
std::invalid_argument | Is thrown if gameInfo is nullptr. |
Implements LibSgfcPlusPlus::ISgfcGame.