本文整理汇总了C++中kode::Code::unindent方法的典型用法代码示例。如果您正苦于以下问题:C++ Code::unindent方法的具体用法?C++ Code::unindent怎么用?C++ Code::unindent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kode::Code
的用法示例。
在下文中一共展示了Code::unindent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generateServerMethod
void Converter::generateServerMethod(KODE::Code &code, const Binding &binding, const Operation &operation, KODE::Class &newClass, bool first)
{
const QString requestVarName = "_request";
const QString responseVarName = "_response";
const Message message = mWSDL.findMessage(operation.input().message());
Message outputMessage;
if (operation.operationType() != Operation::OneWayOperation) {
outputMessage = mWSDL.findMessage(operation.output().message());
}
const QString operationName = operation.name();
const QString methodName = mNameMapper.escape(lowerlize(operationName));
KODE::Function virtualMethod(methodName);
virtualMethod.setVirtualMode(KODE::Function::PureVirtual);
QString condition = "method == \"" + operationName + "\"";
if (binding.type() == Binding::SOAPBinding) {
const SoapBinding soapBinding(binding.soapBinding());
const SoapBinding::Operation op = soapBinding.operations().value(operation.name());
if (!op.action().isEmpty()) {
condition += " || _soapAction == \"" + op.action() + "\"";
}
}
code += QString(first ? "" : "else ") + "if (" + condition + ") {";
code.indent();
QStringList inputVars;
const Part::List parts = message.parts();
for (int partNum = 0; partNum < parts.count(); ++partNum) {
const Part part = parts.at(partNum);
const QString lowerName = lowerlize(part.name());
const QString argType = mTypeMap.localType(part.type(), part.element());
//qDebug() << "localInputType" << part.type().qname() << part.element().qname() << "->" << argType;
if (argType != "void") {
const QString varName = mNameMapper.escape(lowerName);
code += argType + ' ' + varName + ";" + COMMENT;
QString soapValueVarName = requestVarName;
if (soapStyle(binding) == SoapBinding::RPCStyle) {
// RPC comes with a wrapper element, dig into it here
soapValueVarName = "val";
if (partNum > 0) {
soapValueVarName += QString::number(partNum + 1);
}
code += QString::fromLatin1("const KDSoapValue %1 = %2.childValues().at(%3);").arg(soapValueVarName, requestVarName).arg(partNum) + COMMENT;
}
// what if there's more than one?
code.addBlock(demarshalVar(part.type(), part.element(), varName, argType, soapValueVarName, false, false));
inputVars += varName;
newClass.addIncludes(mTypeMap.headerIncludes(part.type()), mTypeMap.forwardDeclarationsForElement(part.element()));
virtualMethod.addArgument(mTypeMap.localInputType(part.type(), part.element()) + ' ' + varName);
}
}
const Part::List outParts = outputMessage.parts();
if (outParts.count() > 1) {
qWarning("ERROR: multiple output parameters are not supported (operation %s) - please file"
"an issue on github with your wsdl file", qPrintable(operation.name()));
virtualMethod.setReturnType("void /*UNSUPPORTED*/");
} else if (outParts.isEmpty()) {
code += lowerlize(operationName) + '(' + inputVars.join(", ") + ");";
virtualMethod.setReturnType("void");
} else {
QString retType;
QString retInputType;
//bool isBuiltin = false;
//bool isComplex = false;
Part retPart;
Q_FOREACH (const Part &outPart, outParts /* only one */) {
retType = mTypeMap.localType(outPart.type(), outPart.element());
retInputType = mTypeMap.localInputType(outPart.type(), outPart.element());
//isBuiltin = mTypeMap.isBuiltinType( outPart.type(), outPart.element() );
//isComplex = mTypeMap.isComplexType( outPart.type(), outPart.element() );
retPart = outPart;
}
const QString methodCall = methodName + '(' + inputVars.join(", ") + ')';
if (retType == "void") {
code += methodCall + ";" + COMMENT;
} else {
code += retType + " ret = " + methodCall + ";" + COMMENT;
}
code += "if (!hasFault()) {";
code.indent();
// TODO factorize with same code in next method
if (soapStyle(binding) == SoapBinding::DocumentStyle) {
code.addBlock(serializePart(retPart, "ret", responseVarName, false));
} else {
code += QString("KDSoapValue wrapper(\"%1\", QVariant(), \"%2\");").arg(outputMessage.name()).arg(outputMessage.nameSpace());
code.addBlock(serializePart(retPart, "ret", "wrapper.childValues()", true));
code += responseVarName + " = wrapper;";
}
code.unindent();
code += "}";
//.........这里部分代码省略.........
示例2: convertServerService
void Converter::convertServerService()
{
Q_FOREACH (const Service &service, mWSDL.definitions().services()) {
Q_ASSERT(!service.name().isEmpty());
QSet<QName> uniqueBindings = mWSDL.uniqueBindings(service);
Q_FOREACH (const QName &bindingName, uniqueBindings) {
//qDebug() << "binding" << bindingName;
const Binding binding = mWSDL.findBinding(bindingName);
QString className = KODE::Style::className(service.name());
QString nameSpace;
if (uniqueBindings.count() > 1) {
// Multiple bindings: use Service::Binding as classname.
nameSpace = className;
className = KODE::Style::className(bindingName.localName());
}
className += "ServerBase";
KODE::Class serverClass(className, nameSpace);
serverClass.addBaseClass(mQObject);
serverClass.addBaseClass(mKDSoapServerObjectInterface);
if (!Settings::self()->exportDeclaration().isEmpty()) {
serverClass.setExportDeclaration(Settings::self()->exportDeclaration());
}
serverClass.setNameSpace(Settings::self()->nameSpace());
// Files included in the header
serverClass.addHeaderInclude("QtCore/QObject");
serverClass.addHeaderInclude("KDSoapServer/KDSoapServerObjectInterface.h");
serverClass.addDeclarationMacro("Q_OBJECT");
serverClass.addDeclarationMacro("Q_INTERFACES(KDSoapServerObjectInterface)");
KODE::Function processRequestMethod(QString::fromLatin1("processRequest"), QString::fromLatin1("void"));
processRequestMethod.addArgument("const KDSoapMessage &_request");
processRequestMethod.addArgument("KDSoapMessage &_response");
processRequestMethod.addArgument("const QByteArray& _soapAction");
KODE::Code body;
const QString responseNs = mWSDL.definitions().targetNamespace();
body.addLine("setResponseNamespace(QLatin1String(\"" + responseNs + "\"));" + COMMENT);
body.addLine("const QByteArray method = _request.name().toLatin1();");
PortType portType = mWSDL.findPortType(binding.portTypeName());
//qDebug() << portType.name();
bool first = true;
const Operation::List operations = portType.operations();
Q_FOREACH (const Operation &operation, operations) {
const Operation::OperationType opType = operation.operationType();
switch (opType) {
case Operation::OneWayOperation:
case Operation::RequestResponseOperation: // the standard case
case Operation::SolicitResponseOperation:
case Operation::NotificationOperation:
generateServerMethod(body, binding, operation, serverClass, first);
break;
}
first = false;
}
if (!first) {
body += "else {";
body.indent();
}
body += "KDSoapServerObjectInterface::processRequest(_request, _response, _soapAction);" + COMMENT;
if (!first) {
body.unindent();
body += "}";
}
processRequestMethod.setBody(body);
serverClass.addFunction(processRequestMethod);
mClasses.addClass(serverClass);
}
}
}
示例3: generate
KODE::Code ElementArgumentSerializer::generate() const
{
Q_ASSERT(!mLocalVarName.isEmpty());
Q_ASSERT(!mOutputVarName.isEmpty());
const QString varAndMethodBefore = mOutputVarName + (mAppend ? QLatin1String(".append(") : QLatin1String(" = "));
const QString varAndMethodAfter = mAppend ? QString::fromLatin1(")") : QString();
KODE::Code block;
// for debugging, add this:
//block += "// type: " + type.qname() + " element:" + elementType.qname();
//if ( name.localName() == "..." )
// qDebug() << "appendElementArg:" << name << "type=" << type << "isBuiltin=" << mTypeMap.isBuiltinType(type) << "isQualified=" << isQualified;
if ( mTypeMap.isTypeAny( mType ) ) {
block += QLatin1String("if (!") + mLocalVarName + QLatin1String(".isNull()) {");
block.indent();
block += varAndMethodBefore + mLocalVarName + varAndMethodAfter + QLatin1String(";") + COMMENT;
block.unindent();
block += "}";
} else {
const QName actualType = mType.isEmpty() ? mElementType : mType;
const QString typeArgs = namespaceString(actualType.nameSpace()) + QLatin1String(", QString::fromLatin1(\"") + actualType.localName() + QLatin1String("\")");
const bool isComplex = mTypeMap.isComplexType( mType, mElementType );
const bool isPolymorphic = mTypeMap.isPolymorphic( mType, mElementType );
if ( mAppend && mOmitIfEmpty ) {
if ( mUsePointer ) {
block += "if (" + mLocalVarName + ") {";
} else {
block += "if (!" + mLocalVarName + "_nil) {";
}
block.indent();
}
if ( isComplex ) {
const QString op = (isPolymorphic || mUsePointer) ? "->" : ".";
block += QLatin1String("KDSoapValue ") + mValueVarName + QLatin1Char('(') + mLocalVarName + op + QLatin1String("serialize(") + mNameArg + QLatin1String("));") + COMMENT;
} else {
if ( mTypeMap.isBuiltinType( mType, mElementType ) ) {
const QString qtTypeName = mTypeMap.localType( mType, mElementType );
const QString value = mTypeMap.serializeBuiltin( mType, mElementType, mLocalVarName, qtTypeName );
block += QLatin1String("KDSoapValue ") + mValueVarName + QLatin1String("(" )+ mNameArg + QLatin1String(", ") + value + QLatin1String(", ") + typeArgs + QLatin1String(");") + COMMENT;
} else {
block += QLatin1String("KDSoapValue ") + mValueVarName + QLatin1String("(") + mNameArg + QLatin1String(", ") + mLocalVarName + QLatin1String(".serialize(), ") + typeArgs + QLatin1String(");") + COMMENT;
}
}
if ( !mNameNamespace.isEmpty() )
block += mValueVarName + QLatin1String(".setNamespaceUri(") + mNameNamespace + QLatin1String(");");
if ( mIsQualified )
block += mValueVarName + QLatin1String(".setQualified(true);");
if ( mNillable )
block += mValueVarName + QLatin1String(".setNillable(true);");
if ( mAppend && mOmitIfEmpty ) { // omit empty children (testcase: MSExchange, no <ParentFolderIds/>)
block += "if (!" + mValueVarName + ".isNil())";
}
block += varAndMethodBefore + mValueVarName + varAndMethodAfter + QLatin1String(";") + COMMENT;
if ( mAppend && mOmitIfEmpty ) {
block.unindent();
block += "}";
}
}
return block;
}
示例4: generateServerMethod
void Converter::generateServerMethod(KODE::Code& code, const Binding& binding, const Operation& operation, KODE::Class &newClass, bool first)
{
const Message message = mWSDL.findMessage( operation.input().message() );
Message outputMessage;
if (operation.operationType() != Operation::OneWayOperation) {
outputMessage = mWSDL.findMessage( operation.output().message() );
}
const QString operationName = operation.name();
const QString methodName = mNameMapper.escape( lowerlize( operationName ) );
KODE::Function virtualMethod(methodName);
virtualMethod.setVirtualMode(KODE::Function::PureVirtual);
QString condition = "method == \"" + operationName + "\"";
if ( binding.type() == Binding::SOAPBinding ) {
const SoapBinding soapBinding( binding.soapBinding() );
const SoapBinding::Operation op = soapBinding.operations().value( operation.name() );
if (!op.action().isEmpty()) {
condition += "|| soapAction == \"" + op.action() + "\"";
}
}
code += QString(first ? "" : "else ") + "if (" + condition + ") {";
code.indent();
QStringList inputVars;
const Part::List parts = message.parts();
if (parts.count() > 1) {
qWarning("ERROR: multiple input parameters are not supported - please report this with your wsdl file to [email protected]");
}
Q_FOREACH( const Part& part, parts ) {
const QString lowerName = lowerlize( part.name() );
const QString argType = mTypeMap.localType( part.type(), part.element() );
//qDebug() << "localInputType" << part.type().qname() << part.element().qname() << "->" << argType;
if ( argType != "void" ) {
const QString varName = mNameMapper.escape( lowerName );
code += argType + ' ' + varName + ";" + COMMENT;
QString soapValueVarName = "request";
if (soapStyle(binding) == SoapBinding::RPCStyle) {
// RPC comes with a wrapper element, dig into it here
code += QLatin1String("const KDSoapValue val = request.childValues().first();") + COMMENT;
soapValueVarName = "val";
}
// what if there's more than one?
code.addBlock( demarshalVar( part.type(), part.element(), varName, argType, soapValueVarName ) );
inputVars += varName;
newClass.addIncludes( mTypeMap.headerIncludes( part.type() ) );
virtualMethod.addArgument( mTypeMap.localInputType( part.type(), part.element() ) + ' ' + varName );
}
}
const Part::List outParts = outputMessage.parts();
if (outParts.count() > 1) {
qWarning("ERROR: multiple output parameters are not supported (operation %s) - please report"
" this with your wsdl file to [email protected]", qPrintable(operation.name()));
virtualMethod.setReturnType("void /*UNSUPPORTED*/");
} else if (outParts.isEmpty()) {
code += operationName + '(' + inputVars.join(", ") + ");";
virtualMethod.setReturnType("void");
} else {
QString retType;
QString retInputType;
//bool isBuiltin = false;
//bool isComplex = false;
Part retPart;
Q_FOREACH( const Part& outPart, outParts /* only one */ ) {
retType = mTypeMap.localType( outPart.type(), outPart.element() );
retInputType = mTypeMap.localInputType( outPart.type(), outPart.element() );
//isBuiltin = mTypeMap.isBuiltinType( outPart.type(), outPart.element() );
//isComplex = mTypeMap.isComplexType( outPart.type(), outPart.element() );
retPart = outPart;
}
const QString methodCall = methodName + '(' + inputVars.join(", ") + ')';
if (retType == "void") {
code += methodCall + ";" + COMMENT;
} else {
code += retType + " ret = " + methodCall + ";" + COMMENT;
}
code += "if (!hasFault()) {";
code.indent();
bool qualified;
const QName elemName = elementNameForPart( retPart, &qualified );
if (soapStyle(binding) == SoapBinding::RPCStyle) {
code += QString("KDSoapValue wrapper(\"%1\", QVariant());").arg(outputMessage.name());
code.addBlock( serializeElementArg( retPart.type(), retPart.element(), elemName, "ret", "wrapper.childValues()", true, qualified ) );
code += "response = wrapper;";
} else {
code.addBlock( serializeElementArg( retPart.type(), retPart.element(), elemName, "ret", "response", false, qualified ) );
}
code.unindent();
code += "}";
Q_ASSERT(!retType.isEmpty());
virtualMethod.setReturnType(retType);
//.........这里部分代码省略.........
示例5: convertSimpleType
void Converter::convertSimpleType( const XSD::SimpleType *type )
{
const QString typeName( mTypeMap.localType( type->qualifiedName() ) );
KODE::Class newClass( typeName );
newClass.addInclude( QString(), "Serializer" );
KODE::Code ctorBody;
KODE::Code dtorBody;
QString classDocumentation;
if ( type->subType() == XSD::SimpleType::TypeRestriction ) {
/**
Use setter and getter method for enums as well.
*/
if ( type->facetType() & XSD::SimpleType::ENUM ) {
classDocumentation = "This class is a wrapper for an enumeration.\n";
QStringList enums = type->facetEnums();
for ( int i = 0; i < enums.count(); ++i )
enums[ i ] = escapeEnum( enums[ i ] );
newClass.addEnum( KODE::Enum( "Type", enums ) );
classDocumentation += "Whenever you have to pass an object of type " + newClass.name() +
" you can also pass the enum directly (e.g. someMethod( " + newClass.name() + "::" + enums.first() + " )).";
// member variables
KODE::MemberVariable variable( "type", "Type" );
newClass.addMemberVariable( variable );
// setter method
KODE::Function setter( "setType", "void" );
setter.addArgument( "Type type" );
setter.setBody( variable.name() + " = type;" );
// getter method
KODE::Function getter( "type", upperlize( newClass.name() ) + "::Type" );
getter.setBody( "return " + variable.name() + ';' );
getter.setConst( true );
// convenience constructor
KODE::Function conctor( upperlize( newClass.name() ) );
conctor.addArgument( "const " + upperlize( newClass.name() ) + "::Type &type" );
KODE::Code code;
code += variable.name() + " = type;";
conctor.setBody( code );
// type operator
KODE::Function op( "operator const " + upperlize( newClass.name() ) + "::Type" );
op.setBody( "return " + variable.name() + ';' );
op.setConst( true );
newClass.addFunction( conctor );
newClass.addFunction( setter );
newClass.addFunction( getter );
newClass.addFunction( op );
}
/**
A class can't derive from basic types (e.g. int or unsigned char), so
we add setter and getter methods to set the value of this class.
*/
if ( type->baseTypeName() != XmlAnyType
&& !type->baseTypeName().isEmpty()
&& !(type->facetType() & XSD::SimpleType::ENUM) ) {
classDocumentation = "This class encapsulates an basic type.\n";
const QName baseName = type->baseTypeName();
const QString typeName = mTypeMap.localType( baseName );
classDocumentation += "Whenever you have to pass an object of type " + newClass.name() +
" you can also pass the value directly (e.g. someMethod( (" + typeName + "*)value )).";
// include header
newClass.addIncludes( QStringList(), mTypeMap.forwardDeclarations( baseName ) );
// member variables
KODE::MemberVariable variable( "value", typeName + '*' );
newClass.addMemberVariable( variable );
ctorBody += variable.name() + " = 0;";
dtorBody += "delete " + variable.name() + "; " + variable.name() + " = 0;";
// setter method
KODE::Function setter( "setValue", "void" );
setter.addArgument( typeName + " *value" );
KODE::Code setterBody;
setterBody += createRangeCheckCode( type, "(*value)", newClass );
setterBody.newLine();
setterBody += "if ( !rangeOk )";
setterBody.indent();
setterBody += "qDebug( \"Invalid range in " + newClass.name() + "::" + setter.name() + "()\" );";
setterBody.unindent();
setterBody.newLine();
setterBody += variable.name() + " = value;";
setter.setBody( setterBody );
// getter method
KODE::Function getter( "value", typeName + '*' );
//.........这里部分代码省略.........
示例6: convertSimpleType
//.........这里部分代码省略.........
KODE::Function op("operator Type");
op.setBody("return " + variable.name() + ';');
op.setConst(true);
newClass.addFunction(conctor);
newClass.addFunction(setter);
newClass.addFunction(getter);
newClass.addFunction(op);
}
/**
A class can't derive from basic types (e.g. int or unsigned char), so
we add setter and getter methods to set the value of this class.
*/
if (type->baseTypeName() != XmlAnyType
&& !type->baseTypeName().isEmpty()
&& !(type->facetType() & XSD::SimpleType::ENUM)) {
classDocumentation = "This class encapsulates a simple type.\n";
const QName baseName = type->baseTypeName();
const QString baseTypeName = mTypeMap.localType(baseName);
Q_ASSERT(!baseTypeName.isEmpty());
QList<QName> parentBasicTypes;
parentBasicTypes.append(baseName);
QName currentType = baseName;
Q_FOREVER {
const XSD::SimpleType simpleType = simpleTypeList.simpleType(currentType);
if (!simpleType.isNull() && simpleType.isRestriction()) {
currentType = simpleType.baseTypeName();
parentBasicTypes.append(currentType);
continue;
}
break;
}
classDocumentation += "Whenever you have to pass an object of type " + newClass.name() +
" you can also pass the value directly as a " + mTypeMap.localType(currentType) + '.';
// include header
newClass.addIncludes(QStringList(), mTypeMap.forwardDeclarations(baseName));
newClass.addHeaderIncludes(mTypeMap.headerIncludes(baseName));
// member variables
KODE::MemberVariable variable("value", baseTypeName);
addVariableInitializer(variable);
newClass.addMemberVariable(variable);
// setter method
KODE::Function setter("setValue", "void");
const QString inputType = mTypeMap.localInputType(baseName, QName());
setter.addArgument(inputType + " value");
KODE::Code setterBody;
if (type->facetType() != XSD::SimpleType::NONE) {
const XSD::SimpleType baseSimpleType = simpleTypeList.simpleType(baseName);
setterBody += createRangeCheckCode(type, baseTypeName, "value", newClass, baseSimpleType);
setterBody.newLine();
setterBody += "if (!rangeOk)";
setterBody.indent();
setterBody += "qDebug( \"Invalid range in " + newClass.name() + "::" + setter.name() + "()\" );";
setterBody.unindent();
setterBody.newLine();
}
setterBody += variable.name() + " = value;"; // ### call setValue in base class?
setter.setBody(setterBody);
newClass.addFunction(setter);
// getter method
KODE::Function getter("value", baseTypeName);
getter.setBody("return " + variable.name() + ';');
getter.setConst(true);
newClass.addFunction(getter);
// convenience constructor
KODE::Function conctor(newClass.name());
conctor.addArgument(inputType + " value");
conctor.addBodyLine("setValue(value);");
newClass.addFunction(conctor);
// even more convenient constructor, for the case of multiple-level simple-type restrictions
//qDebug() << typeName << ": baseName=" << baseName << "further up:" << parentBasicTypes;
if (parentBasicTypes.count() > 1) {
parentBasicTypes.removeLast(); // the top-most one is in "currentType", so it's the input arg.
KODE::Function baseCtor(conctor.name());
baseCtor.addArgument(mTypeMap.localInputType(currentType, QName()) + " value");
QString beginLine = "setValue(";
QString endLine = ")";
Q_FOREACH (const QName &base, parentBasicTypes) {
beginLine += mTypeMap.localType(base) + '(';
endLine += ')';
}
baseCtor.addBodyLine(beginLine + "value" + endLine + ';');
newClass.addFunction(baseCtor);
}
// type operator
KODE::Function op("operator " + baseTypeName);
op.setBody("return " + variable.name() + ';');
op.setConst(true);
newClass.addFunction(op);
}
示例7: createKDETransport
void Converter::createKDETransport()
{
KODE::Class transport( "Transport" );
transport.addBaseClass( mQObject );
transport.addHeaderInclude( "QObject" );
transport.addHeaderInclude( "kio/job.h" );
transport.addInclude( "kdebug.h" );
KODE::MemberVariable url( "url", "QString" );
transport.addMemberVariable( url );
KODE::MemberVariable slotDataVar( "data", "QByteArray" );
transport.addMemberVariable( slotDataVar );
// ctor
KODE::Function ctor( "Transport" );
ctor.addArgument( "const QString &url" );
ctor.setBody( url.name() + " = url;" );
transport.addFunction( ctor );
// query
KODE::Function query( "query", "void" );
query.addArgument( "const QString &xml" );
query.addArgument( "const QString &header" );
KODE::Code queryCode;
queryCode += slotDataVar.name() + ".truncate( 0 );";
queryCode.newLine();
queryCode += "QByteArray postData;";
queryCode += "QDataStream stream( &postData, QIODevice::WriteOnly );";
queryCode += "stream.writeRawData( xml.toUtf8(), xml.toUtf8().length() );";
queryCode.newLine();
queryCode += "KIO::TransferJob* job = KIO::http_post( KUrl( " + url.name() + " ), postData, KIO::HideProgressInfo );";
queryCode += "if ( !job ) {";
queryCode.indent();
queryCode += "kWarning() << \"Unable to create KIO job for \" <<" + url.name() +";";
queryCode += "return;";
queryCode.unindent();
queryCode += '}';
queryCode.newLine();
queryCode += "job->addMetaData( \"UserAgent\", \"KWSDL\" );";
queryCode += "job->addMetaData( \"content-type\", \"Content-Type: application/xml; charset=utf-8\" );";
queryCode += "if ( !header.isEmpty() ) {";
queryCode.indent();
queryCode += "job->addMetaData( \"customHTTPHeader\", \"SOAPAction:\" + header );";
queryCode.unindent();
queryCode += '}';
queryCode.newLine();
queryCode += "connect( job, SIGNAL( data( KIO::Job*, const QByteArray& ) ), this, SLOT( slotData( KIO::Job*, const QByteArray& ) ) );";
queryCode += "connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotResult( KJob* ) ) );";
query.setBody( queryCode );
transport.addFunction( query );
// signal
KODE::Function result( "result", "void", KODE::Function::Signal );
result.addArgument( "const QString &xml" );
KODE::Function error( "error", "void", KODE::Function::Signal );
error.addArgument( "const QString &msg" );
transport.addFunction( result );
transport.addFunction( error );
// data slot
KODE::Function slotData( "slotData", "void", KODE::Function::Private | KODE::Function::Slot );
slotData.addArgument( "KIO::Job*" );
slotData.addArgument( "const QByteArray &data" );
KODE::Code slotDataCode;
slotDataCode += "unsigned int oldSize = " + slotDataVar.name() + ".size();";
slotDataCode += slotDataVar.name() + ".resize( oldSize + data.size() );";
slotDataCode += "memcpy( " + slotDataVar.name() + ".data() + oldSize, data.data(), data.size() );";
slotData.setBody( slotDataCode );
transport.addFunction( slotData );
// result slot
KODE::Function slotResult( "slotResult", "void", KODE::Function::Private | KODE::Function::Slot );
slotResult.addArgument( "KJob* job" );
KODE::Code slotResultCode;
slotResultCode += "if ( job->error() != 0 ) {";
slotResultCode.indent();
slotResultCode += "emit error( job->errorText() );";
slotResultCode += "return;";
slotResultCode.unindent();
slotResultCode += '}';
slotResultCode.newLine();
slotResultCode += "emit result( QString::fromUtf8( " + slotDataVar.name() + ".data(), " + slotDataVar.name() + ".size() ) );";
slotResult.setBody( slotResultCode );
transport.addFunction( slotResult );
//.........这里部分代码省略.........
示例8: createQtTransport
void Converter::createQtTransport()
{
KODE::Class transport( "Transport" );
transport.addBaseClass( mQObject );
transport.addHeaderInclude( "QBuffer" );
transport.addHeaderInclude( "QByteArray" );
transport.addHeaderInclude( "QObject" );
transport.addHeaderInclude( "QHttp" );
transport.addHeaderInclude( "QUrl" );
// member variables
KODE::MemberVariable bufferVar( "buffer", "QBuffer" );
transport.addMemberVariable( bufferVar );
KODE::MemberVariable dataVar( "data", "QByteArray" );
transport.addMemberVariable( dataVar );
KODE::MemberVariable httpVar( "http", "QHttp*" );
transport.addMemberVariable( httpVar );
KODE::MemberVariable urlVar( "url", "QUrl" );
transport.addMemberVariable( urlVar );
KODE::MemberVariable idVar( "id", "int" );
transport.addMemberVariable( idVar );
// functions
KODE::Function ctor( "Transport" );
ctor.addArgument( "const QString &url" );
ctor.addInitializer( "QObject( 0 )" );
ctor.addInitializer( urlVar.name() + "( url )" );
KODE::Function query( "query", "void" );
query.addArgument( "const QString &message" );
query.addArgument( "const QString &headerStr" );
KODE::Function resultSignal( "result", "void", KODE::Function::Signal );
resultSignal.addArgument( "const QString &result" );
KODE::Function errorSignal( "error", "void", KODE::Function::Signal );
errorSignal.addArgument( "const QString &msg" );
KODE::Function finishedSlot( "finished", "void", KODE::Function::Slot | KODE::Function::Private );
finishedSlot.addArgument( "int id" );
finishedSlot.addArgument( "bool errorOccurred" );
// codes
KODE::Code code;
code += "QUrl server( url );";
code.newLine();
code += httpVar.name() + " = new QHttp( this );";
code += httpVar.name() + "->setHost( server.host(), server.port( 80 ) );";
code.newLine();
code += "connect( " + httpVar.name() + ", SIGNAL( requestFinished( int, bool ) ), this, SLOT( " + finishedSlot.name() + "( int, bool ) ) );";
ctor.setBody( code );
code.clear();
code += dataVar.name() + ".clear();";
code += bufferVar.name() + ".setBuffer( &" + dataVar.name() + " );";
code.newLine();
code += "QHttpRequestHeader header;";
code += "header.setRequest( \"POST\", " + urlVar.name() + ".path() );";
code += "header.addValue( \"Connection\", \"Keep-Alive\" );";
code += "header.addValue( \"Content-Type\", \"application/xml; charset=utf-8\" );";
code += "header.addValue( \"Host\", QUrl( " + urlVar.name() + " ).host() );";
code.newLine();
code += "if ( !headerStr.isEmpty() )";
code.indent();
code += "header.addValue( \"SOAPAction\", headerStr );";
code.unindent();
code.newLine();
code += "QUrl server( " + urlVar.name() + " );";
code += "if ( server.port( 80 ) != 80 )";
code.indent();
code += "header.setValue( \"Host\", server.host() + \":\" + QString::number( server.port() ) );";
code.unindent();
code += "else";
code.indent();
code += "header.setValue( \"Host\", server.host() );";
code.unindent();
code.newLine();
code += idVar.name() + " = " + httpVar.name() + "->request( header, message.toUtf8(), &" + bufferVar.name() + " );";
query.setBody( code );
code.clear();
code += "if ( id != " + idVar.name() + " )";
code.indent();
code += "return;";
code.unindent();
code.newLine();
code += "if ( errorOccurred )";
code.indent();
code += "emit " + errorSignal.name() + "( " + httpVar.name() + "->errorString() );";
code.unindent();
code += "else";
code.indent();
code += "emit " + resultSignal.name() + "( QString::fromUtf8( " + dataVar.name() + " ) );";
code.unindent();
finishedSlot.setBody( code );
//.........这里部分代码省略.........
示例9: create
//.........这里部分代码省略.........
code += "data( str );";
code.newLine();
code += "finished();";
code.newLine();
code += "kdDebug(7000) << \"" + className + "CgiProtocol::get() done\" << endl;";
get.setBody(code);
c.addFunction(get);
c.addInclude("kinstance.h");
c.addInclude("kdebug.h");
c.addInclude("sys/types.h");
c.addInclude("unistd.h");
c.addInclude("stdlib.h");
KODE::Function main("kdemain", "int");
main.addArgument("int argc");
main.addArgument("char **argv");
code.clear();
code += "KInstance instance( \"kio_" + protocol + "\" );";
code += "";
code += "kdDebug(7000) << \"Starting kio_" + protocol + "(pid: \" << getpid() << \")\" << endl;";
code += "";
code += "if (argc != 4) {";
code.indent();
code += "fprintf( stderr, \"Usage: kio_" + protocol + " protocol domain-socket1 domain-socket2\\n\");";
code += "exit( -1 );";
code.unindent();
code += "}";
code += "";
code += className + " slave( argv[2], argv[3] );";
code += "slave.dispatchLoop();";
code += "";
code += "return 0;";
main.setBody(code);
file.addFileFunction(main);
file.addExternCDeclaration(p.functionSignature(main));
}
KODE::Function constructor(className);
if(args->isSet("singleton"))
{
constructor.setAccess(KODE::Function::Private);
KODE::Function self("self", className + " *");
self.setStatic(true);
KODE::Code code;
code += "if ( !mSelf ) {";
code += " selfDeleter.setObject( mSelf, new " + className + "() );";
code += "}";
code += "return mSelf;";
self.setBody(code);
c.addFunction(self);