dEngine
Simple 2D C++ game engine
Public Member Functions | Private Member Functions | Private Attributes | List of all members
packer::Packer Class Reference

Takes care of packing files into a .dat file. More...

#include <Packer.h>

Public Member Functions

 Packer (std::string filePath)
 Create a new packer. More...
 
void ReadFileToBuffer (const std::filesystem::path filePath)
 Read a new file into the buffer and write to the packed file. More...
 
void WriteTable ()
 Writes a table of contents to the top of the file. More...
 

Private Member Functions

std::vector< char > MapToVector ()
 
bool fileExists (const std::string &filename)
 Checks if file exists. More...
 
void deleteFileIfExists (const std::string &filename)
 Deletes a file if it exists. More...
 
std::vector< char > compressBuffer (const std::vector< char > &buffer)
 Perform lossless compression on a buffer using zlib. More...
 
std::string getFileType (const std::string &extension)
 Get a file's type based on file extension. More...
 

Private Attributes

std::map< std::string, std::string > fileLocMap
 A map containing every file in the package and it's starting location. More...
 
std::string outFilePath
 
std::vector< char > buffer
 

Detailed Description

Takes care of packing files into a .dat file.

Constructor & Destructor Documentation

◆ Packer()

Packer::Packer ( std::string  filePath)

Create a new packer.

Parameters
filePathFilepath to the output packed file

Member Function Documentation

◆ compressBuffer()

std::vector< char > Packer::compressBuffer ( const std::vector< char > &  buffer)
private

Perform lossless compression on a buffer using zlib.

Parameters
bufferThe buffer to compress

Referenced by ReadFileToBuffer().

◆ deleteFileIfExists()

void Packer::deleteFileIfExists ( const std::string &  filename)
private

Deletes a file if it exists.

Parameters
filenameFile to delete

Referenced by Packer().

◆ fileExists()

bool Packer::fileExists ( const std::string &  filename)
private

Checks if file exists.

Parameters
filenameFile to check
Returns
True if file exists

Referenced by deleteFileIfExists().

◆ getFileType()

std::string Packer::getFileType ( const std::string &  extension)
private

Get a file's type based on file extension.

Parameters
extensionThe file's extension

Referenced by ReadFileToBuffer().

◆ MapToVector()

std::vector< char > Packer::MapToVector ( )
private

Converts a map to a vector<char>

Returns
first:second
See also
fileLocMap

Referenced by WriteTable().

◆ ReadFileToBuffer()

void Packer::ReadFileToBuffer ( const std::filesystem::path  filePath)

Read a new file into the buffer and write to the packed file.

Parameters
filePathFilepath of the file to pack

Referenced by main().

◆ WriteTable()

void Packer::WriteTable ( )

Writes a table of contents to the top of the file.

Referenced by main().

Member Data Documentation

◆ buffer

std::vector<char> packer::Packer::buffer
private

Referenced by ReadFileToBuffer().

◆ fileLocMap

std::map<std::string,std::string> packer::Packer::fileLocMap
private

A map containing every file in the package and it's starting location.

Referenced by MapToVector(), ReadFileToBuffer(), and WriteTable().

◆ outFilePath

std::string packer::Packer::outFilePath
private