void SamplePlayer::refresh() { std::map<QString, param_t>::iterator i; for ( i = parameter.begin(); i != parameter.end(); ++i) { if (i->second.type & (STATE | EVENT)) { QString text = QString::number(getValue(i->second.type, i->second.index)); i->second.edit->setText(text); } else if ((i->second.type & PARAMETER) && !i->second.edit->edited() && i->second.edit->text() != *i->second.str_value) { i->second.edit->setText(*i->second.str_value); } else if ((i->second.type & COMMENT) && !i->second.edit->edited() && i->second.edit->text() != getValueString(COMMENT, i->second.index)) { i->second.edit->setText(getValueString(COMMENT, i->second.index)); } } pauseButton->setOn(!getActive()); }
std::set<std::string> getGlobalCommands() { std::set<std::string> handlersSet; size_t keys = 0; HKEY hTestKey = NULL; if (RegOpenKeyEx(HKEY_CLASSES_ROOT, 0, 0, KEY_READ, &hTestKey) != ERROR_SUCCESS) { return handlersSet; } std::vector<std::string> subkeys = get_subkeys(hTestKey); RegCloseKey(hTestKey); std::vector<std::string>::iterator itr; for (itr = subkeys.begin(); itr != subkeys.end(); itr++) { if (itr->at(0) != '.') { continue; } //extension found! HKEY innerKey1; if (RegOpenKeyExA(HKEY_CLASSES_ROOT, itr->c_str(), 0, KEY_READ, &innerKey1) != ERROR_SUCCESS) { continue; } std::string ext = *itr; std::string handlerName = getValueString(HKEY_CLASSES_ROOT, ext); if (handlerName.length() == 0) continue; std::string path = getValueString(HKEY_CLASSES_ROOT, handlerName + "\\shell\\open\\command"); if (path.length() == 0) continue; handlersSet.insert(handlerName); } return handlersSet; }
static void fprintRanges(FILE *f, int indent, SmiType *smiType) { SmiRange *range; for(range = smiGetFirstRange(smiType); range; range = smiGetNextRange(range)) { fprintSegment(f, indent, "<range", 0); fprint(f, " min=\"%s\"", getValueString(&range->minValue, smiType)); fprint(f, " max=\"%s\"", getValueString(&range->maxValue, smiType)); fprint(f, "/>\n"); } }
void RenderingRulesStorage::printDebug(int state) { HMAP::hash_map<int, RenderingRule*>::iterator it = tagValueGlobalRules[state].begin(); for (; it != tagValueGlobalRules[state].end(); it++) { printf("\n\n%s : %s", getTagString(it->first).c_str(), getValueString(it->first).c_str()); it->second->printDebugRenderingRule(string(""), this); } }
void NoiseLevelSensor::run() { _buffer[_sample++] = analogRead(_sensorPin); if (_sample == _bufferSize) { _sample = 0; // Serial.print("window: "); // Serial.print(_window); // Serial.println("s"); // // Serial.print("max: "); // Serial.print(getVoltage(maximum(_buffer))); // Serial.println(" Volts"); // // Serial.print("min: "); // Serial.print(getVoltage(minimum(_buffer))); // Serial.println(" Volts"); // // Serial.print("avg: "); // Serial.print(getVoltage(average(_buffer))); // Serial.println(" Volts"); // // Serial.println(); // create a sensor reading and send it to the callback _callback(getReading(getValueString())); } }
void DefaultGUIModel::refresh(void) { for (std::map<QString, param_t>::iterator i = parameter.begin(); i!= parameter.end(); ++i) { if (i->second.type & (STATE | EVENT)) { i->second.edit->setText(QString::number(getValue(i->second.type, i->second.index))); palette.setBrush(i->second.edit->foregroundRole(), Qt::darkGray); i->second.edit->setPalette(palette); } else if ((i->second.type & PARAMETER) && !i->second.edit->isModified() && i->second.edit->text() != *i->second.str_value) { i->second.edit->setText(*i->second.str_value); } else if ((i->second.type & COMMENT) && !i->second.edit->isModified() && i->second.edit->text() != QString::fromStdString(getValueString(COMMENT, i->second.index))) { i->second.edit->setText(QString::fromStdString(getValueString(COMMENT, i->second.index))); } } pauseButton->setChecked(!getActive()); }
static void fprintSubtype(FILE *f, SmiType *smiType) { SmiRange *range; SmiNamedNumber *nn; char s[100]; int i; if ((smiType->basetype == SMI_BASETYPE_ENUM) || (smiType->basetype == SMI_BASETYPE_BITS)) { for(i = 0, nn = smiGetFirstNamedNumber(smiType); nn ; i++, nn = smiGetNextNamedNumber(nn)) { if (i) { fprint(f, ", "); } else { fprint(f, " ("); } sprintf(s, "%s(%s)", nn->name, getValueString(&nn->value, smiType)); fprintWrapped(f, INDENTVALUE + INDENT, s); } if (i) { fprint(f, ")"); } } else { for(i = 0, range = smiGetFirstRange(smiType); range ; i++, range = smiGetNextRange(range)) { if (i) { fprint(f, " | "); } else { fprint(f, " ("); } if (memcmp(&range->minValue, &range->maxValue, sizeof(SmiValue))) { sprintf(s, "%s", getValueString(&range->minValue, smiType)); sprintf(&s[strlen(s)], "..%s", getValueString(&range->maxValue, smiType)); } else { sprintf(s, "%s", getValueString(&range->minValue, smiType)); } fprintWrapped(f, INDENTVALUE + INDENT, s); } if (i) { fprint(f, ")"); } } }
QString SamplePlayer::getComment(const QString &name) { std::map<QString, param_t>::iterator n = parameter.find(name); if (n != parameter.end() && (n->second.type & COMMENT)) return QString(getValueString(COMMENT, n->second.index)); else return ""; }
void ModelicaOptionValue::setChildrenSize(QString size) { if (size.compare("1") == 0) { setOptionNone(true); } else { setOptionNone(false); } mpLocalsTreeItem->setDisplayValue(getValueString()); }
static void fprintValue(FILE *f, int indent, SmiValue *smiValue, SmiType *smiType) { if (smiType && smiValue && smiValue->basetype != SMI_BASETYPE_UNKNOWN) { fprintSegment(f, indent, "<default>", 0); fprint(f, "%s", getValueString(smiValue, smiType)); fprint(f, "</default>\n"); } }
void DirectionReader::parseDynamic( const core::Dynamics& dynamic ) { auto mark = api::MarkData{}; const auto valueObject = dynamic.getValue(); mark.markType = myConverter.convertDynamic( valueObject.getValue() ); mark.name = valueObject.getValueString(); impl::parseMarkDataAttributes( *dynamic.getAttributes(), mark ); auto placement = mark.positionData.placement; if( placement == api::Placement::unspecified ) { placement = myOutDirectionData.placement; } mark.name = valueObject.getValueString(); myOutDirectionData.marks.emplace_back( std::move( mark ) ); }
void FloorMatSensor::run() { // take a snapshot of the mat snapshot(); // count people on the mat int n = countPeople(); // create a sensor reading and send it to the callback _callback(getReading(getValueString(n))); }
RenderingRule* RenderingRulesStorage::createTagValueRootWrapperRule(int tagValueKey, RenderingRule* previous) { if (previous->properties.size() > 2) { map<string, string> m; m["tag"] = getTagString(tagValueKey); m["value"] = getValueString(tagValueKey); RenderingRule* toInsert = new RenderingRule(m, this); toInsert->ifElseChildren.push_back(previous); return toInsert; } else { return previous; } }
std::shared_ptr<OsmAnd::MapStyleRule> OsmAnd::MapStyle_P::createTagValueRootWrapperRule( uint64_t id, const std::shared_ptr<MapStyleRule>& rule ) { if(rule->_d->_values.size() <= 2) return rule; QHash< QString, QString > attributes; attributes.insert(QLatin1String("tag"), getTagString(id)); attributes.insert(QLatin1String("value"), getValueString(id)); std::shared_ptr<MapStyleRule> newRule(new MapStyleRule(owner, attributes)); newRule->_d->_ifElseChildren.push_back(rule); return newRule; }
void Options::handle(View* view, OptionSet set, int lastIndex) { vector<ListElem> options; options.emplace_back("Change settings:", ListElem::TITLE); for (OptionId option : optionSets.at(set)) options.push_back(ListElem(names.at(option), getValueString(option, getValue(option))).setTip(hints.at(option))); options.emplace_back("Done"); auto index = view->chooseFromList("", options, lastIndex, getMenuType(set)); if (!index || (*index) == optionSets.at(set).size()) return; OptionId option = optionSets.at(set)[*index]; changeValue(option, getValue(option), view); handle(view, set, *index); }
static void fprintNamedNumbers(FILE *f, int indent, SmiType *smiType) { SmiNamedNumber *nn; if ((smiType->basetype != SMI_BASETYPE_ENUM) && (smiType->basetype != SMI_BASETYPE_BITS)) { return; } for (nn = smiGetFirstNamedNumber(smiType); nn; nn = smiGetNextNamedNumber(nn)) { fprintSegment(f, indent, "<namednumber", 0); fprint(f, " name=\"%s\"", nn->name); fprint(f, " number=\"%s\"", getValueString(&nn->value, smiType)); fprint(f, "/>\n"); } }
bool Options::handleOrExit(View* view, OptionSet set, int lastIndex) { if (!optionSets.count(set)) return true; vector<ListElem> options; options.emplace_back("Change settings:", ListElem::TITLE); for (OptionId option : optionSets.at(set)) options.push_back(ListElem(names.at(option), getValueString(option, getValue(option))).setTip(hints.at(option))); options.emplace_back("Done"); if (lastIndex == -1) lastIndex = optionSets.at(set).size(); auto index = view->chooseFromList("", options, lastIndex, getMenuType(set)); if (!index) return false; else if (index && (*index) == optionSets.at(set).size()) return true; OptionId option = optionSets.at(set)[*index]; changeValue(option, getValue(option), view); return handleOrExit(view, set, *index); }
bool CollectionHandler::read(Variant& v, const NodePtr& node, const char* typeName) { // Check that we've been given a valid Variant if (v.isVoid() || v.type() == nullptr) { return false; } // Container, key, and value types TypeId containerType; TypeId keyVariantType; TypeId valueVariantType; std::string keyInternalType; std::string valueInternalType; // Container const char* containerName = this->getReservedNames().collectionContainerType; std::string containerTypeName = node->getChildNode(containerName, strlen(containerName))->getType(); containerType = TypeId(containerTypeName.c_str()); // Key variant type const char* keyVName = this->getReservedNames().collectionKeyVariantType; std::string keyVTypeName = node->getChildNode(keyVName, strlen(keyVName))->getType(); keyVariantType = TypeId(keyVTypeName.c_str()); // Value variant type const char* valueVName = this->getReservedNames().collectionValueVariantType; std::string valueVTypeName = node->getChildNode(valueVName, strlen(valueVName))->getType(); valueVariantType = TypeId(valueVTypeName.c_str()); // Key internal type const char* keyIName = this->getReservedNames().collectionKeyInternalType; keyInternalType = node->getChildNode(keyIName, strlen(keyIName))->getType(); // Value internal type const char* valueIName = this->getReservedNames().collectionValueInternalType; valueInternalType = node->getChildNode(valueIName, strlen(valueIName))->getType(); // Cast to a collection Collection c; if (!v.tryCast<Collection>(c)) { return false; } // Check that the types match if (strcmp(c.impl()->containerType().getName(), containerType.getName()) != 0) { return false; } // Get handlers std::shared_ptr<SerializationHandler> keyHandler = nullptr; std::shared_ptr<SerializationHandler> valueHandler = nullptr; if (MetaType::find(keyVariantType.getName()) != MetaType::get<Variant>()) { const char* keyHandlerName = this->getReservedNames().collectionKeyHandler; auto keyHandlerNode = node->getChildNode(keyHandlerName, strlen(keyHandlerName)); std::string keyHandlerString = keyHandlerNode->getValueString(); keyHandler = handlerManager_.findHandlerRead(node, keyHandlerString.c_str(), keyInternalType.c_str()); } if (MetaType::find(valueVariantType.getName()) != MetaType::get<Variant>()) { const char* valueHandlerName = this->getReservedNames().collectionValueHandler; auto valueHandlerNode = node->getChildNode(valueHandlerName, strlen(valueHandlerName)); std::string valueHandlerString = valueHandlerNode->getValueString(); valueHandler = handlerManager_.findHandlerRead(node, valueHandlerString.c_str(), valueInternalType.c_str()); } // Get the base node of the collection auto baseNode = node->getChildNode(collectionBaseNodeName_, strlen(collectionBaseNodeName_)); auto nodeChildren = baseNode->getAllChildren(); auto collectionIter = c.begin(); // Iterate through all the children until we reach the nodes for storing type data for (auto nodeIter = nodeChildren.begin(); nodeIter != nodeChildren.end(); ++nodeIter) { std::unique_ptr<SerializationNode>& currentNode = *nodeIter; Variant key = Variant(keyVariantType); // Assign key/value if (currentNode->getName() != keyName_) { return false; } // Read the key node if (keyHandler.get() == nullptr) { // Read as a Variant if (!currentNode->getValueVariant(key, keyVariantType.getName())) { return false; } } else { // Read with a handler, using the type supplied if (!keyHandler->read(key, currentNode, keyVariantType.getName())) { return false; } } // Insert/get the key, which creates the value for us. Collection::Iterator insertIter; if (c.canResize()) { insertIter = c.insert(key); } else { if (key != collectionIter.key()) { return false; } insertIter = collectionIter; ++collectionIter; } if (insertIter == c.end()) { return false; } Variant value = insertIter.value(); auto childNode = currentNode->getChildNode(valueName_, strlen(valueName_)); if (childNode == nullptr) { return false; } // Read the value node if (valueHandler.get() == nullptr) { // Read as a Variant if (!childNode->getValueVariant(value, valueVariantType.getName())) { return false; } } else { // Read with a handler, using the type supplied if (!valueHandler->read(value, childNode, valueVariantType.getName())) { return false; } } // If this collection doesn't support setting values, then it's invalid. if (!insertIter.setValue(value)) { return false; } } return true; }
static void fprintObjects(FILE *f, SmiModule *smiModule) { int i, j; SmiNode *smiNode, *relatedNode; SmiElement *smiElement; SmiType *smiType; int indent = 0; int lastindent = -1; char *s = NULL; SmiNodekind nodekinds; nodekinds = SMI_NODEKIND_NODE | SMI_NODEKIND_TABLE | SMI_NODEKIND_ROW | SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR | SMI_NODEKIND_CAPABILITIES; for(i = 0, smiNode = smiGetFirstNode(smiModule, nodekinds); smiNode; smiNode = smiGetNextNode(smiNode, nodekinds)) { if (smiNode->nodekind == SMI_NODEKIND_NODE) { indent = 0; s = "node"; } else if (smiNode->nodekind == SMI_NODEKIND_CAPABILITIES) { indent = 0; s = "node"; } else if (smiNode->nodekind == SMI_NODEKIND_TABLE) { indent = 0; s = "table"; } else if (smiNode->nodekind == SMI_NODEKIND_ROW) { indent = 1; s = "row"; } else if (smiNode->nodekind == SMI_NODEKIND_COLUMN) { indent = 2; s = "column"; } else if (smiNode->nodekind == SMI_NODEKIND_SCALAR) { indent = 0; s = "scalar"; } if (!i && !silent) { fprint(f, "//\n// OBJECT DEFINITIONS\n//\n\n"); } for (j = lastindent; j >= indent; j--) { fprintSegment(f, (1 + j) * INDENT, "", 0); fprint(f, "};\n"); } fprint(f, "\n"); lastindent = indent; if (smiNode->nodekind == SMI_NODEKIND_CAPABILITIES) { fprintSegment(f, (1 + indent) * INDENT, "", 0); fprint(f, "-- This has been an SMIv2 AGENT-CAPABILITIES node:\n"); } fprintSegment(f, (1 + indent) * INDENT, "", 0); fprint(f, "%s %s {\n", s, smiNode->name); if (smiNode->oid) { fprintSegment(f, (2 + indent) * INDENT, "oid", INDENTVALUE); fprint(f, "%s;\n", getOidString(smiNode, 0)); } smiType = smiGetNodeType(smiNode); if (smiType && (smiType->basetype != SMI_BASETYPE_UNKNOWN)) { fprintSegment(f, (2 + indent) * INDENT, "type", INDENTVALUE); if (!smiType->name) { /* * an implicitly restricted type. */ fprint(f, "%s", getTypeString(smiType->basetype, smiGetParentType(smiType))); fprintSubtype(f, smiType); fprint(f, ";\n"); } else { fprint(f, "%s;\n", getTypeString(smiType->basetype, smiType)); } } if ((smiNode->nodekind != SMI_NODEKIND_TABLE) && (smiNode->nodekind != SMI_NODEKIND_ROW) && (smiNode->nodekind != SMI_NODEKIND_CAPABILITIES) && (smiNode->nodekind != SMI_NODEKIND_NODE)) { if (smiNode->access != SMI_ACCESS_UNKNOWN) { fprintSegment(f, (2 + indent) * INDENT, "access", INDENTVALUE); fprint(f, "%s;\n", getAccessString(smiNode->access)); } } relatedNode = smiGetRelatedNode(smiNode); switch (smiNode->indexkind) { case SMI_INDEX_INDEX: if (smiNode->implied) { fprintSegment(f, (2 + indent) * INDENT, "index implied", INDENTVALUE); } else { fprintSegment(f, (2 + indent) * INDENT, "index", INDENTVALUE); } fprint(f, "("); for (j = 0, smiElement = smiGetFirstElement(smiNode); smiElement; j++, smiElement = smiGetNextElement(smiElement)) { if (j) { fprint(f, ", "); } fprintWrapped(f, INDENTVALUE + 1, smiGetElementNode(smiElement)->name); /* TODO: non-local name if non-local */ } /* TODO: empty? -> print error */ fprint(f, ");\n"); break; case SMI_INDEX_AUGMENT: if (relatedNode) { fprintSegment(f, (2 + indent) * INDENT, "augments", INDENTVALUE); fprint(f, "%s;\n", relatedNode->name); /* TODO: non-local name if non-local */ } /* TODO: else print error */ break; case SMI_INDEX_REORDER: if (relatedNode) { fprintSegment(f, (2 + indent) * INDENT, "", 0); fprint(f, "reorders %s", relatedNode->name); /* TODO: non-local name if non-local */ if (smiNode->implied) { fprint(f, " implied"); } fprint(f, " ("); for (j = 0, smiElement = smiGetFirstElement(smiNode); smiElement; j++, smiElement = smiGetNextElement(smiElement)) { if (j) { fprint(f, ", "); } fprintWrapped(f, INDENTVALUE + 1, smiGetElementNode(smiElement)->name); /* TODO: non-local name if non-local */ } /* TODO: empty? -> print error */ fprint(f, ");\n"); } /* TODO: else print error */ break; case SMI_INDEX_SPARSE: if (relatedNode) { fprintSegment(f, (2 + indent) * INDENT, "sparse", INDENTVALUE); fprint(f, "%s;\n", relatedNode->name); /* TODO: non-local name if non-local */ } /* TODO: else print error */ break; case SMI_INDEX_EXPAND: if (relatedNode) { fprintSegment(f, (2 + indent) * INDENT, "", 0); fprint(f, "expands %s", relatedNode->name); /* TODO: non-local name if non-local */ if (smiNode->implied) { fprint(f, " implied"); } fprint(f, " ("); for (j = 0, smiElement = smiGetFirstElement(smiNode); smiElement; j++, smiElement = smiGetNextElement(smiElement)) { if (j) { fprint(f, ", "); } fprintWrapped(f, INDENTVALUE + 1, smiGetElementNode(smiElement)->name); /* TODO: non-local name if non-local */ } /* TODO: empty? -> print error */ fprint(f, ");\n"); } /* TODO: else print error */ break; case SMI_INDEX_UNKNOWN: break; } if (smiNode->create) { fprintSegment(f, (2 + indent) * INDENT, "create", INDENTVALUE); /* TODO: create list */ fprint(f, ";\n"); } if (smiNode->value.basetype != SMI_BASETYPE_UNKNOWN) { fprintSegment(f, (2 + indent) * INDENT, "default", INDENTVALUE); fprint(f, "%s", getValueString(&smiNode->value, smiType)); fprint(f, ";\n"); } if (smiNode->format) { fprintSegment(f, (2 + indent) * INDENT, "format", INDENTVALUE); fprint(f, "\"%s\";\n",smiNode->format); } if (smiNode->units) { fprintSegment(f, (2 + indent) * INDENT, "units", INDENTVALUE); fprint(f, "\"%s\";\n", smiNode->units); } if ((smiNode->status != SMI_STATUS_CURRENT) && (smiNode->status != SMI_STATUS_UNKNOWN) && (smiNode->status != SMI_STATUS_MANDATORY) && (smiNode->status != SMI_STATUS_OPTIONAL)) { fprintSegment(f, (2 + indent) * INDENT, "status", INDENTVALUE); fprint(f, "%s;\n", getStringStatus(smiNode->status)); } if (smiNode->description) { fprintSegment(f, (2 + indent) * INDENT, "description", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, (2 + indent) * INDENT, smiNode->description); fprint(f, ";\n"); } if (smiNode->reference) { fprintSegment(f, (2 + indent) * INDENT, "reference", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, (2 + indent) * INDENT, smiNode->reference); fprint(f, ";\n"); } i++; } if (i) { fprintSegment(f, (1 + indent) * INDENT, "", 0); fprint(f, "};\n\n"); } }
static void fprintTypedefs(FILE *f, SmiModule *smiModule) { int i, j; SmiType *smiType; for(i = 0, smiType = smiGetFirstType(smiModule); smiType; smiType = smiGetNextType(smiType)) { if ((!(strcmp(smiModule->name, "SNMPv2-SMI"))) || (!(strcmp(smiModule->name, "RFC1155-SMI")))) { for(j=0; excludeType[j]; j++) { if (!strcmp(smiType->name, excludeType[j])) break; } if (excludeType[j]) break; } if (!i && !silent) { fprint(f, "//\n// TYPE DEFINITIONS\n//\n\n"); } fprintSegment(f, INDENT, "", 0); fprint(f, "typedef %s {\n", smiType->name); fprintSegment(f, 2 * INDENT, "type", INDENTVALUE); fprint(f, "%s", getTypeString(smiType->basetype, smiGetParentType(smiType))); fprintSubtype(f, smiType); fprint(f, ";\n"); if (smiType->value.basetype != SMI_BASETYPE_UNKNOWN) { fprintSegment(f, 2 * INDENT, "default", INDENTVALUE); fprint(f, "%s", getValueString(&smiType->value, smiType)); fprint(f, ";\n"); } if (smiType->format) { fprintSegment(f, 2 * INDENT, "format", INDENTVALUE); fprint(f, "\"%s\";\n", smiType->format); } if (smiType->units) { fprintSegment(f, 2 * INDENT, "units", INDENTVALUE); fprint(f, "\"%s\";\n", smiType->units); } if ((smiType->status != SMI_STATUS_CURRENT) && (smiType->status != SMI_STATUS_UNKNOWN) && (smiType->status != SMI_STATUS_MANDATORY) && (smiType->status != SMI_STATUS_OPTIONAL)) { fprintSegment(f, 2 * INDENT, "status", INDENTVALUE); fprint(f, "%s;\n", getStringStatus(smiType->status)); } fprintSegment(f, 2 * INDENT, "description", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, 2 * INDENT, smiType->description); fprint(f, ";\n"); if (smiType->reference) { fprintSegment(f, 2 * INDENT, "reference", INDENTVALUE); fprint(f, "\n"); fprintMultilineString(f, 2 * INDENT, smiType->reference); fprint(f, ";\n"); } fprintSegment(f, INDENT, "};\n\n", 0); i++; } }
QString DefaultGUIModel::getComment(const QString &name) { std::map<QString, param_t>::iterator n = parameter.find(name); if (n != parameter.end() && (n->second.type & COMMENT)) return QString::fromStdString(getValueString(COMMENT, n->second.index)); return ""; }
void ModelicaTupleValue::setChildrenSize(QString size) { setTupleElements(size.toInt()); mpLocalsTreeItem->setDisplayValue(getValueString()); }
void MetaModelicaArrayValue::setChildrenSize(QString size) { setArrayLength(size.toInt()); mpLocalsTreeItem->setDisplayValue(getValueString()); }
string Options::getStringValue(OptionId id) { return getValueString(id, getValue(id)); }