mirror of
https://github.com/ModOrganizer2/modorganizer-esptk.git
synced 2026-07-27 14:03:02 -07:00
Apply clang-format
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
---
|
||||
# We'll use defaults from the LLVM style, but with 4 columns indentation.
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 2
|
||||
---
|
||||
Language: Cpp
|
||||
DeriveLineEnding: false
|
||||
UseCRLF: true
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
||||
AlignConsecutiveAssignments: true
|
||||
AllowShortFunctionsOnASingleLine: Inline
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AllowShortLambdasOnASingleLine: Empty
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
AccessModifierOffset: -2
|
||||
AlignTrailingComments: true
|
||||
SpacesBeforeTrailingComments: 2
|
||||
NamespaceIndentation: Inner
|
||||
MaxEmptyLinesToKeep: 1
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: true
|
||||
AfterControlStatement: false
|
||||
AfterEnum: true
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterStruct: true
|
||||
AfterUnion: true
|
||||
AfterExternBlock: true
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: true
|
||||
ColumnLimit: 88
|
||||
ForEachMacros: ['Q_FOREACH', 'foreach']
|
||||
+10
-10
@@ -3,21 +3,21 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace ESP
|
||||
{
|
||||
|
||||
namespace ESP {
|
||||
|
||||
|
||||
class InvalidRecordException : public std::runtime_error {
|
||||
class InvalidRecordException : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
InvalidRecordException(const std::string &message) : std::runtime_error(message) {}
|
||||
InvalidRecordException(const std::string& message) : std::runtime_error(message) {}
|
||||
};
|
||||
|
||||
|
||||
class InvalidFileException : public std::runtime_error {
|
||||
class InvalidFileException : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
InvalidFileException(const std::string &message) : std::runtime_error(message) {}
|
||||
InvalidFileException(const std::string& message) : std::runtime_error(message) {}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace ESP
|
||||
|
||||
#endif // ESPEXCEPTIONS_H
|
||||
#endif // ESPEXCEPTIONS_H
|
||||
|
||||
+77
-74
@@ -1,35 +1,33 @@
|
||||
#include "espfile.h"
|
||||
#include "espexceptions.h"
|
||||
#include "subrecord.h"
|
||||
#include "tes3subrecord.h"
|
||||
#include "espexceptions.h"
|
||||
#include <sstream>
|
||||
#include <bitset>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
ESP::File::File(const std::string &fileName)
|
||||
ESP::File::File(const std::string& fileName)
|
||||
{
|
||||
m_File.open(fileName, std::fstream::in | std::fstream::binary);
|
||||
init();
|
||||
}
|
||||
|
||||
ESP::File::File(const std::wstring &fileName)
|
||||
ESP::File::File(const std::wstring& fileName)
|
||||
{
|
||||
m_File.open(fileName, std::fstream::in | std::fstream::binary);
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
class membuf : public std::basic_streambuf<char>
|
||||
{
|
||||
public:
|
||||
membuf(const char *start, size_t size) {
|
||||
membuf(const char* start, size_t size)
|
||||
{
|
||||
// baad me! this is intended for an istream only so we're not modifying
|
||||
char *startMod = const_cast<char*>(start);
|
||||
char* startMod = const_cast<char*>(start);
|
||||
setg(startMod, startMod, startMod + size);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void ESP::File::init()
|
||||
{
|
||||
if (!m_File.is_open()) {
|
||||
@@ -42,97 +40,102 @@ void ESP::File::init()
|
||||
throw ESP::InvalidFileException("file incomplete");
|
||||
}
|
||||
if (memcmp(type, "TES3", 4) == 0) {
|
||||
ESP::TES3Record rec;
|
||||
rec.readFrom(m_File);
|
||||
ESP::TES3Record rec;
|
||||
rec.readFrom(m_File);
|
||||
|
||||
while (!m_File.eof() && !m_File.fail()) {
|
||||
ESP::TES3SubRecord subRec;
|
||||
bool success = subRec.readFrom(m_File);
|
||||
int headerSize = sizeof(m_TES3Header);
|
||||
if (success) {
|
||||
if (subRec.type() != TES3SubRecord::TYPE_UNKNOWN) {
|
||||
switch (subRec.type()) {
|
||||
case TES3SubRecord::TYPE_HEDR:
|
||||
if (subRec.data().size() != sizeof(m_TES3Header)) {
|
||||
printf("invalid header size\n");
|
||||
m_Header.version = 0.0f;
|
||||
m_Header.numRecords = 1; // prevent this esp appear like a dummy
|
||||
}
|
||||
else {
|
||||
memcpy(&m_TES3Header, &subRec.data()[0], sizeof(m_TES3Header));
|
||||
}
|
||||
m_Header.version = m_TES3Header.version;
|
||||
//m_Header.numRecords = m_TES3Header.numRecords;
|
||||
m_Author = reinterpret_cast<const char*>(m_TES3Header.author);
|
||||
m_Description = reinterpret_cast<const char*>(m_TES3Header.description);
|
||||
break;
|
||||
case TES3SubRecord::TYPE_MAST:
|
||||
if (subRec.data().size() > 0)
|
||||
m_Masters.insert(reinterpret_cast<const char*>(&subRec.data()[0]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!m_File.eof() && !m_File.fail()) {
|
||||
ESP::TES3SubRecord subRec;
|
||||
bool success = subRec.readFrom(m_File);
|
||||
int headerSize = sizeof(m_TES3Header);
|
||||
if (success) {
|
||||
if (subRec.type() != TES3SubRecord::TYPE_UNKNOWN) {
|
||||
switch (subRec.type()) {
|
||||
case TES3SubRecord::TYPE_HEDR:
|
||||
if (subRec.data().size() != sizeof(m_TES3Header)) {
|
||||
printf("invalid header size\n");
|
||||
m_Header.version = 0.0f;
|
||||
m_Header.numRecords = 1; // prevent this esp appear like a dummy
|
||||
} else {
|
||||
memcpy(&m_TES3Header, &subRec.data()[0], sizeof(m_TES3Header));
|
||||
}
|
||||
m_Header.version = m_TES3Header.version;
|
||||
// m_Header.numRecords = m_TES3Header.numRecords;
|
||||
m_Author = reinterpret_cast<const char*>(m_TES3Header.author);
|
||||
m_Description = reinterpret_cast<const char*>(m_TES3Header.description);
|
||||
break;
|
||||
case TES3SubRecord::TYPE_MAST:
|
||||
if (subRec.data().size() > 0)
|
||||
m_Masters.insert(reinterpret_cast<const char*>(&subRec.data()[0]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (memcmp(type, "TES4", 4) == 0) {
|
||||
m_File.seekg(0);
|
||||
m_File.seekg(0);
|
||||
|
||||
m_MainRecord = readRecord();
|
||||
m_MainRecord = readRecord();
|
||||
|
||||
const std::vector<uint8_t> &data = m_MainRecord.data();
|
||||
membuf buf(reinterpret_cast<const char*>(&data[0]), data.size());
|
||||
const std::vector<uint8_t>& data = m_MainRecord.data();
|
||||
membuf buf(reinterpret_cast<const char*>(&data[0]), data.size());
|
||||
|
||||
std::istream stream(&buf);
|
||||
while (!stream.eof() && !stream.fail()) {
|
||||
SubRecord rec;
|
||||
bool success = rec.readFrom(stream);
|
||||
if (success) {
|
||||
if (rec.type() != SubRecord::TYPE_UNKNOWN) {
|
||||
switch (rec.type()) {
|
||||
case SubRecord::TYPE_HEDR: onHEDR(rec); break;
|
||||
case SubRecord::TYPE_MAST: onMAST(rec); break;
|
||||
case SubRecord::TYPE_CNAM: onCNAM(rec); break;
|
||||
case SubRecord::TYPE_SNAM: onSNAM(rec); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
std::istream stream(&buf);
|
||||
while (!stream.eof() && !stream.fail()) {
|
||||
SubRecord rec;
|
||||
bool success = rec.readFrom(stream);
|
||||
if (success) {
|
||||
if (rec.type() != SubRecord::TYPE_UNKNOWN) {
|
||||
switch (rec.type()) {
|
||||
case SubRecord::TYPE_HEDR:
|
||||
onHEDR(rec);
|
||||
break;
|
||||
case SubRecord::TYPE_MAST:
|
||||
onMAST(rec);
|
||||
break;
|
||||
case SubRecord::TYPE_CNAM:
|
||||
onCNAM(rec);
|
||||
break;
|
||||
case SubRecord::TYPE_SNAM:
|
||||
onSNAM(rec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw ESP::InvalidFileException("invalid file type");
|
||||
throw ESP::InvalidFileException("invalid file type");
|
||||
}
|
||||
}
|
||||
|
||||
void ESP::File::onHEDR(const SubRecord &rec)
|
||||
void ESP::File::onHEDR(const SubRecord& rec)
|
||||
{
|
||||
if (rec.data().size() != sizeof(m_Header)) {
|
||||
printf("invalid header size\n");
|
||||
m_Header.version = 0.0f;
|
||||
m_Header.numRecords = 1; // prevent this esp appear like a dummy
|
||||
m_Header.version = 0.0f;
|
||||
m_Header.numRecords = 1; // prevent this esp appear like a dummy
|
||||
} else {
|
||||
memcpy(&m_Header, &rec.data()[0], sizeof(m_Header));
|
||||
}
|
||||
}
|
||||
|
||||
void ESP::File::onMAST(const SubRecord &rec)
|
||||
void ESP::File::onMAST(const SubRecord& rec)
|
||||
{
|
||||
if (rec.data().size() > 0)
|
||||
m_Masters.insert(reinterpret_cast<const char*>(&rec.data()[0]));
|
||||
|
||||
}
|
||||
|
||||
void ESP::File::onCNAM(const SubRecord &rec)
|
||||
void ESP::File::onCNAM(const SubRecord& rec)
|
||||
{
|
||||
if (rec.data().size() > 0)
|
||||
m_Author = reinterpret_cast<const char*>(&rec.data()[0]);
|
||||
}
|
||||
|
||||
void ESP::File::onSNAM(const SubRecord &rec)
|
||||
void ESP::File::onSNAM(const SubRecord& rec)
|
||||
{
|
||||
if (rec.data().size() > 0)
|
||||
m_Description = reinterpret_cast<const char*>(&rec.data()[0]);
|
||||
}
|
||||
|
||||
|
||||
ESP::Record ESP::File::readRecord()
|
||||
{
|
||||
ESP::Record rec;
|
||||
@@ -147,16 +150,16 @@ bool ESP::File::isMaster() const
|
||||
|
||||
bool ESP::File::isLight(bool overrideSupport) const
|
||||
{
|
||||
if (overrideSupport) {
|
||||
return m_MainRecord.flagSet(Record::FLAG_LIGHT_ALTERNATE);
|
||||
} else {
|
||||
return m_MainRecord.flagSet(Record::FLAG_LIGHT);
|
||||
}
|
||||
if (overrideSupport) {
|
||||
return m_MainRecord.flagSet(Record::FLAG_LIGHT_ALTERNATE);
|
||||
} else {
|
||||
return m_MainRecord.flagSet(Record::FLAG_LIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
bool ESP::File::isOverride() const
|
||||
{
|
||||
return m_MainRecord.flagSet(Record::FLAG_OVERRIDE);
|
||||
return m_MainRecord.flagSet(Record::FLAG_OVERRIDE);
|
||||
}
|
||||
|
||||
bool ESP::File::isDummy() const
|
||||
|
||||
+22
-25
@@ -1,24 +1,22 @@
|
||||
#ifndef ESPFILE_H
|
||||
#define ESPFILE_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
#include "record.h"
|
||||
#include "tes3record.h"
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace ESP {
|
||||
namespace ESP
|
||||
{
|
||||
|
||||
class SubRecord;
|
||||
|
||||
class File
|
||||
{
|
||||
public:
|
||||
|
||||
File(const std::string &fileName);
|
||||
File(const std::wstring &fileName);
|
||||
File(const std::string& fileName);
|
||||
File(const std::wstring& fileName);
|
||||
|
||||
Record readRecord();
|
||||
|
||||
@@ -31,30 +29,30 @@ public:
|
||||
std::set<std::string> masters() const { return m_Masters; }
|
||||
|
||||
private:
|
||||
|
||||
void init();
|
||||
|
||||
void onHEDR(const SubRecord &rec);
|
||||
void onMAST(const SubRecord &rec);
|
||||
void onCNAM(const SubRecord &rec);
|
||||
void onSNAM(const SubRecord &rec);
|
||||
void onHEDR(const SubRecord& rec);
|
||||
void onMAST(const SubRecord& rec);
|
||||
void onCNAM(const SubRecord& rec);
|
||||
void onSNAM(const SubRecord& rec);
|
||||
|
||||
private:
|
||||
|
||||
std::ifstream m_File;
|
||||
|
||||
struct {
|
||||
struct
|
||||
{
|
||||
float version;
|
||||
int32_t numRecords;
|
||||
uint32_t nextObjectId;
|
||||
} m_Header;
|
||||
|
||||
struct {
|
||||
float version;
|
||||
uint32_t unknown;
|
||||
char author[32];
|
||||
char description[256];
|
||||
uint32_t numRecords;
|
||||
struct
|
||||
{
|
||||
float version;
|
||||
uint32_t unknown;
|
||||
char author[32];
|
||||
char description[256];
|
||||
uint32_t numRecords;
|
||||
} m_TES3Header;
|
||||
|
||||
Record m_MainRecord;
|
||||
@@ -63,9 +61,8 @@ private:
|
||||
std::string m_Description;
|
||||
|
||||
std::set<std::string> m_Masters;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace ESP
|
||||
|
||||
#endif // ESPFILE_H
|
||||
#endif // ESPFILE_H
|
||||
|
||||
+5
-5
@@ -1,13 +1,13 @@
|
||||
#ifndef ESPTYPES_H
|
||||
#define ESPTYPES_H
|
||||
|
||||
|
||||
#include <istream>
|
||||
|
||||
|
||||
template <typename T> static T readType(std::istream &stream)
|
||||
template <typename T>
|
||||
static T readType(std::istream& stream)
|
||||
{
|
||||
union {
|
||||
union
|
||||
{
|
||||
char buffer[sizeof(T)];
|
||||
T value;
|
||||
};
|
||||
@@ -16,4 +16,4 @@ template <typename T> static T readType(std::istream &stream)
|
||||
return value;
|
||||
}
|
||||
|
||||
#endif // ESPTYPES_H
|
||||
#endif // ESPTYPES_H
|
||||
|
||||
+3
-10
@@ -1,21 +1,14 @@
|
||||
#include "record.h"
|
||||
#include "espexceptions.h"
|
||||
|
||||
|
||||
ESP::Record::Record()
|
||||
: m_Header()
|
||||
, m_Data()
|
||||
, m_OblivionStyle(false)
|
||||
{
|
||||
|
||||
}
|
||||
ESP::Record::Record() : m_Header(), m_Data(), m_OblivionStyle(false) {}
|
||||
|
||||
bool ESP::Record::flagSet(ESP::Record::EFlag flag) const
|
||||
{
|
||||
return (m_Header.flags & flag) != 0;
|
||||
}
|
||||
|
||||
bool ESP::Record::readFrom(std::istream &stream)
|
||||
bool ESP::Record::readFrom(std::istream& stream)
|
||||
{
|
||||
if (!stream.read(reinterpret_cast<char*>(&m_Header), sizeof(Header))) {
|
||||
if (stream.gcount() == 0) {
|
||||
@@ -30,7 +23,7 @@ bool ESP::Record::readFrom(std::istream &stream)
|
||||
if (memcmp(buf, "HEDR", 4) == 0) {
|
||||
m_OblivionStyle = true;
|
||||
stream.seekg(-4, std::istream::cur);
|
||||
} // skyrim has some version data here I don't know how to interpret anyway
|
||||
} // skyrim has some version data here I don't know how to interpret anyway
|
||||
|
||||
m_Data.resize(m_Header.dataSize);
|
||||
stream.read(reinterpret_cast<char*>(&m_Data[0]), m_Header.dataSize);
|
||||
|
||||
+42
-40
@@ -2,50 +2,52 @@
|
||||
#define RECORD_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
|
||||
namespace ESP
|
||||
{
|
||||
|
||||
namespace ESP {
|
||||
|
||||
/**
|
||||
* @brief record storage class without record-specific information
|
||||
*/
|
||||
class Record
|
||||
/**
|
||||
* @brief record storage class without record-specific information
|
||||
*/
|
||||
class Record
|
||||
{
|
||||
public:
|
||||
enum EFlag
|
||||
{
|
||||
public:
|
||||
enum EFlag {
|
||||
FLAG_MASTER = 0x00000001,
|
||||
FLAG_LIGHT_ALTERNATE = 0x00000100, // SF light flag (FE/FF memory space)
|
||||
FLAG_LIGHT = 0x00000200, // SSE & FO4 light flag (FE/FF memory space)
|
||||
FLAG_OVERRIDE = 0x00000200, // SF override flag (does not claim new memory space, overrules light flag)
|
||||
FLAG_COMPRESSED = 0x00040000
|
||||
};
|
||||
|
||||
public:
|
||||
Record();
|
||||
|
||||
bool readFrom(std::istream& stream);
|
||||
|
||||
bool flagSet(EFlag flag) const;
|
||||
|
||||
const std::vector<uint8_t>& data() const { return m_Data; }
|
||||
|
||||
private:
|
||||
struct Header {
|
||||
char type[4];
|
||||
uint32_t dataSize;
|
||||
uint32_t flags;
|
||||
uint32_t id;
|
||||
uint32_t revision;
|
||||
} m_Header;
|
||||
|
||||
std::vector<uint8_t> m_Data;
|
||||
|
||||
bool m_OblivionStyle;
|
||||
|
||||
FLAG_MASTER = 0x00000001,
|
||||
FLAG_LIGHT_ALTERNATE = 0x00000100, // SF light flag (FE/FF memory space)
|
||||
FLAG_LIGHT = 0x00000200, // SSE & FO4 light flag (FE/FF memory space)
|
||||
FLAG_OVERRIDE = 0x00000200, // SF override flag (does not claim new memory space,
|
||||
// overrules light flag)
|
||||
FLAG_COMPRESSED = 0x00040000
|
||||
};
|
||||
|
||||
}
|
||||
public:
|
||||
Record();
|
||||
|
||||
#endif // RECORD_H
|
||||
bool readFrom(std::istream& stream);
|
||||
|
||||
bool flagSet(EFlag flag) const;
|
||||
|
||||
const std::vector<uint8_t>& data() const { return m_Data; }
|
||||
|
||||
private:
|
||||
struct Header
|
||||
{
|
||||
char type[4];
|
||||
uint32_t dataSize;
|
||||
uint32_t flags;
|
||||
uint32_t id;
|
||||
uint32_t revision;
|
||||
} m_Header;
|
||||
|
||||
std::vector<uint8_t> m_Data;
|
||||
|
||||
bool m_OblivionStyle;
|
||||
};
|
||||
|
||||
} // namespace ESP
|
||||
|
||||
#endif // RECORD_H
|
||||
|
||||
+15
-21
@@ -1,29 +1,20 @@
|
||||
#include "subrecord.h"
|
||||
#include "esptypes.h"
|
||||
#include "espexceptions.h"
|
||||
#include "esptypes.h"
|
||||
#include <boost/assign.hpp>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <boost/assign.hpp>
|
||||
|
||||
|
||||
using namespace boost::assign;
|
||||
|
||||
ESP::SubRecord::SubRecord() : m_Type(TYPE_UNKNOWN), m_Data() {}
|
||||
|
||||
ESP::SubRecord::SubRecord()
|
||||
: m_Type(TYPE_UNKNOWN)
|
||||
, m_Data()
|
||||
bool ESP::SubRecord::readFrom(std::istream& stream, uint32_t sizeOverride)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool ESP::SubRecord::readFrom(std::istream &stream, uint32_t sizeOverride)
|
||||
{
|
||||
static std::unordered_map<std::string, EType> s_TypeMap = map_list_of("HEDR", TYPE_HEDR)
|
||||
("CNAM", TYPE_CNAM)
|
||||
("MAST", TYPE_MAST)
|
||||
("ONAM", TYPE_ONAM)
|
||||
("SNAM", TYPE_SNAM);
|
||||
static std::unordered_map<std::string, EType> s_TypeMap =
|
||||
map_list_of("HEDR", TYPE_HEDR)("CNAM", TYPE_CNAM)("MAST", TYPE_MAST)(
|
||||
"ONAM", TYPE_ONAM)("SNAM", TYPE_SNAM);
|
||||
|
||||
char typeString[5];
|
||||
if (!stream.read(typeString, 4)) {
|
||||
@@ -34,15 +25,17 @@ bool ESP::SubRecord::readFrom(std::istream &stream, uint32_t sizeOverride)
|
||||
}
|
||||
}
|
||||
if (stream.gcount() != 4) {
|
||||
throw ESP::InvalidRecordException(std::string("sub-record type incomplete (invalid type ") + typeString + ")");
|
||||
throw ESP::InvalidRecordException(
|
||||
std::string("sub-record type incomplete (invalid type ") + typeString + ")");
|
||||
}
|
||||
typeString[4] = '\0'; // not sure if this is required, shouldn't be
|
||||
auto iter = s_TypeMap.find(std::string(typeString));
|
||||
typeString[4] = '\0'; // not sure if this is required, shouldn't be
|
||||
auto iter = s_TypeMap.find(std::string(typeString));
|
||||
if (iter != s_TypeMap.end()) {
|
||||
m_Type = iter->second;
|
||||
} else if (strncmp(typeString, "XXXX", 4) == 0) {
|
||||
if (readType<uint16_t>(stream) != 4) {
|
||||
throw ESP::InvalidRecordException("XXXX record is supposed to be 4 bytes in size");
|
||||
throw ESP::InvalidRecordException(
|
||||
"XXXX record is supposed to be 4 bytes in size");
|
||||
}
|
||||
return readFrom(stream, readType<uint32_t>(stream));
|
||||
} else {
|
||||
@@ -57,7 +50,8 @@ bool ESP::SubRecord::readFrom(std::istream &stream, uint32_t sizeOverride)
|
||||
|
||||
stream.read(reinterpret_cast<char*>(&m_Data[0]), dataSize);
|
||||
if (!stream) {
|
||||
throw ESP::InvalidRecordException(std::string("sub-record incomplete: ") + typeString);
|
||||
throw ESP::InvalidRecordException(std::string("sub-record incomplete: ") +
|
||||
typeString);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
+8
-11
@@ -1,14 +1,12 @@
|
||||
#ifndef SUBRECORD_H
|
||||
#define SUBRECORD_H
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace ESP {
|
||||
|
||||
namespace ESP
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief sub-record storage class without record-specific information
|
||||
@@ -16,8 +14,8 @@ namespace ESP {
|
||||
class SubRecord
|
||||
{
|
||||
public:
|
||||
|
||||
enum EType {
|
||||
enum EType
|
||||
{
|
||||
TYPE_UNKNOWN,
|
||||
TYPE_HEDR,
|
||||
TYPE_CNAM,
|
||||
@@ -31,17 +29,16 @@ public:
|
||||
public:
|
||||
SubRecord();
|
||||
|
||||
bool readFrom(std::istream &stream, uint32_t sizeOverride = 0UL);
|
||||
bool readFrom(std::istream& stream, uint32_t sizeOverride = 0UL);
|
||||
|
||||
EType type() const { return m_Type; }
|
||||
const std::vector<uint8_t> &data() const { return m_Data; }
|
||||
const std::vector<uint8_t>& data() const { return m_Data; }
|
||||
|
||||
private:
|
||||
|
||||
EType m_Type;
|
||||
std::vector<uint8_t> m_Data;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace ESP
|
||||
|
||||
#endif // SUBRECORD_H
|
||||
#endif // SUBRECORD_H
|
||||
|
||||
+10
-14
@@ -1,20 +1,16 @@
|
||||
#include "tes3record.h"
|
||||
#include "espexceptions.h"
|
||||
|
||||
ESP::TES3Record::TES3Record() : m_Header() {}
|
||||
|
||||
ESP::TES3Record::TES3Record()
|
||||
: m_Header()
|
||||
{ }
|
||||
|
||||
bool ESP::TES3Record::readFrom(std::istream &stream)
|
||||
bool ESP::TES3Record::readFrom(std::istream& stream)
|
||||
{
|
||||
if (!stream.read(reinterpret_cast<char*>(&m_Header), sizeof(Header))) {
|
||||
if (stream.gcount() == 0) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
throw ESP::InvalidRecordException("record incomplete");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
if (!stream.read(reinterpret_cast<char*>(&m_Header), sizeof(Header))) {
|
||||
if (stream.gcount() == 0) {
|
||||
return false;
|
||||
} else {
|
||||
throw ESP::InvalidRecordException("record incomplete");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
+21
-20
@@ -2,30 +2,31 @@
|
||||
#define TES3_RECORD_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
|
||||
namespace ESP
|
||||
{
|
||||
|
||||
namespace ESP {
|
||||
/**
|
||||
* @brief record storage class without record-specific information
|
||||
*/
|
||||
class TES3Record
|
||||
{
|
||||
public:
|
||||
TES3Record();
|
||||
|
||||
/**
|
||||
* @brief record storage class without record-specific information
|
||||
*/
|
||||
class TES3Record
|
||||
{
|
||||
public:
|
||||
TES3Record();
|
||||
bool readFrom(std::istream& stream);
|
||||
|
||||
bool readFrom(std::istream &stream);
|
||||
private:
|
||||
struct Header
|
||||
{
|
||||
char type[4];
|
||||
float version;
|
||||
long unknown;
|
||||
} m_Header;
|
||||
};
|
||||
|
||||
private:
|
||||
struct Header {
|
||||
char type[4];
|
||||
float version;
|
||||
long unknown;
|
||||
} m_Header;
|
||||
};
|
||||
} // namespace ESP
|
||||
|
||||
}
|
||||
|
||||
#endif // TES3_RECORD_H
|
||||
#endif // TES3_RECORD_H
|
||||
|
||||
+17
-23
@@ -1,27 +1,19 @@
|
||||
#include "tes3subrecord.h"
|
||||
#include "esptypes.h"
|
||||
#include "espexceptions.h"
|
||||
#include "esptypes.h"
|
||||
#include <boost/assign.hpp>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <boost/assign.hpp>
|
||||
|
||||
|
||||
using namespace boost::assign;
|
||||
|
||||
ESP::TES3SubRecord::TES3SubRecord() : m_Type(TYPE_UNKNOWN), m_Data() {}
|
||||
|
||||
ESP::TES3SubRecord::TES3SubRecord()
|
||||
: m_Type(TYPE_UNKNOWN)
|
||||
, m_Data()
|
||||
bool ESP::TES3SubRecord::readFrom(std::istream& stream, uint32_t sizeOverride)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool ESP::TES3SubRecord::readFrom(std::istream &stream, uint32_t sizeOverride)
|
||||
{
|
||||
static std::unordered_map<std::string, EType> s_TypeMap = map_list_of("HEDR", TYPE_HEDR)
|
||||
("MAST", TYPE_MAST)
|
||||
("DATA", TYPE_DATA);
|
||||
static std::unordered_map<std::string, EType> s_TypeMap =
|
||||
map_list_of("HEDR", TYPE_HEDR)("MAST", TYPE_MAST)("DATA", TYPE_DATA);
|
||||
|
||||
char typeString[5];
|
||||
if (!stream.read(typeString, 4)) {
|
||||
@@ -32,18 +24,19 @@ bool ESP::TES3SubRecord::readFrom(std::istream &stream, uint32_t sizeOverride)
|
||||
}
|
||||
}
|
||||
if (stream.gcount() != 4) {
|
||||
throw ESP::InvalidRecordException(std::string("sub-record type incomplete (invalid type ") + typeString + ")");
|
||||
throw ESP::InvalidRecordException(
|
||||
std::string("sub-record type incomplete (invalid type ") + typeString + ")");
|
||||
}
|
||||
typeString[4] = '\0'; // not sure if this is required, shouldn't be
|
||||
auto iter = s_TypeMap.find(std::string(typeString));
|
||||
typeString[4] = '\0'; // not sure if this is required, shouldn't be
|
||||
auto iter = s_TypeMap.find(std::string(typeString));
|
||||
uint32_t dataSize;
|
||||
if (iter != s_TypeMap.end()) {
|
||||
m_Type = iter->second;
|
||||
dataSize = readType<uint32_t>(stream);
|
||||
m_Type = iter->second;
|
||||
dataSize = readType<uint32_t>(stream);
|
||||
} else {
|
||||
m_Type = TYPE_UNKNOWN;
|
||||
dataSize = readType<uint32_t>(stream);
|
||||
stream.seekg(8, std::istream::cur);
|
||||
m_Type = TYPE_UNKNOWN;
|
||||
dataSize = readType<uint32_t>(stream);
|
||||
stream.seekg(8, std::istream::cur);
|
||||
}
|
||||
|
||||
if (sizeOverride != 0UL) {
|
||||
@@ -53,7 +46,8 @@ bool ESP::TES3SubRecord::readFrom(std::istream &stream, uint32_t sizeOverride)
|
||||
|
||||
stream.read(reinterpret_cast<char*>(&m_Data[0]), dataSize);
|
||||
if (!stream) {
|
||||
throw ESP::InvalidRecordException(std::string("sub-record incomplete: ") + typeString);
|
||||
throw ESP::InvalidRecordException(std::string("sub-record incomplete: ") +
|
||||
typeString);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
+11
-14
@@ -1,14 +1,12 @@
|
||||
#ifndef TES3_SUBRECORD_H
|
||||
#define TES3_SUBRECORD_H
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
#include <istream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace ESP {
|
||||
|
||||
namespace ESP
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief sub-record storage class without record-specific information
|
||||
@@ -16,30 +14,29 @@ namespace ESP {
|
||||
class TES3SubRecord
|
||||
{
|
||||
public:
|
||||
|
||||
enum EType {
|
||||
enum EType
|
||||
{
|
||||
TYPE_UNKNOWN,
|
||||
TYPE_HEDR,
|
||||
TYPE_MAST,
|
||||
TYPE_DATA
|
||||
TYPE_MAST,
|
||||
TYPE_DATA
|
||||
};
|
||||
|
||||
static const int NUM_TYPES = TYPE_DATA;
|
||||
|
||||
public:
|
||||
TES3SubRecord();
|
||||
TES3SubRecord();
|
||||
|
||||
bool readFrom(std::istream &stream, uint32_t sizeOverride = 0UL);
|
||||
bool readFrom(std::istream& stream, uint32_t sizeOverride = 0UL);
|
||||
|
||||
EType type() const { return m_Type; }
|
||||
const std::vector<uint8_t> &data() const { return m_Data; }
|
||||
const std::vector<uint8_t>& data() const { return m_Data; }
|
||||
|
||||
private:
|
||||
|
||||
EType m_Type;
|
||||
std::vector<uint8_t> m_Data;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace ESP
|
||||
|
||||
#endif // TES3_SUBRECORD_H
|
||||
#endif // TES3_SUBRECORD_H
|
||||
|
||||
Reference in New Issue
Block a user