KiCad PCB EDA Suite
asset_archive.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef KICAD_ASSET_ARCHIVE_H
21#define KICAD_ASSET_ARCHIVE_H
22
23#include <unordered_map>
24#include <vector>
25
26#include <core/wx_stl_compat.h>
27
36{
37public:
38 ASSET_ARCHIVE( const wxString& aFilePath, bool aLoadNow = true );
39
40 ~ASSET_ARCHIVE() = default;
41
42 bool Load();
43
51 long GetFileContents( const wxString& aFilePath, const unsigned char* aDest, size_t aMaxLen );
52
59 long GetFilePointer( const wxString& aFilePath, const unsigned char** aDest );
60
61private:
62 struct FILE_INFO
63 {
64 size_t offset;
65 size_t length;
66 };
67
69 std::unordered_map<wxString, FILE_INFO> m_fileInfoCache;
70
72 std::vector<unsigned char> m_cache;
73
75 wxString m_filePath;
76};
77
78#endif // KICAD_ASSET_ARCHIVE_H
An asset archive represents a file containing data assets that are loaded from disk and then cached i...
Definition: asset_archive.h:36
std::unordered_map< wxString, FILE_INFO > m_fileInfoCache
Cache of file info for a given file path.
Definition: asset_archive.h:69
~ASSET_ARCHIVE()=default
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.
wxString m_filePath
Path to the source archive file.
Definition: asset_archive.h:75
ASSET_ARCHIVE(const wxString &aFilePath, bool aLoadNow=true)
std::vector< unsigned char > m_cache
The full file contents.
Definition: asset_archive.h:72