libsgfc++ 2.0.1
A C++ library that uses SGFC to read and write SGF (Smart Game Format) data.
|
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. | |
The SgfcUtility class is a container for static helper functions.
|
static |
Appends string to the file located at path in the filesystem. If the file does not exist it is created.
std::runtime_error | Is thrown if the file cannot be opened for writing for any reason. |
|
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.
std::runtime_error | Is thrown if the file cannot be opened for writing for any reason. |
|
static |
Deletes the file located at path in the filesystem if it exists. Does nothing if the file does not exist.
true | if the file exists and was deleted. |
false | if the file does not exist. |
std::runtime_error | Is thrown if the file exists but cannot be deleted for any reason. |
|
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.
true | if the data that was read or written is valid. |
false | if the data that was read or written is invalid. |
|
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.
std::filesystem::filesystem_error | Is 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. |
|
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:
|
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().
|
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.
std::invalid_argument | Is 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. |
|
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.
std::invalid_argument | Is 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. |
|
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.
|
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.
|
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.
|
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.
std::invalid_argument | Is 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. |
|
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.
std::invalid_argument | Is 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. |
|
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.
std::invalid_argument | Is 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. |
|
static |
Reads the entire content of the file located at path in the filesystem into memory and returns the content as a string.
std::runtime_error | Is thrown if the file cannot be opened for reading for any reason. |