Skip to content

Commit

Permalink
Introduce ObjectImpl<ConfigObject>#GetParentsAffectingLogging()
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed Aug 15, 2023
1 parent 88f06b0 commit f8b6330
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions tools/mkclass/class_lexer.ll
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ deprecated { yylval->num = FADeprecated; return T_FIELD_ATTRIBUTE; }
get_virtual { yylval->num = FAGetVirtual; return T_FIELD_ATTRIBUTE; }
set_virtual { yylval->num = FASetVirtual; return T_FIELD_ATTRIBUTE; }
signal_with_old_value { yylval->num = FASignalWithOldValue; return T_FIELD_ATTRIBUTE; }
parent_affecting_logging { yylval->num = FAParentAffectingLogging; return T_FIELD_ATTRIBUTE; }
virtual { yylval->num = FAGetVirtual | FASetVirtual; return T_FIELD_ATTRIBUTE; }
navigation { return T_NAVIGATION; }
validator { return T_VALIDATOR; }
Expand Down
81 changes: 81 additions & 0 deletions tools/mkclass/classcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,87 @@ void ClassCompiler::HandleClass(const Klass& klass, const ClassDebugInfo&)
<< field.GetFriendlyName() << "ChangedWithOldValue;" << std::endl << std::endl;
}
}

/* override ConfigObject#GetParentsAffectingLogging() */

bool overrideGetParentsAffectingLogging = klass.Name == "ConfigObject";

if (!overrideGetParentsAffectingLogging) {
for (auto& field : klass.Fields) {
if (field.Attributes & FAParentAffectingLogging && (field.Type.IsName || field.Attributes & FANavigation)) {
overrideGetParentsAffectingLogging = true;
break;
}
}
}

if (overrideGetParentsAffectingLogging) {
m_Header << "protected:" << std::endl << "\t";

if (klass.Name == "ConfigObject") {
m_Header << "virtual void GetParentsAffectingLogging(std::vector<intrusive_ptr<ConfigObject>>& output) const;";
} else {
m_Header << "void GetParentsAffectingLogging(std::vector<ConfigObject::Ptr>& output) const override;";
}

m_Header << std::endl;

m_Impl << "void ObjectImpl<" << klass.Name
<< ">::GetParentsAffectingLogging(std::vector<ConfigObject::Ptr>& output) const" << std::endl
<< "{" << std::endl;

std::set<std::string> types;

for (auto& field : klass.Fields) {
if (field.Attributes & FAParentAffectingLogging && field.Type.IsName && types.emplace(field.Type.TypeName).second) {
m_Impl << "\t" << "static const auto type" << field.Type.TypeName
<< " (Type::GetByName(\"" << field.Type.TypeName << "\"));" << std::endl
<< "\t" << "static const auto configType" << field.Type.TypeName
<< " (dynamic_cast<ConfigType*>(type" << field.Type.TypeName << ".get()));" << std::endl;
}
}

if (klass.Name != "ConfigObject") {
m_Impl << std::endl << "\t" << klass.Parent << "::GetParentsAffectingLogging(output);" << std::endl;
}

for (auto& field : klass.Fields) {
if (field.Attributes & FAParentAffectingLogging && (field.Type.IsName || field.Attributes & FANavigation)) {
m_Impl << std::endl << "\t";

if (field.Type.IsName) {
if (field.Type.ArrayRank) {
m_Impl << "auto names" << field.GetFriendlyName()
<< " (Get" << field.GetFriendlyName() << "());" << std::endl << std::endl
<< "\t" << "if (names" << field.GetFriendlyName() << ") {" << std::endl
<< "\t\t" << "ObjectLock lock (names" << field.GetFriendlyName() << ");" << std::endl << std::endl
<< "\t\t" << "for (auto& name : names" << field.GetFriendlyName() << ") {" << std::endl
<< "\t\t\t" << "auto object (configType" << field.Type.TypeName << "->GetObject(name));" << std::endl << std::endl
<< "\t\t\t" << "if (object) {" << std::endl
<< "\t\t\t\t" << "output.emplace_back(std::move(object));" << std::endl
<< "\t\t\t" << "}" << std::endl
<< "\t\t" << "}";
} else {
m_Impl << "auto object" << field.GetFriendlyName()
<< " (configType" << field.Type.TypeName << "->GetObject(Get"
<< field.GetFriendlyName() << "()));" << std::endl << std::endl
<< "\t" << "if (object" << field.GetFriendlyName() << ") {" << std::endl
<< "\t\t" << "output.emplace_back(std::move(object" << field.GetFriendlyName() << "));";
}
} else {
m_Impl << "auto object" << field.GetFriendlyName()
<< " (static_pointer_cast<ConfigObject>(Navigate"
<< field.GetFriendlyName() << "()));" << std::endl << std::endl
<< "\t" << "if (object" << field.GetFriendlyName() << ") {" << std::endl
<< "\t\t" << "output.emplace_back(std::move(object" << field.GetFriendlyName() << "));";
}

m_Impl << std::endl << "\t" << "}" << std::endl;
}
}

m_Impl << "}" << std::endl << std::endl;
}
}

if (klass.Name == "ConfigObject")
Expand Down
1 change: 1 addition & 0 deletions tools/mkclass/classcompiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ enum FieldAttribute
FASetVirtual = 16384,
FAActivationPriority = 32768,
FASignalWithOldValue = 65536,
FAParentAffectingLogging = 131072,
};

struct FieldType
Expand Down

0 comments on commit f8b6330

Please sign in to comment.