Maze Builder Docs 8.10.23
Loading...
Searching...
No Matches
mazes::io_utils Class Reference

Handles file writing for text, stdout, and object files. More...

#include <io_utils.h>

Static Public Member Functions

static bool write (std::ostream &oss, std::string_view data, std::string_view delimiter="\n") noexcept
 Handles writing to an output stream.
static bool write_file (std::string_view filename, std::string_view data) noexcept
 Write to a file.
static bool is_an_absolute_path (std::string_view path) noexcept
 Check if a path is an absolute path.
static bool is_valid_path (std::string_view path) noexcept
 Check if a path is valid.
static std::string parent_path (std::string_view filepath) noexcept
 Get the directory path from a full file path.
static std::vector< std::uint8_t > read_file_to_bytes (const std::filesystem::path &file_path) noexcept
 Read an entire file into memory.
static bool write_png (const std::filesystem::path &file_path, const std::vector< std::uint8_t > &pixels, int width, int height) noexcept
 Writes pixel data to a PNG image file.
static bool write_jpg (const std::filesystem::path &file_path, const std::vector< std::uint8_t > &pixels, int width, int height, int quality=95) noexcept
 Writes image data to a JPEG file.
static bool write_bmp (const std::filesystem::path &file_path, const std::vector< std::uint8_t > &pixels, int width, int height) noexcept
 Writes a BMP image file from pixel data.

Detailed Description

Handles file writing for text, stdout, and object files.

Member Function Documentation

◆ is_an_absolute_path()

bool mazes::io_utils::is_an_absolute_path ( std::string_view path)
staticnoexcept

Check if a path is an absolute path.

Parameters
pathPath to check

◆ is_valid_path()

bool mazes::io_utils::is_valid_path ( std::string_view path)
staticnoexcept

Check if a path is valid.

Parameters
path
Returns

◆ parent_path()

std::string mazes::io_utils::parent_path ( std::string_view filepath)
staticnoexcept

Get the directory path from a full file path.

Parameters
filepathFull file path
Returns
Directory path

◆ read_file_to_bytes()

std::vector< std::uint8_t > mazes::io_utils::read_file_to_bytes ( const std::filesystem::path & file_path)
staticnoexcept

Read an entire file into memory.

Parameters
file_pathFull file path
Returns
The file contents as bytes, or an empty vector on failure

◆ write()

bool mazes::io_utils::write ( std::ostream & oss,
std::string_view data,
std::string_view delimiter = "\n" )
staticnoexcept

Handles writing to an output stream.

Parameters
oss
data
delimiterDelimiter to use between data entries
Returns
True if the write was successful, false otherwise

◆ write_bmp()

bool mazes::io_utils::write_bmp ( const std::filesystem::path & file_path,
const std::vector< std::uint8_t > & pixels,
int width,
int height )
staticnoexcept

Writes a BMP image file from pixel data.

Parameters
file_pathThe path where the BMP file will be written.
pixelsA vector containing the pixel data to write.
widthThe width of the image in pixels.
heightThe height of the image in pixels.
Returns
Returns true if the BMP file was successfully written, false otherwise.

◆ write_file()

bool mazes::io_utils::write_file ( std::string_view filename,
std::string_view data )
staticnoexcept

Write to a file.

Parameters
filenameFull file path
dataData to write
Returns
True if the write was successful, false otherwise

◆ write_jpg()

bool mazes::io_utils::write_jpg ( const std::filesystem::path & file_path,
const std::vector< std::uint8_t > & pixels,
int width,
int height,
int quality = 95 )
staticnoexcept

Writes image data to a JPEG file.

Parameters
file_pathThe file system path where the JPEG file will be written.
pixelsA vector containing the pixel data in RGB or RGBA format.
widthThe width of the image in pixels.
heightThe height of the image in pixels.
qualityThe JPEG compression quality (0-100, default is 95). Higher values produce better quality but larger files.
Returns
True if the JPEG file was successfully written, false otherwise.

◆ write_png()

bool mazes::io_utils::write_png ( const std::filesystem::path & file_path,
const std::vector< std::uint8_t > & pixels,
int width,
int height )
staticnoexcept

Writes pixel data to a PNG image file.

Parameters
file_pathThe filesystem path where the PNG file will be written.
pixelsA vector containing the pixel data as 8-bit unsigned integers.
widthThe width of the image in pixels.
heightThe height of the image in pixels.
Returns
True if the PNG file was successfully written, false otherwise.

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