Skip to content

Commit

Permalink
switched foreach to range-based for
Browse files Browse the repository at this point in the history
  • Loading branch information
anoymouserver authored and dfaure-kdab committed May 26, 2021
1 parent 8dbfc82 commit dc4754f
Show file tree
Hide file tree
Showing 27 changed files with 176 additions and 196 deletions.
56 changes: 31 additions & 25 deletions kdwsdl2cpp/src/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ void Converter::setWSDL(const WSDL &wsdl)

// overwrite with prefixes from settings
Settings::NSMapping mapping = Settings::self()->namespaceMapping();
Settings::NSMapping::Iterator it;
for (it = mapping.begin(); it != mapping.end(); ++it) {
for (auto it = mapping.begin(); it != mapping.end(); ++it) {
mNSManager.setPrefix(it.value(), it.key());
}

Expand Down Expand Up @@ -94,16 +93,15 @@ class TypeCollector
void registerDerivedClasses()
{
XSD::ComplexType::List complexTypes = m_allTypes.complexTypes();
Q_FOREACH (const XSD::ComplexType &derivedType, complexTypes) {
for (const XSD::ComplexType &derivedType : qAsConst(complexTypes)) {
const QName base = derivedType.baseTypeName();
if (!base.isEmpty()) {
// Look for the base class and register type. Linear search, maybe we should use a QHash...
for (int i = 0; i < complexTypes.count(); ++i) {
XSD::ComplexType &t = complexTypes[i];
if (base == t.qualifiedName())
for (XSD::ComplexType &complexType : complexTypes) {
if (base == complexType.qualifiedName())
// qDebug() << "Adding derived type" << derivedType.name() << "to base" << base;
{
t.addDerivedType(derivedType.qualifiedName());
complexType.addDerivedType(derivedType.qualifiedName());
}
}
}
Expand All @@ -116,7 +114,7 @@ class TypeCollector
QSet<QName> typesToProcess = m_allUsedTypes;
do {
m_alsoUsedTypes.clear();
Q_FOREACH (const QName &typeName, typesToProcess) {
for (const QName &typeName : qAsConst(typesToProcess)) {
if (typeName.isEmpty()) {
continue;
}
Expand All @@ -130,14 +128,17 @@ class TypeCollector
usedComplexTypes.insert(typeName, complexType);

addDependency(complexType.baseTypeName());
Q_FOREACH (const QName &derivedTypeName, complexType.derivedTypes()) {
const auto derivedTypes = complexType.derivedTypes();
for (const QName &derivedTypeName : derivedTypes) {
addDependency(derivedTypeName);
}

Q_FOREACH (const XSD::Element &element, complexType.elements()) {
const auto elements = complexType.elements();
for (const XSD::Element &element : elements) {
addDependency(element.type());
}
Q_FOREACH (const XSD::Attribute &attribute, complexType.attributes()) {
const auto attributes = complexType.attributes();
for (const XSD::Attribute &attribute : attributes) {
addDependency(attribute.type());
}
addDependency(complexType.arrayType());
Expand Down Expand Up @@ -205,15 +206,17 @@ class MessageCollector

QSet<QName> collectMessages(const WSDL &wsdl)
{
Q_FOREACH (const Service &service, wsdl.definitions().services()) {
Q_FOREACH (const Port &port, service.ports()) {
const Service::List services = wsdl.definitions().services();
for (const Service &service : services) {
const Port::List ports = service.ports();
for (const Port &port : ports) {
Binding binding = wsdl.findBinding(port.bindingName());
// portTypeNames.insert( binding.portTypeName() );
// qDebug() << "binding" << port.bindingName() << binding.name() << "port type" << binding.portTypeName();
PortType portType = wsdl.findPortType(binding.portTypeName());
const Operation::List operations = portType.operations();
// qDebug() << "portType" << portType.name() << operations.count() << "operations";
Q_FOREACH (const Operation &operation, operations) {
for (const Operation &operation : qAsConst(operations)) {
// qDebug() << " operation" << operation.operationType() << operation.name();
switch (operation.operationType()) {
case Operation::OneWayOperation:
Expand All @@ -231,10 +234,12 @@ class MessageCollector
if (binding.type() == Binding::SOAPBinding) {
const SoapBinding soapBinding(binding.soapBinding());
const SoapBinding::Operation op = soapBinding.operations().value(operation.name());
Q_FOREACH (const SoapBinding::Header &header, op.inputHeaders()) {
const SoapBinding::Headers inputHeaders = op.inputHeaders();
for (const SoapBinding::Header &header : inputHeaders) {
addMessage(header.message());
}
Q_FOREACH (const SoapBinding::Header &header, op.outputHeaders()) {
const SoapBinding::Headers outputHeaders = op.outputHeaders();
for (const SoapBinding::Header &header : outputHeaders) {
addMessage(header.message());
}
}
Expand Down Expand Up @@ -270,10 +275,10 @@ void Converter::cleanupUnusedTypes()
qDebug() << types.simpleTypes().count() << "simple types";
qDebug() << types.elements().count() << "elements";

// Q_FOREACH(const XSD::Element& elem, types.elements()) {
// for (const XSD::Element& elem : types.elements()) {
// qDebug() << "element:" << elem.qualifiedName();
//}
// Q_FOREACH(const XSD::ComplexType& complexType, types.complexTypes()) {
// for (const XSD::ComplexType& complexType : types.complexTypes()) {
// qDebug() << "complex type:" << complexType.qualifiedName();
//}
}
Expand All @@ -287,11 +292,12 @@ void Converter::cleanupUnusedTypes()
QSet<QString> usedTypesStrings; // for debug
QSet<QName> usedElementNames;
Message::List newMessages;
Q_FOREACH (const QName &messageName, usedMessageNames) {
for (const QName &messageName : qAsConst(usedMessageNames)) {
// qDebug() << "used message:" << messageName;
Message message = mWSDL.findMessage(messageName);
newMessages.append(message);
Q_FOREACH (const Part &part, message.parts()) {
const Part::List messageParts = message.parts();
for (const Part &part : messageParts) {
if (!part.type().isEmpty()) {
usedTypes.insert(part.type());
usedTypesStrings.insert(part.type().qname());
Expand Down Expand Up @@ -351,7 +357,7 @@ void Converter::cleanupUnusedTypes()
qDebug() << types.complexTypes().count() << "complex types";
qDebug() << types.simpleTypes().count() << "simple types";
qDebug() << types.elements().count() << "elements";
// Q_FOREACH(const XSD::ComplexType& complexType, types.complexTypes()) {
// for (const XSD::ComplexType& complexType : types.complexTypes()) {
// qDebug() << "complex type:" << complexType.qualifiedName();
//}
}
Expand Down Expand Up @@ -383,14 +389,14 @@ void Converter::convertTypes()

XSD::SimpleType::List simpleTypes = types.simpleTypes();
qDebug() << "Converting" << simpleTypes.count() << "simple types";
for (int i = 0; i < simpleTypes.count(); ++i) {
convertSimpleType(&(simpleTypes[i]), simpleTypes);
for (const XSD::SimpleType &simpleType : qAsConst(simpleTypes)) {
convertSimpleType(&simpleType, simpleTypes);
}

XSD::ComplexType::List complexTypes = types.complexTypes();
qDebug() << "Converting" << complexTypes.count() << "complex types";
for (int i = 0; i < complexTypes.count(); ++i) {
convertComplexType(&(complexTypes[i]));
for (const XSD::ComplexType &complexType : qAsConst(complexTypes)) {
convertComplexType(&complexType);
}
}

Expand Down
35 changes: 19 additions & 16 deletions kdwsdl2cpp/src/converter_clientstub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ static Part::List selectedParts(const Binding &binding, const Message &message,
const QString selectedPart = input ? op.input().part() : op.output().part();
if (!selectedPart.isEmpty()) {
Part::List selected;
Q_FOREACH (const Part &part, message.parts()) {
const Part::List parts = message.parts();
for (const Part &part : parts) {
if (part.name() == selectedPart) { // support for <soap:body parts="MoveFolderResult"/> (msexchange)
selected << part;
}
Expand Down Expand Up @@ -68,13 +69,14 @@ static SoapBinding::Headers getOutputHeaders(const Binding &binding, const QStri
bool Converter::convertClientService()
{
KODE::Class::List bindingClasses;
Q_FOREACH (const Service &service, mWSDL.definitions().services()) {
const Service::List services = mWSDL.definitions().services();
for (const Service &service : services) {
Q_ASSERT(!service.name().isEmpty());

QSet<QName> uniqueBindings = mWSDL.uniqueBindings(service);
// qDebug() << "Looking at" << service.name() << uniqueBindings;

Q_FOREACH (const QName &bindingName, uniqueBindings) {
for (const QName &bindingName : qAsConst(uniqueBindings)) {
const Binding binding = mWSDL.findBinding(bindingName);

QString className = KODE::Style::className(service.name());
Expand Down Expand Up @@ -309,7 +311,7 @@ bool Converter::convertClientService()
PortType portType = mWSDL.findPortType(binding.portTypeName());
// qDebug() << portType.name();
const Operation::List operations = portType.operations();
Q_FOREACH (const Operation &operation, operations) {
for (const Operation &operation : operations) {
Operation::OperationType opType = operation.operationType();
switch (opType) {
case Operation::OneWayOperation:
Expand Down Expand Up @@ -343,14 +345,15 @@ bool Converter::convertClientService()
}

// Collect message parts used as headers
Q_FOREACH (const SoapBinding::Header &header, getInputHeaders(binding, operation.name())) {
const SoapBinding::Headers inputHeaders = getInputHeaders(binding, operation.name());
for (const SoapBinding::Header &header : inputHeaders) {
if (!soapHeaders.contains(header)) {
soapHeaders.append(header);
}
}
} // end of for each operation

Q_FOREACH (const SoapBinding::Header &header, soapHeaders) {
for (const SoapBinding::Header &header : qAsConst(soapHeaders)) {
createHeader(header, newClass);
}
bindingClasses.append(newClass);
Expand All @@ -364,7 +367,7 @@ bool Converter::convertClientService()
}

// for each operation, create a job class
Q_FOREACH (const Operation &operation, operations) {
for (const Operation &operation : qAsConst(operations)) {
Operation::OperationType opType = operation.operationType();
if (opType != Operation::SolicitResponseOperation && opType != Operation::RequestResponseOperation) {
continue;
Expand Down Expand Up @@ -393,15 +396,15 @@ bool Converter::convertClientService()
ctor.addInitializer(QLatin1String("mService(service)"));

const Message message = mWSDL.findMessage(operation.input().message());
Q_FOREACH (const Part &part, selectedParts(binding, message, operation, true /*input*/)) {
for (const Part &part : selectedParts(binding, message, operation, true /*input*/)) {
const QString partName = part.name();
ctor.addInitializer(KODE::MemberVariable::memberVariableName(partName) + "()");
jobClass.addHeaderIncludes(mTypeMap.headerIncludes(part.type()));
}

const Message outputMsg = mWSDL.findMessage(operation.output().message());

Q_FOREACH (const Part &part, selectedParts(binding, outputMsg, operation, false /*output*/)) {
for (const Part &part : selectedParts(binding, outputMsg, operation, false /*output*/)) {
const QString varName = mNameMapper.escape(QLatin1String("result") + upperlize(part.name()));
ctor.addInitializer(KODE::MemberVariable::memberVariableName(varName) + "()");
jobClass.addHeaderIncludes(mTypeMap.headerIncludes(part.type()));
Expand All @@ -411,7 +414,7 @@ bool Converter::convertClientService()

QStringList inputGetters;

Q_FOREACH (const Part &part, selectedParts(binding, message, operation, true /*input*/)) {
for (const Part &part : selectedParts(binding, message, operation, true /*input*/)) {
const QString varType = mTypeMap.localType(part.type(), part.element());
const KODE::MemberVariable member(part.name(), varType);
jobClass.addMemberVariable(member);
Expand Down Expand Up @@ -482,7 +485,7 @@ bool Converter::convertClientService()
slotCode += QLatin1String("_reply = _reply.childValues().at(0);") + COMMENT;
}

Q_FOREACH (const Part &part, outputParts) {
for (const Part &part : qAsConst(outputParts)) {
const QString varName = mNameMapper.escape(QLatin1String("result") + upperlize(part.name()));
const KODE::MemberVariable member(varName, QString());
slotCode.addBlock(
Expand All @@ -491,7 +494,7 @@ bool Converter::convertClientService()
addJobResultMember(jobClass, part, varName, inputGetters);
}
}
Q_FOREACH (const SoapBinding::Header &header, outputHeaders) {
for (const SoapBinding::Header &header : qAsConst(outputHeaders)) {
const QName messageName = header.message();
const QString partName = header.part();
const Message message = mWSDL.findMessage(messageName);
Expand Down Expand Up @@ -563,7 +566,7 @@ void Converter::clientAddArguments(KODE::Function &callFunc, const Message &mess
const Binding &binding)
{
const Part::List parts = selectedParts(binding, message, operation, true /*input*/);
Q_FOREACH (const Part &part, parts) {
for (const Part &part : parts) {
clientAddOneArgument(callFunc, part, newClass);
}
}
Expand Down Expand Up @@ -636,7 +639,7 @@ void Converter::clientGenerateMessage(KODE::Code &code, const Binding &binding,

bool isBuiltin = false;

Q_FOREACH (const Part &part, selectedParts(binding, message, operation, true /*input*/)) {
for (const Part &part : selectedParts(binding, message, operation, true /*input*/)) {
isBuiltin = isBuiltin || mTypeMap.isBuiltinType(part.type(), part.element());
addMessageArgument(code, soapStyle(binding), part, part.name(), "message", varsAreMembers);
}
Expand Down Expand Up @@ -747,7 +750,7 @@ bool Converter::convertClientCall(const Operation &operation, const Binding &bin
code.unindent();
Q_ASSERT(soapStyle(binding) == SoapBinding::DocumentStyle); // RPC with multiple return values? impossible, we generate a single wrapper

Q_FOREACH (const Part &part, outParts) {
for (const Part &part : qAsConst(outParts)) {
const QString argType = mTypeMap.localType(part.type(), part.element());
Q_ASSERT(!argType.isEmpty());
const QString lowerName = lowerlize(part.name());
Expand Down Expand Up @@ -845,7 +848,7 @@ void Converter::convertClientOutputMessage(const Operation &operation, const Bin
const Message message = mWSDL.findMessage(operation.output().message());

const Part::List parts = selectedParts(binding, message, operation, false /*output*/);
Q_FOREACH (const Part &part, parts) {
for (const Part &part : parts) {
const QString partType = mTypeMap.localType(part.type(), part.element());
if (partType.isEmpty()) {
qWarning("Skipping part '%s'", qPrintable(part.name()));
Expand Down
16 changes: 7 additions & 9 deletions kdwsdl2cpp/src/converter_complextype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void Converter::convertComplexType(const XSD::ComplexType *type)

// elements in the complex type
const XSD::Element::List elements = type->elements();
Q_FOREACH (const XSD::Element &elemIt, elements) {
for (const XSD::Element &elemIt : elements) {

if (elemIt.type().isEmpty()) {
qDebug() << "ERROR: Element from" << *type << "with no type:" << elemIt << "(skipping)";
Expand Down Expand Up @@ -210,8 +210,8 @@ void Converter::convertComplexType(const XSD::ComplexType *type)
}

// attributes in the complex type
XSD::Attribute::List attributes = type->attributes();
Q_FOREACH (const XSD::Attribute &attribute, attributes) {
const XSD::Attribute::List attributes = type->attributes();
for (const XSD::Attribute &attribute : attributes) {
QString typeName, inputTypeName;

typeName = mTypeMap.localType(attribute.type());
Expand Down Expand Up @@ -566,9 +566,8 @@ void Converter::createComplexTypeSerializer(KODE::Class &newClass, const XSD::Co
if (elements.at(0).isQualified()) {
marshalCode += QLatin1String("mainValue.setQualified(true);") + COMMENT;
}
demarshalCode += "for (int argNr = 0; argNr < args.count(); ++argNr) {";
demarshalCode += "for (const KDSoapValue& val : qAsConst(args)) {";
demarshalCode.indent();
demarshalCode += "const KDSoapValue& val = args.at(argNr);";
demarshalCode += "const QString _name = val.name();";
} else {
// The Q_UNUSED is not necessarily true in case of attributes, but who cares.
Expand Down Expand Up @@ -609,7 +608,7 @@ void Converter::createComplexTypeSerializer(KODE::Class &newClass, const XSD::Co
demarshalCode.addBlock(deserializer.demarshalArray("val"));
} else {
bool first = true;
Q_FOREACH (const XSD::Element &elem, elements) {
for (const XSD::Element &elem : qAsConst(elements)) {

const QString elemName = elem.name();
const QString typeName = mTypeMap.localType(elem.type());
Expand Down Expand Up @@ -683,13 +682,12 @@ void Converter::createComplexTypeSerializer(KODE::Class &newClass, const XSD::Co
marshalCode += "KDSoapValueList attribs;";

demarshalCode += "const QList<KDSoapValue> attribs = args.attributes();";
demarshalCode += "for (int attrNr = 0; attrNr < attribs.count(); ++attrNr) {";
demarshalCode += "for (const KDSoapValue& val : qAsConst(attribs)) {";
demarshalCode.indent();
demarshalCode += "const KDSoapValue& val = attribs.at(attrNr);";
demarshalCode += "const QString _name = val.name();";

bool first = true;
Q_FOREACH (const XSD::Attribute &attribute, attributes) {
for (const XSD::Attribute &attribute : qAsConst(attributes)) {
const QString attrName = attribute.name();
if (attrName.isEmpty()) {
continue;
Expand Down
Loading

0 comments on commit dc4754f

Please sign in to comment.