cxx: Use set for forward classes

This avoids duplication. Not very important as there are FWD_GUARD
macros anyway.
This commit is contained in:
Jean-Philippe Andre 2017-11-22 20:46:26 +09:00
parent 4fdc5fd0b2
commit 03af836332
2 changed files with 10 additions and 6 deletions

View File

@ -74,7 +74,7 @@ generate(const Eolian_Class* klass, eolian_cxx::options_type const& opts,
efl::eolian::grammar::attributes::klass_def klass_def(klass, opts.unit);
std::vector<efl::eolian::grammar::attributes::klass_def> klasses{klass_def};
std::vector<efl::eolian::grammar::attributes::klass_def> forward_klasses{};
std::set<efl::eolian::grammar::attributes::klass_def> forward_klasses{};
std::set<std::string> c_headers;
std::set<std::string> cpp_headers;
@ -90,8 +90,7 @@ generate(const Eolian_Class* klass, eolian_cxx::options_type const& opts,
c_headers.insert(eolian_class_file_get(klass2) + std::string(".h"));
cpp_headers.insert(eolian_class_file_get(klass2) + std::string(".hh"));
efl::eolian::grammar::attributes::klass_def cls{klass2, opts.unit};
if(std::find(forward_klasses.begin(), forward_klasses.end(), cls) == forward_klasses.end())
forward_klasses.push_back(cls);
forward_klasses.insert(cls);
};
auto complex_function
= [&] (efl::eolian::grammar::attributes::complex_type_def const& complex)
@ -123,8 +122,7 @@ generate(const Eolian_Class* klass, eolian_cxx::options_type const& opts,
c_headers.insert(eolian_class_file_get(inherit) + std::string(".h"));
cpp_headers.insert(eolian_class_file_get(inherit) + std::string(".hh"));
efl::eolian::grammar::attributes::klass_def klass3{inherit, opts.unit};
if(std::find(forward_klasses.begin(), forward_klasses.end(), klass3) == forward_klasses.end())
forward_klasses.push_back(klass3);
forward_klasses.insert(klass3);
klass_function(inherit);
}
@ -157,7 +155,7 @@ generate(const Eolian_Class* klass, eolian_cxx::options_type const& opts,
std::tuple<std::string, std::set<std::string>&, std::set<std::string>&
, std::string const&
, std::vector<efl::eolian::grammar::attributes::klass_def>&
, std::vector<efl::eolian::grammar::attributes::klass_def>&
, std::set<efl::eolian::grammar::attributes::klass_def> const&
, std::vector<efl::eolian::grammar::attributes::klass_def>&
, std::vector<efl::eolian::grammar::attributes::klass_def>&
> attributes

View File

@ -719,6 +719,12 @@ struct klass_def
{
return !(lhs == rhs);
}
friend inline bool operator<(klass_def const& lhs, klass_def const& rhs)
{
return lhs.eolian_name < rhs.eolian_name
|| lhs.cxx_name < rhs.cxx_name
|| lhs.namespaces < rhs.namespaces;
}
klass_def(std::string eolian_name, std::string cxx_name, std::string filename
, std::vector<std::string> namespaces