feat support Public,Private,Protected
This commit is contained in:
parent
e17ae812be
commit
2e3503efb3
@ -46,9 +46,25 @@ Class::ToString() const
|
|||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "class " << BaseType::ToString() << " {\n";
|
ss << "class " << BaseType::ToString() << " {\n";
|
||||||
for (auto &field : fields_) { ss << " " << field->ToString() << ";\n"; }
|
auto builder = [this](bool filter(const BaseType &)) {
|
||||||
ss << "\n";
|
std::stringstream tmp_ss;
|
||||||
for (auto &method : methods_) { ss << " " << method->ToString() << ";\n"; }
|
for (auto &field : fields_) {
|
||||||
|
if (filter(*field)) { tmp_ss << " " << field->ToString() << ";\n"; }
|
||||||
|
}
|
||||||
|
for (auto &method : methods_) {
|
||||||
|
if (filter(*method)) { tmp_ss << " " << method->ToString() << ";\n"; }
|
||||||
|
}
|
||||||
|
return tmp_ss.str();
|
||||||
|
};
|
||||||
|
|
||||||
|
auto public_section = builder([](const BaseType &base) { return base.IsPublic(); });
|
||||||
|
auto protected_section = builder([](const BaseType &base) { return base.IsProtected(); });
|
||||||
|
auto private_section = builder([](const BaseType &base) { return base.IsPrivate(); });
|
||||||
|
|
||||||
|
if (!sled::Trim(public_section).empty()) { ss << "public:\n" << public_section; }
|
||||||
|
if (!sled::Trim(protected_section).empty()) { ss << "protected:\n" << protected_section; }
|
||||||
|
if (!sled::Trim(private_section).empty()) { ss << "private:\n" << private_section; }
|
||||||
|
|
||||||
ss << "};\n";
|
ss << "};\n";
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user