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

The SgfcSinglePropertyValue class provides an implementation of the ISgfcSinglePropertyValue interface. See the interface header file for documentation. More...

#include <SgfcSinglePropertyValue.h>

Inheritance diagram for LibSgfcPlusPlus::SgfcSinglePropertyValue:
LibSgfcPlusPlus::ISgfcSinglePropertyValue LibSgfcPlusPlus::ISgfcPropertyValue LibSgfcPlusPlus::SgfcColorPropertyValue LibSgfcPlusPlus::SgfcDoublePropertyValue LibSgfcPlusPlus::SgfcMovePropertyValue LibSgfcPlusPlus::SgfcNumberPropertyValue LibSgfcPlusPlus::SgfcPointPropertyValue LibSgfcPlusPlus::SgfcRealPropertyValue LibSgfcPlusPlus::SgfcSimpleTextPropertyValue LibSgfcPlusPlus::SgfcStonePropertyValue LibSgfcPlusPlus::SgfcTextPropertyValue

Public Member Functions

 SgfcSinglePropertyValue (const std::string &rawValue)
 Initializes a newly constructed SgfcSinglePropertyValue object that has the raw property string value rawValue. The value type is SgfcPropertyValueType::Unknown, HasTypedValue() returns false and GetTypeConversionErrorMessage() returns an empty string.
 
 SgfcSinglePropertyValue (const std::string &rawValue, SgfcPropertyValueType valueType)
 Initializes a newly constructed SgfcSinglePropertyValue object that has the raw property string value rawValue and the value type valueType. HasTypedValue() returns true and GetTypeConversionErrorMessage() returns an empty string.
 
 SgfcSinglePropertyValue (const std::string &rawValue, SgfcPropertyValueType valueType, const std::string &typeConversionErrorMessage)
 Initializes a newly constructed SgfcSinglePropertyValue object that has the raw property string value rawValue and the value type valueType. HasTypedValue() returns false and GetTypeConversionErrorMessage() returns typeConversionErrorMessage.
 
virtual ~SgfcSinglePropertyValue ()
 Destroys and cleans up the SgfcSinglePropertyValue object.
 
virtual bool IsComposedValue () const override
 Returns true if the ISgfcPropertyValue object holds a "composed" value, i.e. a value that consists of a composite of two single values. Returns false if the ISgfcPropertyValue holds only a single value.
 
virtual const ISgfcSinglePropertyValueToSingleValue () const override
 Returns nullptr if IsComposedValue() returns true. Returns an ISgfcSinglePropertyValue object if IsComposedValue() returns false. The caller is not the owner of the ISgfcSinglePropertyValue object.
 
virtual SgfcPropertyValueType GetValueType () const override
 Returns the concrete type of the property value object. Depending on the value returned, a caller then knows which one of the convenience casting methods to use.
 
virtual bool HasTypedValue () const override
 Returns true if the raw string value returned by GetRawValue() is available as a typed value. Otherwise returns false.
 
virtual std::string GetTypeConversionErrorMessage () const override
 Returns an error message that describes why the raw string value returned by GetRawValue() could not be converted to the typed value returned by GetValueType().
 
virtual std::string GetRawValue () const override
 Returns the property value as a raw string, i.e. as close as possible as it appears in the original SGF content.
 
virtual const ISgfcNumberPropertyValueToNumberValue () const override
 Returns an ISgfcNumberPropertyValue object if GetValueType() returns SgfcPropertyValueType::Number. Returns nullptr otherwise. The caller is not the owner of the returned object.
 
virtual const ISgfcRealPropertyValueToRealValue () const override
 Returns an ISgfcRealPropertyValue object if GetValueType() returns SgfcPropertyValueType::Real. Returns nullptr otherwise. The caller is not the owner of the returned object.
 
virtual const ISgfcDoublePropertyValueToDoubleValue () const override
 Returns an ISgfcDoublePropertyValue object if GetValueType() returns SgfcPropertyValueType::Double. Returns nullptr otherwise. The caller is not the owner of the returned object.
 
virtual const ISgfcColorPropertyValueToColorValue () const override
 Returns an ISgfcColorPropertyValue object if GetValueType() returns SgfcPropertyValueType::Color. Returns nullptr otherwise. The caller is not the owner of the returned object.
 
virtual const ISgfcSimpleTextPropertyValueToSimpleTextValue () const override
 Returns an ISgfcSimpleTextPropertyValue object if GetValueType() returns SgfcPropertyValueType::SimpleText. Returns nullptr otherwise. The caller is not the owner of the returned object.
 
virtual const ISgfcTextPropertyValueToTextValue () const override
 Returns an ISgfcTextPropertyValue object if GetValueType() returns SgfcPropertyValueType::Text. Returns nullptr otherwise. The caller is not the owner of the returned object.
 
virtual const ISgfcPointPropertyValueToPointValue () const override
 Returns an ISgfcPointPropertyValue object if GetValueType() returns SgfcPropertyValueType::Point. Returns nullptr otherwise. The caller is not the owner of the returned object.
 
virtual const ISgfcMovePropertyValueToMoveValue () const override
 Returns an ISgfcMovePropertyValue object if GetValueType() returns SgfcPropertyValueType::Move. Returns nullptr otherwise. The caller is not the owner of the returned object.
 
virtual const ISgfcStonePropertyValueToStoneValue () const override
 Returns an ISgfcStonePropertyValue object if GetValueType() returns SgfcPropertyValueType::Stone. Returns nullptr otherwise. The caller is not the owner of the returned object.
 
- Public Member Functions inherited from LibSgfcPlusPlus::ISgfcSinglePropertyValue
 ISgfcSinglePropertyValue ()
 Initializes a newly constructed ISgfcSinglePropertyValue object.
 
virtual ~ISgfcSinglePropertyValue ()
 Destroys and cleans up the ISgfcSinglePropertyValue object.
 
- Public Member Functions inherited from LibSgfcPlusPlus::ISgfcPropertyValue
 ISgfcPropertyValue ()
 Initializes a newly constructed ISgfcPropertyValue object.
 
virtual ~ISgfcPropertyValue ()
 Destroys and cleans up the ISgfcPropertyValue object.
 
virtual const ISgfcComposedPropertyValueToComposedValue () const
 Returns an ISgfcComposedPropertyValue object if IsComposedValue() returns true. Returns nullptr if IsComposedValue() returns false. The caller is not the owner of the ISgfcComposedPropertyValue object.
 

Detailed Description

The SgfcSinglePropertyValue class provides an implementation of the ISgfcSinglePropertyValue interface. See the interface header file for documentation.

Constructor & Destructor Documentation

◆ SgfcSinglePropertyValue()

LibSgfcPlusPlus::SgfcSinglePropertyValue::SgfcSinglePropertyValue ( const std::string & rawValue,
SgfcPropertyValueType valueType )

Initializes a newly constructed SgfcSinglePropertyValue object that has the raw property string value rawValue and the value type valueType. HasTypedValue() returns true and GetTypeConversionErrorMessage() returns an empty string.

Subclasses are expected to use this constructor.

Member Function Documentation

◆ GetRawValue()

std::string LibSgfcPlusPlus::SgfcSinglePropertyValue::GetRawValue ( ) const
overridevirtual

Returns the property value as a raw string, i.e. as close as possible as it appears in the original SGF content.

If the property value object was created programmatically by the library client by invoking a factory method, then GetRawValue() returns a properly stringified version of the typed property value. Color and Double values are converted to the string value as defined by the SGF standard.

If the property value object was created internally by libsgfc++ as part of parsing SGF content, then the following processing is applied to the original SGF content before it is made available from this getter as raw string:

  • The escape character ("\") is stripped from SimpleText and Text values (unless it was escaped itself). - Values that are not SimpleText or Text are trimmed of leading and trailing whitespace. - In SimpleText values, whitespace characters other than space are converted to space. Exception: Escaped line breaks are removed entirely. - In Text values, whitespace characters other than line breaks are converted to space. In addition, escaped line breaks are removed entirely. - In Move values, if the game type is Go and the board size is <= 19x19, the value "tt" is converted to an empty string. This is in accord with the SGF standard that defines an empty string and value "tt" both to express a pass move, but in FF4 the "tt" representation is kept only for compatibility with FF3.

Implements LibSgfcPlusPlus::ISgfcSinglePropertyValue.

◆ GetTypeConversionErrorMessage()

std::string LibSgfcPlusPlus::SgfcSinglePropertyValue::GetTypeConversionErrorMessage ( ) const
overridevirtual

Returns an error message that describes why the raw string value returned by GetRawValue() could not be converted to the typed value returned by GetValueType().

Returns an empty string if HasTypedValue() returns true, or if it returns false but GetValueType() returns SgfcPropertyValueType::Unknown.

This method is intended for when the property value object was created internally by libsgfc++ as part of parsing SGF content, but there was an error converting the raw string value to the expected value type.

If the property value object was created programmatically by the library client by invoking a factory method, then GetTypeConversionErrorMessage() always returns an empty string because the library client is not allowed to specify untyped property values.

Implements LibSgfcPlusPlus::ISgfcSinglePropertyValue.

◆ GetValueType()

SgfcPropertyValueType LibSgfcPlusPlus::SgfcSinglePropertyValue::GetValueType ( ) const
overridevirtual

Returns the concrete type of the property value object. Depending on the value returned, a caller then knows which one of the convenience casting methods to use.

If the property value object was created internally by libsgfc++ as part of parsing SGF content, then the outcome is as follows:

If the property value object was created programmatically by the library client by invoking a factory method, then GetValueType() returns whichever SgfcPropertyValueType was requested by the library client. HasTypeValue() always returns true, unless the library client explicitly requested an untyped property value for a custom property.

Note
GetValueType() never returns SgfcPropertyValueType::None.

Implements LibSgfcPlusPlus::ISgfcSinglePropertyValue.

◆ HasTypedValue()

bool LibSgfcPlusPlus::SgfcSinglePropertyValue::HasTypedValue ( ) const
overridevirtual

Returns true if the raw string value returned by GetRawValue() is available as a typed value. Otherwise returns false.

"Available as a typed value" means that ISgfcSinglePropertyValue can be cast to a concrete type and that type can then be used to retrieve the typed value. Example: GetValueType() returns SgfcPropertyValueType::Number. ToNumberValue() can therefore be invoked to obtain an ISgfcNumberPropertyValue object, and ISgfcNumberPropertyValue::GetNumberValue() can then be invoked to retrieve the signed integer number that corresponds to the raw string value that GetRawValue() returns.

"Not available as a typed value" (i.e. HasTypedValue() returns false) means that the ISgfcSinglePropertyValue object cannot be cast to any concrete type, i.e. all of the convenience casting methods return nullptr. The interpretation of the raw property string value returned by GetRawValue() is left to the library client.

If the property value object was created internally by libsgfc++ as part of parsing SGF content, then the outcome is as follows:

  • For values of properties that are defined in the SGF standard libsgfc++ attempts to interpret the raw property string value according to the value type defined property in the SGF standard. HasTypedValue() returns true if that interpretation succeeds, otherwwise it returns false and GetTypeConversionErrorMessage() returns a description of why the interpretation failed.
  • HasTypedValue() always returns false for values of properties that are not defined in the SGF standard (aka "custom properties"). GetTypeConversionErrorMessage() returns an empty string in that case because libsgfc++ did not attempt an interpretation.

If the property value object was created programmatically by the library client by invoking a factory method, then HasTypedValue() returns true unless the library client explicitly requested an untyped property value for a custom property.

Implements LibSgfcPlusPlus::ISgfcSinglePropertyValue.

◆ IsComposedValue()

bool LibSgfcPlusPlus::SgfcSinglePropertyValue::IsComposedValue ( ) const
overridevirtual

Returns true if the ISgfcPropertyValue object holds a "composed" value, i.e. a value that consists of a composite of two single values. Returns false if the ISgfcPropertyValue holds only a single value.

Implements LibSgfcPlusPlus::ISgfcPropertyValue.

◆ ToColorValue()

const ISgfcColorPropertyValue * LibSgfcPlusPlus::SgfcSinglePropertyValue::ToColorValue ( ) const
overridevirtual

Returns an ISgfcColorPropertyValue object if GetValueType() returns SgfcPropertyValueType::Color. Returns nullptr otherwise. The caller is not the owner of the returned object.

Implements LibSgfcPlusPlus::ISgfcSinglePropertyValue.

Reimplemented in LibSgfcPlusPlus::SgfcColorPropertyValue.

◆ ToDoubleValue()

const ISgfcDoublePropertyValue * LibSgfcPlusPlus::SgfcSinglePropertyValue::ToDoubleValue ( ) const
overridevirtual

Returns an ISgfcDoublePropertyValue object if GetValueType() returns SgfcPropertyValueType::Double. Returns nullptr otherwise. The caller is not the owner of the returned object.

Implements LibSgfcPlusPlus::ISgfcSinglePropertyValue.

Reimplemented in LibSgfcPlusPlus::SgfcDoublePropertyValue.

◆ ToMoveValue()

const ISgfcMovePropertyValue * LibSgfcPlusPlus::SgfcSinglePropertyValue::ToMoveValue ( ) const
overridevirtual

Returns an ISgfcMovePropertyValue object if GetValueType() returns SgfcPropertyValueType::Move. Returns nullptr otherwise. The caller is not the owner of the returned object.

Implements LibSgfcPlusPlus::ISgfcSinglePropertyValue.

Reimplemented in LibSgfcPlusPlus::SgfcMovePropertyValue.

◆ ToNumberValue()

const ISgfcNumberPropertyValue * LibSgfcPlusPlus::SgfcSinglePropertyValue::ToNumberValue ( ) const
overridevirtual

Returns an ISgfcNumberPropertyValue object if GetValueType() returns SgfcPropertyValueType::Number. Returns nullptr otherwise. The caller is not the owner of the returned object.

Implements LibSgfcPlusPlus::ISgfcSinglePropertyValue.

Reimplemented in LibSgfcPlusPlus::SgfcNumberPropertyValue.

◆ ToPointValue()

const ISgfcPointPropertyValue * LibSgfcPlusPlus::SgfcSinglePropertyValue::ToPointValue ( ) const
overridevirtual

Returns an ISgfcPointPropertyValue object if GetValueType() returns SgfcPropertyValueType::Point. Returns nullptr otherwise. The caller is not the owner of the returned object.

Implements LibSgfcPlusPlus::ISgfcSinglePropertyValue.

Reimplemented in LibSgfcPlusPlus::SgfcPointPropertyValue.

◆ ToRealValue()

const ISgfcRealPropertyValue * LibSgfcPlusPlus::SgfcSinglePropertyValue::ToRealValue ( ) const
overridevirtual

Returns an ISgfcRealPropertyValue object if GetValueType() returns SgfcPropertyValueType::Real. Returns nullptr otherwise. The caller is not the owner of the returned object.

Implements LibSgfcPlusPlus::ISgfcSinglePropertyValue.

Reimplemented in LibSgfcPlusPlus::SgfcRealPropertyValue.

◆ ToSimpleTextValue()

const ISgfcSimpleTextPropertyValue * LibSgfcPlusPlus::SgfcSinglePropertyValue::ToSimpleTextValue ( ) const
overridevirtual

Returns an ISgfcSimpleTextPropertyValue object if GetValueType() returns SgfcPropertyValueType::SimpleText. Returns nullptr otherwise. The caller is not the owner of the returned object.

Implements LibSgfcPlusPlus::ISgfcSinglePropertyValue.

Reimplemented in LibSgfcPlusPlus::SgfcSimpleTextPropertyValue.

◆ ToSingleValue()

const ISgfcSinglePropertyValue * LibSgfcPlusPlus::SgfcSinglePropertyValue::ToSingleValue ( ) const
overridevirtual

Returns nullptr if IsComposedValue() returns true. Returns an ISgfcSinglePropertyValue object if IsComposedValue() returns false. The caller is not the owner of the ISgfcSinglePropertyValue object.

Reimplemented from LibSgfcPlusPlus::ISgfcPropertyValue.

◆ ToStoneValue()

const ISgfcStonePropertyValue * LibSgfcPlusPlus::SgfcSinglePropertyValue::ToStoneValue ( ) const
overridevirtual

Returns an ISgfcStonePropertyValue object if GetValueType() returns SgfcPropertyValueType::Stone. Returns nullptr otherwise. The caller is not the owner of the returned object.

Implements LibSgfcPlusPlus::ISgfcSinglePropertyValue.

Reimplemented in LibSgfcPlusPlus::SgfcStonePropertyValue.

◆ ToTextValue()

const ISgfcTextPropertyValue * LibSgfcPlusPlus::SgfcSinglePropertyValue::ToTextValue ( ) const
overridevirtual

Returns an ISgfcTextPropertyValue object if GetValueType() returns SgfcPropertyValueType::Text. Returns nullptr otherwise. The caller is not the owner of the returned object.

Implements LibSgfcPlusPlus::ISgfcSinglePropertyValue.

Reimplemented in LibSgfcPlusPlus::SgfcTextPropertyValue.


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