Files
pip/libs/main/resources/piresourcesstorage.h

180 lines
5.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
PIP - Platform Independent Primitives
Resources subsystem
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//! \~english Resources storage subsystem
//! \~russian Подсистема хранения ресурсов
//! \defgroup Resources Resources
//! \~\brief
//! \~english Resources storage subsystem
//! \~russian Подсистема хранения ресурсов
#ifndef PIRESOURCES_P_H
#define PIRESOURCES_P_H
#include "pichunkstream.h"
#include "pimap.h"
#include "pistring.h"
class PIResources;
//! \~english Storage for compiled-in resources
//! \~russian Хранилище вкомпиленных ресурсов
class PIP_EXPORT PIResourcesStorage {
friend class PIResources;
public:
//! \~english Get singleton instance
//! \~russian Получить синглтон
static PIResourcesStorage * instance();
//! \~english Section containing resource entries
//! \~russian Секция, содержащая записи ресурсов
struct PIP_EXPORT Section {
//! \~english Constructor
//! \~russian Конструктор
Section();
//! \~english Destructor
//! \~russian Деструктор
~Section();
//! \~english Add another section to this one
//! \~russian Добавить другую секцию к этой
void add(const Section & s);
//! \~english Clear all entries
//! \~russian Очистить все записи
void purge();
//! \~english Map of resource names to data
//! \~russian Карта имен ресурсов к данным
PIMap<PIString, PIByteArray *> entries;
};
struct PIP_EXPORT __RCEntry {
__RCEntry(const PIString & s = PIString(),
const PIString & n = PIString(),
const PIString & a = PIString(),
const PIString & f = PIString(),
llong o = 0,
llong si = 0,
int fl = 0) {
section = s;
name = n;
alias = a;
file = f;
offset = o;
size = si;
flags = fl;
}
//! \~english Section name
//! \~russian Имя секции
PIString section;
//! \~english Resource name
//! \~russian Имя ресурса
PIString name;
//! \~english Alias
//! \~russian Псевдоним
PIString alias;
//! \~english Source file
//! \~russian Исходный файл
PIString file;
//! \~english Offset in file
//! \~russian Смещение в файле
llong offset;
//! \~english Size
//! \~russian Размер
llong size;
//! \~english Flags
//! \~russian Флаги
int flags;
};
//! \~english Register a section with data
//! \~russian Зарегистрировать секцию с данными
//! \param section_name Name of the section
//! \param data Section data
void registerSection(const PIString & section_name, const Section & data);
//! \~english Register from raw data
//! \~russian Зарегистрировать из сырых данных
//! \param rc_data Resource data
//! \param rc_desc Resource description
//! \param rc_desc_size Description size
void registerSection(const uchar * rc_data, const uchar * rc_desc, int rc_desc_size);
//! \~english Get section by name
//! \~russian Получить секцию по имени
//! \param section_name Name of section
//! \return Pointer to section or nullptr
Section * section(const PIString & section_name) const;
//! \~english Get resource by section and name
//! \~russian Получить ресурс по секции и имени
PIByteArray get(const PIString & section_name, const PIString & entry_name) const;
//! \~english Get resource by name (searches all sections)
//! \~russian Получить ресурс по имени (ищет во всех секциях)
PIByteArray get(const PIString & entry_name) const;
//! \~english Clear all sections
//! \~russian Очистить все секции
void clear();
private:
PIResourcesStorage();
~PIResourcesStorage();
PIMap<PIString, Section *> sections;
};
BINARY_STREAM_WRITE(PIResourcesStorage::__RCEntry) {
PIChunkStream cs;
cs.add(1, v.section).add(2, v.name).add(3, v.file).add(4, v.size).add(5, v.offset).add(6, v.flags).add(7, v.alias);
s << cs.data();
return s;
}
BINARY_STREAM_READ(PIResourcesStorage::__RCEntry) {
PIByteArray ba;
s >> ba;
PIChunkStream cs(ba);
while (!cs.atEnd()) {
switch (cs.read()) {
case 1: cs.get(v.section); break;
case 2: cs.get(v.name); break;
case 3: cs.get(v.file); break;
case 4: cs.get(v.size); break;
case 5: cs.get(v.offset); break;
case 6: cs.get(v.flags); break;
case 7: cs.get(v.alias); break;
}
}
return s;
}
#endif // PIRESOURCES_H