//------------------------------------------------ RandRangeFloat::RandRangeFloat( const std::string& str ) { float min = 0; float max = 0; std::vector< std::string > tokens; stringTokenizer( str, tokens, "~" ); if( tokens.size() == 1 ) { float count = 0; stringToType( tokens[0], &count ); min = count; max = count; } else if( tokens.size() == 2 ) { if( !stringToType( tokens[0], &min ) ) { min = 0; } if( !stringToType( tokens[1], &max ) ) { max = 0; } } assertion( min <= max, "Min value: %f is not less than max value: %f", min, max ); m_min = min; m_max = max; }
static void addKey(struct afsconf_dir *dir, int argc, char **argv) { struct afsconf_typedKey *typedKey; int type; int kvno; int code; switch (argc) { case 4: typedKey = keyFromCommandLine(afsconf_rxkad, atoi(argv[2]), 0, argv[3], 8); break; case 5: typedKey = keyFromKeytab(atoi(argv[2]), afsconf_rxkad, 0, argv[3], argv[4]); break; case 6: type = stringToType(argv[2]); kvno = atoi(argv[3]); if (type == afsconf_rxkad) { typedKey = keyFromCommandLine(afsconf_rxkad, kvno, 0, argv[5], 8); } else if (type == afsconf_rxkad_krb5){ fprintf(stderr, "Raw keys for afsconf_rxkad_krb5 are unsupported"); exit(1); } else { fprintf(stderr, "Unknown key type %s\n", argv[2]); exit(1); } break; case 7: type = stringToType(argv[2]); kvno = atoi(argv[3]); if (type == afsconf_rxkad || type == afsconf_rxkad_krb5) { typedKey = keyFromKeytab(kvno, type, atoi(argv[4]), argv[5], argv[6]); } else { fprintf(stderr, "Unknown key type %s\n", argv[2]); exit(1); } break; default: fprintf(stderr, "%s add: usage is '%s add <kvno> <keyfile> " "<princ>\n", argv[0], argv[0]); fprintf(stderr, "\tOR\n\t%s add <kvno> <key>\n", argv[0]); fprintf(stderr, "\tOR\n\t%s add <type> <kvno> <subtype> <key>\n", argv[0]); fprintf(stderr, "\tOR\n\t%s add <type> <kvno> <subtype> <keyfile> <princ>\n", argv[0]); fprintf(stderr, "\t\tEx: %s add 0 \"80b6a7cd7a9dadb6\"\n", argv[0]); exit(1); } code = afsconf_AddTypedKey(dir, typedKey, 1); afsconf_typedKey_put(&typedKey); if (code) { afs_com_err("asetkey", code, "while adding new key"); exit(1); } }
static std::error_code getTypeFlags(ExecState& exec, const JSValue& typeValue, ResourceFlags& flags, uint16_t (*stringToType)(const String&)) { VM& vm = exec.vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (!typeValue.isObject()) return { }; const JSObject* object = typeValue.toObject(&exec); ASSERT(!scope.exception()); if (!isJSArray(object)) return ContentExtensionError::JSONInvalidTriggerFlagsArray; const JSArray* array = jsCast<const JSArray*>(object); unsigned length = array->length(); for (unsigned i = 0; i < length; ++i) { const JSValue value = array->getIndex(&exec, i); if (scope.exception() || !value) return ContentExtensionError::JSONInvalidObjectInTriggerFlagsArray; String name = value.toWTFString(&exec); uint16_t type = stringToType(name); if (!type) return ContentExtensionError::JSONInvalidStringInTriggerFlagsArray; flags |= type; } return { }; }
bool QLCInputChannel::loadXML(const QDomElement& root) { /* Verify that the tag contains an input channel */ if (root.tagName() != KXMLQLCInputChannel) { qWarning() << Q_FUNC_INFO << "Channel node not found"; return false; } /* Go thru all sub tags */ QDomNode node = root.firstChild(); while (node.isNull() == false) { QDomElement tag = node.toElement(); if (tag.tagName() == KXMLQLCInputChannelName) { setName(tag.text()); } else if (tag.tagName() == KXMLQLCInputChannelType) { setType(stringToType(tag.text())); } else { qWarning() << Q_FUNC_INFO << "Unknown input channel tag" << tag.tagName(); } node = node.nextSibling(); } return true; }
virtual void fromJson(const rapidjson::Value &v, const Scene &/*scene*/) override { if (!JsonUtils::fromJson(v, "type", _typeString)) { DBG("Warning: Missing output buffer type"); } else { _type = stringToType(_typeString); if (_type == OutputUnknown) DBG("Warning: Unknown output buffer type '%s'", _typeString); } JsonUtils::fromJson(v, "ldr_output_file", _ldrOutputFile); JsonUtils::fromJson(v, "hdr_output_file", _hdrOutputFile); JsonUtils::fromJson(v, "two_buffer_variance", _twoBufferVariance); JsonUtils::fromJson(v, "sample_variance", _sampleVariance); }
void IMassSpectrum::saveData(QString fileName, QString fileFilter) { MassSpecType type = stringToType(fileFilter); if (m_type == NODATA) { QMessageBox::information(qobject_cast<QWidget*>(this), "Сохранение файла", "Пустые данные: файл не был сохранён"); return; } switch(type) { case TOFFILE: QMessageBox::information(qobject_cast<QWidget*>(this), "Сохранение файла", "Нет операции сохранения для данного типа данных"); return; case TDCSTREAM: if (m_type == TOFFILE) QMessageBox::information(qobject_cast<QWidget*>(this), "Сохранение файла", "Конвертация .tof-файла в поток событий невозможна."); m_msDataStruct->needToSave(false); if (m_type == TDCSTREAM) { emit state("Сохранение файла..."); if ( qobject_cast<TdcDataStorage*>(m_msDataStruct) ->saveFileAscii(fileName) != 0 ) QMessageBox::information(qobject_cast<QWidget*>(this), "Сохранение файла", "Ошибка при сохранении файла."); emit state(fileName); } return; case NODATA: return; } }
void JingleS5BTransportMethodPayloadParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { if (level == 0) { getPayloadInternal()->setSessionID(attributes.getAttributeValue("sid").get_value_or("")); std::string mode = attributes.getAttributeValue("mode").get_value_or("tcp"); if (mode == "tcp") { getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); } else if(mode == "udp") { getPayloadInternal()->setMode(JingleS5BTransportPayload::UDPMode); } else { SWIFT_LOG(warning) << "Unknown S5B mode; falling back to defaul!"; getPayloadInternal()->setMode(JingleS5BTransportPayload::TCPMode); } getPayloadInternal()->setDstAddr(attributes.getAttributeValue("dstaddr").get_value_or("")); } else if (level == 1) { if (element == "candidate") { JingleS5BTransportPayload::Candidate candidate; candidate.cid = attributes.getAttributeValue("cid").get_value_or(""); int port = -1; try { port = boost::lexical_cast<int>(attributes.getAttributeValue("port").get_value_or("-1")); } catch(boost::bad_lexical_cast &) { } candidate.hostPort = HostAddressPort(HostAddress(attributes.getAttributeValue("host").get_value_or("")), port); candidate.jid = JID(attributes.getAttributeValue("jid").get_value_or("")); int priority = -1; try { priority = boost::lexical_cast<int>(attributes.getAttributeValue("priority").get_value_or("-1")); } catch(boost::bad_lexical_cast &) { } candidate.priority = priority; candidate.type = stringToType(attributes.getAttributeValue("type").get_value_or("direct")); getPayloadInternal()->addCandidate(candidate); } else if (element == "candidate-used") { getPayloadInternal()->setCandidateUsed(attributes.getAttributeValue("cid").get_value_or("")); } else if (element == "candidate-error") { getPayloadInternal()->setCandidateError(true); } else if (element == "activated") { getPayloadInternal()->setActivated(attributes.getAttributeValue("cid").get_value_or("")); } else if (element == "proxy-error") { getPayloadInternal()->setProxyError(true); } } ++level; }
bool QLCInputChannel::loadXML(const QDomElement* root) { QDomElement tag; QDomNode node; Q_ASSERT(root != NULL); /* Verify that the tag contains an input channel */ if (root->tagName() != KXMLQLCInputChannel) { qWarning() << "Channel node not found"; return false; } /* Get the channel number */ setChannel(root->attribute(KXMLQLCInputChannelNumber).toInt()); /* Go thru all sub tags */ node = root->firstChild(); while (node.isNull() == false) { tag = node.toElement(); if (tag.tagName() == KXMLQLCInputChannelName) { setName(tag.text()); } else if (tag.tagName() == KXMLQLCInputChannelType) { setType(stringToType(tag.text())); } else { qDebug() << "Unknown input channel tag" << tag.tagName(); } node = node.nextSibling(); } return true; }
bool QLCInputChannel::loadXML(QXmlStreamReader &root) { if (root.isStartElement() == false || root.name() != KXMLQLCInputChannel) { qWarning() << Q_FUNC_INFO << "Channel node not found"; return false; } while (root.readNextStartElement()) { if (root.name() == KXMLQLCInputChannelName) { setName(root.readElementText()); } else if (root.name() == KXMLQLCInputChannelType) { setType(stringToType(root.readElementText())); } else if (root.name() == KXMLQLCInputChannelExtraPress) { root.readElementText(); setSendExtraPress(true); } else if (root.name() == KXMLQLCInputChannelMovement) { if (root.attributes().hasAttribute(KXMLQLCInputChannelSensitivity)) setMovementSensitivity(root.attributes().value(KXMLQLCInputChannelSensitivity).toString().toInt()); if (root.readElementText() == KXMLQLCInputChannelRelative) setMovementType(Relative); } else { qWarning() << Q_FUNC_INFO << "Unknown input channel tag" << root.name(); root.skipCurrentElement(); } } return true; }
void IMassSpectrum::loadMassSpec(QString fileName, QString fileFilter) { MassSpecType type = stringToType(fileFilter); switch(type) { case TOFFILE: { removeData(); m_msDataStruct = new TofMacSupport(this); emit state("Загрузка файла " + fileName + " ..."); QApplication::setOverrideCursor(Qt::WaitCursor); reinterpret_cast<TofMacSupport*>(m_msDataStruct)->loadMassSpec(fileName); QApplication::restoreOverrideCursor(); if(m_msDataStruct->isError()) { QMessageBox::information ( qobject_cast<QWidget*>(this), "Oшибка", "Ошибка при загрузке файла!" ); emit state(QString()); return; } m_type = TOFFILE; emit state(QString()); emit showMassSpec(qobject_cast<QObject*>(m_msDataStruct)); return; } default: QMessageBox::information(qobject_cast<QWidget*>(this),"Загрузка нового файла","Неизвестный тип файла"); } }
bool QLCInputChannel::loadXML(QXmlStreamReader &root) { if (root.isStartElement() == false || root.name() != KXMLQLCInputChannel) { qWarning() << Q_FUNC_INFO << "Channel node not found"; return false; } while (root.readNextStartElement()) { if (root.name() == KXMLQLCInputChannelName) { setName(root.readElementText()); } else if (root.name() == KXMLQLCInputChannelType) { setType(stringToType(root.readElementText())); } else if (root.name() == KXMLQLCInputChannelMovement) { if (root.attributes().hasAttribute(KXMLQLCInputChannelSensitivity)) #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) setMovementSensitivity(root.attributes().value(KXMLQLCInputChannelSensitivity).toString().toInt()); #else setMovementSensitivity(root.attributes().value(KXMLQLCInputChannelSensitivity).toInt()); #endif if (root.readElementText() == KXMLQLCInputChannelRelative) setMovementType(Relative); } else { qWarning() << Q_FUNC_INFO << "Unknown input channel tag" << root.name(); } } return true; }
bool VCClock::loadXML(const QDomElement* root) { Q_ASSERT(root != NULL); if (root->tagName() != KXMLQLCVCClock) { qWarning() << Q_FUNC_INFO << "Clock node not found"; return false; } if (root->hasAttribute(KXMLQLCVCClockType)) { setClockType(stringToType(root->attribute(KXMLQLCVCClockType))); if (clockType() == Countdown) { int h = 0, m = 0, s = 0; if (root->hasAttribute(KXMLQLCVCClockHours)) h = root->attribute(KXMLQLCVCClockHours).toInt(); if (root->hasAttribute(KXMLQLCVCClockMinutes)) m = root->attribute(KXMLQLCVCClockMinutes).toInt(); if (root->hasAttribute(KXMLQLCVCClockSeconds)) s = root->attribute(KXMLQLCVCClockSeconds).toInt(); setCountdown(h, m ,s); } } /* Widget commons */ loadXMLCommon(root); /* Children */ QDomNode node = root->firstChild(); while (node.isNull() == false) { QDomElement tag = node.toElement(); if (tag.tagName() == KXMLQLCWindowState) { int x = 0, y = 0, w = 0, h = 0; bool visible = false; loadXMLWindowState(&tag, &x, &y, &w, &h, &visible); setGeometry(x, y, w, h); } else if (tag.tagName() == KXMLQLCVCWidgetAppearance) { loadXMLAppearance(&tag); } else if (tag.tagName() == KXMLQLCVCClockSchedule) { VCClockSchedule sch; if (sch.loadXML(&tag) == true) addSchedule(sch); } else { qWarning() << Q_FUNC_INFO << "Unknown clock tag:" << tag.tagName(); } node = node.nextSibling(); } return true; }
bool VCMatrixControl::loadXML(const QDomElement &root) { QDomNode node; QDomElement tag; if (root.tagName() != KXMLQLCVCMatrixControl) { qWarning() << Q_FUNC_INFO << "Matrix control node not found"; return false; } if (root.hasAttribute(KXMLQLCVCMatrixControlID) == false) { qWarning() << Q_FUNC_INFO << "Matrix control ID not found"; return false; } m_id = root.attribute(KXMLQLCVCMatrixControlID).toUInt(); /* Children */ node = root.firstChild(); while (node.isNull() == false) { tag = node.toElement(); if (tag.tagName() == KXMLQLCVCMatrixControlType) { m_type = stringToType(tag.text()); } else if (tag.tagName() == KXMLQLCVCMatrixControlColor) { m_color = QColor(tag.text()); } else if (tag.tagName() == KXMLQLCVCMatrixControlResource) { m_resource = tag.text(); } else if (tag.tagName() == KXMLQLCVCMatrixControlProperty) { if (tag.hasAttribute(KXMLQLCVCMatrixControlPropertyName)) { QString pName = tag.attribute(KXMLQLCVCMatrixControlPropertyName); QString pValue = tag.text(); m_properties[pName] = pValue; } } else if (tag.tagName() == KXMLQLCVCMatrixControlInput) { if (tag.hasAttribute(KXMLQLCVCMatrixControlInputUniverse) && tag.hasAttribute(KXMLQLCVCMatrixControlInputChannel)) { quint32 uni = tag.attribute(KXMLQLCVCMatrixControlInputUniverse).toUInt(); quint32 ch = tag.attribute(KXMLQLCVCMatrixControlInputChannel).toUInt(); m_inputSource = new QLCInputSource(uni, ch); } } else { qWarning() << Q_FUNC_INFO << "Unknown VCMatrixControl tag:" << tag.tagName(); } node = node.nextSibling(); } return true; }
GridProperties::GridProperties(const XmlDomElement& domElement) noexcept { mType = stringToType(domElement.getAttribute<QString>("type", true)); mInterval = domElement.getAttribute<Length>("interval", true); mUnit = domElement.getAttribute<LengthUnit>("unit", true); }
void Channel::loadChannel(const json_t* channode) { lastActivity = time(nullptr); { json_t* descnode = json_object_get(channode, "description"); if (descnode) { const char* descstring = json_string_value(descnode); if (descstring) description = descstring; } else { LOG(WARNING) << "Channel json for " << name << " contains no description item."; } } { json_t* modenode = json_object_get(channode, "mode"); if (modenode) { const char* modestring = json_string_value(modenode); if (modestring) chatMode = stringToMode(modestring); } else { LOG(WARNING) << "Channel json for " << name << " contains no mode item."; } } { json_t* ownernode = json_object_get(channode, "owner"); if (ownernode) { const char* ownerstring = json_string_value(ownernode); if (ownerstring) owner = ownerstring; } else { LOG(WARNING) << "Channel json for " << name << " contains no owner item."; } } { json_t* bansnode = json_object_get(channode, "banlist"); if (json_is_array(bansnode)) { int bansize = json_array_size(bansnode); bansize = (bansize > 300) ? 300 : bansize; for (int l = 0; l < bansize; ++l) { json_t* ban = json_array_get(bansnode, l); if (!ban) { LOG(WARNING) << "Calculation error in ban list loop. l:" << l; break; } BanRecord b; { json_t* bannernode = json_object_get(ban, "banner"); if (bannernode) { const char* bannerstring = json_string_value(bannernode); if (bannerstring) b.banner = bannerstring; } else { LOG(WARNING) << "Ban json for channel " << name << " contains no banner item."; continue; } } { json_t* timenode = json_object_get(ban, "time"); if (timenode) { b.time = json_integer_value(timenode); } else { LOG(WARNING) << "Ban json for channel " << name << " contains no time item."; continue; } } { json_t* timeoutnode = json_object_get(ban, "timeout"); if (timeoutnode) { b.timeout = json_integer_value(timeoutnode); } else { b.timeout = 0; LOG(WARNING) << "Ban json for channel " << name << " contains no timeout item."; } } { json_t* namenode = json_object_get(ban, "name"); if (namenode) { const char* namestring = json_string_value(namenode); if (namestring) { string lowername = namestring; int len = lowername.length(); for (int i = 0; i < len; ++i) { lowername[i] = (char) tolower(lowername[i]); } bans[lowername] = b; } } else { LOG(WARNING) << "Ban json for channel " << name << " contains no name item."; continue; } } } } else { LOG(WARNING) << "Channel json for " << name << " contains no banlist item."; } } { json_t* modsnode = json_object_get(channode, "modlist"); if (json_is_array(modsnode)) { int modsize = json_array_size(modsnode); for (int l = 0; l < modsize; ++l) { json_t* mod = json_array_get(modsnode, l); if (!mod) { LOG(WARNING) << "Calculation error in mod list loop. l:" << l; break; } ModRecord m; { json_t* moddernode = json_object_get(mod, "modder"); if (moddernode) { const char* modderstring = json_string_value(moddernode); if (modderstring) { m.modder = modderstring; } else { m.modder = ""; } } else { LOG(WARNING) << "Mod json for channel " << name << " contains no modder item."; continue; } } { json_t* timenode = json_object_get(mod, "time"); if (timenode) { m.time = json_integer_value(timenode); } else { LOG(WARNING) << "Mod json for channel " << name << " contains no time item."; continue; } } { json_t* namenode = json_object_get(mod, "name"); if (namenode) { const char* namestring = json_string_value(namenode); if (namestring) { moderators[namestring] = m; } } else { LOG(WARNING) << "Mod json for channel " << name << " contains no name item."; continue; } } } } else { LOG(WARNING) << "Channel json for " << name << " contains no banlist item."; } } { json_t* titlenode = json_object_get(channode, "title"); if (titlenode) { const char* titlestring = json_string_value(titlenode); if (titlestring) title = titlestring; } else { LOG(WARNING) << "Channel json for " << name << " contains no title item."; } } { json_t* topnode = json_object_get(channode, "top"); if (topnode) { topUsers = json_integer_value(topnode); } else { LOG(WARNING) << "Channel json for " << name << " contains no top item."; } } { json_t* typenode = json_object_get(channode, "type"); if (typenode) { const char* typestring = json_string_value(typenode); if (typestring) { type = stringToType(typestring); } else { LOG(WARNING) << "Channel json for " << name << " fails to provide a string for a type."; } } else { LOG(WARNING) << "Channel json for " << name << " contains no type item."; } } }
QIcon QLCInputChannel::stringToIcon(const QString& str) { return typeToIcon(stringToType(str)); }
bool ViNeuron::importData(ViElement element) { if(element.name() != "neuron") { return false; } bool success = true; ViElement id = element.child("id"); if(id.isNull()) { success = false; } else { setId(id.toString()); } ViElement theType = element.child("type"); if(theType.isNull()) { success = false; } else { setType(stringToType(theType.toString())); } if(type() == ViNeuron::HiddenNeuron || type() == ViNeuron::OutputNeuron) { if(id.isNull()) { success = false; setActivationFunction(NULL); } else { setActivationFunction(ViActivationFunctionManager::create(element)); } if(mActivationFunction == NULL) { setActivationFunction(ViActivationFunctionManager::createDefault()); LOG("Unable to create the required activation function from the import data. The default activation function (" + mActivationFunction->name() + ") will be used.", QtCriticalMsg); } else { if(!mActivationFunction->importData(element)) { success = false; } } } else if(type() == ViNeuron::BiasNeuron) { ViElement value = element.child("value"); if(value.isNull()) { success = false; setActivationFunction(NULL); } else { setValue(value.toReal()); } } return success; }
ReconstructionFilter(const std::string &name = "tent") : _typeString(name), _type(stringToType(name)) { precompute(); }
TokenType Token::getType() { if(this->stype != "") this->type = stringToType(this->stype); return this->type; }