Skip to content

Commit 66cbdb4

Browse files
authored
Refactor function checkElements (#2493)
* Refactor function checkElements * Refactor function checkElements
1 parent 7923a22 commit 66cbdb4

File tree

5 files changed

+148
-101
lines changed

5 files changed

+148
-101
lines changed

VideoHppGenerator.cpp

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ VideoHppGenerator::VideoHppGenerator( tinyxml2::XMLDocument const & document )
2525
// read the document and check its correctness
2626
int line = document.GetLineNum();
2727
std::vector<tinyxml2::XMLElement const *> elements = getChildElements( &document );
28-
checkElements( line, elements, { { "registry", true } } );
28+
checkElements( line, elements, { { "registry", MultipleAllowed::No } } );
2929
checkForError( elements.size() == 1, line, "encountered " + std::to_string( elements.size() ) + " elements named <registry> but only one is allowed" );
3030
readRegistry( elements[0] );
3131
addImplicitlyRequiredTypes();
@@ -35,8 +35,7 @@ VideoHppGenerator::VideoHppGenerator( tinyxml2::XMLDocument const & document )
3535

3636
void VideoHppGenerator::generateCppmFile() const
3737
{
38-
generateFileFromTemplate(
39-
"vulkan_video.cppm", "VideoCppmTemplate.hpp", { { "copyrightMessage", m_copyrightMessage }, { "includes", generateIncludes() } } );
38+
generateFileFromTemplate( "vulkan_video.cppm", "VideoCppmTemplate.hpp", { { "copyrightMessage", m_copyrightMessage }, { "includes", generateIncludes() } } );
4039
}
4140

4241
void VideoHppGenerator::generateHppFile() const
@@ -156,8 +155,8 @@ void VideoHppGenerator::checkCorrectness() const
156155

157156
void VideoHppGenerator::checkElements( int line,
158157
std::vector<tinyxml2::XMLElement const *> const & elements,
159-
std::map<std::string, bool> const & required,
160-
std::set<std::string> const & optional ) const
158+
std::map<std::string, MultipleAllowed> const & required,
159+
std::map<std::string, MultipleAllowed> const & optional ) const
161160
{
162161
::checkElements( "VideoHppGenerator", line, elements, required, optional );
163162
}
@@ -175,7 +174,7 @@ void VideoHppGenerator::checkForWarning( bool condition, int line, std::string c
175174
std::string VideoHppGenerator::generateConstants() const
176175
{
177176
{
178-
const std::string enumsTemplate = R"(
177+
std::string const enumsTemplate = R"(
179178
//=================
180179
//=== CONSTANTs ===
181180
//=================
@@ -252,7 +251,7 @@ std::string VideoHppGenerator::generateEnum( std::pair<std::string, EnumData> co
252251
enumValues = "\n" + enumValues + " ";
253252
}
254253

255-
const std::string enumTemplate = R"( enum class ${enumName}
254+
std::string const enumTemplate = R"( enum class ${enumName}
256255
{${enumValues}};
257256
)";
258257

@@ -262,7 +261,7 @@ std::string VideoHppGenerator::generateEnum( std::pair<std::string, EnumData> co
262261
std::string VideoHppGenerator::generateEnums() const
263262
{
264263
{
265-
const std::string enumsTemplate = R"(
264+
std::string const enumsTemplate = R"(
266265
//=============
267266
//=== ENUMs ===
268267
//=============
@@ -314,7 +313,7 @@ std::string VideoHppGenerator::generateIncludes() const
314313

315314
std::string VideoHppGenerator::generateStruct( std::pair<std::string, StructureData> const & structData ) const
316315
{
317-
static const std::string structureTemplate = R"( struct ${structureType}
316+
static std::string const structureTemplate = R"( struct ${structureType}
318317
{
319318
using NativeType = StdVideo${structureType};
320319
@@ -351,7 +350,7 @@ std::string VideoHppGenerator::generateStruct( std::pair<std::string, StructureD
351350

352351
std::string VideoHppGenerator::generateStructCompareOperators( std::pair<std::string, StructureData> const & structData ) const
353352
{
354-
static const std::set<std::string> simpleTypes = { "char", "double", "DWORD", "float", "HANDLE", "HINSTANCE", "HMONITOR",
353+
static std::set<std::string> const simpleTypes = { "char", "double", "DWORD", "float", "HANDLE", "HINSTANCE", "HMONITOR",
355354
"HWND", "int", "int8_t", "int16_t", "int32_t", "int64_t", "LPCWSTR",
356355
"size_t", "uint8_t", "uint16_t", "uint32_t", "uint64_t" };
357356

@@ -377,7 +376,7 @@ std::string VideoHppGenerator::generateStructCompareOperators( std::pair<std::st
377376
intro = "\n && ";
378377
}
379378

380-
static const std::string compareTemplate = R"(
379+
static std::string const compareTemplate = R"(
381380
bool operator==( ${name} const & rhs ) const VULKAN_HPP_NOEXCEPT
382381
{
383382
return ${compareMembers};
@@ -447,7 +446,7 @@ std::string VideoHppGenerator::generateStructMembers( std::pair<std::string, Str
447446

448447
std::string VideoHppGenerator::generateStructs() const
449448
{
450-
const std::string structsTemplate = R"(
449+
std::string const structsTemplate = R"(
451450
//===============
452451
//=== STRUCTS ===
453452
//===============
@@ -497,7 +496,7 @@ void VideoHppGenerator::readEnums( tinyxml2::XMLElement const * element )
497496
std::map<std::string, std::string> attributes = getAttributes( element );
498497
checkAttributes( line, attributes, { { "name", {} } }, { { "type", { "enum" } } } );
499498
std::vector<tinyxml2::XMLElement const *> children = getChildElements( element );
500-
checkElements( line, children, { { "enum", {} } }, { "comment" } );
499+
checkElements( line, children, { { "enum", MultipleAllowed::Yes } }, { { "comment", MultipleAllowed::No } } );
501500

502501
std::string name;
503502
for ( auto const & attribute : attributes )
@@ -596,7 +595,7 @@ void VideoHppGenerator::readExtension( tinyxml2::XMLElement const * element )
596595
std::vector<tinyxml2::XMLElement const *> children = getChildElements( element );
597596

598597
checkAttributes( line, attributes, { { "name", {} }, { "comment", {} }, { "number", {} }, { "supported", { "vulkan" } } }, {} );
599-
checkElements( line, children, { { "require", false } } );
598+
checkElements( line, children, { { "require", MultipleAllowed::No } } );
600599

601600
ExtensionData extensionData{ .xmlLine = line };
602601
std::string supported;
@@ -630,7 +629,7 @@ void VideoHppGenerator::readExtension( tinyxml2::XMLElement const * element )
630629

631630
for ( auto child : children )
632631
{
633-
const std::string value = child->Value();
632+
std::string const value = child->Value();
634633
assert( value == "require" );
635634
readExtensionRequire( child, extensionData );
636635
}
@@ -644,7 +643,7 @@ void VideoHppGenerator::readExtensionRequire( tinyxml2::XMLElement const * eleme
644643
std::map<std::string, std::string> attributes = getAttributes( element );
645644
checkAttributes( line, attributes, {}, {} );
646645
std::vector<tinyxml2::XMLElement const *> children = getChildElements( element );
647-
checkElements( line, children, {}, { "enum", "type" } );
646+
checkElements( line, children, { { "type", MultipleAllowed::Yes } }, { { "enum", MultipleAllowed::Yes } } );
648647

649648
extensionData.requireData.xmlLine = line;
650649

@@ -668,11 +667,11 @@ void VideoHppGenerator::readExtensions( tinyxml2::XMLElement const * element )
668667
int line = element->GetLineNum();
669668
checkAttributes( line, getAttributes( element ), {}, {} );
670669
std::vector<tinyxml2::XMLElement const *> children = getChildElements( element );
671-
checkElements( line, children, { { "extension", false } } );
670+
checkElements( line, children, { { "extension", MultipleAllowed::Yes } } );
672671

673672
for ( auto child : children )
674673
{
675-
const std::string value = child->Value();
674+
std::string const value = child->Value();
676675
assert( value == "extension" );
677676
readExtension( child );
678677
}
@@ -689,10 +688,13 @@ void VideoHppGenerator::readRegistry( tinyxml2::XMLElement const * element )
689688
checkAttributes( line, getAttributes( element ), {}, {} );
690689

691690
std::vector<tinyxml2::XMLElement const *> children = getChildElements( element );
692-
checkElements( line, children, { { "comment", false }, { "enums", false }, { "extensions", true }, { "types", true } } );
691+
checkElements(
692+
line,
693+
children,
694+
{ { "comment", MultipleAllowed::Yes }, { "enums", MultipleAllowed::Yes }, { "extensions", MultipleAllowed::No }, { "types", MultipleAllowed::No } } );
693695
for ( auto child : children )
694696
{
695-
const std::string value = child->Value();
697+
std::string const value = child->Value();
696698
if ( value == "comment" )
697699
{
698700
std::string comment = readComment( child );
@@ -722,8 +724,8 @@ void VideoHppGenerator::readRequireEnum( tinyxml2::XMLElement const * element, s
722724
{
723725
int line = element->GetLineNum();
724726
std::map<std::string, std::string> attributes = getAttributes( element );
725-
checkElements( line, getChildElements( element ), {} );
726727
checkAttributes( line, attributes, { { "name", {} }, { "value", {} } }, { { "type", { "uint32_t", "uint8_t" } } } );
728+
checkElements( line, getChildElements( element ), {} );
727729

728730
std::string name, type, value;
729731
for ( auto const & attribute : attributes )
@@ -780,7 +782,10 @@ void VideoHppGenerator::readStructMember( tinyxml2::XMLElement const * element,
780782
std::map<std::string, std::string> attributes = getAttributes( element );
781783
checkAttributes( line, attributes, {}, { { "len", {} }, { "optional", { "false", "true" } } } );
782784
std::vector<tinyxml2::XMLElement const *> children = getChildElements( element );
783-
checkElements( line, children, { { "name", true }, { "type", true } }, { "comment", "enum" } );
785+
checkElements( line,
786+
children,
787+
{ { "name", MultipleAllowed::No }, { "type", MultipleAllowed::No } },
788+
{ { "comment", MultipleAllowed::No }, { "enum", MultipleAllowed::Yes } } );
784789

785790
MemberData memberData;
786791
memberData.xmlLine = line;
@@ -803,7 +808,7 @@ void VideoHppGenerator::readStructMember( tinyxml2::XMLElement const * element,
803808
{
804809
int childLine = child->GetLineNum();
805810
checkAttributes( childLine, getAttributes( child ), {}, {} );
806-
checkElements( childLine, getChildElements( child ), {}, {} );
811+
checkElements( childLine, getChildElements( child ), {} );
807812

808813
std::string value = child->Value();
809814
if ( value == "enum" )
@@ -840,7 +845,7 @@ void VideoHppGenerator::readTypeDefine( tinyxml2::XMLElement const * element, st
840845
int line = element->GetLineNum();
841846
checkAttributes( line, attributes, { { "category", { "define" } } }, { { "requires", {} } } );
842847
std::vector<tinyxml2::XMLElement const *> children = getChildElements( element );
843-
checkElements( line, children, { { "name", false } }, { "type" } );
848+
checkElements( line, children, { { "name", MultipleAllowed::No } }, { { "type", MultipleAllowed::No } } );
844849

845850
std::string require;
846851
for ( auto const & attribute : attributes )
@@ -854,7 +859,7 @@ void VideoHppGenerator::readTypeDefine( tinyxml2::XMLElement const * element, st
854859
std::string name, type;
855860
for ( auto child : children )
856861
{
857-
const std::string value = child->Value();
862+
std::string const value = child->Value();
858863
if ( value == "name" )
859864
{
860865
name = child->GetText();
@@ -935,7 +940,7 @@ void VideoHppGenerator::readTypes( tinyxml2::XMLElement const * element )
935940
int line = element->GetLineNum();
936941
checkAttributes( line, getAttributes( element ), { { "comment", {} } }, {} );
937942
std::vector<tinyxml2::XMLElement const *> children = getChildElements( element );
938-
checkElements( line, children, { { "type", false } } );
943+
checkElements( line, children, { { "type", MultipleAllowed::Yes } } );
939944

940945
for ( auto child : children )
941946
{
@@ -952,7 +957,7 @@ void VideoHppGenerator::readTypeStruct( tinyxml2::XMLElement const * element, st
952957
int line = element->GetLineNum();
953958
checkAttributes( line, attributes, { { "category", { "struct" } }, { "name", {} } }, { { "comment", {} }, { "requires", {} } } );
954959
std::vector<tinyxml2::XMLElement const *> children = getChildElements( element );
955-
checkElements( line, children, { { "member", false } }, { "comment" } );
960+
checkElements( line, children, { { "member", MultipleAllowed::Yes } }, { { "comment", MultipleAllowed::Yes } } );
956961

957962
StructureData structureData{ .xmlLine = line };
958963

VideoHppGenerator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ class VideoHppGenerator
101101
void checkCorrectness() const;
102102
void checkElements( int line,
103103
std::vector<tinyxml2::XMLElement const *> const & elements,
104-
std::map<std::string, bool> const & required,
105-
std::set<std::string> const & optional = {} ) const;
104+
std::map<std::string, MultipleAllowed> const & required,
105+
std::map<std::string, MultipleAllowed> const & optional = {} ) const;
106106
void checkForError( bool condition, int line, std::string const & message ) const;
107107
void checkForWarning( bool condition, int line, std::string const & message ) const;
108108
std::string generateConstants() const;

0 commit comments

Comments
 (0)