Kaydet (Commit) 87bd462e authored tarafından Arkadiy Illarionov's avatar Arkadiy Illarionov Kaydeden (comit) Noel Grandin

Simplify containers iterations in unodevtools, unoidl

Use range-based loop or replace with STL functions.

Change-Id: I3089a4d4a94eea849cad442b04906908908e4c27
Reviewed-on: https://gerrit.libreoffice.org/61854
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst ccb2a1f6
......@@ -57,13 +57,11 @@ static void generateIncludes(std::ostream & o,
o << "#include \"cppuhelper/propertysetmixin.hxx\"\n";
}
std::set< OUString >::const_iterator iter = interfaces.begin();
while (iter != interfaces.end())
for (const auto& rIface : interfaces)
{
o << "#include \""
<< (*iter).replace('.', '/')
<< rIface.replace('.', '/')
<< ".hpp\"\n";
++iter;
}
}
......@@ -153,13 +151,11 @@ static void generateCompHelperDefinition(std::ostream & o,
"_getSupportedServiceNames()\n{\n css::uno::Sequence< "
"::rtl::OUString > s(" << services.size() << ");\n";
std::set< OUString >::const_iterator iter = services.begin();
short i=0;
while (iter != services.end())
for (const auto& rService : services)
{
o << " s[" << i++ << "] = ::rtl::OUString(\""
<< *iter << "\");\n";
++iter;
<< rService << "\");\n";
}
o << " return s;\n}\n\n";
......@@ -424,20 +420,17 @@ void generateXDispatch(std::ostream& o,
"css::uno::Sequence< css::beans::PropertyValue >& aArguments ) throw"
"(css::uno::RuntimeException)\n{\n";
ProtocolCmdMap::const_iterator iter = protocolCmdMap.begin();
while (iter != protocolCmdMap.end()) {
o << " if ( aURL.Protocol.equalsAscii(\"" << (*iter).first
for (const auto& rEntry : protocolCmdMap) {
o << " if ( aURL.Protocol.equalsAscii(\"" << rEntry.first
<< "\") == 0 )\n {\n";
for (std::vector< OString >::const_iterator i = (*iter).second.begin();
i != (*iter).second.end(); ++i) {
o << " if ( aURL.Path.equalsAscii(\"" << (*i) << "\") )\n"
for (const auto& rCmd : rEntry.second) {
o << " if ( aURL.Path.equalsAscii(\"" << rCmd << "\") )\n"
" {\n // add your own code here\n"
" return;\n }\n";
}
o << " }\n";
++iter;
}
o << "}\n\n";
......@@ -469,19 +462,16 @@ void generateXDispatchProvider(std::ostream& o,
"css::frame::XDispatch > xRet;\n"
" if ( !m_xFrame.is() )\n return 0;\n\n";
ProtocolCmdMap::const_iterator iter = protocolCmdMap.begin();
while (iter != protocolCmdMap.end()) {
o << " if ( aURL.Protocol.equalsAscii(\"" << (*iter).first
for (const auto& rEntry : protocolCmdMap) {
o << " if ( aURL.Protocol.equalsAscii(\"" << rEntry.first
<< "\") == 0 )\n {\n";
for (std::vector< OString >::const_iterator i = (*iter).second.begin();
i != (*iter).second.end(); ++i) {
o << " if ( aURL.Path.equalsAscii(\"" << (*i) << "\") == 0 )\n"
for (const auto& rCmd : rEntry.second) {
o << " if ( aURL.Path.equalsAscii(\"" << rCmd << "\") == 0 )\n"
" xRet = this;\n";
}
o << " }\n";
++iter;
}
o << " return xRet;\n}\n\n";
......@@ -580,16 +570,15 @@ static void generateMemberInitialization(std::ostream& o,
AttributeInfo const & members)
{
if (!members.empty()) {
for (AttributeInfo::const_iterator i(members.begin());
i != members.end(); ++i)
for (const auto& rMember : members)
{
sal_Int32 rank;
if ((manager->decompose(i->type, true, nullptr, &rank, nullptr, nullptr)
if ((manager->decompose(rMember.type, true, nullptr, &rank, nullptr, nullptr)
<= codemaker::UnoType::Sort::Char)
&& rank == 0)
{
o << ",\n m_" << i->name << "(";
printType(o, options, manager, i->type, 16, true);
o << ",\n m_" << rMember.name << "(";
printType(o, options, manager, rMember.type, 16, true);
o << ")";
}
}
......@@ -601,12 +590,11 @@ static void generateMemberDeclaration(std::ostream& o,
rtl::Reference< TypeManager > const & manager,
AttributeInfo const & members)
{
for (AttributeInfo::const_iterator i(members.begin());
i != members.end(); ++i)
for (const auto& rMember : members)
{
o << " ";
printType(o, options, manager, i->type, 1);
o << " m_" << i->name << ";\n";
printType(o, options, manager, rMember.type, 1);
o << " m_" << rMember.name << ";\n";
}
}
......@@ -693,13 +681,11 @@ static OString generateClassDefinition(std::ostream& o,
<< parent << "::release(); }\n\n";
}
std::set< OUString >::const_iterator it = interfaces.begin();
codemaker::GeneratedTypeSet generated;
while (it != interfaces.end())
for (const auto& rIface : interfaces)
{
printMethods(o, options, manager, *it, generated, "", "", " ",
printMethods(o, options, manager, rIface, generated, "", "", " ",
true, propertyhelper);
++it;
}
o << "private:\n " << classname << "(const " << classname << " &); // not defined\n"
......@@ -877,17 +863,15 @@ static void generateMethodBodies(std::ostream& o,
OUString const & propertyhelper)
{
OString name(classname.concat("::"));
std::set< OUString >::const_iterator iter = interfaces.begin();
codemaker::GeneratedTypeSet generated;
while (iter != interfaces.end()) {
if ( *iter == "com.sun.star.lang.XServiceInfo" ) {
for (const auto& rIface : interfaces) {
if ( rIface == "com.sun.star.lang.XServiceInfo" ) {
generateXServiceInfoBodies(o, name, comphelpernamespace);
generated.add(u2b(*iter));
generated.add(u2b(rIface));
} else {
printMethods(o, options, manager, *iter, generated, "_",
printMethods(o, options, manager, rIface, generated, "_",
name, "", true, propertyhelper);
}
++iter;
}
}
......@@ -957,10 +941,8 @@ void generateSkeleton(ProgramOptions const & options,
bool serviceobject = false;
bool supportxcomponent = false;
std::vector< OString >::const_iterator iter = types.begin();
while (iter != types.end()) {
checkType(manager, b2u(*iter), interfaces, services, properties);
++iter;
for (const auto& rType : types) {
checkType(manager, b2u(rType), interfaces, services, properties);
}
if (options.componenttype == 3) {
......@@ -1090,10 +1072,8 @@ void generateCalcAddin(ProgramOptions const & options,
bool supportxcomponent = false;
std::vector< OString >::const_iterator iter = types.begin();
while (iter != types.end()) {
checkType(manager, b2u(*iter), interfaces, services, properties);
++iter;
for (const auto& rType : types) {
checkType(manager, b2u(rType), interfaces, services, properties);
}
OUString sAddinService;
......
......@@ -256,18 +256,17 @@ static void registerProperties(std::ostream& o,
if (!properties.empty()) {
bool cast = false;
OStringBuffer attributeValue;
for (AttributeInfo::const_iterator i(properties.begin());
i != properties.end(); ++i)
for (const auto& rProp : properties)
{
if (i->attributes != 0) {
cast = checkAttribute(attributeValue, i->attributes);
if (rProp.attributes != 0) {
cast = checkAttribute(attributeValue, rProp.attributes);
} else {
cast = true;
attributeValue.append('0');
}
o << indentation << "registerProperty(\"" << i->name
<< "\", \"m_" << i->name << "\",\n"
o << indentation << "registerProperty(\"" << rProp.name
<< "\", \"m_" << rProp.name << "\",\n"
<< indentation << " ";
if (cast)
o << "(short)";
......@@ -425,20 +424,17 @@ static void generateXDispatchBodies(std::ostream& o, ProgramOptions const & opti
" public void dispatch( com.sun.star.util.URL aURL,\n"
" com.sun.star.beans.PropertyValue[] aArguments )\n {\n";
ProtocolCmdMap::const_iterator iter = options.protocolCmdMap.begin();
while (iter != options.protocolCmdMap.end()) {
o << " if ( aURL.Protocol.equals(\"" << (*iter).first
for (const auto& rEntry : options.protocolCmdMap) {
o << " if ( aURL.Protocol.equals(\"" << rEntry.first
<< "\") )\n {\n";
for (std::vector< OString >::const_iterator i = (*iter).second.begin();
i != (*iter).second.end(); ++i) {
o << " if ( aURL.Path.equals(\"" << (*i) << "\") )\n"
for (const auto& rCmd : rEntry.second) {
o << " if ( aURL.Path.equals(\"" << rCmd << "\") )\n"
" {\n // add your own code here\n"
" return;\n }\n";
}
o << " }\n";
++iter;
}
o << " }\n\n";
......@@ -462,19 +458,16 @@ static void generateXDispatchProviderBodies(std::ostream& o, ProgramOptions cons
" String sTargetFrameName,\n"
" int iSearchFlags )\n {\n";
ProtocolCmdMap::const_iterator iter = options.protocolCmdMap.begin();
while (iter != options.protocolCmdMap.end()) {
o << " if ( aURL.Protocol.equals(\"" << (*iter).first
for (const auto& rEntry : options.protocolCmdMap) {
o << " if ( aURL.Protocol.equals(\"" << rEntry.first
<< "\") )\n {\n";
for (std::vector< OString >::const_iterator i = (*iter).second.begin();
i != (*iter).second.end(); ++i) {
o << " if ( aURL.Path.equals(\"" << (*i) << "\") )\n"
for (const auto& rCmd : rEntry.second) {
o << " if ( aURL.Path.equals(\"" << rCmd << "\") )\n"
" return this;\n";
}
o << " }\n";
++iter;
}
o << " return null;\n }\n\n";
......@@ -498,11 +491,9 @@ static void generateMethodBodies(std::ostream& o,
const std::set< OUString >& interfaces,
const OString& indentation, bool usepropertymixin)
{
std::set< OUString >::const_iterator iter = interfaces.begin();
codemaker::GeneratedTypeSet generated;
while (iter != interfaces.end()) {
OUString type(*iter);
++iter;
for (const auto& rIface : interfaces) {
OUString type(rIface);
if (type == "com.sun.star.lang.XServiceInfo") {
generateXServiceInfoBodies(o);
generated.add(u2b(type));
......@@ -760,26 +751,20 @@ static void generateClassDefinition(std::ostream& o,
// attribute/property members
if (!properties.empty()) {
AttributeInfo::const_iterator iter =
properties.begin();
o << " // properties\n";
while (iter != properties.end()) {
for (const auto& rProp : properties) {
o << " protected ";
printType(o, options, manager, iter->type, false);
o << " m_" << iter->name << ";\n";
++iter;
printType(o, options, manager, rProp.type, false);
o << " m_" << rProp.name << ";\n";
}
} else if (!attributes.empty()) {
AttributeInfo::const_iterator iter =
attributes.begin();
o << " // attributes\n";
while (iter != attributes.end()) {
for (const auto& rAttr : attributes) {
o << " private ";
printType(o, options, manager, iter->type, false);
o << " m_" << iter->name << " = ";
printType(o, options, manager, iter->type, false, true);
printType(o, options, manager, rAttr.type, false);
o << " m_" << rAttr.name << " = ";
printType(o, options, manager, rAttr.type, false, true);
o <<";\n";
++iter;
}
}
......@@ -827,10 +812,8 @@ void generateSkeleton(ProgramOptions const & options,
bool serviceobject = false;
bool supportxcomponent = false;
std::vector< OString >::const_iterator iter = types.begin();
while (iter != types.end()) {
checkType(manager, b2u(*iter), interfaces, services, properties);
++iter;
for (const auto& rType : types) {
checkType(manager, b2u(rType), interfaces, services, properties);
}
if (options.componenttype == 3) {
......
......@@ -260,32 +260,29 @@ SAL_IMPLEMENT_MAIN()
}
rtl::Reference< TypeManager > manager(new TypeManager);
for (std::vector< OString >::const_iterator i(registries.begin());
i != registries.end(); ++i)
for (const auto& rRegistry : registries)
{
manager->loadProvider(convertToFileUrl(*i), true);
manager->loadProvider(convertToFileUrl(rRegistry), true);
}
if ( options.dump ) {
std::vector< OString >::const_iterator iter = types.begin();
while (iter != types.end()) {
for (const auto& rType : types) {
std::cout << "\n/***************************************************"
"*****************************/\n";
switch (options.language )
{
case 1: //Java
java::generateDocumentation(std::cout, options, manager,
*iter, delegate);
rType, delegate);
break;
case 2: //C++
cpp::generateDocumentation(std::cout, options, manager,
*iter, delegate);
rType, delegate);
break;
default:
OSL_ASSERT(false);
break;
}
++iter;
}
} else {
switch ( options.language )
......
......@@ -9,6 +9,7 @@
#include <sal/config.h>
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdlib>
......@@ -445,6 +446,12 @@ void mapCursor(
}
}
template<typename T>
bool hasNotEmptyAnnotations(const std::vector<T>& v)
{
return std::any_of(v.begin(), v.end(), [](const T& rItem) { return !rItem.annotations.empty(); });
}
sal_uInt64 writeMap(
osl::File & file, std::map< OUString, Item > & map, std::size_t * rootSize)
{
......@@ -458,12 +465,8 @@ sal_uInt64 writeMap(
rtl::Reference< unoidl::EnumTypeEntity > ent2(
static_cast< unoidl::EnumTypeEntity * >(
i.second.entity.get()));
bool ann = !ent2->getAnnotations().empty();
for (auto j(ent2->getMembers().begin());
!ann && j != ent2->getMembers().end(); ++j)
{
ann = !j->annotations.empty();
}
bool ann = !ent2->getAnnotations().empty() ||
hasNotEmptyAnnotations(ent2->getMembers());
i.second.dataOffset = getOffset(file);
writeKind(file, ent2.get(), ann);
write32(file, ent2->getMembers().size());
......@@ -480,12 +483,8 @@ sal_uInt64 writeMap(
rtl::Reference< unoidl::PlainStructTypeEntity > ent2(
static_cast< unoidl::PlainStructTypeEntity * >(
i.second.entity.get()));
bool ann = !ent2->getAnnotations().empty();
for (auto j(ent2->getDirectMembers().begin());
!ann && j != ent2->getDirectMembers().end(); ++j)
{
ann = !j->annotations.empty();
}
bool ann = !ent2->getAnnotations().empty() ||
hasNotEmptyAnnotations(ent2->getDirectMembers());
i.second.dataOffset = getOffset(file);
writeKind(
file, ent2.get(), ann, !ent2->getDirectBase().isEmpty());
......@@ -508,12 +507,8 @@ sal_uInt64 writeMap(
static_cast<
unoidl::PolymorphicStructTypeTemplateEntity * >(
i.second.entity.get()));
bool ann = !ent2->getAnnotations().empty();
for (auto j(ent2->getMembers().begin());
!ann && j != ent2->getMembers().end(); ++j)
{
ann = !j->annotations.empty();
}
bool ann = !ent2->getAnnotations().empty() ||
hasNotEmptyAnnotations(ent2->getMembers());
i.second.dataOffset = getOffset(file);
writeKind(file, ent2.get(), ann);
write32(file, ent2->getTypeParameters().size());
......@@ -539,12 +534,8 @@ sal_uInt64 writeMap(
rtl::Reference< unoidl::ExceptionTypeEntity > ent2(
static_cast< unoidl::ExceptionTypeEntity * >(
i.second.entity.get()));
bool ann = !ent2->getAnnotations().empty();
for (auto j(ent2->getDirectMembers().begin());
!ann && j != ent2->getDirectMembers().end(); ++j)
{
ann = !j->annotations.empty();
}
bool ann = !ent2->getAnnotations().empty() ||
hasNotEmptyAnnotations(ent2->getDirectMembers());
i.second.dataOffset = getOffset(file);
writeKind(
file, ent2.get(), ann, !ent2->getDirectBase().isEmpty());
......@@ -565,27 +556,11 @@ sal_uInt64 writeMap(
rtl::Reference< unoidl::InterfaceTypeEntity > ent2(
static_cast< unoidl::InterfaceTypeEntity * >(
i.second.entity.get()));
bool ann = !ent2->getAnnotations().empty();
for (auto j(ent2->getDirectMandatoryBases().begin());
!ann && j != ent2->getDirectMandatoryBases().end(); ++j)
{
ann = !j->annotations.empty();
}
for (auto j(ent2->getDirectOptionalBases().begin());
!ann && j != ent2->getDirectOptionalBases().end(); ++j)
{
ann = !j->annotations.empty();
}
for (auto j(ent2->getDirectAttributes().begin());
!ann && j != ent2->getDirectAttributes().end(); ++j)
{
ann = !j->annotations.empty();
}
for (auto j(ent2->getDirectMethods().begin());
!ann && j != ent2->getDirectMethods().end(); ++j)
{
ann = !j->annotations.empty();
}
bool ann = !ent2->getAnnotations().empty() ||
hasNotEmptyAnnotations(ent2->getDirectMandatoryBases()) ||
hasNotEmptyAnnotations(ent2->getDirectOptionalBases()) ||
hasNotEmptyAnnotations(ent2->getDirectAttributes()) ||
hasNotEmptyAnnotations(ent2->getDirectMethods());
i.second.dataOffset = getOffset(file);
writeKind(file, ent2.get(), ann);
write32(file, ent2->getDirectMandatoryBases().size());
......@@ -757,11 +732,8 @@ sal_uInt64 writeMap(
&& ent2->getConstructors()[0].defaultConstructor;
bool ann = !ent2->getAnnotations().empty();
if (!dfltCtor) {
for (auto j(ent2->getConstructors().begin());
!ann && j != ent2->getConstructors().end(); ++j)
{
ann = !j->annotations.empty();
}
if (!ann)
ann = hasNotEmptyAnnotations(ent2->getConstructors());
}
i.second.dataOffset = getOffset(file);
writeKind(file, ent2.get(), ann, dfltCtor);
......@@ -801,37 +773,12 @@ sal_uInt64 writeMap(
rtl::Reference< unoidl::AccumulationBasedServiceEntity > ent2(
static_cast< unoidl::AccumulationBasedServiceEntity * >(
i.second.entity.get()));
bool ann = !ent2->getAnnotations().empty();
for (auto j(ent2->getDirectMandatoryBaseServices().begin());
!ann && j != ent2->getDirectMandatoryBaseServices().end();
++j)
{
ann = !j->annotations.empty();
}
for (auto j(ent2->getDirectOptionalBaseServices().begin());
!ann && j != ent2->getDirectOptionalBaseServices().end();
++j)
{
ann = !j->annotations.empty();
}
for (auto j(ent2->getDirectMandatoryBaseInterfaces().begin());
(!ann
&& j != ent2->getDirectMandatoryBaseInterfaces().end());
++j)
{
ann = !j->annotations.empty();
}
for (auto j(ent2->getDirectOptionalBaseInterfaces().begin());
!ann && j != ent2->getDirectOptionalBaseInterfaces().end();
++j)
{
ann = !j->annotations.empty();
}
for (auto j(ent2->getDirectProperties().begin());
!ann && j != ent2->getDirectProperties().end(); ++j)
{
ann = !j->annotations.empty();
}
bool ann = !ent2->getAnnotations().empty() ||
hasNotEmptyAnnotations(ent2->getDirectMandatoryBaseServices()) ||
hasNotEmptyAnnotations(ent2->getDirectOptionalBaseServices()) ||
hasNotEmptyAnnotations(ent2->getDirectMandatoryBaseInterfaces()) ||
hasNotEmptyAnnotations(ent2->getDirectOptionalBaseInterfaces()) ||
hasNotEmptyAnnotations(ent2->getDirectProperties());
i.second.dataOffset = getOffset(file);
writeKind(file, ent2.get(), ann);
write32(file, ent2->getDirectMandatoryBaseServices().size());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment