Rename StructuredDataDef classes to remove "Def" from classes that do not need it

This commit is contained in:
Jan 2022-01-22 14:47:47 +01:00
parent 2da6ab8479
commit 497c9fc6cf
28 changed files with 450 additions and 450 deletions

View File

@ -22,38 +22,38 @@ bool AssetLoaderStructuredDataDefSet::CanLoadFromRaw() const
return true; return true;
} }
StructuredDataType AssetLoaderStructuredDataDefSet::ConvertType(CommonStructuredDataDefType inputType) StructuredDataType AssetLoaderStructuredDataDefSet::ConvertType(CommonStructuredDataType inputType)
{ {
switch (inputType.m_category) switch (inputType.m_category)
{ {
case CommonStructuredDataDefTypeCategory::INT: case CommonStructuredDataTypeCategory::INT:
return {DATA_INT, {0}}; return {DATA_INT, {0}};
case CommonStructuredDataDefTypeCategory::BYTE: case CommonStructuredDataTypeCategory::BYTE:
return {DATA_BYTE, {0}}; return {DATA_BYTE, {0}};
case CommonStructuredDataDefTypeCategory::BOOL: case CommonStructuredDataTypeCategory::BOOL:
return {DATA_BOOL, {0}}; return {DATA_BOOL, {0}};
case CommonStructuredDataDefTypeCategory::FLOAT: case CommonStructuredDataTypeCategory::FLOAT:
return {DATA_FLOAT, {0}}; return {DATA_FLOAT, {0}};
case CommonStructuredDataDefTypeCategory::SHORT: case CommonStructuredDataTypeCategory::SHORT:
return {DATA_SHORT, {0}}; return {DATA_SHORT, {0}};
case CommonStructuredDataDefTypeCategory::STRING: case CommonStructuredDataTypeCategory::STRING:
return {DATA_STRING, {inputType.m_info.string_length}}; return {DATA_STRING, {inputType.m_info.string_length}};
case CommonStructuredDataDefTypeCategory::ENUM: case CommonStructuredDataTypeCategory::ENUM:
return {DATA_ENUM, {inputType.m_info.type_index}}; return {DATA_ENUM, {inputType.m_info.type_index}};
case CommonStructuredDataDefTypeCategory::STRUCT: case CommonStructuredDataTypeCategory::STRUCT:
return {DATA_STRUCT, {inputType.m_info.type_index}}; return {DATA_STRUCT, {inputType.m_info.type_index}};
case CommonStructuredDataDefTypeCategory::INDEXED_ARRAY: case CommonStructuredDataTypeCategory::INDEXED_ARRAY:
return {DATA_INDEXED_ARRAY, {inputType.m_info.type_index}}; return {DATA_INDEXED_ARRAY, {inputType.m_info.type_index}};
case CommonStructuredDataDefTypeCategory::ENUM_ARRAY: case CommonStructuredDataTypeCategory::ENUM_ARRAY:
return {DATA_ENUM_ARRAY, {inputType.m_info.type_index}}; return {DATA_ENUM_ARRAY, {inputType.m_info.type_index}};
case CommonStructuredDataDefTypeCategory::UNKNOWN: case CommonStructuredDataTypeCategory::UNKNOWN:
default: default:
assert(false); assert(false);
return {DATA_INT, {0}}; return {DATA_INT, {0}};
} }
} }
void AssetLoaderStructuredDataDefSet::ConvertEnum(StructuredDataEnum* outputEnum, const CommonStructuredDataDefEnum* inputEnum, MemoryManager* memory) void AssetLoaderStructuredDataDefSet::ConvertEnum(StructuredDataEnum* outputEnum, const CommonStructuredDataEnum* inputEnum, MemoryManager* memory)
{ {
outputEnum->entryCount = static_cast<int>(inputEnum->m_entries.size()); outputEnum->entryCount = static_cast<int>(inputEnum->m_entries.size());
if (inputEnum->m_reserved_entry_count <= 0) if (inputEnum->m_reserved_entry_count <= 0)
@ -78,7 +78,7 @@ void AssetLoaderStructuredDataDefSet::ConvertEnum(StructuredDataEnum* outputEnum
outputEnum->entries = nullptr; outputEnum->entries = nullptr;
} }
void AssetLoaderStructuredDataDefSet::ConvertStruct(StructuredDataStruct* outputStruct, const CommonStructuredDataDefStruct* inputStruct, MemoryManager* memory) void AssetLoaderStructuredDataDefSet::ConvertStruct(StructuredDataStruct* outputStruct, const CommonStructuredDataStruct* inputStruct, MemoryManager* memory)
{ {
outputStruct->size = static_cast<int>(inputStruct->m_size_in_byte); outputStruct->size = static_cast<int>(inputStruct->m_size_in_byte);
outputStruct->bitOffset = inputStruct->m_bit_offset; outputStruct->bitOffset = inputStruct->m_bit_offset;
@ -108,14 +108,14 @@ void AssetLoaderStructuredDataDefSet::ConvertStruct(StructuredDataStruct* output
outputStruct->properties = nullptr; outputStruct->properties = nullptr;
} }
void AssetLoaderStructuredDataDefSet::ConvertIndexedArray(StructuredDataIndexedArray* outputIndexedArray, const CommonStructuredDataDefIndexedArray* inputIndexedArray, MemoryManager* memory) void AssetLoaderStructuredDataDefSet::ConvertIndexedArray(StructuredDataIndexedArray* outputIndexedArray, const CommonStructuredDataIndexedArray* inputIndexedArray, MemoryManager* memory)
{ {
outputIndexedArray->arraySize = static_cast<int>(inputIndexedArray->m_element_count); outputIndexedArray->arraySize = static_cast<int>(inputIndexedArray->m_element_count);
outputIndexedArray->elementType = ConvertType(inputIndexedArray->m_array_type); outputIndexedArray->elementType = ConvertType(inputIndexedArray->m_array_type);
outputIndexedArray->elementSize = inputIndexedArray->m_element_size_in_bits; outputIndexedArray->elementSize = inputIndexedArray->m_element_size_in_bits;
} }
void AssetLoaderStructuredDataDefSet::ConvertEnumedArray(StructuredDataEnumedArray* outputEnumedArray, const CommonStructuredDataDefEnumedArray* inputEnumedArray, MemoryManager* memory) void AssetLoaderStructuredDataDefSet::ConvertEnumedArray(StructuredDataEnumedArray* outputEnumedArray, const CommonStructuredDataEnumedArray* inputEnumedArray, MemoryManager* memory)
{ {
outputEnumedArray->enumIndex = static_cast<int>(inputEnumedArray->m_enum_index); outputEnumedArray->enumIndex = static_cast<int>(inputEnumedArray->m_enum_index);
outputEnumedArray->elementType = ConvertType(inputEnumedArray->m_array_type); outputEnumedArray->elementType = ConvertType(inputEnumedArray->m_array_type);

View File

@ -12,11 +12,11 @@ namespace IW4
public: public:
_NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override; _NODISCARD void* CreateEmptyAsset(const std::string& assetName, MemoryManager* memory) override;
_NODISCARD bool CanLoadFromRaw() const override; _NODISCARD bool CanLoadFromRaw() const override;
static StructuredDataType ConvertType(CommonStructuredDataDefType inputType); static StructuredDataType ConvertType(CommonStructuredDataType inputType);
static void ConvertEnum(StructuredDataEnum* outputEnum, const CommonStructuredDataDefEnum* inputEnum, MemoryManager* memory); static void ConvertEnum(StructuredDataEnum* outputEnum, const CommonStructuredDataEnum* inputEnum, MemoryManager* memory);
static void ConvertStruct(StructuredDataStruct* outputStruct, const CommonStructuredDataDefStruct* inputStruct, MemoryManager* memory); static void ConvertStruct(StructuredDataStruct* outputStruct, const CommonStructuredDataStruct* inputStruct, MemoryManager* memory);
static void ConvertIndexedArray(StructuredDataIndexedArray* outputIndexedArray, const CommonStructuredDataDefIndexedArray* inputIndexedArray, MemoryManager* memory); static void ConvertIndexedArray(StructuredDataIndexedArray* outputIndexedArray, const CommonStructuredDataIndexedArray* inputIndexedArray, MemoryManager* memory);
static void ConvertEnumedArray(StructuredDataEnumedArray* outputEnumedArray, const CommonStructuredDataDefEnumedArray* inputEnumedArray, MemoryManager* memory); static void ConvertEnumedArray(StructuredDataEnumedArray* outputEnumedArray, const CommonStructuredDataEnumedArray* inputEnumedArray, MemoryManager* memory);
static void ConvertDef(StructuredDataDef* outputDef, const CommonStructuredDataDef* inputDef, MemoryManager* memory); static void ConvertDef(StructuredDataDef* outputDef, const CommonStructuredDataDef* inputDef, MemoryManager* memory);
static StructuredDataDefSet* ConvertSet(const std::string& assetName, const std::vector<std::unique_ptr<CommonStructuredDataDef>>& defs, MemoryManager* memory); static StructuredDataDefSet* ConvertSet(const std::string& assetName, const std::vector<std::unique_ptr<CommonStructuredDataDef>>& defs, MemoryManager* memory);
bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override; bool LoadFromRaw(const std::string& assetName, ISearchPath* searchPath, MemoryManager* memory, IAssetLoadingManager* manager, Zone* zone) const override;

View File

@ -3,20 +3,20 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "CommonStructuredDataDefEnum.h" #include "CommonStructuredDataEnum.h"
#include "CommonStructuredDataDefStruct.h" #include "CommonStructuredDataStruct.h"
class CommonStructuredDataDef class CommonStructuredDataDef
{ {
public: public:
std::vector<std::unique_ptr<CommonStructuredDataDefEnum>> m_enums; std::vector<std::unique_ptr<CommonStructuredDataEnum>> m_enums;
std::vector< std::unique_ptr<CommonStructuredDataDefStruct>> m_structs; std::vector<std::unique_ptr<CommonStructuredDataStruct>> m_structs;
std::vector<CommonStructuredDataDefIndexedArray> m_indexed_arrays; std::vector<CommonStructuredDataIndexedArray> m_indexed_arrays;
std::vector<CommonStructuredDataDefEnumedArray> m_enumed_arrays; std::vector<CommonStructuredDataEnumedArray> m_enumed_arrays;
int m_version; int m_version;
size_t m_checksum; size_t m_checksum;
CommonStructuredDataDefType m_root_type; CommonStructuredDataType m_root_type;
size_t m_size_in_byte; size_t m_size_in_byte;
CommonStructuredDataDef(); CommonStructuredDataDef();

View File

@ -1,34 +0,0 @@
#include "CommonStructuredDataDefEnum.h"
CommonStructuredDataDefEnumEntry::CommonStructuredDataDefEnumEntry()
: m_value(0u)
{
}
CommonStructuredDataDefEnumEntry::CommonStructuredDataDefEnumEntry(std::string name, const size_t value)
: m_name(std::move(name)),
m_value(value)
{
}
CommonStructuredDataDefEnum::CommonStructuredDataDefEnum()
: m_reserved_entry_count(-1)
{
}
CommonStructuredDataDefEnum::CommonStructuredDataDefEnum(std::string name)
: m_name(std::move(name)),
m_reserved_entry_count(-1)
{
}
CommonStructuredDataDefEnum::CommonStructuredDataDefEnum(std::string name, const int reservedEntryCount)
: m_name(std::move(name)),
m_reserved_entry_count(reservedEntryCount)
{
}
size_t CommonStructuredDataDefEnum::ElementCount() const
{
return m_reserved_entry_count > 0 ? static_cast<size_t>(m_reserved_entry_count) : m_entries.size();
}

View File

@ -1,28 +0,0 @@
#pragma once
#include <string>
#include <vector>
#include "Utils/ClassUtils.h"
struct CommonStructuredDataDefEnumEntry
{
std::string m_name;
size_t m_value;
CommonStructuredDataDefEnumEntry();
CommonStructuredDataDefEnumEntry(std::string name, size_t value);
};
struct CommonStructuredDataDefEnum
{
std::string m_name;
int m_reserved_entry_count;
std::vector<CommonStructuredDataDefEnumEntry> m_entries;
CommonStructuredDataDefEnum();
explicit CommonStructuredDataDefEnum(std::string name);
CommonStructuredDataDefEnum(std::string name, int reservedEntryCount);
_NODISCARD size_t ElementCount() const;
};

View File

@ -1,32 +0,0 @@
#include "CommonStructuredDataDefStruct.h"
CommonStructuredDataDefStructEntry::CommonStructuredDataDefStructEntry()
: m_offset_in_bits(0u)
{
}
CommonStructuredDataDefStructEntry::CommonStructuredDataDefStructEntry(std::string name)
: m_name(std::move(name)),
m_offset_in_bits(0u)
{
}
CommonStructuredDataDefStructEntry::CommonStructuredDataDefStructEntry(std::string name, const CommonStructuredDataDefType type, const size_t offsetInBits)
: m_name(std::move(name)),
m_type(type),
m_offset_in_bits(offsetInBits)
{
}
CommonStructuredDataDefStruct::CommonStructuredDataDefStruct()
: m_bit_offset(0u),
m_size_in_byte(0u)
{
}
CommonStructuredDataDefStruct::CommonStructuredDataDefStruct(std::string name)
: m_name(std::move(name)),
m_bit_offset(0u),
m_size_in_byte(0u)
{
}

View File

@ -1,28 +0,0 @@
#pragma once
#include <string>
#include <vector>
#include "CommonStructuredDataDefTypes.h"
struct CommonStructuredDataDefStructEntry
{
std::string m_name;
CommonStructuredDataDefType m_type;
size_t m_offset_in_bits;
CommonStructuredDataDefStructEntry();
explicit CommonStructuredDataDefStructEntry(std::string name);
CommonStructuredDataDefStructEntry(std::string name, CommonStructuredDataDefType type, size_t offsetInBits);
};
struct CommonStructuredDataDefStruct
{
std::string m_name;
std::vector<CommonStructuredDataDefStructEntry> m_properties;
size_t m_bit_offset;
size_t m_size_in_byte;
CommonStructuredDataDefStruct();
explicit CommonStructuredDataDefStruct(std::string name);
};

View File

@ -1,126 +0,0 @@
#include "CommonStructuredDataDefTypes.h"
CommonStructuredDataDefType::CommonStructuredDataDefType()
: m_category(CommonStructuredDataDefTypeCategory::UNKNOWN),
m_info({0})
{
}
CommonStructuredDataDefType::CommonStructuredDataDefType(const CommonStructuredDataDefTypeCategory category)
: m_category(category),
m_info({0})
{
}
CommonStructuredDataDefType::CommonStructuredDataDefType(const CommonStructuredDataDefTypeCategory category, const size_t extraInfo)
: m_category(category),
m_info({extraInfo})
{
}
bool operator<(const CommonStructuredDataDefType& lhs, const CommonStructuredDataDefType& rhs)
{
if (lhs.m_category < rhs.m_category)
return true;
if (rhs.m_category < lhs.m_category)
return false;
return lhs.m_info.type_index < rhs.m_info.type_index;
}
bool operator<=(const CommonStructuredDataDefType& lhs, const CommonStructuredDataDefType& rhs)
{
return !(rhs < lhs);
}
bool operator>(const CommonStructuredDataDefType& lhs, const CommonStructuredDataDefType& rhs)
{
return rhs < lhs;
}
bool operator>=(const CommonStructuredDataDefType& lhs, const CommonStructuredDataDefType& rhs)
{
return !(lhs < rhs);
}
CommonStructuredDataDefIndexedArray::CommonStructuredDataDefIndexedArray()
: CommonStructuredDataDefIndexedArray({}, 0u)
{
}
CommonStructuredDataDefIndexedArray::CommonStructuredDataDefIndexedArray(const CommonStructuredDataDefType type, const size_t elementCount)
: CommonStructuredDataDefIndexedArray(type, elementCount, 0u)
{
}
CommonStructuredDataDefIndexedArray::CommonStructuredDataDefIndexedArray(const CommonStructuredDataDefType type, const size_t elementCount, const size_t elementSize)
: m_array_type(type),
m_element_count(elementCount),
m_element_size_in_bits(elementSize)
{
}
bool operator<(const CommonStructuredDataDefIndexedArray& lhs, const CommonStructuredDataDefIndexedArray& rhs)
{
if (lhs.m_array_type < rhs.m_array_type)
return true;
if (rhs.m_array_type < lhs.m_array_type)
return false;
return lhs.m_element_count < rhs.m_element_count;
}
bool operator<=(const CommonStructuredDataDefIndexedArray& lhs, const CommonStructuredDataDefIndexedArray& rhs)
{
return !(rhs < lhs);
}
bool operator>(const CommonStructuredDataDefIndexedArray& lhs, const CommonStructuredDataDefIndexedArray& rhs)
{
return rhs < lhs;
}
bool operator>=(const CommonStructuredDataDefIndexedArray& lhs, const CommonStructuredDataDefIndexedArray& rhs)
{
return !(lhs < rhs);
}
CommonStructuredDataDefEnumedArray::CommonStructuredDataDefEnumedArray()
: CommonStructuredDataDefEnumedArray({}, 0u)
{
}
CommonStructuredDataDefEnumedArray::CommonStructuredDataDefEnumedArray(const CommonStructuredDataDefType type, const size_t enumIndex)
: CommonStructuredDataDefEnumedArray(type, enumIndex, 0u, 0u)
{
}
CommonStructuredDataDefEnumedArray::CommonStructuredDataDefEnumedArray(const CommonStructuredDataDefType type, const size_t enumIndex, const size_t elementCount, const size_t elementSizeInBits)
: m_array_type(type),
m_enum_index(enumIndex),
m_element_count(elementCount),
m_element_size_in_bits(elementSizeInBits)
{
}
bool operator<(const CommonStructuredDataDefEnumedArray& lhs, const CommonStructuredDataDefEnumedArray& rhs)
{
if (lhs.m_array_type < rhs.m_array_type)
return true;
if (rhs.m_array_type < lhs.m_array_type)
return false;
return lhs.m_enum_index < rhs.m_enum_index;
}
bool operator<=(const CommonStructuredDataDefEnumedArray& lhs, const CommonStructuredDataDefEnumedArray& rhs)
{
return !(rhs < lhs);
}
bool operator>(const CommonStructuredDataDefEnumedArray& lhs, const CommonStructuredDataDefEnumedArray& rhs)
{
return rhs < lhs;
}
bool operator>=(const CommonStructuredDataDefEnumedArray& lhs, const CommonStructuredDataDefEnumedArray& rhs)
{
return !(lhs < rhs);
}

View File

@ -1,72 +0,0 @@
#pragma once
#include <cstddef>
enum class CommonStructuredDataDefTypeCategory
{
UNKNOWN,
INT,
BYTE,
BOOL,
FLOAT,
SHORT,
STRING,
ENUM,
STRUCT,
INDEXED_ARRAY,
ENUM_ARRAY
};
union CommonStructuredDataDefTypeExtraInfo
{
size_t string_length;
size_t type_index;
};
struct CommonStructuredDataDefType
{
CommonStructuredDataDefTypeCategory m_category;
CommonStructuredDataDefTypeExtraInfo m_info;
CommonStructuredDataDefType();
explicit CommonStructuredDataDefType(CommonStructuredDataDefTypeCategory category);
CommonStructuredDataDefType(CommonStructuredDataDefTypeCategory category, size_t extraInfo);
friend bool operator<(const CommonStructuredDataDefType& lhs, const CommonStructuredDataDefType& rhs);
friend bool operator<=(const CommonStructuredDataDefType& lhs, const CommonStructuredDataDefType& rhs);
friend bool operator>(const CommonStructuredDataDefType& lhs, const CommonStructuredDataDefType& rhs);
friend bool operator>=(const CommonStructuredDataDefType& lhs, const CommonStructuredDataDefType& rhs);
};
struct CommonStructuredDataDefIndexedArray
{
CommonStructuredDataDefType m_array_type;
size_t m_element_count;
size_t m_element_size_in_bits;
CommonStructuredDataDefIndexedArray();
CommonStructuredDataDefIndexedArray(CommonStructuredDataDefType type, size_t elementCount);
CommonStructuredDataDefIndexedArray(CommonStructuredDataDefType type, size_t elementCount, size_t elementSize);
friend bool operator<(const CommonStructuredDataDefIndexedArray& lhs, const CommonStructuredDataDefIndexedArray& rhs);
friend bool operator<=(const CommonStructuredDataDefIndexedArray& lhs, const CommonStructuredDataDefIndexedArray& rhs);
friend bool operator>(const CommonStructuredDataDefIndexedArray& lhs, const CommonStructuredDataDefIndexedArray& rhs);
friend bool operator>=(const CommonStructuredDataDefIndexedArray& lhs, const CommonStructuredDataDefIndexedArray& rhs);
};
struct CommonStructuredDataDefEnumedArray
{
CommonStructuredDataDefType m_array_type;
size_t m_enum_index;
size_t m_element_count;
size_t m_element_size_in_bits;
CommonStructuredDataDefEnumedArray();
CommonStructuredDataDefEnumedArray(CommonStructuredDataDefType type, size_t enumIndex);
CommonStructuredDataDefEnumedArray(CommonStructuredDataDefType type, size_t enumIndex, size_t elementCount, size_t elementSizeInBits);
friend bool operator<(const CommonStructuredDataDefEnumedArray& lhs, const CommonStructuredDataDefEnumedArray& rhs);
friend bool operator<=(const CommonStructuredDataDefEnumedArray& lhs, const CommonStructuredDataDefEnumedArray& rhs);
friend bool operator>(const CommonStructuredDataDefEnumedArray& lhs, const CommonStructuredDataDefEnumedArray& rhs);
friend bool operator>=(const CommonStructuredDataDefEnumedArray& lhs, const CommonStructuredDataDefEnumedArray& rhs);
};

View File

@ -0,0 +1,34 @@
#include "CommonStructuredDataEnum.h"
CommonStructuredDataEnumEntry::CommonStructuredDataEnumEntry()
: m_value(0u)
{
}
CommonStructuredDataEnumEntry::CommonStructuredDataEnumEntry(std::string name, const size_t value)
: m_name(std::move(name)),
m_value(value)
{
}
CommonStructuredDataEnum::CommonStructuredDataEnum()
: m_reserved_entry_count(-1)
{
}
CommonStructuredDataEnum::CommonStructuredDataEnum(std::string name)
: m_name(std::move(name)),
m_reserved_entry_count(-1)
{
}
CommonStructuredDataEnum::CommonStructuredDataEnum(std::string name, const int reservedEntryCount)
: m_name(std::move(name)),
m_reserved_entry_count(reservedEntryCount)
{
}
size_t CommonStructuredDataEnum::ElementCount() const
{
return m_reserved_entry_count > 0 ? static_cast<size_t>(m_reserved_entry_count) : m_entries.size();
}

View File

@ -0,0 +1,28 @@
#pragma once
#include <string>
#include <vector>
#include "Utils/ClassUtils.h"
struct CommonStructuredDataEnumEntry
{
std::string m_name;
size_t m_value;
CommonStructuredDataEnumEntry();
CommonStructuredDataEnumEntry(std::string name, size_t value);
};
struct CommonStructuredDataEnum
{
std::string m_name;
int m_reserved_entry_count;
std::vector<CommonStructuredDataEnumEntry> m_entries;
CommonStructuredDataEnum();
explicit CommonStructuredDataEnum(std::string name);
CommonStructuredDataEnum(std::string name, int reservedEntryCount);
_NODISCARD size_t ElementCount() const;
};

View File

@ -0,0 +1,32 @@
#include "CommonStructuredDataStruct.h"
CommonStructuredDataStructEntry::CommonStructuredDataStructEntry()
: m_offset_in_bits(0u)
{
}
CommonStructuredDataStructEntry::CommonStructuredDataStructEntry(std::string name)
: m_name(std::move(name)),
m_offset_in_bits(0u)
{
}
CommonStructuredDataStructEntry::CommonStructuredDataStructEntry(std::string name, const CommonStructuredDataType type, const size_t offsetInBits)
: m_name(std::move(name)),
m_type(type),
m_offset_in_bits(offsetInBits)
{
}
CommonStructuredDataStruct::CommonStructuredDataStruct()
: m_bit_offset(0u),
m_size_in_byte(0u)
{
}
CommonStructuredDataStruct::CommonStructuredDataStruct(std::string name)
: m_name(std::move(name)),
m_bit_offset(0u),
m_size_in_byte(0u)
{
}

View File

@ -0,0 +1,28 @@
#pragma once
#include <string>
#include <vector>
#include "CommonStructuredDataTypes.h"
struct CommonStructuredDataStructEntry
{
std::string m_name;
CommonStructuredDataType m_type;
size_t m_offset_in_bits;
CommonStructuredDataStructEntry();
explicit CommonStructuredDataStructEntry(std::string name);
CommonStructuredDataStructEntry(std::string name, CommonStructuredDataType type, size_t offsetInBits);
};
struct CommonStructuredDataStruct
{
std::string m_name;
std::vector<CommonStructuredDataStructEntry> m_properties;
size_t m_bit_offset;
size_t m_size_in_byte;
CommonStructuredDataStruct();
explicit CommonStructuredDataStruct(std::string name);
};

View File

@ -0,0 +1,126 @@
#include "CommonStructuredDataTypes.h"
CommonStructuredDataType::CommonStructuredDataType()
: m_category(CommonStructuredDataTypeCategory::UNKNOWN),
m_info({0})
{
}
CommonStructuredDataType::CommonStructuredDataType(const CommonStructuredDataTypeCategory category)
: m_category(category),
m_info({0})
{
}
CommonStructuredDataType::CommonStructuredDataType(const CommonStructuredDataTypeCategory category, const size_t extraInfo)
: m_category(category),
m_info({extraInfo})
{
}
bool operator<(const CommonStructuredDataType& lhs, const CommonStructuredDataType& rhs)
{
if (lhs.m_category < rhs.m_category)
return true;
if (rhs.m_category < lhs.m_category)
return false;
return lhs.m_info.type_index < rhs.m_info.type_index;
}
bool operator<=(const CommonStructuredDataType& lhs, const CommonStructuredDataType& rhs)
{
return !(rhs < lhs);
}
bool operator>(const CommonStructuredDataType& lhs, const CommonStructuredDataType& rhs)
{
return rhs < lhs;
}
bool operator>=(const CommonStructuredDataType& lhs, const CommonStructuredDataType& rhs)
{
return !(lhs < rhs);
}
CommonStructuredDataIndexedArray::CommonStructuredDataIndexedArray()
: CommonStructuredDataIndexedArray({}, 0u)
{
}
CommonStructuredDataIndexedArray::CommonStructuredDataIndexedArray(const CommonStructuredDataType type, const size_t elementCount)
: CommonStructuredDataIndexedArray(type, elementCount, 0u)
{
}
CommonStructuredDataIndexedArray::CommonStructuredDataIndexedArray(const CommonStructuredDataType type, const size_t elementCount, const size_t elementSize)
: m_array_type(type),
m_element_count(elementCount),
m_element_size_in_bits(elementSize)
{
}
bool operator<(const CommonStructuredDataIndexedArray& lhs, const CommonStructuredDataIndexedArray& rhs)
{
if (lhs.m_array_type < rhs.m_array_type)
return true;
if (rhs.m_array_type < lhs.m_array_type)
return false;
return lhs.m_element_count < rhs.m_element_count;
}
bool operator<=(const CommonStructuredDataIndexedArray& lhs, const CommonStructuredDataIndexedArray& rhs)
{
return !(rhs < lhs);
}
bool operator>(const CommonStructuredDataIndexedArray& lhs, const CommonStructuredDataIndexedArray& rhs)
{
return rhs < lhs;
}
bool operator>=(const CommonStructuredDataIndexedArray& lhs, const CommonStructuredDataIndexedArray& rhs)
{
return !(lhs < rhs);
}
CommonStructuredDataEnumedArray::CommonStructuredDataEnumedArray()
: CommonStructuredDataEnumedArray({}, 0u)
{
}
CommonStructuredDataEnumedArray::CommonStructuredDataEnumedArray(const CommonStructuredDataType type, const size_t enumIndex)
: CommonStructuredDataEnumedArray(type, enumIndex, 0u, 0u)
{
}
CommonStructuredDataEnumedArray::CommonStructuredDataEnumedArray(const CommonStructuredDataType type, const size_t enumIndex, const size_t elementCount, const size_t elementSizeInBits)
: m_array_type(type),
m_enum_index(enumIndex),
m_element_count(elementCount),
m_element_size_in_bits(elementSizeInBits)
{
}
bool operator<(const CommonStructuredDataEnumedArray& lhs, const CommonStructuredDataEnumedArray& rhs)
{
if (lhs.m_array_type < rhs.m_array_type)
return true;
if (rhs.m_array_type < lhs.m_array_type)
return false;
return lhs.m_enum_index < rhs.m_enum_index;
}
bool operator<=(const CommonStructuredDataEnumedArray& lhs, const CommonStructuredDataEnumedArray& rhs)
{
return !(rhs < lhs);
}
bool operator>(const CommonStructuredDataEnumedArray& lhs, const CommonStructuredDataEnumedArray& rhs)
{
return rhs < lhs;
}
bool operator>=(const CommonStructuredDataEnumedArray& lhs, const CommonStructuredDataEnumedArray& rhs)
{
return !(lhs < rhs);
}

View File

@ -0,0 +1,72 @@
#pragma once
#include <cstddef>
enum class CommonStructuredDataTypeCategory
{
UNKNOWN,
INT,
BYTE,
BOOL,
FLOAT,
SHORT,
STRING,
ENUM,
STRUCT,
INDEXED_ARRAY,
ENUM_ARRAY
};
union CommonStructuredDataTypeExtraInfo
{
size_t string_length;
size_t type_index;
};
struct CommonStructuredDataType
{
CommonStructuredDataTypeCategory m_category;
CommonStructuredDataTypeExtraInfo m_info;
CommonStructuredDataType();
explicit CommonStructuredDataType(CommonStructuredDataTypeCategory category);
CommonStructuredDataType(CommonStructuredDataTypeCategory category, size_t extraInfo);
friend bool operator<(const CommonStructuredDataType& lhs, const CommonStructuredDataType& rhs);
friend bool operator<=(const CommonStructuredDataType& lhs, const CommonStructuredDataType& rhs);
friend bool operator>(const CommonStructuredDataType& lhs, const CommonStructuredDataType& rhs);
friend bool operator>=(const CommonStructuredDataType& lhs, const CommonStructuredDataType& rhs);
};
struct CommonStructuredDataIndexedArray
{
CommonStructuredDataType m_array_type;
size_t m_element_count;
size_t m_element_size_in_bits;
CommonStructuredDataIndexedArray();
CommonStructuredDataIndexedArray(CommonStructuredDataType type, size_t elementCount);
CommonStructuredDataIndexedArray(CommonStructuredDataType type, size_t elementCount, size_t elementSize);
friend bool operator<(const CommonStructuredDataIndexedArray& lhs, const CommonStructuredDataIndexedArray& rhs);
friend bool operator<=(const CommonStructuredDataIndexedArray& lhs, const CommonStructuredDataIndexedArray& rhs);
friend bool operator>(const CommonStructuredDataIndexedArray& lhs, const CommonStructuredDataIndexedArray& rhs);
friend bool operator>=(const CommonStructuredDataIndexedArray& lhs, const CommonStructuredDataIndexedArray& rhs);
};
struct CommonStructuredDataEnumedArray
{
CommonStructuredDataType m_array_type;
size_t m_enum_index;
size_t m_element_count;
size_t m_element_size_in_bits;
CommonStructuredDataEnumedArray();
CommonStructuredDataEnumedArray(CommonStructuredDataType type, size_t enumIndex);
CommonStructuredDataEnumedArray(CommonStructuredDataType type, size_t enumIndex, size_t elementCount, size_t elementSizeInBits);
friend bool operator<(const CommonStructuredDataEnumedArray& lhs, const CommonStructuredDataEnumedArray& rhs);
friend bool operator<=(const CommonStructuredDataEnumedArray& lhs, const CommonStructuredDataEnumedArray& rhs);
friend bool operator>(const CommonStructuredDataEnumedArray& lhs, const CommonStructuredDataEnumedArray& rhs);
friend bool operator>=(const CommonStructuredDataEnumedArray& lhs, const CommonStructuredDataEnumedArray& rhs);
};

View File

@ -1,15 +0,0 @@
#pragma once
#include "Parsing/Sequence/AbstractScopeSequenceHolder.h"
#include "Parsing/StructuredDataDef/StructuredDataDefParser.h"
namespace sdd
{
class StructuredDataDefEnumScopeSequences final : AbstractScopeSequenceHolder<StructuredDataDefParser>
{
public:
StructuredDataDefEnumScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences, std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences);
void AddSequences() const;
};
}

View File

@ -1,15 +0,0 @@
#pragma once
#include "Parsing/Sequence/AbstractScopeSequenceHolder.h"
#include "Parsing/StructuredDataDef/StructuredDataDefParser.h"
namespace sdd
{
class StructuredDataDefNoScopeSequences final : AbstractScopeSequenceHolder<StructuredDataDefParser>
{
public:
StructuredDataDefNoScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences, std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences);
void AddSequences() const;
};
}

View File

@ -1,4 +1,4 @@
#include "StructuredDataDefDefScopeSequences.h" #include "StructuredDataDefScopeSequences.h"
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h" #include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
@ -31,7 +31,7 @@ namespace sdd::def_scope_sequences
{ {
assert(state->m_current_def); assert(state->m_current_def);
auto newEnum = std::make_unique<CommonStructuredDataDefEnum>(result.NextCapture(CAPTURE_NAME).IdentifierValue()); auto newEnum = std::make_unique<CommonStructuredDataEnum>(result.NextCapture(CAPTURE_NAME).IdentifierValue());
if (result.HasNextCapture(CAPTURE_RESERVED_COUNT)) if (result.HasNextCapture(CAPTURE_RESERVED_COUNT))
{ {
const auto& reservedCountToken = result.NextCapture(CAPTURE_RESERVED_COUNT); const auto& reservedCountToken = result.NextCapture(CAPTURE_RESERVED_COUNT);
@ -42,7 +42,7 @@ namespace sdd::def_scope_sequences
} }
state->m_current_enum = newEnum.get(); state->m_current_enum = newEnum.get();
state->m_def_types_by_name.emplace(newEnum->m_name, CommonStructuredDataDefType(CommonStructuredDataDefTypeCategory::ENUM, state->m_current_def->m_enums.size())); state->m_def_types_by_name.emplace(newEnum->m_name, CommonStructuredDataType(CommonStructuredDataTypeCategory::ENUM, state->m_current_def->m_enums.size()));
state->m_current_def->m_enums.emplace_back(std::move(newEnum)); state->m_current_def->m_enums.emplace_back(std::move(newEnum));
} }
}; };
@ -68,19 +68,19 @@ namespace sdd::def_scope_sequences
{ {
assert(state->m_current_def); assert(state->m_current_def);
auto newStruct = std::make_unique<CommonStructuredDataDefStruct>(result.NextCapture(CAPTURE_NAME).IdentifierValue()); auto newStruct = std::make_unique<CommonStructuredDataStruct>(result.NextCapture(CAPTURE_NAME).IdentifierValue());
auto* newStructPtr = newStruct.get(); auto* newStructPtr = newStruct.get();
const auto newStructIndex = state->m_current_def->m_structs.size(); const auto newStructIndex = state->m_current_def->m_structs.size();
state->m_current_struct = newStructPtr; state->m_current_struct = newStructPtr;
state->m_def_types_by_name.emplace(newStruct->m_name, CommonStructuredDataDefType(CommonStructuredDataDefTypeCategory::STRUCT, newStructIndex)); state->m_def_types_by_name.emplace(newStruct->m_name, CommonStructuredDataType(CommonStructuredDataTypeCategory::STRUCT, newStructIndex));
state->m_current_def->m_structs.emplace_back(std::move(newStruct)); state->m_current_def->m_structs.emplace_back(std::move(newStruct));
state->m_current_struct_offset_in_bits = 0; state->m_current_struct_offset_in_bits = 0;
if(newStructPtr->m_name == "root") if (newStructPtr->m_name == "root")
{ {
state->m_current_struct_offset_in_bits = 64u; state->m_current_struct_offset_in_bits = 64u;
state->m_current_def->m_root_type = CommonStructuredDataDefType(CommonStructuredDataDefTypeCategory::STRUCT, newStructIndex); state->m_current_def->m_root_type = CommonStructuredDataType(CommonStructuredDataTypeCategory::STRUCT, newStructIndex);
} }
else else
state->m_current_struct_offset_in_bits = 0; state->m_current_struct_offset_in_bits = 0;
@ -106,14 +106,14 @@ namespace sdd::def_scope_sequences
{ {
if (state->m_current_def->m_structs.empty()) if (state->m_current_def->m_structs.empty())
{ {
state->m_current_def->m_structs.emplace_back(std::make_unique<CommonStructuredDataDefStruct>()); state->m_current_def->m_structs.emplace_back(std::make_unique<CommonStructuredDataStruct>());
state->m_current_def->m_root_type = CommonStructuredDataDefType(CommonStructuredDataDefTypeCategory::STRUCT, 0u); state->m_current_def->m_root_type = CommonStructuredDataType(CommonStructuredDataTypeCategory::STRUCT, 0u);
} }
} }
static void SetDefSizeFromRootStruct(const StructuredDataDefParserState* state) static void SetDefSizeFromRootStruct(const StructuredDataDefParserState* state)
{ {
if (state->m_current_def->m_root_type.m_category == CommonStructuredDataDefTypeCategory::STRUCT if (state->m_current_def->m_root_type.m_category == CommonStructuredDataTypeCategory::STRUCT
&& state->m_current_def->m_root_type.m_info.type_index < state->m_current_def->m_structs.size()) && state->m_current_def->m_root_type.m_info.type_index < state->m_current_def->m_structs.size())
{ {
const auto* _struct = state->m_current_def->m_structs[state->m_current_def->m_root_type.m_info.type_index].get(); const auto* _struct = state->m_current_def->m_structs[state->m_current_def->m_root_type.m_info.type_index].get();
@ -141,13 +141,13 @@ namespace sdd::def_scope_sequences
using namespace sdd; using namespace sdd;
using namespace def_scope_sequences; using namespace def_scope_sequences;
StructuredDataDefDefScopeSequences::StructuredDataDefDefScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences, StructuredDataDefScopeSequences::StructuredDataDefScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences,
std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences) std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences)
: AbstractScopeSequenceHolder(allSequences, scopeSequences) : AbstractScopeSequenceHolder(allSequences, scopeSequences)
{ {
} }
void StructuredDataDefDefScopeSequences::AddSequences() const void StructuredDataDefScopeSequences::AddSequences() const
{ {
AddSequence(std::make_unique<SequenceCloseScope>()); AddSequence(std::make_unique<SequenceCloseScope>());
AddSequence(std::make_unique<SequenceEnum>()); AddSequence(std::make_unique<SequenceEnum>());

View File

@ -0,0 +1,15 @@
#pragma once
#include "Parsing/Sequence/AbstractScopeSequenceHolder.h"
#include "Parsing/StructuredDataDef/StructuredDataDefParser.h"
namespace sdd
{
class StructuredDataDefScopeSequences final : AbstractScopeSequenceHolder<StructuredDataDefParser>
{
public:
StructuredDataDefScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences, std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences);
void AddSequences() const;
};
}

View File

@ -1,15 +0,0 @@
#pragma once
#include "Parsing/Sequence/AbstractScopeSequenceHolder.h"
#include "Parsing/StructuredDataDef/StructuredDataDefParser.h"
namespace sdd
{
class StructuredDataDefStructScopeSequences final : AbstractScopeSequenceHolder<StructuredDataDefParser>
{
public:
StructuredDataDefStructScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences, std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences);
void AddSequences() const;
};
}

View File

@ -1,4 +1,4 @@
#include "StructuredDataDefEnumScopeSequences.h" #include "StructuredDataEnumScopeSequences.h"
#include <algorithm> #include <algorithm>
@ -55,7 +55,7 @@ namespace sdd::enum_scope_sequences
{ {
assert(state->m_current_enum != nullptr); assert(state->m_current_enum != nullptr);
std::sort(state->m_current_enum->m_entries.begin(), state->m_current_enum->m_entries.end(), [](const CommonStructuredDataDefEnumEntry& e1, const CommonStructuredDataDefEnumEntry& e2) std::sort(state->m_current_enum->m_entries.begin(), state->m_current_enum->m_entries.end(), [](const CommonStructuredDataEnumEntry& e1, const CommonStructuredDataEnumEntry& e2)
{ {
return e1.m_name < e2.m_name; return e1.m_name < e2.m_name;
}); });
@ -68,13 +68,13 @@ namespace sdd::enum_scope_sequences
using namespace sdd; using namespace sdd;
using namespace enum_scope_sequences; using namespace enum_scope_sequences;
StructuredDataDefEnumScopeSequences::StructuredDataDefEnumScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences, StructuredDataEnumScopeSequences::StructuredDataEnumScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences,
std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences) std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences)
: AbstractScopeSequenceHolder(allSequences, scopeSequences) : AbstractScopeSequenceHolder(allSequences, scopeSequences)
{ {
} }
void StructuredDataDefEnumScopeSequences::AddSequences() const void StructuredDataEnumScopeSequences::AddSequences() const
{ {
AddSequence(std::make_unique<SequenceCloseEnum>()); AddSequence(std::make_unique<SequenceCloseEnum>());
AddSequence(std::make_unique<SequenceEnumEntry>()); AddSequence(std::make_unique<SequenceEnumEntry>());

View File

@ -0,0 +1,15 @@
#pragma once
#include "Parsing/Sequence/AbstractScopeSequenceHolder.h"
#include "Parsing/StructuredDataDef/StructuredDataDefParser.h"
namespace sdd
{
class StructuredDataEnumScopeSequences final : AbstractScopeSequenceHolder<StructuredDataDefParser>
{
public:
StructuredDataEnumScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences, std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences);
void AddSequences() const;
};
}

View File

@ -1,4 +1,4 @@
#include "StructuredDataDefNoScopeSequences.h" #include "StructuredDataNoScopeSequences.h"
#include "Parsing/Simple/Matcher/SimpleMatcherFactory.h" #include "Parsing/Simple/Matcher/SimpleMatcherFactory.h"
@ -33,13 +33,13 @@ namespace sdd::no_scope_sequences
using namespace sdd; using namespace sdd;
using namespace no_scope_sequences; using namespace no_scope_sequences;
StructuredDataDefNoScopeSequences::StructuredDataDefNoScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences, StructuredDataNoScopeSequences::StructuredDataNoScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences,
std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences) std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences)
: AbstractScopeSequenceHolder(allSequences, scopeSequences) : AbstractScopeSequenceHolder(allSequences, scopeSequences)
{ {
} }
void StructuredDataDefNoScopeSequences::AddSequences() const void StructuredDataNoScopeSequences::AddSequences() const
{ {
AddSequence(std::make_unique<SequenceVersion>()); AddSequence(std::make_unique<SequenceVersion>());
} }

View File

@ -0,0 +1,15 @@
#pragma once
#include "Parsing/Sequence/AbstractScopeSequenceHolder.h"
#include "Parsing/StructuredDataDef/StructuredDataDefParser.h"
namespace sdd
{
class StructuredDataNoScopeSequences final : AbstractScopeSequenceHolder<StructuredDataDefParser>
{
public:
StructuredDataNoScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences, std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences);
void AddSequences() const;
};
}

View File

@ -1,4 +1,4 @@
#include "StructuredDataDefStructScopeSequences.h" #include "StructuredDataStructScopeSequences.h"
#include <algorithm> #include <algorithm>
@ -65,7 +65,7 @@ namespace sdd::struct_scope_sequences
} }
private: private:
static CommonStructuredDataDefType ProcessType(StructuredDataDefParserState* state, SequenceResult<SimpleParserValue>& result, size_t& currentSize, size_t& currentBitAlign) static CommonStructuredDataType ProcessType(StructuredDataDefParserState* state, SequenceResult<SimpleParserValue>& result, size_t& currentSize, size_t& currentBitAlign)
{ {
const auto typeTag = result.NextTag(); const auto typeTag = result.NextTag();
@ -74,23 +74,23 @@ namespace sdd::struct_scope_sequences
case TAG_TYPE_INT: case TAG_TYPE_INT:
currentSize = 32; currentSize = 32;
currentBitAlign = 8; currentBitAlign = 8;
return CommonStructuredDataDefType(CommonStructuredDataDefTypeCategory::INT); return CommonStructuredDataType(CommonStructuredDataTypeCategory::INT);
case TAG_TYPE_BYTE: case TAG_TYPE_BYTE:
currentSize = 8; currentSize = 8;
currentBitAlign = 8; currentBitAlign = 8;
return CommonStructuredDataDefType(CommonStructuredDataDefTypeCategory::BYTE); return CommonStructuredDataType(CommonStructuredDataTypeCategory::BYTE);
case TAG_TYPE_BOOL: case TAG_TYPE_BOOL:
currentSize = 1; currentSize = 1;
currentBitAlign = 0; currentBitAlign = 0;
return CommonStructuredDataDefType(CommonStructuredDataDefTypeCategory::BOOL); return CommonStructuredDataType(CommonStructuredDataTypeCategory::BOOL);
case TAG_TYPE_FLOAT: case TAG_TYPE_FLOAT:
currentSize = 32; currentSize = 32;
currentBitAlign = 8; currentBitAlign = 8;
return CommonStructuredDataDefType(CommonStructuredDataDefTypeCategory::FLOAT); return CommonStructuredDataType(CommonStructuredDataTypeCategory::FLOAT);
case TAG_TYPE_SHORT: case TAG_TYPE_SHORT:
currentSize = 16; currentSize = 16;
currentBitAlign = 8; currentBitAlign = 8;
return CommonStructuredDataDefType(CommonStructuredDataDefTypeCategory::SHORT); return CommonStructuredDataType(CommonStructuredDataTypeCategory::SHORT);
case TAG_TYPE_STRING: case TAG_TYPE_STRING:
{ {
currentBitAlign = 8; currentBitAlign = 8;
@ -101,7 +101,7 @@ namespace sdd::struct_scope_sequences
throw ParsingException(stringLengthToken.GetPos(), "String length must be greater than zero"); throw ParsingException(stringLengthToken.GetPos(), "String length must be greater than zero");
currentSize = stringLength * 8; currentSize = stringLength * 8;
return {CommonStructuredDataDefTypeCategory::STRING, static_cast<size_t>(stringLength)}; return {CommonStructuredDataTypeCategory::STRING, static_cast<size_t>(stringLength)};
} }
case TAG_TYPE_NAMED: case TAG_TYPE_NAMED:
{ {
@ -113,13 +113,13 @@ namespace sdd::struct_scope_sequences
if (existingType == state->m_def_types_by_name.end()) if (existingType == state->m_def_types_by_name.end())
throw ParsingException(typeNameToken.GetPos(), "No type defined under this name"); throw ParsingException(typeNameToken.GetPos(), "No type defined under this name");
if (existingType->second.m_category == CommonStructuredDataDefTypeCategory::STRUCT) if (existingType->second.m_category == CommonStructuredDataTypeCategory::STRUCT)
{ {
assert(existingType->second.m_info.type_index < state->m_current_def->m_structs.size()); assert(existingType->second.m_info.type_index < state->m_current_def->m_structs.size());
const auto* _struct = state->m_current_def->m_structs[existingType->second.m_info.type_index].get(); const auto* _struct = state->m_current_def->m_structs[existingType->second.m_info.type_index].get();
currentSize = _struct->m_size_in_byte * 8; currentSize = _struct->m_size_in_byte * 8;
} }
else if (existingType->second.m_category == CommonStructuredDataDefTypeCategory::ENUM) else if (existingType->second.m_category == CommonStructuredDataTypeCategory::ENUM)
{ {
assert(existingType->second.m_info.type_index < state->m_current_def->m_enums.size()); assert(existingType->second.m_info.type_index < state->m_current_def->m_enums.size());
currentSize = 16; currentSize = 16;
@ -137,8 +137,8 @@ namespace sdd::struct_scope_sequences
} }
} }
static CommonStructuredDataDefType ProcessArray(StructuredDataDefParserState* state, const SimpleParserValue& arrayToken, const CommonStructuredDataDefType currentType, static CommonStructuredDataType ProcessArray(StructuredDataDefParserState* state, const SimpleParserValue& arrayToken, const CommonStructuredDataType currentType,
size_t& currentSize, size_t& currentBitAlign) size_t& currentSize, size_t& currentBitAlign)
{ {
currentBitAlign = 8; currentBitAlign = 8;
@ -151,15 +151,15 @@ namespace sdd::struct_scope_sequences
currentSize *= arrayElementCount; currentSize *= arrayElementCount;
const CommonStructuredDataDefIndexedArray indexedArray(currentType, arrayElementCount); const CommonStructuredDataIndexedArray indexedArray(currentType, arrayElementCount);
const auto existingIndexedArray = state->m_def_indexed_arrays.find(indexedArray); const auto existingIndexedArray = state->m_def_indexed_arrays.find(indexedArray);
if (existingIndexedArray != state->m_def_indexed_arrays.end()) if (existingIndexedArray != state->m_def_indexed_arrays.end())
return {CommonStructuredDataDefTypeCategory::INDEXED_ARRAY, existingIndexedArray->second}; return {CommonStructuredDataTypeCategory::INDEXED_ARRAY, existingIndexedArray->second};
const auto newIndexedArrayIndex = state->m_current_def->m_indexed_arrays.size(); const auto newIndexedArrayIndex = state->m_current_def->m_indexed_arrays.size();
state->m_current_def->m_indexed_arrays.push_back(indexedArray); state->m_current_def->m_indexed_arrays.push_back(indexedArray);
return {CommonStructuredDataDefTypeCategory::INDEXED_ARRAY, newIndexedArrayIndex}; return {CommonStructuredDataTypeCategory::INDEXED_ARRAY, newIndexedArrayIndex};
} }
if (arrayToken.m_type == SimpleParserValueType::IDENTIFIER) if (arrayToken.m_type == SimpleParserValueType::IDENTIFIER)
@ -169,7 +169,7 @@ namespace sdd::struct_scope_sequences
const auto existingType = state->m_def_types_by_name.find(enumName); const auto existingType = state->m_def_types_by_name.find(enumName);
if (existingType == state->m_def_types_by_name.end()) if (existingType == state->m_def_types_by_name.end())
throw ParsingException(arrayToken.GetPos(), "No type defined under this name"); throw ParsingException(arrayToken.GetPos(), "No type defined under this name");
if (existingType->second.m_category != CommonStructuredDataDefTypeCategory::ENUM) if (existingType->second.m_category != CommonStructuredDataTypeCategory::ENUM)
throw ParsingException(arrayToken.GetPos(), "Type for enumed array must be an enum"); throw ParsingException(arrayToken.GetPos(), "Type for enumed array must be an enum");
assert(existingType->second.m_info.type_index < state->m_current_def->m_enums.size()); assert(existingType->second.m_info.type_index < state->m_current_def->m_enums.size());
@ -179,15 +179,15 @@ namespace sdd::struct_scope_sequences
assert(enumElementCount > 0); assert(enumElementCount > 0);
currentSize *= enumElementCount; currentSize *= enumElementCount;
const CommonStructuredDataDefEnumedArray enumedArray(currentType, existingType->second.m_info.type_index); const CommonStructuredDataEnumedArray enumedArray(currentType, existingType->second.m_info.type_index);
const auto existingEnumedArray = state->m_def_enumed_arrays.find(enumedArray); const auto existingEnumedArray = state->m_def_enumed_arrays.find(enumedArray);
if (existingEnumedArray != state->m_def_enumed_arrays.end()) if (existingEnumedArray != state->m_def_enumed_arrays.end())
return {CommonStructuredDataDefTypeCategory::ENUM_ARRAY, existingEnumedArray->second}; return {CommonStructuredDataTypeCategory::ENUM_ARRAY, existingEnumedArray->second};
const auto newEnumedArrayIndex = state->m_current_def->m_enumed_arrays.size(); const auto newEnumedArrayIndex = state->m_current_def->m_enumed_arrays.size();
state->m_current_def->m_enumed_arrays.push_back(enumedArray); state->m_current_def->m_enumed_arrays.push_back(enumedArray);
return {CommonStructuredDataDefTypeCategory::ENUM_ARRAY, newEnumedArrayIndex}; return {CommonStructuredDataTypeCategory::ENUM_ARRAY, newEnumedArrayIndex};
} }
throw ParsingException(arrayToken.GetPos(), "Invalid Token for Array @ ProcessArray!!!"); throw ParsingException(arrayToken.GetPos(), "Invalid Token for Array @ ProcessArray!!!");
@ -207,7 +207,7 @@ namespace sdd::struct_scope_sequences
while (result.HasNextCapture(CAPTURE_ARRAY_SIZE)) while (result.HasNextCapture(CAPTURE_ARRAY_SIZE))
arrayTokens.emplace_back(result.NextCapture(CAPTURE_ARRAY_SIZE)); arrayTokens.emplace_back(result.NextCapture(CAPTURE_ARRAY_SIZE));
for(auto i = arrayTokens.rbegin(); i != arrayTokens.rend(); ++i) for (auto i = arrayTokens.rbegin(); i != arrayTokens.rend(); ++i)
currentType = ProcessArray(state, i->get(), currentType, currentSize, currentAlign); currentType = ProcessArray(state, i->get(), currentType, currentSize, currentAlign);
if (currentAlign > 0) if (currentAlign > 0)
@ -246,7 +246,7 @@ namespace sdd::struct_scope_sequences
// Sort the entries of the struct alphabetically // Sort the entries of the struct alphabetically
std::sort(state->m_current_struct->m_properties.begin(), state->m_current_struct->m_properties.end(), std::sort(state->m_current_struct->m_properties.begin(), state->m_current_struct->m_properties.end(),
[](const CommonStructuredDataDefStructEntry& e1, const CommonStructuredDataDefStructEntry& e2) [](const CommonStructuredDataStructEntry& e1, const CommonStructuredDataStructEntry& e2)
{ {
return e1.m_name < e2.m_name; return e1.m_name < e2.m_name;
}); });
@ -258,13 +258,13 @@ namespace sdd::struct_scope_sequences
using namespace sdd; using namespace sdd;
using namespace struct_scope_sequences; using namespace struct_scope_sequences;
StructuredDataDefStructScopeSequences::StructuredDataDefStructScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences, StructuredDataStructScopeSequences::StructuredDataStructScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences,
std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences) std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences)
: AbstractScopeSequenceHolder(allSequences, scopeSequences) : AbstractScopeSequenceHolder(allSequences, scopeSequences)
{ {
} }
void StructuredDataDefStructScopeSequences::AddSequences() const void StructuredDataStructScopeSequences::AddSequences() const
{ {
AddSequence(std::make_unique<SequenceCloseStruct>()); AddSequence(std::make_unique<SequenceCloseStruct>());
AddSequence(std::make_unique<SequenceStructEntry>()); AddSequence(std::make_unique<SequenceStructEntry>());

View File

@ -5,10 +5,10 @@
namespace sdd namespace sdd
{ {
class StructuredDataDefDefScopeSequences final : AbstractScopeSequenceHolder<StructuredDataDefParser> class StructuredDataStructScopeSequences final : AbstractScopeSequenceHolder<StructuredDataDefParser>
{ {
public: public:
StructuredDataDefDefScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences, std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences); StructuredDataStructScopeSequences(std::vector<std::unique_ptr<StructuredDataDefParser::sequence_t>>& allSequences, std::vector<StructuredDataDefParser::sequence_t*>& scopeSequences);
void AddSequences() const; void AddSequences() const;
}; };

View File

@ -1,9 +1,9 @@
#include "StructuredDataDefParser.h" #include "StructuredDataDefParser.h"
#include "Sequence/StructuredDataDefDefScopeSequences.h" #include "Sequence/StructuredDataDefScopeSequences.h"
#include "Sequence/StructuredDataDefEnumScopeSequences.h" #include "Sequence/StructuredDataEnumScopeSequences.h"
#include "Sequence/StructuredDataDefNoScopeSequences.h" #include "Sequence/StructuredDataNoScopeSequences.h"
#include "Sequence/StructuredDataDefStructScopeSequences.h" #include "Sequence/StructuredDataStructScopeSequences.h"
using namespace sdd; using namespace sdd;
@ -21,16 +21,16 @@ void StructuredDataDefParser::CreateSequenceCollections()
m_enum_tests.clear(); m_enum_tests.clear();
m_struct_tests.clear(); m_struct_tests.clear();
const StructuredDataDefNoScopeSequences noScopeSequences(m_all_tests, m_no_scope_tests); const StructuredDataNoScopeSequences noScopeSequences(m_all_tests, m_no_scope_tests);
noScopeSequences.AddSequences(); noScopeSequences.AddSequences();
const StructuredDataDefDefScopeSequences defScopeSequences(m_all_tests, m_def_tests); const StructuredDataDefScopeSequences defScopeSequences(m_all_tests, m_def_tests);
defScopeSequences.AddSequences(); defScopeSequences.AddSequences();
const StructuredDataDefEnumScopeSequences enumScopeSequences(m_all_tests, m_enum_tests); const StructuredDataEnumScopeSequences enumScopeSequences(m_all_tests, m_enum_tests);
enumScopeSequences.AddSequences(); enumScopeSequences.AddSequences();
const StructuredDataDefStructScopeSequences structScopeSequences(m_all_tests, m_struct_tests); const StructuredDataStructScopeSequences structScopeSequences(m_all_tests, m_struct_tests);
structScopeSequences.AddSequences(); structScopeSequences.AddSequences();
} }

View File

@ -15,13 +15,13 @@ namespace sdd
std::vector<std::unique_ptr<CommonStructuredDataDef>> m_defs; std::vector<std::unique_ptr<CommonStructuredDataDef>> m_defs;
CommonStructuredDataDef* m_current_def; CommonStructuredDataDef* m_current_def;
CommonStructuredDataDefEnum* m_current_enum; CommonStructuredDataEnum* m_current_enum;
CommonStructuredDataDefStruct* m_current_struct; CommonStructuredDataStruct* m_current_struct;
size_t m_current_struct_offset_in_bits; size_t m_current_struct_offset_in_bits;
std::map<std::string, CommonStructuredDataDefType> m_def_types_by_name; std::map<std::string, CommonStructuredDataType> m_def_types_by_name;
std::map<CommonStructuredDataDefIndexedArray, size_t> m_def_indexed_arrays; std::map<CommonStructuredDataIndexedArray, size_t> m_def_indexed_arrays;
std::map<CommonStructuredDataDefEnumedArray, size_t> m_def_enumed_arrays; std::map<CommonStructuredDataEnumedArray, size_t> m_def_enumed_arrays;
StructuredDataDefParserState(); StructuredDataDefParserState();
}; };