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

The SgfcMessage class provides an implementation of the ISgfcMessage interface. See the interface header file for documentation. More...

#include <SgfcMessage.h>

Inheritance diagram for LibSgfcPlusPlus::SgfcMessage:
LibSgfcPlusPlus::ISgfcMessage

Public Member Functions

 SgfcMessage (SgfcMessageID messageID, SgfcMessageType messageType, unsigned long lineNumber, unsigned long columnNumber, bool isCriticalMessage, int libraryErrorNumber, const std::string &messageText, const std::string &formattedMessageText)
 Initializes a newly constructed SgfcMessage object with the supplied parameter values.
 
 SgfcMessage (SgfcMessageID messageID, const std::string &messageText)
 Initializes a newly constructed SgfcMessage object with the supplied parameter values. The SgfcMessage has message type SgfcMessageType::FatalError.
 
virtual ~SgfcMessage ()
 Destroys and cleans up the ISgfcMessage object.
 
virtual SgfcMessageID GetMessageID () const override
 Returns the message's unique identification number.
 
virtual SgfcMessageType GetMessageType () const override
 Returns the type of message.
 
virtual unsigned long GetLineNumber () const override
 Returns the number of the line (1-based) in the parsed SGF data that caused the message. Returns SgfcConstants::InvalidLineNumber if the message does not refer to a specific line in the SGF data (most fatal errors, but also some errors and warnings).
 
virtual unsigned long GetColumnNumber () const override
 Returns the number of the column (1-based) in the parsed SGF data that caused the message. Returns SgfcConstants::InvalidColumnNumber if the message does not refer to a specific column in the SGF data (most fatal errors, but also some errors and warnings).
 
virtual bool IsCriticalMessage () const override
 Returns true if the message describes a critical problem. Only warning and error messages can be critical. Always returns false for fatal errors.
 
virtual int GetLibraryErrorNumber () const override
 Returns an error number that indicates what went wrong when a standard C library function was invoked by SGFC. The value 0 (zero) indicates "no error", a non-zero value indicates an error.
 
virtual std::string GetMessageText () const override
 Returns the message text.
 
virtual std::string GetFormattedMessageText () const override
 Returns the formatted message text as if it had been printed by SGFC on the command-line. If the message was generated by libsgfc++ this returns the same value as GetMessageText().
 
- Public Member Functions inherited from LibSgfcPlusPlus::ISgfcMessage
 ISgfcMessage ()
 Initializes a newly constructed ISgfcMessage object.
 
virtual ~ISgfcMessage ()
 Destroys and cleans up the ISgfcMessage object.
 

Detailed Description

The SgfcMessage class provides an implementation of the ISgfcMessage interface. See the interface header file for documentation.

Constructor & Destructor Documentation

◆ SgfcMessage() [1/2]

LibSgfcPlusPlus::SgfcMessage::SgfcMessage ( SgfcMessageID messageID,
SgfcMessageType messageType,
unsigned long lineNumber,
unsigned long columnNumber,
bool isCriticalMessage,
int libraryErrorNumber,
const std::string & messageText,
const std::string & formattedMessageText )

Initializes a newly constructed SgfcMessage object with the supplied parameter values.

This constructor is intended to be used for messages that are generated by SGFC.

Exceptions
std::invalid_argumentIs thrown if the numeric value underlying messageID is not zero or a positive number. Is thrown if the message type is SgfcMessageType::FatalError and isCriticalMessage is true.
Note
The exceptions enforce the details specified in the ISgfcMessage interface documentation.

◆ SgfcMessage() [2/2]

LibSgfcPlusPlus::SgfcMessage::SgfcMessage ( SgfcMessageID messageID,
const std::string & messageText )

Initializes a newly constructed SgfcMessage object with the supplied parameter values. The SgfcMessage has message type SgfcMessageType::FatalError.

This constructor is intended to be used for messages that are generated by libsgfc++.

Exceptions
std::invalid_argumentIs thrown if the numeric value underlying messageID is not a negative number

Member Function Documentation

◆ GetColumnNumber()

unsigned long LibSgfcPlusPlus::SgfcMessage::GetColumnNumber ( ) const
overridevirtual

Returns the number of the column (1-based) in the parsed SGF data that caused the message. Returns SgfcConstants::InvalidColumnNumber if the message does not refer to a specific column in the SGF data (most fatal errors, but also some errors and warnings).

Implements LibSgfcPlusPlus::ISgfcMessage.

◆ GetFormattedMessageText()

std::string LibSgfcPlusPlus::SgfcMessage::GetFormattedMessageText ( ) const
overridevirtual

Returns the formatted message text as if it had been printed by SGFC on the command-line. If the message was generated by libsgfc++ this returns the same value as GetMessageText().

When the command-line version of SGFC prints messages it assembles the individual message parts into a formatted text. libsgfc++ emulates this formatting as closely as possible to generate the value returned by this method. There is no guarantee for an exact match, though.

Implements LibSgfcPlusPlus::ISgfcMessage.

◆ GetLibraryErrorNumber()

int LibSgfcPlusPlus::SgfcMessage::GetLibraryErrorNumber ( ) const
overridevirtual

Returns an error number that indicates what went wrong when a standard C library function was invoked by SGFC. The value 0 (zero) indicates "no error", a non-zero value indicates an error.

As a convenience the library provides the constant SgfcConstants::LibraryErrorNumberNoError in case you prefer to use a constant to implement your program logic.

A non-zero value is a copy of the global errno value, made shortly after the failing function call. In the unlikely case that you need to evaluate this, consult the standard C library documentation of errno.

In case this method returns a non-zero error number, the text returned by GetFormattedMessageText() already includes an error message that results from invoking strerror() with the error number.

Note
Messages for which this method returns a non-zero value are usually fatal error messages related to file I/O. There is no guarantee that this will always be the case, though.
This method always returns 0 (zero) for messages generated by libsgfc++.

Implements LibSgfcPlusPlus::ISgfcMessage.

◆ GetLineNumber()

unsigned long LibSgfcPlusPlus::SgfcMessage::GetLineNumber ( ) const
overridevirtual

Returns the number of the line (1-based) in the parsed SGF data that caused the message. Returns SgfcConstants::InvalidLineNumber if the message does not refer to a specific line in the SGF data (most fatal errors, but also some errors and warnings).

Implements LibSgfcPlusPlus::ISgfcMessage.

◆ GetMessageID()

SgfcMessageID LibSgfcPlusPlus::SgfcMessage::GetMessageID ( ) const
overridevirtual

Returns the message's unique identification number.

Every message generated by SGFC has its own unique message ID. Consult the SGFC documentation for a list of message IDs. SGFC calls them "error codes". The exception is when libsgfc++ is unable to determine the message ID when it receives the message data from SGFC - in the very unlikely case that this happens libsgfc++ sets the message ID to SgfcMessageID::UnknownSgfcMessageID.

Every message generated by libsgfc++ also has its own unique message ID that is distinct from all SGFC-generated message IDs.

See also
SgfcMessageID

Implements LibSgfcPlusPlus::ISgfcMessage.

◆ GetMessageText()

std::string LibSgfcPlusPlus::SgfcMessage::GetMessageText ( ) const
overridevirtual

Returns the message text.

Implements LibSgfcPlusPlus::ISgfcMessage.

◆ GetMessageType()

SgfcMessageType LibSgfcPlusPlus::SgfcMessage::GetMessageType ( ) const
overridevirtual

Returns the type of message.

Messages generated by SGFC can be of all types. Messages generated by libsgfc++ are always fatal errors (although this may change in the future).

Attention
For SGFC-generated messages one and the same message ID can have different message types, depending on the context in which the message is generated. Examples: SgfcMessageID::EmptyValueDeleted, SgfcMessageID::IllegalSingleValueCorrected, etc.. Refer to the SGFC documentation for details.

Implements LibSgfcPlusPlus::ISgfcMessage.

◆ IsCriticalMessage()

bool LibSgfcPlusPlus::SgfcMessage::IsCriticalMessage ( ) const
overridevirtual

Returns true if the message describes a critical problem. Only warning and error messages can be critical. Always returns false for fatal errors.

A critical problem indicates that the SGF content parsed by SGFC may be severely damaged and that information may be lost if the parsed SGF data is written.

Implements LibSgfcPlusPlus::ISgfcMessage.


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