2022-06-23 21:36:00 -04:00
|
|
|
#ifndef CHUNK_H
|
|
|
|
#define CHUNK_H
|
|
|
|
|
|
|
|
#include <fstream>
|
2022-07-03 11:57:43 -04:00
|
|
|
#include <map>
|
2022-06-23 21:36:00 -04:00
|
|
|
#include <memory>
|
|
|
|
|
2022-07-03 11:57:43 -04:00
|
|
|
#include "common.h"
|
2022-07-11 00:15:58 -04:00
|
|
|
#include "core.h"
|
2022-07-03 23:45:05 -04:00
|
|
|
#include "sitypes.h"
|
2022-06-23 21:36:00 -04:00
|
|
|
#include "types.h"
|
|
|
|
|
2022-06-27 12:44:50 -04:00
|
|
|
namespace si {
|
|
|
|
|
2022-07-11 00:15:58 -04:00
|
|
|
class Chunk : public Core
|
2022-06-23 21:36:00 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Type
|
|
|
|
{
|
2022-06-27 12:44:50 -04:00
|
|
|
TYPE_RIFF = 0x46464952,
|
|
|
|
TYPE_LIST = 0x5453494c,
|
|
|
|
TYPE_MxSt = 0x7453784d,
|
|
|
|
TYPE_MxHd = 0x6448784d,
|
|
|
|
TYPE_MxCh = 0x6843784d,
|
|
|
|
TYPE_MxOf = 0x664f784d,
|
|
|
|
TYPE_MxOb = 0x624f784d,
|
2022-07-11 17:18:56 -04:00
|
|
|
TYPE_MxDa = 0x6144784d,
|
2022-06-27 12:44:50 -04:00
|
|
|
TYPE_pad_ = 0x20646170
|
2022-06-23 21:36:00 -04:00
|
|
|
};
|
|
|
|
|
2022-07-11 17:18:56 -04:00
|
|
|
LIBWEAVER_EXPORT Chunk(uint32_t id = 0);
|
2022-07-03 11:57:43 -04:00
|
|
|
virtual LIBWEAVER_EXPORT ~Chunk();
|
2022-06-23 21:36:00 -04:00
|
|
|
|
2022-07-03 11:57:43 -04:00
|
|
|
LIBWEAVER_EXPORT bool Read(const std::string &f);
|
|
|
|
LIBWEAVER_EXPORT bool Read(const char *f);
|
|
|
|
LIBWEAVER_EXPORT void Clear();
|
2022-06-23 21:36:00 -04:00
|
|
|
|
2022-07-11 17:18:56 -04:00
|
|
|
LIBWEAVER_EXPORT bool Write(const std::string &f);
|
|
|
|
LIBWEAVER_EXPORT bool Write(const char *f);
|
|
|
|
|
2022-07-03 11:57:43 -04:00
|
|
|
LIBWEAVER_EXPORT Type type() const { return static_cast<Type>(id_); }
|
2022-07-11 00:09:39 -04:00
|
|
|
LIBWEAVER_EXPORT const uint32_t &id() const { return id_; }
|
|
|
|
LIBWEAVER_EXPORT const uint32_t &offset() const { return offset_; }
|
2022-07-03 11:57:43 -04:00
|
|
|
|
|
|
|
LIBWEAVER_EXPORT Data &data(const std::string &key) { return data_[key]; }
|
|
|
|
LIBWEAVER_EXPORT const Data &data(const std::string &key) const { return data_.at(key); }
|
|
|
|
|
|
|
|
LIBWEAVER_EXPORT static const char *GetTypeDescription(Type type);
|
|
|
|
LIBWEAVER_EXPORT const char *GetTypeDescription() const
|
2022-06-23 21:36:00 -04:00
|
|
|
{
|
|
|
|
return GetTypeDescription(type());
|
|
|
|
}
|
|
|
|
|
2022-07-03 23:45:05 -04:00
|
|
|
LIBWEAVER_EXPORT Chunk *FindChildWithType(Type type) const;
|
2022-07-11 00:09:39 -04:00
|
|
|
LIBWEAVER_EXPORT Chunk *FindChildWithOffset(uint32_t offset) const;
|
2022-07-03 23:45:05 -04:00
|
|
|
|
2022-06-23 21:36:00 -04:00
|
|
|
private:
|
2022-07-11 00:09:39 -04:00
|
|
|
bool Read(std::ifstream &f, uint32_t &version, uint32_t &alignment);
|
2022-07-11 17:18:56 -04:00
|
|
|
bool Write(std::ofstream &f, const uint32_t &version) const;
|
2022-06-27 12:44:50 -04:00
|
|
|
|
2022-07-03 23:45:05 -04:00
|
|
|
static RIFF *GetReaderFromType(Type type);
|
|
|
|
|
2022-07-11 00:09:39 -04:00
|
|
|
uint32_t id_;
|
|
|
|
uint32_t offset_;
|
2022-07-03 11:57:43 -04:00
|
|
|
std::map<std::string, Data> data_;
|
2022-06-23 21:36:00 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-06-27 12:44:50 -04:00
|
|
|
}
|
|
|
|
|
2022-06-23 21:36:00 -04:00
|
|
|
#endif // CHUNK_H
|