Dump structured data def structs

This commit is contained in:
Jan
2022-01-15 23:14:37 +01:00
parent 02769fe21d
commit 0aad5a42cb
5 changed files with 210 additions and 7 deletions

View File

@ -83,7 +83,7 @@ void StructuredDataDefDumper::EndEnum()
m_stream << ",\n";
Indent();
m_stream << entry;
m_stream << "\"" << entry << "\"";
}
if (!firstEntry)
@ -94,6 +94,7 @@ void StructuredDataDefDumper::EndEnum()
m_stream << "};\n";
m_block = Block::BLOCK_NONE;
m_flags.m_empty_line_before_block = true;
m_enum_entries.clear();
}
void StructuredDataDefDumper::WriteEnumEntry(const std::string& entryName, const size_t entryValue)
@ -141,3 +142,50 @@ void StructuredDataDefDumper::EndStruct()
m_block = Block::BLOCK_NONE;
m_flags.m_empty_line_before_block = true;
}
void StructuredDataDefDumper::BeginProperty(const std::string& propertyName)
{
assert(m_flags.m_in_version);
assert(m_block == Block::BLOCK_STRUCT);
if (m_block != Block::BLOCK_STRUCT)
return;
m_property_name = propertyName;
m_block = Block::BLOCK_PROPERTY;
}
void StructuredDataDefDumper::AddPropertyArraySpecifier(const std::string& specifierName)
{
m_property_array_specifiers.emplace_back(specifierName);
}
void StructuredDataDefDumper::SetPropertyTypeName(const std::string& typeName)
{
m_property_type_name = typeName;
}
void StructuredDataDefDumper::EndProperty()
{
assert(m_block == Block::BLOCK_PROPERTY);
if (m_block != Block::BLOCK_PROPERTY)
return;
Indent();
m_stream << m_property_type_name << " " << m_property_name;
for(const auto& arraySpecifierName : m_property_array_specifiers)
{
m_stream << "[" << arraySpecifierName << "]";
}
m_stream << ";\n";
m_block = Block::BLOCK_STRUCT;
m_property_array_specifiers.clear();
m_property_name = std::string();
m_property_type_name = std::string();
}

View File

@ -10,7 +10,8 @@ class StructuredDataDefDumper : AbstractTextDumper
{
BLOCK_NONE = 0,
BLOCK_ENUM = 1,
BLOCK_STRUCT = 2
BLOCK_STRUCT = 2,
BLOCK_PROPERTY = 3
} m_block;
struct
@ -23,6 +24,10 @@ class StructuredDataDefDumper : AbstractTextDumper
std::vector<std::string> m_enum_entries;
size_t m_enum_size;
std::string m_property_name;
std::string m_property_type_name;
std::vector<std::string> m_property_array_specifiers;
public:
explicit StructuredDataDefDumper(std::ostream& stream);
@ -35,4 +40,8 @@ public:
void BeginStruct(const std::string& structName);
void EndStruct();
void BeginProperty(const std::string& propertyName);
void AddPropertyArraySpecifier(const std::string& specifierName);
void SetPropertyTypeName(const std::string& typeName);
void EndProperty();
};