本文整理汇总了C++中KstScalarPtr::writeLock方法的典型用法代码示例。如果您正苦于以下问题:C++ KstScalarPtr::writeLock方法的具体用法?C++ KstScalarPtr::writeLock怎么用?C++ KstScalarPtr::writeLock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KstScalarPtr
的用法示例。
在下文中一共展示了KstScalarPtr::writeLock方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createFitScalars
// FIXME: KstPlugin should not know about fit scalars!!
void KstPlugin::createFitScalars() {
if (_plugin->data()._isFit && _outputVectors.contains("Parameters")) {
KstVectorPtr vectorParam = _outputVectors["Parameters"];
if (vectorParam) {
QString paramName;
int i = 0;
int length = vectorParam->length();
for (paramName = _plugin->parameterName(i);
!paramName.isEmpty() && i < length;
paramName = _plugin->parameterName(++i)) {
double scalarValue = vectorParam->value(i);
if (!_outputScalars.contains(paramName)) {
QString scalarName = i18n("%1-%2").arg(tagName()).arg(paramName);
KstScalarPtr s = new KstScalar(scalarName, scalarValue);
s->writeLock();
s->setProvider(this);
s->writeUnlock();
_outputScalars.insert(paramName, s);
} else {
_outputScalars[paramName]->setValue(scalarValue);
}
}
}
}
}
示例2: makeDuplicate
KstDataObjectPtr KstPlugin::makeDuplicate(KstDataObjectDataObjectMap& duplicatedMap) {
KstPluginPtr plugin = new KstPlugin;
// use same inputs
for (KstVectorMap::ConstIterator iter = _inputVectors.begin(); iter != _inputVectors.end(); ++iter) {
plugin->inputVectors().insert(iter.key(), iter.data());
}
for (KstScalarMap::ConstIterator iter = _inputScalars.begin(); iter != _inputScalars.end(); ++iter) {
plugin->inputScalars().insert(iter.key(), iter.data());
}
for (KstStringMap::ConstIterator iter = _inputStrings.begin(); iter != _inputStrings.end(); ++iter) {
plugin->inputStrings().insert(iter.key(), iter.data());
}
// create new outputs
for (KstVectorMap::ConstIterator iter = outputVectors().begin(); iter != outputVectors().end(); ++iter) {
KstVectorPtr v = new KstVector;
v->writeLock();
plugin->outputVectors().insert(iter.key(), v);
v->setTagName(iter.data()->tagName() + "'");
v->setProvider(plugin.data());
KST::addVectorToList(v);
v->writeUnlock();
}
for (KstScalarMap::ConstIterator iter = outputScalars().begin(); iter != outputScalars().end(); ++iter) {
KstScalarPtr s = new KstScalar;
s->writeLock();
plugin->outputScalars().insert(iter.key(), s);
s->setTagName(iter.data()->tagName() + "'");
s->setProvider(plugin.data());
s->writeUnlock();
}
for (KstStringMap::ConstIterator iter = outputStrings().begin(); iter != outputStrings().end(); ++iter) {
KstStringPtr s = new KstString;
s->writeLock();
plugin->outputStrings().insert(iter.key(), s);
s->setTagName(iter.data()->tagName() + "'");
s->setProvider(plugin.data());
s->writeUnlock();
}
// set the same plugin
plugin->setPlugin(_plugin);
plugin->setTagName(tagName() + "'");
duplicatedMap.insert(this, KstDataObjectPtr(plugin));
return KstDataObjectPtr(plugin);
}
示例3: doUpdates
bool UpdateThread::doUpdates(bool force, bool *gotData) {
KstObject::UpdateType U = KstObject::NO_CHANGE;
_updatedCurves.clear(); // HACK
if (gotData) {
*gotData = false;
}
#if UPDATEDEBUG > 0
if (force) {
qDebug() << "Forced update!" << endl;
}
#endif
_updateCounter++;
if (_updateCounter < 1) {
_updateCounter = 1; // check for wrap around
}
#if UPDATEDEBUG > 2
qDebug() << "UPDATE: counter=" << _updateCounter << endl;
#endif
{
// Must make a copy to avoid deadlock
KstBaseCurveList cl;
KstDataObjectList dol;
kstObjectSplitList<KstDataObject, KstBaseCurve>(KST::dataObjectList, cl, dol);
qSort(cl);
qSort(dol);
// Update all curves
for (uint i = 0; i < cl.count(); ++i) {
KstBaseCurvePtr bcp = cl[i];
bcp->writeLock();
assert(bcp.data());
#if UPDATEDEBUG > 1
qDebug() << "updating curve: " << (void*)bcp << " - " << bcp->tagName() << endl;
#endif
KstObject::UpdateType ut = bcp->update(_updateCounter);
bcp->unlock();
if (ut == KstObject::UPDATE) { // HACK
_updatedCurves.append(bcp);
}
if (U != KstObject::UPDATE) {
U = ut;
if (U == KstObject::UPDATE) {
#if UPDATEDEBUG > 0
qDebug() << "Curve " << bcp->tagName() << " said UPDATE" << endl;
#endif
}
}
if (_done || (_paused && !force)) {
#if UPDATEDEBUG > 1
qDebug() << "5 Returning from scan with U=" << (int)U << endl;
#endif
return U == KstObject::UPDATE;
}
}
// Update all data objects
for (uint i = 0; i < dol.count(); ++i) {
KstDataObjectPtr dp = dol[i];
dp->writeLock();
assert(dp.data());
#if UPDATEDEBUG > 1
qDebug() << "updating data object: " << (void*)dp << " - " << dp->tagName() << endl;
#endif
dp->update(_updateCounter);
dp->unlock();
if (_done || (_paused && !force)) {
#if UPDATEDEBUG > 1
qDebug() << "5 Returning from scan with U=" << (int)U << endl;
#endif
return U == KstObject::UPDATE;
}
}
}
// Update the files
if (!_paused) { // don't update even if paused && force
KST::dataSourceList.lock().readLock();
unsigned cnt = KST::dataSourceList.count();
for (uint i = 0; i < cnt; ++i) {
KstDataSourcePtr dsp = KST::dataSourceList[i];
dsp->writeLock();
dsp->update(_updateCounter);
dsp->unlock();
if (_done) {
KST::dataSourceList.lock().unlock();
return false;
}
}
//.........这里部分代码省略.........
示例4: saveOutputs
bool KstPluginDialogI::saveOutputs(KstCPluginPtr plugin, KstSharedPtr<Plugin> p) {
const QValueList<Plugin::Data::IOValue>& otable = p->data()._outputs;
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin(); it != otable.end(); ++it) {
QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "QLineEdit");
if (!field) {
continue; // Some are unsupported
}
QLineEdit *li = static_cast<QLineEdit*>(field);
if (li->text().isEmpty()) {
QString tagName = _tagName->text();
if (tagName==plugin_defaultTag) {
tagName = plugin->tagName();
}
li->setText(tagName + "-" + (*it)._name);
}
QString nt = li->text();
if ((*it)._type == Plugin::Data::IOValue::TableType) {
if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
// Implicitly creates it if it doesn't exist
KstVectorPtr v = plugin->outputVectors()[(*it)._name];
if (!v) {
v = new KstVector(nt, 0, plugin.data());
v->writeLock();
plugin->outputVectors().insert((*it)._name, v);
KST::addVectorToList(v);
}
} else if (plugin->outputVectors()[(*it)._name]->tagName() != nt) {
while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
nt += "'";
}
KstVectorPtr v;
if (plugin->outputVectors().contains((*it)._name)) {
v = plugin->outputVectors()[(*it)._name];
} else {
v = new KstVector(nt, 0, plugin.data());
v->writeLock();
plugin->outputVectors().insert((*it)._name, v);
KST::addVectorToList(v);
}
}
} else if ((*it)._type == Plugin::Data::IOValue::StringType) {
if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
KstStringPtr s;
if (plugin->outputStrings().contains((*it)._name)) {
s = plugin->outputStrings()[(*it)._name];
} else {
s = new KstString(nt, plugin.data());
s->writeLock();
plugin->outputStrings().insert((*it)._name, s);
}
} else if (plugin->outputStrings()[(*it)._name]->tagName() != nt) {
while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
nt += "'";
}
KstStringPtr s;
if (plugin->outputStrings().contains((*it)._name)) {
s = plugin->outputStrings()[(*it)._name];
} else {
s = new KstString(nt, plugin.data());
s->writeLock();
plugin->outputStrings().insert((*it)._name, s);
}
}
} else if ((*it)._type == Plugin::Data::IOValue::PidType) {
// Nothing
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
if (!KstData::self()->vectorTagNameNotUnique(nt, false)) {
KstScalarPtr s;
if (plugin->outputScalars().contains((*it)._name)) {
s = plugin->outputScalars()[(*it)._name];
} else {
s = new KstScalar(nt, plugin.data());
s->writeLock();
plugin->outputScalars().insert((*it)._name, s);
}
} else if (plugin->outputScalars()[(*it)._name]->tagName() != nt) {
while (KstData::self()->vectorTagNameNotUnique(nt, false)) {
nt += "'";
}
KstScalarPtr s;
if (plugin->outputScalars().contains((*it)._name)) {
s = plugin->outputScalars()[(*it)._name];
} else {
s = new KstScalar(nt, plugin.data());
s->writeLock();
plugin->outputScalars().insert((*it)._name, s);
}
}
}
}
return true;
}
示例5: saveInputs
bool KstPluginDialogI::saveInputs(KstCPluginPtr plugin, KstSharedPtr<Plugin> p) {
bool rc = true;
KST::vectorList.lock().readLock();
KST::scalarList.lock().readLock();
KST::stringList.lock().readLock();
const QValueList<Plugin::Data::IOValue>& itable = p->data()._inputs;
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = itable.begin(); it != itable.end(); ++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "VectorSelector");
assert(field);
VectorSelector *vs = static_cast<VectorSelector*>(field);
KstVectorPtr v = *KST::vectorList.findTag(vs->selectedVector());
if (v) {
v->writeLock(); // to match with plugin->writeLock()
if (plugin->inputVectors().contains((*it)._name) && plugin->inputVectors()[(*it)._name] != v) {
plugin->inputVectors()[(*it)._name]->unlock();
}
plugin->inputVectors().insert((*it)._name, v);
} else if (plugin->inputVectors().contains((*it)._name)) {
plugin->inputVectors().erase((*it)._name);
rc = false;
}
} else if ((*it)._type == Plugin::Data::IOValue::StringType) {
QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "StringSelector");
assert(field);
StringSelector *ss = static_cast<StringSelector*>(field);
KstStringPtr s = *KST::stringList.findTag(ss->selectedString());
if (s == *KST::stringList.end()) {
QString val = ss->_string->currentText();
KstStringPtr newString = new KstString(ss->_string->currentText(), 0L, val, true, false);
newString->writeLock(); // to match with plugin->writeLock()
if (plugin->inputStrings().contains((*it)._name) && plugin->inputStrings()[(*it)._name] != s) {
plugin->inputStrings()[(*it)._name]->unlock();
}
plugin->inputStrings().insert((*it)._name, newString);
} else {
s->writeLock(); // to match with plugin->writeLock()
if (plugin->inputStrings().contains((*it)._name) && plugin->inputStrings()[(*it)._name] != s) {
plugin->inputStrings()[(*it)._name]->unlock();
}
plugin->inputStrings().insert((*it)._name, s);
}
} else if ((*it)._type == Plugin::Data::IOValue::PidType) {
// Nothing
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
QObject *field = _w->_pluginInputOutputFrame->child((*it)._name.latin1(), "ScalarSelector");
assert(field);
ScalarSelector *ss = static_cast<ScalarSelector*>(field);
KstScalarPtr s = *KST::scalarList.findTag(ss->selectedScalar());
if (s == *KST::scalarList.end()) {
bool ok;
double val = ss->_scalar->currentText().toDouble(&ok);
if (ok) {
KstScalarPtr newScalar = new KstScalar(ss->_scalar->currentText(), 0L, val, true, false, false);
newScalar->writeLock(); // to match with plugin->writeLock()
if (plugin->inputScalars().contains((*it)._name) && plugin->inputScalars()[(*it)._name] != s) {
plugin->inputScalars()[(*it)._name]->unlock();
}
plugin->inputScalars().insert((*it)._name, newScalar);
} else {
s->writeLock(); // to match with plugin->writeLock()
if (plugin->inputScalars().contains((*it)._name) && plugin->inputScalars()[(*it)._name] != s) {
plugin->inputScalars()[(*it)._name]->unlock();
}
plugin->inputScalars().insert((*it)._name, s);
}
} else {
s->writeLock(); // to match with plugin->writeLock()
if (plugin->inputScalars().contains((*it)._name) && plugin->inputScalars()[(*it)._name] != s) {
plugin->inputScalars()[(*it)._name]->unlock();
}
plugin->inputScalars().insert((*it)._name, s);
}
} else {
}
}
KST::stringList.lock().unlock();
KST::scalarList.lock().unlock();
KST::vectorList.lock().unlock();
return rc;
}
示例6: setPlugin
bool KstPlugin::setPlugin(KstSharedPtr<Plugin> plugin) {
// Assumes that this is called with a write lock in place on this object
if (plugin == _plugin) {
return true;
}
freeParameters();
if (_localData) {
if (!_plugin || !_plugin->freeLocalData(&_localData)) {
free(_localData);
}
_localData = 0L;
}
if (!plugin) {
_inputVectors.clear();
_inputScalars.clear();
_inputStrings.clear();
_outputVectors.clear();
_outputScalars.clear();
_outputStrings.clear();
_plugin = 0L;
return true;
}
Plugin::countScalarsVectorsAndStrings(plugin->data()._inputs, _inScalarCnt, _inArrayCnt, _inStringCnt, _inPid);
if (_inputVectors.count() != _inArrayCnt ||
_inputScalars.count() != _inScalarCnt - _inPid ||
_inputStrings.count() != _inStringCnt) {
_plugin = 0L;
return false;
}
_outScalarCnt = 0;
_outArrayCnt = 0;
_outStringCnt = 0;
_outputVectors.clear();
_outputScalars.clear();
_outputStrings.clear();
const QValueList<Plugin::Data::IOValue>& otable = plugin->data()._outputs;
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin();
it != otable.end();
++it) {
if ((*it)._type == Plugin::Data::IOValue::TableType) {
KstVectorPtr v;
if ((*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) {
v = new KstVector(QString::null, 0, true);
} else {
v = new KstVector;
}
v->writeLock();
v->setProvider(this);
_outputVectors.insert((*it)._name, v);
_outArrayCnt++;
KST::addVectorToList(v);
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
KstScalarPtr s = new KstScalar;
s->writeLock();
s->setProvider(this);
_outputScalars.insert((*it)._name, s);
_outScalarCnt++;
} else if ((*it)._type == Plugin::Data::IOValue::StringType) {
KstStringPtr s = new KstString;
s->writeLock();
s->setProvider(this);
_outputStrings.insert((*it)._name, s);
_outStringCnt++;
}
}
allocateParameters();
_plugin = plugin;
return true;
}
示例7: KstDataObject
KstPlugin::KstPlugin(const QDomElement& e)
: KstDataObject(e) {
QString pluginName;
_inStringCnt = 0;
_outStringCnt = 0;
commonConstructor();
QDomNode n = e.firstChild();
while (!n.isNull()) {
QDomElement e = n.toElement();
if (!e.isNull()) {
if (e.tagName() == "tag") {
setTagName(e.text());
} else if (e.tagName() == "name") {
pluginName = e.text();
} else if (e.tagName() == "ivector") {
_inputVectorLoadQueue.append(qMakePair(e.attribute("name"), e.text()));
} else if (e.tagName() == "iscalar") {
_inputScalarLoadQueue.append(qMakePair(e.attribute("name"), e.text()));
} else if (e.tagName() == "istring") {
_inputStringLoadQueue.append(qMakePair(e.attribute("name"), e.text()));
} else if (e.tagName() == "ovector") {
KstVectorPtr v;
if (e.attribute("scalarList", "0").toInt()) {
v = new KstVector(e.text(), 0, true);
} else {
v = new KstVector(e.text(), 0, false);
}
v->setProvider(this);
_outputVectors.insert(e.attribute("name"), v);
KST::addVectorToList(v);
} else if (e.tagName() == "oscalar") {
KstScalarPtr sp = new KstScalar(e.text());
sp->writeLock();
sp->setProvider(this);
sp->writeUnlock();
_outputScalars.insert(e.attribute("name"), sp);
} else if (e.tagName() == "ostring") {
KstStringPtr sp = new KstString(e.text());
sp->writeLock();
sp->setProvider(this);
sp->writeUnlock();
_outputStrings.insert(e.attribute("name"), sp);
}
}
n = n.nextSibling();
}
_plugin = PluginCollection::self()->plugin(pluginName);
if (!_plugin.data()) {
KstDebug::self()->log(i18n("Unable to load plugin %1 for \"%2\".").arg(pluginName).arg(tagName()), KstDebug::Warning);
} else {
Plugin::countScalarsVectorsAndStrings(_plugin->data()._inputs, _inScalarCnt, _inArrayCnt, _inStringCnt, _inPid);
const QValueList<Plugin::Data::IOValue>& otable = _plugin->data()._outputs;
for (QValueList<Plugin::Data::IOValue>::ConstIterator it = otable.begin();
it != otable.end();
++it) {
// FIXME: i18n?
if ((*it)._type == Plugin::Data::IOValue::TableType) {
_outArrayCnt++;
if (!_outputVectors.contains((*it)._name)) {
KstVectorPtr v;
if ((*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) {
v = new KstVector(tagName() + " vector - " + (*it)._name, 0, true);
} else {
v = new KstVector(tagName() + " vector - " + (*it)._name, 0, false);
}
v->setProvider(this);
_outputVectors.insert((*it)._name, v);
KST::addVectorToList(v);
}
} else if ((*it)._type == Plugin::Data::IOValue::MatrixType) {
abort(); // FIXME:
#if 0
_outArrayCnt += 2;
if (!_outputMatrices.contains((*it)._name)) {
KstMatrixPtr m;
if ((*it)._subType == Plugin::Data::IOValue::FloatNonVectorSubType) {
m = new KstMatrix(tagName() + " matrix - " + (*it)._name, 0, true);
} else {
m = new KstMatrix(tagName() + " matrix - " + (*it)._name, 0, false);
}
m->setProvider(this);
_outputMatrices.insert((*it)._name, m);
KST::addVectorToList(v);
}
#endif
} else if ((*it)._type == Plugin::Data::IOValue::FloatType) {
_outScalarCnt++;
if (!_outputScalars.contains((*it)._name)) {
KstScalarPtr s = new KstScalar(tagName() + " scalar - " + (*it)._name);
s->writeLock();
s->setProvider(this);
s->writeUnlock();
//.........这里部分代码省略.........