galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
galaxy::fileutils Namespace Reference

Functions

std::optional< std::string > extension (const std::string &filepath) noexcept
 Get a file or path's extension.
 
std::expected< std::string, FileErrorread (const std::string &filepath)
 Read a non-binary file on disk.
 
std::optional< FileErrorwrite (const std::string &filepath, const std::string &data)
 Writes a non-binary file to disk.
 
std::optional< nlohmann::json > read_json (const std::string &filepath)
 Read a json file from disk.
 
bool write_json (const std::string &filepath, const nlohmann::json &json)
 Write json to disk.
 
void open_url (const std::string &url) noexcept
 Open URL in default webbrowser.
 

Function Documentation

◆ extension()

std::optional< std::string > galaxy::fileutils::extension ( const std::string & filepath)
nodiscardnoexcept

Get a file or path's extension.

Parameters
filepathFilename or path with a filename.
Returns
Extension, including dot. Nullopt if errors.

Definition at line 21 of file FileUtils.cpp.

+ Here is the caller graph for this function:

◆ read()

std::expected< std::string, FileError > galaxy::fileutils::read ( const std::string & filepath)
nodiscard

Read a non-binary file on disk.

Parameters
filepathPath to file to read.
Returns
Data, or filerror if an unexpected error occured.

Definition at line 32 of file FileUtils.cpp.

+ Here is the caller graph for this function:

◆ write()

std::optional< FileError > galaxy::fileutils::write ( const std::string & filepath,
const std::string & data )
nodiscard

Writes a non-binary file to disk.

Parameters
filepathPath to file to write to.
dataData to write to file.
Returns
Nullopt on success, FileError on failure.

Definition at line 62 of file FileUtils.cpp.

+ Here is the caller graph for this function:

◆ read_json()

std::optional< nlohmann::json > galaxy::fileutils::read_json ( const std::string & filepath)
nodiscard

Read a json file from disk.

Parameters
filepathPath to file to read.
Returns
Fully parsed json object. Nullopt if parsing failed.

Definition at line 89 of file FileUtils.cpp.

+ Here is the call graph for this function:

◆ write_json()

bool galaxy::fileutils::write_json ( const std::string & filepath,
const nlohmann::json & json )
nodiscard

Write json to disk.

Parameters
filepathPath to file to write to.
jsonJson data to write.
Returns
True on success.

Definition at line 103 of file FileUtils.cpp.

+ Here is the call graph for this function:

◆ open_url()

void galaxy::fileutils::open_url ( const std::string & url)
noexcept

Open URL in default webbrowser.

Parameters
urlURL to website to open.

Definition at line 115 of file FileUtils.cpp.

+ Here is the caller graph for this function: