本文整理汇总了C++中qpatternist::AutoPtr类的典型用法代码示例。如果您正苦于以下问题:C++ AutoPtr类的具体用法?C++ AutoPtr怎么用?C++ AutoPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AutoPtr类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setQuery
/*!
Sets this QXmlQuery to the XQuery read from the \a queryURI. Use
isValid() after calling this function. If an error occurred reading
\a queryURI, e.g., the query does not exist, cannot be read, or is
invalid, isValid() will return \e false.
The supported URI schemes are the same as those in the XQuery
function \c{fn:doc}, except that queryURI can be the object of
a variable binding.
\a baseURI is the Base URI of the static context, as defined in the
\l {http://www.w3.org/TR/xquery/}{XQuery language}. It is used
internally to resolve relative URIs that appear in the query, and
for message reporting. If \a baseURI is empty, \a queryURI is used.
Otherwise, \a baseURI is used, and it is resolved against the \l
{QCoreApplication::applicationFilePath()} {application file path} if
it is relative.
If \a queryURI is empty or invalid, or if \a baseURI is invalid,
the behavior of this function is undefined.
*/
void QXmlQuery::setQuery(const QUrl &queryURI, const QUrl &baseURI)
{
Q_ASSERT_X(queryURI.isValid(), Q_FUNC_INFO, "The passed URI must be valid.");
const QUrl canonicalURI(QPatternist::XPathHelper::normalizeQueryURI(queryURI));
Q_ASSERT(canonicalURI.isValid());
Q_ASSERT(!canonicalURI.isRelative());
Q_ASSERT(baseURI.isValid() || baseURI.isEmpty());
d->queryURI = QPatternist::XPathHelper::normalizeQueryURI(baseURI.isEmpty() ? queryURI : baseURI);
QPatternist::AutoPtr<QIODevice> result;
try
{
result.reset(QPatternist::AccelTreeResourceLoader::load(canonicalURI, d->m_networkAccessDelegator,
d->staticContext()));
}
catch(const QPatternist::Exception)
{
/* We do nothing, result will be 0. */
}
if(result)
{
setQuery(result.data(), d->queryURI);
result->close();
}
else
d->recompileRequired();
}
示例2: load
void QXmlSchemaPrivate::load(const QUrl &source, const QString &targetNamespace)
{
m_documentUri = QPatternist::XPathHelper::normalizeQueryURI(source);
m_schemaContext->setMessageHandler(messageHandler());
m_schemaContext->setUriResolver(uriResolver());
m_schemaContext->setNetworkAccessManager(networkAccessManager());
const QPatternist::AutoPtr<QNetworkReply> reply(QPatternist::AccelTreeResourceLoader::load(source, m_schemaContext->networkAccessManager(),
m_schemaContext, QPatternist::AccelTreeResourceLoader::ContinueOnError));
if (reply)
load(reply.data(), source, targetNamespace);
}
示例3: validate
/*!
Validates the XML instance document read from \a source against the schema.
Returns \c true if the XML instance document is valid according to the
schema, \c false otherwise.
Example:
\snippet qxmlschemavalidator/main.cpp 0
*/
bool QXmlSchemaValidator::validate(const QUrl &source) const
{
d->m_context->setMessageHandler(messageHandler());
d->m_context->setUriResolver(uriResolver());
d->m_context->setNetworkAccessManager(networkAccessManager());
const QPatternist::AutoPtr<QNetworkReply> reply(QPatternist::AccelTreeResourceLoader::load(source, d->m_context->networkAccessManager(),
d->m_context, QPatternist::AccelTreeResourceLoader::ContinueOnError));
if (reply)
return validate(reply.data(), source);
else
return false;
}
示例4: checkTestSuiteResult
void tst_SuiteTest::checkTestSuiteResult() const
{
if(m_abortRun)
QSKIP("This test takes too long time to run on the majority of platforms.", SkipAll);
typedef QList<QFileInfo> QFileInfoList;
const QFileInfo baseline(m_existingBaseline);
const QFileInfo result(m_candidateBaseline);
QFileInfoList list;
list.append(baseline);
list.append(result);
const QFileInfoList::const_iterator end(list.constEnd());
QEventLoop eventLoop;
const QPatternist::AutoPtr<Worker> worker(new Worker(eventLoop, m_existingBaseline, result));
/* Passed to ResultThreader so it knows what kind of file it is handling. */
ResultThreader::Type type = ResultThreader::Baseline;
QProcess::execute(QLatin1String("p4 edit ") + m_existingBaseline);
for(QFileInfoList::const_iterator it(list.constBegin()); it != end; ++it)
{
QFileInfo i(*it);
i.makeAbsolute();
QVERIFY2(i.exists(), qPrintable(QString::fromLatin1("File %1 does not exist.")
.arg(i.fileName())));
QFile *const file = new QFile(i.absoluteFilePath(), worker.data());
QVERIFY2(file->open(QIODevice::ReadOnly), qPrintable(QString::fromLatin1("Could not open file %1 for reading.")
.arg(i.fileName())));
ResultThreader *handler = new ResultThreader(eventLoop, file, type, worker.data());
QObject::connect(handler, SIGNAL(finished()), worker.data(), SLOT(threadFinished()));
handler->start(); /* Start the thread. It now parses the file
and emits threadFinished() when done. */
type = ResultThreader::Result;
}
const int exitCode = eventLoop.exec();
QProcess::execute(QLatin1String("p4 revert -a ") + m_existingBaseline);
QCOMPARE(exitCode, 0);
}
示例5: main
//.........这里部分代码省略.........
"also affected by the is-uris option."),
QVariant::String);
focus.setMinimumOccurrence(0);
focus.setNameless(true);
parser.addArgument(focus);
QApplicationArgument output(QLatin1String("output"),
QXmlPatternistCLI::tr("A local file to which the output should be written. "
"The file is overwritten, or if not exist, created. "
"If absent, stdout is used."),
qMetaTypeId<QIODevice *>());
parser.addArgument(output);
if(!parser.parse())
return parser.exitCode();
/* Get the query URI. */
const QUrl effectiveURI(finalizeURI(parser, isURI, queryURI));
QXmlQuery::QueryLanguage lang;
if(effectiveURI.toString().endsWith(QLatin1String(".xsl")))
lang = QXmlQuery::XSLT20;
else
lang = QXmlQuery::XQuery10;
if(lang == QXmlQuery::XQuery10 && parser.has(initialTemplateName))
{
parser.message(QXmlPatternistCLI::tr("An initial template name cannot be specified when running an XQuery."));
return QApplicationArgumentParser::ParseError;
}
QXmlQuery query(lang, namePool);
query.setInitialTemplateName(qvariant_cast<QXmlName>(parser.value(initialTemplateName)));
/* Bind external variables. */
{
const QVariantList parameters(parser.values(param));
const int len = parameters.count();
/* For tracking duplicates. */
QSet<QString> usedParameters;
for(int i = 0; i < len; ++i)
{
const Parameter p(qvariant_cast<Parameter>(parameters.at(i)));
if(usedParameters.contains(p.first))
{
parser.message(QXmlPatternistCLI::tr("Each parameter must be unique, %1 is specified at least twice.").arg(p.first));
return QApplicationArgumentParser::ParseError;
}
else
{
usedParameters.insert(p.first);
query.bindVariable(p.first, QXmlItem(p.second));
}
}
}
if(parser.has(focus))
{
if(!query.setFocus(finalizeURI(parser, isURI, focus)))
return QueryFailure;
}
else if(lang == QXmlQuery::XSLT20 && !parser.has(initialTemplateName))
{
parser.message(QXmlPatternistCLI::tr("When a stylesheet is used, a "
"document must be specified as a focus, or an "
"initial template name must be specified, or both."));
return QApplicationArgumentParser::ParseError;
}
query.setQuery(effectiveURI);
const QPatternist::AutoPtr<QIODevice> outDevice(qvariant_cast<QIODevice *>(parser.value(output)));
Q_ASSERT(outDevice);
Q_ASSERT(outDevice->isWritable());
if(query.isValid())
{
typedef QPatternist::AutoPtr<QAbstractXmlReceiver> RecPtr;
RecPtr receiver;
if(parser.has(noformat))
receiver = RecPtr(new QXmlSerializer(query, outDevice.data()));
else
receiver = RecPtr(new QXmlFormatter(query, outDevice.data()));
const bool success = query.evaluateTo(receiver.data());
if(success)
return parser.exitCode();
else
return QueryFailure;
}
else
return QueryFailure;
}