155 lines
5.7 KiB
C++
155 lines
5.7 KiB
C++
//! \~\file piresourcesstorage.h
|
||
//! \~\ingroup Resources
|
||
//! \~\brief
|
||
//! \~english Storage for compiled resources
|
||
//! \~russian Хранилище вкомпиленных ресурсов
|
||
/*
|
||
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/>.
|
||
*/
|
||
|
||
#ifndef PIRESOURCES_P_H
|
||
#define PIRESOURCES_P_H
|
||
|
||
#include "pichunkstream.h"
|
||
#include "pimap.h"
|
||
#include "pistring.h"
|
||
|
||
class PIResources;
|
||
|
||
//! \~\ingroup Resources
|
||
//! \~\brief
|
||
//! \~english Global storage for sections and entries registered by the resources subsystem.
|
||
//! \~russian Глобальное хранилище секций и элементов, зарегистрированных подсистемой ресурсов.
|
||
class PIP_EXPORT PIResourcesStorage {
|
||
friend class PIResources;
|
||
|
||
public:
|
||
//! \~english Returns singleton storage instance.
|
||
//! \~russian Возвращает экземпляр глобального хранилища.
|
||
static PIResourcesStorage * instance();
|
||
|
||
//! \~\ingroup Resources
|
||
//! \~\brief
|
||
//! \~english One logical resource section with named binary entries.
|
||
//! \~russian Одна логическая секция ресурсов с именованными бинарными элементами.
|
||
struct PIP_EXPORT Section {
|
||
//! \~english Constructs an empty section.
|
||
//! \~russian Создает пустую секцию.
|
||
Section();
|
||
|
||
//! \~english Destroys the section object.
|
||
//! \~russian Уничтожает объект секции.
|
||
~Section();
|
||
|
||
//! \~english Adds entries from another section without replacing existing names.
|
||
//! \~russian Добавляет элементы из другой секции, не заменяя уже существующие имена.
|
||
void add(const Section & s);
|
||
|
||
//! \~english Deletes stored entry buffers and clears the section.
|
||
//! \~russian Удаляет сохраненные буферы элементов и очищает секцию.
|
||
void purge();
|
||
|
||
//! \~english Section entries indexed by resource name or alias.
|
||
//! \~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;
|
||
}
|
||
PIString section;
|
||
PIString name;
|
||
PIString alias;
|
||
PIString file;
|
||
llong offset;
|
||
llong size;
|
||
int flags;
|
||
};
|
||
|
||
//! \~english Registers or merges a ready section under name `section_name`.
|
||
//! \~russian Регистрирует или объединяет готовую секцию под именем `section_name`.
|
||
void registerSection(const PIString & section_name, const Section & data);
|
||
|
||
//! \~english Registers compiled resources from raw data and serialized descriptors.
|
||
//! \~russian Регистрирует вкомпиленные ресурсы из сырых данных и сериализованных дескрипторов.
|
||
void registerSection(const uchar * rc_data, const uchar * rc_desc, int rc_desc_size);
|
||
|
||
//! \~english Returns registered section by name, or null if it is absent.
|
||
//! \~russian Возвращает зарегистрированную секцию по имени или null, если она отсутствует.
|
||
Section * section(const PIString & section_name) const;
|
||
|
||
//! \~english Returns entry data by section and entry name.
|
||
//! \~russian Возвращает данные элемента по секции и имени элемента.
|
||
PIByteArray get(const PIString & section_name, const PIString & entry_name) const;
|
||
|
||
//! \~english Returns first entry with name `entry_name` across all sections.
|
||
//! \~russian Возвращает первый элемент с именем `entry_name` среди всех секций.
|
||
PIByteArray get(const PIString & entry_name) const;
|
||
|
||
//! \~english Removes all registered sections and entry buffers.
|
||
//! \~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_P_H
|