本文整理汇总了C++中KviKvsVariant::asString方法的典型用法代码示例。如果您正苦于以下问题:C++ KviKvsVariant::asString方法的具体用法?C++ KviKvsVariant::asString怎么用?C++ KviKvsVariant::asString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KviKvsVariant
的用法示例。
在下文中一共展示了KviKvsVariant::asString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: KviKvsHashElement
KviKvsRWEvaluationResult * KviKvsTreeNodeHashElement::evaluateReadWriteInObjectScope(KviKvsObject *o,KviKvsRunTimeContext * c)
{
KviKvsVariant key;
if(!m_pKey->evaluateReadOnly(c,&key))return 0;
QString szKey;
key.asString(szKey);
if(szKey.isEmpty())
{
c->warning(this,__tr2qs_ctx("Hash key evaluated to empty string: fix the script","kvs"));
}
KviKvsRWEvaluationResult * result;
if(o)result = m_pSource->evaluateReadWriteInObjectScope(o,c);
else result = m_pSource->evaluateReadWrite(c);
if(!result)return 0;
if(!result->result()->isHash())
{
// convert to hash in some way
//#warning "Supply a *real* conversion from other types to array ?"
if(!result->result()->isNothing())
{
QString szType;
result->result()->getTypeName(szType);
c->warning(this,__tr2qs_ctx("The argument of the {} subscript didn't evaluate to a hash: automatic conversion from %Q supplied","kvs"),&szType);
}
result->result()->setHash(new KviKvsHash());
}
return new KviKvsHashElement(result,result->result()->hash()->get(szKey),result->result()->hash(),szKey);
}
示例2: run
int KviKvsScript::run(KviWindow * pWnd, KviKvsVariantList * pParams, QString & szRetVal, int iRunFlags, KviKvsExtendedRunTimeData * pExtData)
{
KviKvsVariant retVal;
int iRet = run(pWnd, pParams, &retVal, iRunFlags, pExtData);
retVal.asString(szRetVal);
return iRet;
}
示例3: evaluateReadOnly
bool KviKvsTreeNodeMultipleParameterIdentifier::evaluateReadOnly(KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
{
KviKvsVariant * v = c->parameterList()->at(m_iStart);
if(!v)
{
pBuffer->setNothing();
return true;
}
QString sz;
v->asString(sz);
if(m_iEnd >= m_iStart)
{
// only up to m_iEnd
int idx = m_iStart;
for(v = c->parameterList()->next(); v && (idx < m_iEnd); v = c->parameterList()->next())
{
sz += QChar(' ');
v->appendAsString(sz);
idx++;
}
} else {
// all up to the end of the list
for(v = c->parameterList()->next(); v; v = c->parameterList()->next())
{
sz += QChar(' ');
v->appendAsString(sz);
}
}
pBuffer->setString(sz);
return true;
}
示例4: execute
bool KviKvsTreeNodeSpecialCommandSwitchLabelRegexp::execute(KviKvsRunTimeContext * c,KviKvsVariant * pRealParameter, bool * bPassThrough)
{
if(!(*bPassThrough))
{
KviKvsVariant v;
if(!m_pParameter->evaluateReadOnly(c,&v))return false;
QString reg;
v.asString(reg);
// QRegExp rx(reg,false,false);
QRegExp rx(reg,Qt::CaseInsensitive,QRegExp::RegExp);
QString val;
pRealParameter->asString(val);
if(!rx.exactMatch(val))return true; // no match
}
*bPassThrough = true;
if(m_pInstruction)
{
if(!m_pInstruction->execute(c))return false; // might be a break too
}
if(m_bHasTerminatingBreak)
{
c->setBreakPending();
return false;
}
return true;
}
示例5: urllist_module_event_onUrl
bool urllist_module_event_onUrl(KviKvsModuleEventCall * c)
{
KviKvsVariant * vUrl = c->firstParam();
QString szUrl;
if(vUrl)vUrl->asString(szUrl);
if (check_url(c->window(),szUrl) == 0)
{
KviUrl *tmp = new KviUrl;
QString tmpTimestamp;
QDate d = QDate::currentDate();
QString date;
date.sprintf("%d-%d%d-%d%d",d.year(),d.month() / 10,d.month() % 10,d.day() / 10,d.day() % 10);
tmpTimestamp = "["+date+"]"+" [";
tmpTimestamp += QTime::currentTime().toString()+"]";
tmp->url = szUrl;
tmp->window = c->window()->plainTextCaption();
tmp->count = 1;
tmp->timestamp = tmpTimestamp;
g_pList->append(tmp);
for (UrlDlgList *tmpitem=g_pUrlDlgList->first();tmpitem;tmpitem=g_pUrlDlgList->next()) {
if (tmpitem->dlg) {
QString tmpCount;
tmpCount.setNum(tmp->count);
tmpitem->dlg->addUrl(QString(tmp->url), QString(tmp->window), tmpCount, QString(tmp->timestamp));
tmpitem->dlg->windowListItem()->highlight(false);
}
}
}
return true;
}
示例6: nextAsString
bool KviKvsVariantList::nextAsString(QString & szBuffer)
{
KviKvsVariant * v = next();
if(!v)
return false;
v->asString(szBuffer);
return true;
}
示例7: evaluateAsString
int KviKvsScript::evaluateAsString(const QString & szCode, KviWindow * pWindow, KviKvsVariantList * pParams, QString & szRetVal)
{
// static helper
KviKvsVariant ret;
KviKvsScript s("kvirc::corecall(evaluate)", szCode, Parameter);
int iRet = s.run(pWindow, pParams, &ret, PreserveParams);
ret.asString(szRetVal);
return iRet;
}
示例8: getDefaultLogFileName
void KviWindow::getDefaultLogFileName(QString & szBuffer, QDate date, bool bGzip, unsigned int uDatetimeFormat)
{
QString szLog;
// dynamic log path
QString szDynamicPath = KVI_OPTION_STRING(KviOption_stringLogsDynamicPath).trimmed();
if(!szDynamicPath.isEmpty())
{
KviQString::escapeKvs(&szDynamicPath, KviQString::PermitVariables | KviQString::PermitFunctions);
KviKvsVariant vRet;
if(KviKvsScript::evaluate(szDynamicPath, this, nullptr, &vRet))
vRet.asString(szDynamicPath);
}
g_pApp->getLocalKvircDirectory(szLog, KviApplication::Log, szDynamicPath);
KviQString::ensureLastCharIs(szLog, KVI_PATH_SEPARATOR_CHAR);
//ensure the directory exists
KviFileUtils::makeDir(szLog);
QString szDate;
switch(uDatetimeFormat)
{
case 1:
szDate = date.toString(Qt::ISODate);
break;
case 2:
szDate = date.toString(Qt::SystemLocaleShortDate);
break;
case 0:
default:
szDate = date.toString("yyyy.MM.dd");
break;
}
szDate.replace('_', '-'); // this would confuse the log viewer
KviFileUtils::cleanFileName(szDate);
QString szBase;
getBaseLogFileName(szBase);
KviFileUtils::encodeFileName(szBase);
szBase = szBase.toLower();
szBase.replace("%%2e", "%2e");
QString szTmp;
if(bGzip)
szTmp = "%1_%2_%3.log.gz";
else
szTmp = "%1_%2_%3.log";
szLog.append(QString(szTmp).arg(typeString(), szBase, szDate));
szBuffer = szLog;
}
示例9: theme_kvs_cmd_pack
static bool theme_kvs_cmd_pack(KviKvsModuleCommandCall * c)
{
QString szPath, szName, szVersion, szDescription, szAuthor, szImage;
KviKvsArrayCast aCast;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("package_path", KVS_PT_NONEMPTYSTRING, 0, szPath)
KVSM_PARAMETER("package_name", KVS_PT_NONEMPTYSTRING, 0, szName)
KVSM_PARAMETER("package_version", KVS_PT_NONEMPTYSTRING, 0, szVersion)
KVSM_PARAMETER("package_description", KVS_PT_STRING, 0, szDescription)
KVSM_PARAMETER("package_author", KVS_PT_NONEMPTYSTRING, 0, szAuthor)
KVSM_PARAMETER("package_image", KVS_PT_STRING, 0, szImage)
KVSM_PARAMETER("theme", KVS_PT_ARRAYCAST, 0, aCast)
KVSM_PARAMETERS_END(c)
KviKvsArray * pArray = aCast.array();
if((!pArray) || (pArray->size() < 1))
{
c->error(__tr2qs_ctx("No themes specified", "theme"));
return false;
}
kvs_uint_t s = pArray->size();
QStringList lThemeList;
for(kvs_uint_t i = 0; i < s; i++)
{
KviKvsVariant * v = pArray->at(i);
if(!v)
continue; // ?
QString szVal;
v->asString(szVal);
if(szVal.isEmpty())
continue;
lThemeList.append(szVal);
}
KviPointerList<KviThemeInfo> lThemeInfoList;
lThemeInfoList.setAutoDelete(true);
Q_FOREACH(QString szTheme, lThemeList)
{
KviThemeInfo * pInfo = new KviThemeInfo();
if(!pInfo->load(szTheme, KviThemeInfo::External))
{
QString szErr = pInfo->lastError();
c->error(__tr2qs_ctx("Failed to load theme from directory %Q: %Q", "theme"), &szTheme, &szErr);
delete pInfo;
return false;
}
lThemeInfoList.append(pInfo);
}
示例10: execute
bool KviKvsTreeNodeSpecialCommandDefpopup::execute(KviKvsRunTimeContext * c)
{
KviKvsVariant v;
if(!m_pPopupName->evaluateReadOnly(c,&v))return false;
QString szName;
v.asString(szName);
KviKvsSwitchList swl;
if(m_pSwitches)
{
if(!(m_pSwitches->evaluate(c,&swl)))return false;
}
KviKvsPopupMenu * pPopup = KviKvsPopupManager::instance()->lookup(szName);
bool bWasAlreadyThere;
if(!pPopup)
{
if(m_pMainPopup->isEmpty())return true; // we wanted to remove it anyway: exit silently
// we want to create it
pPopup = new KviKvsPopupMenu(szName);
KviKvsPopupManager::instance()->add(szName,pPopup);
bWasAlreadyThere = false;
} else {
bWasAlreadyThere = true;
if(pPopup->isHardLocked())
{
c->error(__tr2qs_ctx("The popup '%s' is actually locked: 'self-modifications' are not allowed","kvs"),&szName);
return false;
}
if(m_pMainPopup->isEmpty())
{
// we want to remove it
KviKvsPopupManager::instance()->remove(szName);
return true;
}
// we want to (re)create it
if(!swl.find('m',"--merge"))pPopup->doClear();
}
if(!m_pMainPopup->fill(c,pPopup))
{
if(!bWasAlreadyThere)KviKvsPopupManager::instance()->remove(szName);
return false;
}
KviKvsPopupManager::instance()->emitRefresh(szName);
return true;
}
示例11: evaluateReadOnlyInObjectScope
bool KviKvsTreeNodeHashElement::evaluateReadOnlyInObjectScope(KviKvsObject *o,KviKvsRunTimeContext * c,KviKvsVariant * pBuffer)
{
KviKvsVariant key;
if(!m_pKey->evaluateReadOnly(c,&key))return false;
QString szKey;
key.asString(szKey);
if(szKey.isEmpty())
{
c->warning(this,__tr2qs_ctx("Hash key evaluated to empty string: fix the script","kvs"));
pBuffer->setNothing();
return true;
}
KviKvsVariant val;
if(o)
{
if(!m_pSource->evaluateReadOnlyInObjectScope(o,c,&val))return false;
} else {
if(!m_pSource->evaluateReadOnly(c,&val))return false;
}
if(!val.isHash())
{
if(!val.isNothing())
{
QString szType;
val.getTypeName(szType);
c->warning(this,__tr2qs_ctx("The argument of the {} subscript didn't evaluate to a hash: automatic conversion from type '%Q' supplied","kvs"),&szType);
}
pBuffer->setNothing();
return true;
}
KviKvsVariant * v = val.hash()->find(szKey);
if(!v)
{
pBuffer->setNothing();
return true;
}
pBuffer->copyFrom(v);
return true;
}
示例12: process
bool process(KviKvsVariantList * pVariantList, KviKvsRunTimeContext * pContext, KviKvsParameterProcessor::ParameterFormat * pFmtArray)
{
KviKvsVariant * v = pVariantList->first();
while(pFmtArray->szName)
{
if(!v)
{
// parameter not present
// it MUST be optional
if(!(pFmtArray->uFlags & KVS_PF_OPTIONAL))
{
// bad luck
QString szError = QString(__tr2qs_ctx("Missing non-optional parameter \"%1\"", "kvs")).arg(pFmtArray->szName);
pContext->error(szError);
return false;
}
// ok, missing but optional (all the following are implicitly optional too)
// set to default values
do
{
setDefaultValue(pFmtArray);
pFmtArray++;
} while(pFmtArray->szName);
return true;
}
// here we do only "light" casts: hard ones must be done explicitly by the user
switch(pFmtArray->uType)
{
case KVS_PT_STRING:
v->asString(*((QString *)(pFmtArray->pContainer)));
if(pFmtArray->uFlags & KVS_PF_APPENDREMAINING)
{
v = pVariantList->next();
while(v)
{
*((QString *)(pFmtArray->pContainer)) += QChar(' ');
v->appendAsString(*((QString *)(pFmtArray->pContainer)));
v = pVariantList->next();
}
return true;
}
break;
case KVS_PT_STRINGLIST:
{
((QStringList *)(pFmtArray->pContainer))->clear();
QString pSz;
v->asString(pSz);
((QStringList *)(pFmtArray->pContainer))->append(pSz);
v = pVariantList->next();
while(v)
{
v->asString(pSz);
((QStringList *)(pFmtArray->pContainer))->append(pSz);
v = pVariantList->next();
}
return true;
}
break;
case KVS_PT_VARIANTLIST:
{
((KviKvsVariantList *)(pFmtArray->pContainer))->clear();
((KviKvsVariantList *)(pFmtArray->pContainer))->setAutoDelete(false);
((KviKvsVariantList *)(pFmtArray->pContainer))->append(v);
v = pVariantList->next();
while(v)
{
((KviKvsVariantList *)(pFmtArray->pContainer))->append(v);
v = pVariantList->next();
}
return true;
}
break;
case KVS_PT_NONEMPTYSTRING:
{
v->asString(*((QString *)(pFmtArray->pContainer)));
bool bDoReturn = false;
if(pFmtArray->uFlags & KVS_PF_APPENDREMAINING)
{
v = pVariantList->next();
while(v)
{
*((QString *)(pFmtArray->pContainer)) += QChar(' ');
v->appendAsString(*((QString *)(pFmtArray->pContainer)));
v = pVariantList->next();
}
bDoReturn = true;
}
if(((QString *)(pFmtArray->pContainer))->isEmpty())
{
QString szError = QString(__tr2qs_ctx("Invalid data type for parameter \"%1\": found empty string while a non empty one was expected", "kvs")).arg(pFmtArray->szName);
pContext->error(szError);
return false;
}
if(bDoReturn)
return true;
}
break;
case KVS_PT_CSTRING:
{
//.........这里部分代码省略.........
示例13: handler
KVSO_CLASS_FUNCTION(xmlReader, parse)
{
KviKvsVariant * pVariantData;
KVSO_PARAMETERS_BEGIN(c)
KVSO_PARAMETER("string_or_memorybuffer_object", KVS_PT_VARIANT, 0, pVariantData)
KVSO_PARAMETERS_END(c)
#ifdef QT_NO_XML
fatalError(__tr2qs_ctx("XML support not available in the Qt library"));
c->returnValue()->setBoolean(false);
#else
m_szLastError = "";
KviXmlHandler handler(this);
QXmlInputSource source;
if(pVariantData->isHObject())
{
KviKvsObject * pObject;
kvs_hobject_t hObject;
pVariantData->asHObject(hObject);
pObject = KviKvsKernel::instance()->objectController()->lookupObject(hObject);
if(!pObject)
{
c->warning(__tr2qs_ctx("Data parameter is not an object", "objects"));
return true;
}
if(pObject->inheritsClass("memorybuffer"))
{
source.setData(*((KvsObject_memoryBuffer *)pObject)->pBuffer());
}
else
{
c->warning(__tr2qs_ctx("Data parameter is not a memorybuffer object", "objects"));
return true;
}
}
else if(pVariantData->isString())
{
QString szString;
pVariantData->asString(szString);
// We have a problem here.. most kvirc functions already interpret the data
// read from files. We should have binary data handling features to get this to work correctly.
// The following snippet of code tries to provide a best-effort workaround.
QByteArray utf8data = szString.toUtf8();
QByteArray data = utf8data;
data.truncate(utf8data.length()); // don't include the null terminator in data
source.setData(data);
//qDebug("PARSING(%s) LEN(%d)",szString.toUtf8().data(),szString.toUtf8().length());
}
else
{
c->warning(__tr2qs_ctx("Data is not a memorybuffer object or string", "objects"));
return true;
}
QXmlSimpleReader reader;
reader.setContentHandler(&handler);
reader.setErrorHandler(&handler);
c->returnValue()->setBoolean(reader.parse(source));
#endif
return true;
}
示例14: perl_kvs_cmd_begin
static bool perl_kvs_cmd_begin(KviKvsModuleCommandCall * c)
{
// This command is somewhat special in the fact that has a dedicated
// parsing routine in the KVS core parser.
// The parser sets the perl code as the first parameter of our call,
// the remaining params are the context name and the arguments
QString szCode,szContext;
KviKvsVariantList vList;
KVSM_PARAMETERS_BEGIN(c)
KVSM_PARAMETER("code",KVS_PT_STRING,0,szCode)
KVSM_PARAMETER("context",KVS_PT_STRING,KVS_PF_OPTIONAL,szContext)
KVSM_PARAMETER("args",KVS_PT_VARIANTLIST,KVS_PF_OPTIONAL,vList)
KVSM_PARAMETERS_END(c)
KVS_CHECK_MODULE_STATE(m,c)
#ifdef COMPILE_PERL_SUPPORT
KviPerlCoreCtrlCommand_execute ex;
ex.uSize = sizeof(KviPerlCoreCtrlCommand_execute);
ex.pKvsContext = c->context();
ex.szContext = szContext;
ex.szCode = szCode;
for(KviKvsVariant * v = vList.first();v;v = vList.next())
{
QString tmp;
v->asString(tmp);
ex.lArgs.append(tmp);
}
ex.bQuiet = c->switches()->find('q',"quiet");
if(!g_pPerlCoreModule->ctrl(KVI_PERLCORECTRLCOMMAND_EXECUTE,&ex))
{
if(!c->switches()->find('q',"quiet"))
c->warning(__tr2qs_ctx("The perlcore module failed to execute the code: something is wrong with the perl support","perl"));
return true;
}
if(!ex.lWarnings.isEmpty())
{
for(QStringList::Iterator it = ex.lWarnings.begin();it != ex.lWarnings.end();++it)
c->warning(*it);
}
if(!ex.bExitOk)
{
if(!c->switches()->find('q',"quiet"))
{
if(c->switches()->find('f',"fail-on-error"))
{
c->warning(__tr2qs_ctx("Perl execution error:","perl"));
c->warning(ex.szError);
return false;
} else {
c->warning(__tr2qs_ctx("Perl execution error:","perl"));
c->error(ex.szError);
}
}
}
if(!c->switches()->find('n',"no-return"))
c->context()->returnValue()->setString(ex.szRetVal);
#endif //COMPILE_PERL_SUPPORT
return true;
}
示例15: execute
bool KviKvsTreeNodeSpecialCommandClass::execute(KviKvsRunTimeContext * c)
{
KviKvsVariantList l;
if(!m_pParams->evaluate(c,&l))return false;
KviKvsVariant * pClassName = l.first();
if(!pClassName)
{
c->error(this,__tr2qs_ctx("Missing class name","kvs"));
return false;
}
KviKvsVariant * pBaseClassName = l.next();
QString szClassName;
QString szBaseClassName;
pClassName->asString(szClassName);
QRegExp re("[\\w:]+");
if(!re.exactMatch(szClassName))
{
c->error(this,__tr2qs_ctx("Class names can contain only letters, digits, underscores and '::' namespace separators","kvs"));
return false;
}
if(pBaseClassName)
pBaseClassName->asString(szBaseClassName);
if(szClassName.isEmpty())
{
c->error(this,__tr2qs_ctx("Missing class name","kvs"));
return false;
}
if(szBaseClassName.isEmpty())szBaseClassName = "object";
// avoid infinite recursion in loading the base class
if(KviQString::equalCI(szBaseClassName,szClassName))
{
c->error(__tr2qs_ctx("A class can't be a subclass of itself","kvs"));
return false;
}
KviKvsObjectClass * pBaseClass = KviKvsKernel::instance()->objectController()->lookupClass(szBaseClassName);
if(!pBaseClass)
{
c->error(this,__tr2qs_ctx("Couln't find base class named '%Q'","kvs"),&szBaseClassName);
return false;
}
// walk the inheritance tree of the base class in order to detect loops
KviKvsObjectClass * pClass = pBaseClass;
while(pClass)
{
if(KviQString::equalCI(pClass->name(),szClassName))
{
c->error(this,__tr2qs_ctx("Detected a loop in the inheritance tree of the base class '%Q': redefine that class first","kvs"),&szBaseClassName);
return false;
}
pClass = pClass->parentClass();
}
KviKvsObjectClass * pActualClass = KviKvsKernel::instance()->objectController()->lookupClass(szClassName,true);
if(pActualClass)
{
c->error(this,__tr2qs_ctx("Can't override the builtin class '%Q'","kvs"),&szClassName);
return false;
}
pActualClass = new KviKvsObjectClass(pBaseClass,szClassName,0,false);
for(KviKvsTreeNodeSpecialCommandClassFunctionDefinition * d = m_pFunctions->first();d;d = m_pFunctions->next())
{
pActualClass->registerFunctionHandler(d->name(),d->buffer(),d->reminder(),d->handlerFlags());
}
return true;
}