Harmonic Flow Framework (libhffwk)
Cross platform C++ 2D Game Engine Framework
Classes | Macros | Typedefs | Functions | Variables
PakInterface.h File Reference

Interface for accessing pak files created with tool hfpak. More...

#include "HFDataTypes.h"
#include "platform/FileDirUtils.h"
#include <map>
#include <list>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <errno.h>
#include <dirent.h>
Include dependency graph for PakInterface.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  HFCore::PakRecord
 Interface representing an individual record within pak file. More...
 
class  HFCore::PakCollection
 Interface representing the actual memory mapped pak file. More...
 
struct  HFCore::PFILE
 Struct holding PakRecord, pointer to actual FILE and position. More...
 
class  HFCore::PakInterfaceBase
 Base interface for implementors to use. More...
 
class  HFCore::PakInterface
 Interface which implements base interface PakInterfaceBase. More...
 

Typedefs

typedef std::map< std::string, PakRecord * > HFCore::PakRecordMap
 typedef for std::map holding fileName uppercase and PakRecord pairs.
 
typedef std::list< PakCollection > HFCore::PakCollectionList
 typedef for std::list holding PakCollection pointers.
 

Functions

HFCore::PakInterfaceBasegetPakPtr ()
 Get a pointer to global gPakInterface. More...
 
HFCore::PFILEp_fopen (const int8_hf *fileName, const int8_hf *access)
 Open a file (within pak file or outside of it). More...
 
HFCore::PFILEp_fopen (const wchar_t *fileName, const wchar_t *access)
 Open a file (within pak file or outside of it). More...
 
int32_hf p_fclose (HFCore::PFILE *file)
 Closes and deletes a HFCore::PFILE. More...
 
int32_hf p_fseek (HFCore::PFILE *file, long offset, int32_hf origin)
 Sets the position indicator associated with the stream to a new position. More...
 
int32_hf p_ftell (HFCore::PFILE *file)
 Returns the current value of the position indicator of the HFCore::PFILE stream. More...
 
size_t p_fread (void *ptr, int32_hf size, int32_hf count, HFCore::PFILE *file)
 Reads an array of count elements, each one with a size of size bytes, from the stream and stores them in the block of memory specified by ptr. More...
 
size_t p_fwrite (const void *ptr, int32_hf size, int32_hf count, HFCore::PFILE *file)
 Write block of data to HFCore::PFILE stream. More...
 
int32_hf p_fgetc (HFCore::PFILE *file)
 Get character from HFCore::PFILE stream. More...
 
int32_hf p_ungetc (int32_hf ch, HFCore::PFILE *file)
 Unget character from HFCore::PFILE stream. More...
 
int8_hfp_fgets (int8_hf *ptr, int32_hf size, HFCore::PFILE *file)
 Get string from stream. More...
 
wchar_t * p_fgets (wchar_t *ptr, int32_hf size, HFCore::PFILE *file)
 Get string from stream. More...
 
int32_hf p_feof (HFCore::PFILE *file)
 Check end-of-file indicator. More...
 

Variables

HFCore::PakInterfacegPakInterface
 Global that should be used to create the HFCore::PakInterface instance. More...
 

Detailed Description

Interface for accessing pak files created with tool hfpak.

Definition in file PakInterface.h.

Function Documentation

◆ getPakPtr()

HFCore::PakInterfaceBase* getPakPtr ( )

Get a pointer to global gPakInterface.

Returns
Pointer to global gPakInterface.

Definition at line 704 of file PakInterface.cpp.

◆ p_fclose()

int32_hf p_fclose ( HFCore::PFILE file)

Closes and deletes a HFCore::PFILE.

For more details, see HFCore::PakInterface::FClose().

Parameters
filePointer to HFCore::PFILE.
Returns
0 if successful.

Definition at line 797 of file PakInterface.cpp.

◆ p_feof()

int32_hf p_feof ( HFCore::PFILE file)

Check end-of-file indicator.

For more details, see HFCore::PakInterface::FEof().

Parameters
filePointer to HFCore::PFILE.
Returns
A non-zero value is returned in the case that the end-of-file indicator associated with the stream is set. Otherwise, zero is returned.

Definition at line 871 of file PakInterface.cpp.

◆ p_fgetc()

int32_hf p_fgetc ( HFCore::PFILE file)

Get character from HFCore::PFILE stream.

Fore more details, see HFCore::PakInterface::FGetC().

Parameters
filePointer to HFCore::PFILE.
Returns
On success, the character read is returned (promoted to an int value). The return type is int to accommodate for the special value EOF, which indicates failure.

Definition at line 839 of file PakInterface.cpp.

◆ p_fgets() [1/2]

int8_hf* p_fgets ( int8_hf ptr,
int32_hf  size,
HFCore::PFILE file 
)

Get string from stream.

For more details, see HFCore::PakInterface::FGetS().

Parameters
ptrPointer to an array of chars where the string read is copied.
sizeMaximum number of characters to be copied into ptr (including the terminating null-character).
filePointer to HFCore::PFILE.
Returns
On success, the function returns ptr. If the end-of-file is encountered while attempting to read a character, the eof indicator is set (p_feof). If this happens before any characters could be read, the pointer returned is a null pointer (and the contents of str remain unchanged). If a read error occurs, a null pointer is also returned (but the contents pointed by ptr may have changed).

Definition at line 855 of file PakInterface.cpp.

◆ p_fgets() [2/2]

wchar_t* p_fgets ( wchar_t *  ptr,
int32_hf  size,
HFCore::PFILE file 
)

Get string from stream.

For more details, see HFCore::PakInterface::FGetS().

Parameters
ptrPointer to an array of chars where the string read is copied.
sizeMaximum number of characters to be copied into ptr (including the terminating null-character).
filePointer to HFCore::PFILE.
Returns
On success, the function returns ptr. If the end-of-file is encountered while attempting to read a character, the eof indicator is set (p_feof). If this happens before any characters could be read, the pointer returned is a null pointer (and the contents of str remain unchanged). If a read error occurs, a null pointer is also returned (but the contents pointed by ptr may have changed).

Definition at line 863 of file PakInterface.cpp.

◆ p_fopen() [1/2]

HFCore::PFILE* p_fopen ( const int8_hf fileName,
const int8_hf access 
)

Open a file (within pak file or outside of it).

For more details, see HFCore::PakInterface::FOpen().

Parameters
fileNameFile name to open.
accessAccess flags to use.
Returns
HFCore::PFILE if successful, else NULL.

Definition at line 731 of file PakInterface.cpp.

◆ p_fopen() [2/2]

HFCore::PFILE* p_fopen ( const wchar_t *  fileName,
const wchar_t *  access 
)

Open a file (within pak file or outside of it).

For more details, see HFCore::PakInterface::FOpen().

Parameters
fileNameFile name to open.
accessAccess flags to use.
Returns
HFCore::PFILE if successful, else NULL.

Definition at line 761 of file PakInterface.cpp.

◆ p_fread()

size_t p_fread ( void *  ptr,
int32_hf  size,
int32_hf  count,
HFCore::PFILE file 
)

Reads an array of count elements, each one with a size of size bytes, from the stream and stores them in the block of memory specified by ptr.

For more details, see HFCore::PakInterface::FRead().

Parameters
ptrPointer to a block of memory with a size of at least (size*count) bytes, converted to a void*.
sizeSize, in bytes, of each element to be read.
countNumber of elements, each one with a size of size bytes.
filePointer to HFCore::PFILE.
Returns
The total number of elements successfully read is returned. If this number differs from the count parameter, either a reading error occurred or the end-of-file was reached while reading.

Definition at line 823 of file PakInterface.cpp.

◆ p_fseek()

int32_hf p_fseek ( HFCore::PFILE file,
long  offset,
int32_hf  origin 
)

Sets the position indicator associated with the stream to a new position.

For more details, see HFCore::PakInterface::FSeek().

Parameters
filePointer to HFCore::PFILE.
offsetBinary files: Number of bytes to offset from origin. Text files: Either zero, or a value returned by FTell.
originPosition used as reference for the offset. It is specified by one of the following constants:
SEEK_SET = Beginning of file
SEEK_CUR = Current position of the file pointer
SEEK_END = End of file *
Returns
If successful, the function returns zero, else non-zero value.

Definition at line 807 of file PakInterface.cpp.

◆ p_ftell()

int32_hf p_ftell ( HFCore::PFILE file)

Returns the current value of the position indicator of the HFCore::PFILE stream.

For more details, see HFCore::PakInterface::FTell().

Parameters
filePointer to HFCore::PFILE.
Returns
On success, the current value of the position indicator is returned. On failure, -1L is returned.

Definition at line 815 of file PakInterface.cpp.

◆ p_fwrite()

size_t p_fwrite ( const void *  ptr,
int32_hf  size,
int32_hf  count,
HFCore::PFILE file 
)

Write block of data to HFCore::PFILE stream.

Parameters
ptrPointer to the array of elements to be written, converted to a const void*.
sizeSize in bytes of each element to be written.
countNumber of elements, each one with a size of size bytes.
filePointer to HFCore::PFILE.
Returns
The total number of elements successfully written is returned. If this number differs from the count parameter, a writing error prevented the function from completing. If either size or count is zero, the function returns zero and the error indicator remains unchanged.

Definition at line 831 of file PakInterface.cpp.

◆ p_ungetc()

int32_hf p_ungetc ( int32_hf  ch,
HFCore::PFILE file 
)

Unget character from HFCore::PFILE stream.

For more details, see HFCore::PakInterface::UnGetC().

Parameters
chThe int32_hf promotion of the character to be put back.
filePointer to HFCore::PFILE.
Returns
On success, the character put back is returned, else EOF is returned.

Definition at line 847 of file PakInterface.cpp.

Variable Documentation

◆ gPakInterface

HFCore::PakInterface* gPakInterface

Global that should be used to create the HFCore::PakInterface instance.

If you initialize game with a supplied pakDataFile to HFCore::Environment::init(), gPakInterface will be created automatically.

HFCore::PakInterface must be created using gPakInterface as all the c like functions (p_fopen, p_fclose, p_fread, p_fseek etc.) rely on it:

Definition at line 51 of file PakInterface.cpp.