libsgfc++ 2.0.1
A C++ library that uses SGFC to read and write SGF (Smart Game Format) data.
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
LibSgfcPlusPlus::SgfcUtility Class Reference

The SgfcUtility class is a container for static helper functions. More...

#include <SgfcUtility.h>

Static Public Member Functions

static std::string MapPropertyTypeToPropertyName (SgfcPropertyType propertyType)
 Returns the property name, as defined by the SGF standard, that corresponds to propertyType. propertyType must not be SgfcPropertyType::Unknown.
 
static SgfcPropertyType MapPropertyNameToPropertyType (const std::string &propertyName)
 Returns the SgfcPropertyType value that corresponds to propertyName. Returns SgfcPropertyType::Unknown if propertyName cannot be mapped, which is the case if propertyName is not the name of a property as defined by the SGF standard.
 
static SgfcPropertyCategory MapPropertyTypeToPropertyCategory (SgfcPropertyType propertyType)
 Returns the property category, as defined by the SGF standard, that corresponds to propertyType.
 
static SgfcPropertyTraits MapPropertyTypeToPropertyTraits (SgfcPropertyType propertyType)
 Returns the property traits, as defined by the SGF standard, that the property with property type propertyType has.
 
static SgfcNodeTraits MapPropertyCategoryToNodeTraits (SgfcPropertyCategory propertyCategory)
 Returns the node trait, as defined by the SGF standard, that corresponds to propertyCategory. Returns SgfcConstants::NodeTraitsNone if propertyCategory cannot be mapped.
 
static SgfcNumber MapGameTypeToNumberValue (SgfcGameType gameType)
 Returns the SgfcNumber value that corresponds to the SgfcGameType value gameType. gameType must not be SgfcGameType::Unknown.
 
static SgfcGameType MapNumberValueToGameType (SgfcNumber gameTypeAsNumber)
 Returns the SgfcGameType value that corresponds to the Number value gameTypeAsNumber. Returns SgfcGameType::Unknown if the Number value cannot be mapped, which is the case if the Number value does not correspond to one of the known values defined by the SGF standard.
 
static SgfcExitCode GetSgfcExitCodeFromMessageCollection (const std::vector< std::shared_ptr< ISgfcMessage > > &messageCollection)
 Returns an SgfcExitCode value that represents the messages in messageCollection. See the documentation of the individual enumeration values for details.
 
static bool GetIsSgfDataValidFromMessageCollection (const std::vector< std::shared_ptr< ISgfcMessage > > &messageCollection)
 Returns whether messageCollection, which is the result of an SGFC read or write operation, indicate that the piece of SGF data that was read or written is valid.
 
static std::string MapArgumentTypeToCmdlineOption (SgfcArgumentType argumentType)
 Returns the command line option, as defined by the SGFC documentation, that corresponds to argumentType.
 
static std::string GetTempFolderPath ()
 Returns the full path of a folder that is suitable for temporary files. The path is guaranteed to exist and to be a directory. The returned path string is UTF-8 encoded.
 
static std::string GetUniqueTempFileName ()
 Returns the unique base name of a file that is extremely unlikely to already exist in the temporary folder returned by GetTempPath(). This method never returns the same value twice.
 
static std::string GetUniqueTempFilePath ()
 Returns the unique absolute path of a file that is extremely unlikely to already exist in the temporary folder returned by GetTempPath(). The returned path string is UTF-8 encoded. This method never returns the same value twice.
 
static std::string JoinPathComponents (const std::string &component1, const std::string &component2)
 Joins two filesystem path components together using the platform-specific directory separator.
 
static bool StringStartsWith (const std::string &string, const std::string &prefix)
 Returns true if string begins with prefix. Returns false if string does not begin with prefix. Comparison is case sensitive.
 
static bool StringEndsWith (const std::string &string, const std::string &suffix)
 Returns true if string ends with suffix. Returns false if string does not end with suffix. Comparison is case sensitive.
 
static std::vector< std::string > SplitString (const std::string &string, char delimiter)
 Splits string into substrings using the single character delimiter as the delimiter.
 
static std::vector< std::string > SplitString (const std::string &string, const std::string &delimiter)
 Splits string into substrings using the string delimiter as the delimiter.
 
static std::string CreateUuid ()
 Returns a newly generated random UUID.
 
static void CreateOrTruncateFile (const std::string &path)
 Makes sure that the file located at path in the filesystem exists and has zero length. If the file does not exist it is created. If the file already exists it is truncated to zero length.
 
static bool DeleteFileIfExists (const std::string &path)
 Deletes the file located at path in the filesystem if it exists. Does nothing if the file does not exist.
 
static void AppendTextToFile (const std::string &path, const std::string &string)
 Appends string to the file located at path in the filesystem. If the file does not exist it is created.
 
static std::string ReadFileContent (const std::string &path)
 Reads the entire content of the file located at path in the filesystem into memory and returns the content as a string.
 

Detailed Description

The SgfcUtility class is a container for static helper functions.

Member Function Documentation

◆ AppendTextToFile()

void LibSgfcPlusPlus::SgfcUtility::AppendTextToFile ( const std::string & path,
const std::string & string )
static

Appends string to the file located at path in the filesystem. If the file does not exist it is created.

Exceptions
std::runtime_errorIs thrown if the file cannot be opened for writing for any reason.

◆ CreateOrTruncateFile()

void LibSgfcPlusPlus::SgfcUtility::CreateOrTruncateFile ( const std::string & path)
static

Makes sure that the file located at path in the filesystem exists and has zero length. If the file does not exist it is created. If the file already exists it is truncated to zero length.

Exceptions
std::runtime_errorIs thrown if the file cannot be opened for writing for any reason.

◆ DeleteFileIfExists()

bool LibSgfcPlusPlus::SgfcUtility::DeleteFileIfExists ( const std::string & path)
static

Deletes the file located at path in the filesystem if it exists. Does nothing if the file does not exist.

Return values
trueif the file exists and was deleted.
falseif the file does not exist.
Exceptions
std::runtime_errorIs thrown if the file exists but cannot be deleted for any reason.

◆ GetIsSgfDataValidFromMessageCollection()

bool LibSgfcPlusPlus::SgfcUtility::GetIsSgfDataValidFromMessageCollection ( const std::vector< std::shared_ptr< ISgfcMessage > > & messageCollection)
static

Returns whether messageCollection, which is the result of an SGFC read or write operation, indicate that the piece of SGF data that was read or written is valid.

Return values
trueif the data that was read or written is valid.
falseif the data that was read or written is invalid.

◆ GetTempFolderPath()

std::string LibSgfcPlusPlus::SgfcUtility::GetTempFolderPath ( )
static

Returns the full path of a folder that is suitable for temporary files. The path is guaranteed to exist and to be a directory. The returned path string is UTF-8 encoded.

The implementation makes use of std::filesystem::temp_directory_path(), which is defined in C++17 but may not be available on older platform versions (notably on macOS it is available only from macOS 10.15). For more details about how the path is determined, see https://en.cppreference.com/w/cpp/filesystem/temp_directory_path.

Exceptions
std::filesystem::filesystem_errorIs thrown if invoking the underlying operating system API results in an error. The exception object is constructed with the temporary folder path as the first path argument and the operating system error code as the error code argument.

◆ GetUniqueTempFileName()

std::string LibSgfcPlusPlus::SgfcUtility::GetUniqueTempFileName ( )
static

Returns the unique base name of a file that is extremely unlikely to already exist in the temporary folder returned by GetTempPath(). This method never returns the same value twice.

The file name is composed of the following parts:

  • A prefix that indicates that the file origin is this library
  • The ID of the system process that hosts the library
  • A randomly generated UUID
  • A file extension suffix that indicates that the file is a temporary file

◆ GetUniqueTempFilePath()

std::string LibSgfcPlusPlus::SgfcUtility::GetUniqueTempFilePath ( )
static

Returns the unique absolute path of a file that is extremely unlikely to already exist in the temporary folder returned by GetTempPath(). The returned path string is UTF-8 encoded. This method never returns the same value twice.

This is a convenience function that invokes JoinPathComponents() using the return values of GetTempFolderPath() and GetUniqueTempFileName().

◆ MapArgumentTypeToCmdlineOption()

std::string LibSgfcPlusPlus::SgfcUtility::MapArgumentTypeToCmdlineOption ( SgfcArgumentType argumentType)
static

Returns the command line option, as defined by the SGFC documentation, that corresponds to argumentType.

This is a convenience function that looks up argumentType in SgfcPrivateConstants::ArgumentTypeToCmdlineOptionMap.

Exceptions
std::invalid_argumentIs thrown if there is no mapping, i.e. if argumentType does not appear in SgfcPrivateConstants::ArgumentTypeToCmdlineOptionMap. In practice this should never occur. If it occurs it indicates a programming error in the library, i.e. an SgfcArgumentType value was not added to SgfcPrivateConstants::ArgumentTypeToCmdlineOptionMap.

◆ MapGameTypeToNumberValue()

SgfcNumber LibSgfcPlusPlus::SgfcUtility::MapGameTypeToNumberValue ( SgfcGameType gameType)
static

Returns the SgfcNumber value that corresponds to the SgfcGameType value gameType. gameType must not be SgfcGameType::Unknown.

This is a convenience function that looks up gameType in SgfcConstants::GameTypeToGameTypeAsNumberMap.

Exceptions
std::invalid_argumentIs thrown if there is no mapping, i.e. if gameType does not appear in SgfcConstants::GameTypeToGameTypeAsNumberMap. This should only occur if gameType is SgfcGameType::Unknown, because obviously that game type has no corresponding Number value. Otherwise this indicates a programming error in the library, i.e. an SgfcGameType value was not added to SgfcConstants::GameTypeToGameTypeAsNumberMap.

◆ MapNumberValueToGameType()

SgfcGameType LibSgfcPlusPlus::SgfcUtility::MapNumberValueToGameType ( SgfcNumber gameTypeAsNumber)
static

Returns the SgfcGameType value that corresponds to the Number value gameTypeAsNumber. Returns SgfcGameType::Unknown if the Number value cannot be mapped, which is the case if the Number value does not correspond to one of the known values defined by the SGF standard.

This is a convenience function that looks up gameTypeAsNumber in SgfcConstants::GameTypeAsNumberToGameTypeMap.

◆ MapPropertyCategoryToNodeTraits()

SgfcNodeTraits LibSgfcPlusPlus::SgfcUtility::MapPropertyCategoryToNodeTraits ( SgfcPropertyCategory propertyCategory)
static

Returns the node trait, as defined by the SGF standard, that corresponds to propertyCategory. Returns SgfcConstants::NodeTraitsNone if propertyCategory cannot be mapped.

This is a convenience function that looks up propertyCategory in SgfcPrivateConstants::PropertyCategoryToNodeTraitMap.

◆ MapPropertyNameToPropertyType()

SgfcPropertyType LibSgfcPlusPlus::SgfcUtility::MapPropertyNameToPropertyType ( const std::string & propertyName)
static

Returns the SgfcPropertyType value that corresponds to propertyName. Returns SgfcPropertyType::Unknown if propertyName cannot be mapped, which is the case if propertyName is not the name of a property as defined by the SGF standard.

This is a convenience function that looks up propertyName in SgfcConstants::PropertyNameToPropertyTypeMap.

◆ MapPropertyTypeToPropertyCategory()

SgfcPropertyCategory LibSgfcPlusPlus::SgfcUtility::MapPropertyTypeToPropertyCategory ( SgfcPropertyType propertyType)
static

Returns the property category, as defined by the SGF standard, that corresponds to propertyType.

This is a convenience function that looks up propertyType in SgfcConstants::PropertyTypeToPropertyCategoryMap.

Exceptions
std::invalid_argumentIs thrown if there is no mapping, i.e. if propertyType does not appear in SgfcConstants::PropertyTypeToPropertyCategoryMap. If this occurs it indicates a programming error in the library, i.e. an SgfcPropertyType value was not added to SgfcConstants::PropertyTypeToPropertyCategoryMap.

◆ MapPropertyTypeToPropertyName()

std::string LibSgfcPlusPlus::SgfcUtility::MapPropertyTypeToPropertyName ( SgfcPropertyType propertyType)
static

Returns the property name, as defined by the SGF standard, that corresponds to propertyType. propertyType must not be SgfcPropertyType::Unknown.

This is a convenience function that looks up propertyType in SgfcConstants::PropertyTypeToPropertyNameMap.

Exceptions
std::invalid_argumentIs thrown if there is no mapping, i.e. if propertyType does not appear in SgfcConstants::PropertyTypeToPropertyNameMap. This should only occur if propertyType is SgfcPropertyType::Unknown, because obviously that property type has no corresponding property name. Otherwise this indicates a programming error in the library, i.e. an SgfcPropertyType value was not added to SgfcConstants::PropertyTypeToPropertyNameMap.

◆ MapPropertyTypeToPropertyTraits()

SgfcPropertyTraits LibSgfcPlusPlus::SgfcUtility::MapPropertyTypeToPropertyTraits ( SgfcPropertyType propertyType)
static

Returns the property traits, as defined by the SGF standard, that the property with property type propertyType has.

This is a convenience function that looks up propertyType in SgfcConstants::PropertyTypeToPropertyTraitsMap.

Exceptions
std::invalid_argumentIs thrown if there is no mapping, i.e. if propertyType does not appear in SgfcConstants::PropertyTypeToPropertyTraitsMap. If this occurs it indicates a programming error in the library, i.e. an SgfcPropertyType value was not added to SgfcConstants::PropertyTypeToPropertyTraitsMap.

◆ ReadFileContent()

std::string LibSgfcPlusPlus::SgfcUtility::ReadFileContent ( const std::string & path)
static

Reads the entire content of the file located at path in the filesystem into memory and returns the content as a string.

Exceptions
std::runtime_errorIs thrown if the file cannot be opened for reading for any reason.

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