KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ASSET_ARCHIVE Class Reference

An asset archive represents a file containing data assets that are loaded from disk and then cached in memory. More...

#include <asset_archive.h>

Classes

struct  FILE_INFO
 

Public Member Functions

 ASSET_ARCHIVE (const wxString &aFilePath, bool aLoadNow=true)
 
 ~ASSET_ARCHIVE ()=default
 
bool Load ()
 
long GetFileContents (const wxString &aFilePath, const unsigned char *aDest, size_t aMaxLen)
 Retrieves a file with the given path from the cached archive.
 
long GetFilePointer (const wxString &aFilePath, const unsigned char **aDest)
 Retrieves a pointer to a file with the given path from the cached archive.
 

Private Attributes

std::unordered_map< wxString, FILE_INFOm_fileInfoCache
 Cache of file info for a given file path.
 
std::vector< unsigned char > m_cache
 The full file contents.
 
wxString m_filePath
 Path to the source archive file.
 

Detailed Description

An asset archive represents a file containing data assets that are loaded from disk and then cached in memory.

For example, a set of bitmap images.

The entire contents of the archive will be uncompressed and kept resident in memory in the current implementation, so consider this before reusing this as-is for new use cases.

Definition at line 36 of file asset_archive.h.

Constructor & Destructor Documentation

◆ ASSET_ARCHIVE()

ASSET_ARCHIVE::ASSET_ARCHIVE ( const wxString &  aFilePath,
bool  aLoadNow = true 
)

Definition at line 27 of file asset_archive.cpp.

References Load().

◆ ~ASSET_ARCHIVE()

ASSET_ARCHIVE::~ASSET_ARCHIVE ( )
default

Member Function Documentation

◆ GetFileContents()

long ASSET_ARCHIVE::GetFileContents ( const wxString &  aFilePath,
const unsigned char *  aDest,
size_t  aMaxLen 
)

Retrieves a file with the given path from the cached archive.

Parameters
aFilePathis the path within the archive to the requested file
aDestis the target byte array to copy into
aMaxLenis the maximum bytes that can be copied into aDest
Returns
the number of bytes copied, or -1 if the given file was not found

Definition at line 87 of file asset_archive.cpp.

◆ GetFilePointer()

long ASSET_ARCHIVE::GetFilePointer ( const wxString &  aFilePath,
const unsigned char **  aDest 
)

Retrieves a pointer to a file with the given path from the cached archive.

Parameters
aFilePathis the path within the archive to the requested file
aDestwill be set to point to the start of the file if the file was found
Returns
the file size, or -1 if the given file was not found

Definition at line 95 of file asset_archive.cpp.

References ASSET_ARCHIVE::FILE_INFO::length, m_cache, m_fileInfoCache, and ASSET_ARCHIVE::FILE_INFO::offset.

◆ Load()

bool ASSET_ARCHIVE::Load ( )

Member Data Documentation

◆ m_cache

std::vector<unsigned char> ASSET_ARCHIVE::m_cache
private

The full file contents.

Definition at line 73 of file asset_archive.h.

Referenced by GetFilePointer(), and Load().

◆ m_fileInfoCache

std::unordered_map<wxString, FILE_INFO> ASSET_ARCHIVE::m_fileInfoCache
private

Cache of file info for a given file path.

Definition at line 70 of file asset_archive.h.

Referenced by GetFilePointer(), and Load().

◆ m_filePath

wxString ASSET_ARCHIVE::m_filePath
private

Path to the source archive file.

Definition at line 76 of file asset_archive.h.

Referenced by Load().


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