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::ISgfcCommandLine Class Referenceabstract

The ISgfcCommandLine interface is used to operate the SGFC backend in command line mode. Use SgfcPlusPlusFactory to construct new ISgfcCommandLine objects. More...

#include <ISgfcCommandLine.h>

Inheritance diagram for LibSgfcPlusPlus::ISgfcCommandLine:
LibSgfcPlusPlus::SgfcCommandLine

Public Member Functions

 ISgfcCommandLine ()
 Initializes a newly constructed ISgfcCommandLine object.
 
virtual ~ISgfcCommandLine ()
 Destroys and cleans up the ISgfcCommandLine object.
 
virtual std::vector< std::shared_ptr< ISgfcArgument > > GetArguments () const =0
 Returns the SGFC command line arguments that were used to construct the ISgfcCommandLine object.
 
virtual bool IsCommandLineValid () const =0
 Returns true if the SGFC command line arguments that GetArguments() returns are valid. Returns false if they are not valid.
 
virtual std::shared_ptr< ISgfcMessageGetInvalidCommandLineReason () const =0
 Returns an ISgfcMessage object with message type SgfcMessageType::FatalError that describes why the SGFC command line arguments that GetArguments() returns are not valid. This method may only be invoked if IsCommandLineValid() returns false.
 
virtual SgfcExitCode LoadSgfFile (const std::string &sgfFilePath)=0
 Loads a single .sgf file from the specified path and puts it through the SGFC parser. This method may only be invoked if IsCommandLineValid() returns true.
 
virtual SgfcExitCode LoadSgfContent (const std::string &sgfContent)=0
 Loads the specified SGF content and puts it through the SGFC parser. This method may only be invoked if IsCommandLineValid() returns true.
 
virtual bool IsSgfContentValid () const =0
 Returns true if the SGF content that was loaded and parsed by the most recent invocation of either LoadSgfFile() or LoadSgfContent() is valid. Returns false if the SGF content is not valid, or if none of the methods have been invoked yet.
 
virtual std::vector< std::shared_ptr< ISgfcMessage > > GetParseResult () const =0
 Returns a collection of ISgfcMessage objects which together form the parse result from the most recent invocation of either LoadSgfFile() or LoadSgfContent().
 
virtual SgfcExitCode SaveSgfFile (const std::string &sgfFilePath)=0
 Saves the SGF content generated by SGFC after the most recent invocation of either LoadSgfFile() or LoadSgfContent() to the .sgf file at the specified path. This method may only be invoked if IsSgfContentValid() returns true.
 
virtual SgfcExitCode SaveSgfContent (std::string &sgfContent)=0
 Saves the SGF content generated by SGFC after the most recent invocation of either LoadSgfFile() or LoadSgfContent() into the specified string object. This method may only be invoked if IsSgfContentValid() returns true.
 
virtual std::vector< std::shared_ptr< ISgfcMessage > > GetSaveResult () const =0
 Returns a collection of ISgfcMessage objects which together form the result from the most recent invocation of either SaveSgfFile() or SaveSgfContent().
 

Detailed Description

The ISgfcCommandLine interface is used to operate the SGFC backend in command line mode. Use SgfcPlusPlusFactory to construct new ISgfcCommandLine objects.

The ISgfcCommandLine interface is designed to give clients control over when they want to execute load and save operations, and how they want the operations to behave. Clients specify SGFC command line arguments when they construct the ISgfcCommandLine object. The SGFC command line arguments cannot be changed after construction.

A client typically uses the ISgfcCommandLine interface by following this sequence, which corresponds to invoking SGFC on the command line with an input file path and an output file path.

A client may deviate from this sequence e.g. by repeatedly loading SGF content without saving (syntax checking), or by repeatedly saving the same SGF content to different locations.

A client that deviates from the sequence must still follow a certain common-sense protocol in using the interface:

Member Function Documentation

◆ GetArguments()

virtual std::vector< std::shared_ptr< ISgfcArgument > > LibSgfcPlusPlus::ISgfcCommandLine::GetArguments ( ) const
pure virtual

Returns the SGFC command line arguments that were used to construct the ISgfcCommandLine object.

Implemented in LibSgfcPlusPlus::SgfcCommandLine.

◆ GetInvalidCommandLineReason()

virtual std::shared_ptr< ISgfcMessage > LibSgfcPlusPlus::ISgfcCommandLine::GetInvalidCommandLineReason ( ) const
pure virtual

Returns an ISgfcMessage object with message type SgfcMessageType::FatalError that describes why the SGFC command line arguments that GetArguments() returns are not valid. This method may only be invoked if IsCommandLineValid() returns false.

Exceptions
std::logic_errorIs thrown if IsCommandLineValid() returns true.

Implemented in LibSgfcPlusPlus::SgfcCommandLine.

◆ GetParseResult()

virtual std::vector< std::shared_ptr< ISgfcMessage > > LibSgfcPlusPlus::ISgfcCommandLine::GetParseResult ( ) const
pure virtual

Returns a collection of ISgfcMessage objects which together form the parse result from the most recent invocation of either LoadSgfFile() or LoadSgfContent().

The collection is empty if none of the methods have been invoked yet, or if the most recent load operation did not generate any messages.

If the collection is not empty, the messages appear in the order in which they were generated by SGFC.

Exceptions
std::logic_errorIs thrown if IsCommandLineValid() returns false.

Implemented in LibSgfcPlusPlus::SgfcCommandLine.

◆ GetSaveResult()

virtual std::vector< std::shared_ptr< ISgfcMessage > > LibSgfcPlusPlus::ISgfcCommandLine::GetSaveResult ( ) const
pure virtual

Returns a collection of ISgfcMessage objects which together form the result from the most recent invocation of either SaveSgfFile() or SaveSgfContent().

The collection is empty if none of the methods have been invoked yet, or if the most recent save operation did not generate any messages.

If the collection is not empty, the messages appear in the order in which they were generated by SGFC.

Exceptions
std::logic_errorIs thrown if IsCommandLineValid() returns false.

Implemented in LibSgfcPlusPlus::SgfcCommandLine.

◆ IsCommandLineValid()

virtual bool LibSgfcPlusPlus::ISgfcCommandLine::IsCommandLineValid ( ) const
pure virtual

Returns true if the SGFC command line arguments that GetArguments() returns are valid. Returns false if they are not valid.

One known case where the command line arguments can be invalid is if an illegal parameter is specified for one of the arguments that require a parameter. Example: SgfcArgumentType::BeginningOfSgfData requires an integer parameter. The argument is invalid if an integer value is specified that is not within the accepted range.

There may be other cases. Invoke GetInvalidCommandLineReason() to learn the actual reason why the command line arguments are not valid.

Implemented in LibSgfcPlusPlus::SgfcCommandLine.

◆ IsSgfContentValid()

virtual bool LibSgfcPlusPlus::ISgfcCommandLine::IsSgfContentValid ( ) const
pure virtual

Returns true if the SGF content that was loaded and parsed by the most recent invocation of either LoadSgfFile() or LoadSgfContent() is valid. Returns false if the SGF content is not valid, or if none of the methods have been invoked yet.

The SGF content is considered valid if LoadSgfFile() or LoadSgfContent() have been invoked at least once, and if their invocation did not generate a fatal error. A fatal error shows up in the collection of ISgfcMessage objects that GetParseResult() returns, as an ISgfcMessage object with message type SgfcMessageType::FatalError.

Exceptions
std::logic_errorIs thrown if IsCommandLineValid() returns false.

Implemented in LibSgfcPlusPlus::SgfcCommandLine.

◆ LoadSgfContent()

virtual SgfcExitCode LibSgfcPlusPlus::ISgfcCommandLine::LoadSgfContent ( const std::string & sgfContent)
pure virtual

Loads the specified SGF content and puts it through the SGFC parser. This method may only be invoked if IsCommandLineValid() returns true.

Returns
An SgfcExitCode value whose numeric value matches one of the exit codes of SGFC.
Exceptions
std::logic_errorIs thrown if IsCommandLineValid() returns false.

Implemented in LibSgfcPlusPlus::SgfcCommandLine.

◆ LoadSgfFile()

virtual SgfcExitCode LibSgfcPlusPlus::ISgfcCommandLine::LoadSgfFile ( const std::string & sgfFilePath)
pure virtual

Loads a single .sgf file from the specified path and puts it through the SGFC parser. This method may only be invoked if IsCommandLineValid() returns true.

Returns
An SgfcExitCode value whose numeric value matches one of the exit codes of SGFC.
Exceptions
std::logic_errorIs thrown if IsCommandLineValid() returns false.

Implemented in LibSgfcPlusPlus::SgfcCommandLine.

◆ SaveSgfContent()

virtual SgfcExitCode LibSgfcPlusPlus::ISgfcCommandLine::SaveSgfContent ( std::string & sgfContent)
pure virtual

Saves the SGF content generated by SGFC after the most recent invocation of either LoadSgfFile() or LoadSgfContent() into the specified string object. This method may only be invoked if IsSgfContentValid() returns true.

The previous content of sgfContent is overwritten.

Returns
An SgfcExitCode value whose numeric value matches one of the exit codes of SGFC.
Exceptions
std::logic_errorIs thrown if IsSgfContentValid() returns false.

Implemented in LibSgfcPlusPlus::SgfcCommandLine.

◆ SaveSgfFile()

virtual SgfcExitCode LibSgfcPlusPlus::ISgfcCommandLine::SaveSgfFile ( const std::string & sgfFilePath)
pure virtual

Saves the SGF content generated by SGFC after the most recent invocation of either LoadSgfFile() or LoadSgfContent() to the .sgf file at the specified path. This method may only be invoked if IsSgfContentValid() returns true.

If a file already exists at the specified path it is overwritten.

Returns
An SgfcExitCode value whose numeric value matches one of the exit codes of SGFC.
Exceptions
std::logic_errorIs thrown if IsSgfContentValid() returns false.

Implemented in LibSgfcPlusPlus::SgfcCommandLine.


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