TNuiInteractionStream::TNuiInteractionStream(TNuiSensor *sensor) : TNuiStream(sensor) { if (d == nullptr) d = new TNuiInteractionStreamInternal(sensor); setInternal(d); }
void MonoLed::blink( uint16_t timeOn, uint16_t timeOff ) { setInternal( true ); blinkTimeOn = timeOn; blinkPeriod = timeOn + timeOff; blinkStartMillis = pins->millis(); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Settings::setString(const string& key, const string& value) { if(int idx = getInternalPos(key) != -1) setInternal(key, value, idx); else setExternal(key, value); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Settings::setBool(const string& key, const bool value) { ostringstream stream; stream << value; if(int idx = getInternalPos(key) != -1) setInternal(key, stream.str(), idx); else setExternal(key, stream.str()); }
void MonoLed::loop() { if( isBlinking() ) { unsigned long timeSinceStart = pins->millis() - blinkStartMillis; unsigned long timeInBlinkPeriod = timeSinceStart % blinkPeriod; bool ledOn = ( timeInBlinkPeriod < blinkTimeOn ); setInternal( ledOn ); } }
void KVStore::setInternal(const std::string& key, const std::vector<std::string>& values) { if (values.size() > std::numeric_limits<unsigned int>::max()) { throw ConfigException("Too many values to insert"); } Transaction transaction(*this); remove(key); // Save vector's capacity setInternal(key, values.size()); // Save vector's elements for (unsigned int i = 0; i < values.size(); ++i) { setInternal(config::key(key, std::to_string(i)), values[i]); } transaction.commit(); }
void fromString(const std::string &string) override { uint8_t rgba[4] = { 0, 0, 0, 255 }; for (int i = 0; i < string.length() && i < 8; ++i) { if (!(i % 2)) rgba[i / 2] = 0; rgba[i / 2] |= (hexToInt(string[i]) << ((i % 2) ? 0 : 4)); } rgba_t next{}; next.r = float(rgba[0]) / 255.f; next.g = float(rgba[1]) / 255.f; next.b = float(rgba[2]) / 255.f; next.a = float(rgba[3]) / 255.f; setInternal(next); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Settings::loadConfig() { string line, key, value; string::size_type equalPos, garbage; ifstream in(myOSystem->configFile().c_str()); if(!in || !in.is_open()) { cout << "Error: Couldn't load settings file\n"; return; } while(getline(in, line)) { // Strip all whitespace and tabs from the line while((garbage = line.find("\t")) != string::npos) line.erase(garbage, 1); // Ignore commented and empty lines if((line.length() == 0) || (line[0] == ';')) continue; // Search for the equal sign and discard the line if its not found if((equalPos = line.find("=")) == string::npos) continue; // Split the line into key/value pairs and trim any whitespace key = line.substr(0, equalPos); value = line.substr(equalPos + 1, line.length() - key.length() - 1); key = trim(key); value = trim(value); // Check for absent key or value if((key.length() == 0) || (value.length() == 0)) continue; // Only settings which have been previously set are valid if(int idx = getInternalPos(key) != -1) setInternal(key, value, idx, true); } in.close(); }
void CoreAccount::fromVariantMap(const QVariantMap &v) { setAccountId((AccountId)v.value("AccountId").toInt()); setAccountName(v.value("AccountName").toString()); setUuid(QUuid(v.value("Uuid").toString())); setInternal(v.value("Internal").toBool()); setUser(v.value("User").toString()); setPassword(v.value("Password").toString()); setStorePassword(v.value("StorePassword").toBool()); setHostName(v.value("HostName").toString()); setPort(v.value("Port").toUInt()); setUseSsl(v.value("UseSSL").toBool()); setProxyType((QNetworkProxy::ProxyType)v.value("ProxyType").toInt()); setProxyUser(v.value("ProxyUser").toString()); setProxyPassword(v.value("ProxyPassword").toString()); setProxyHostName(v.value("ProxyHostName").toString()); setProxyPort(v.value("ProxyPort").toUInt()); _storePassword = !password().isEmpty(); }
void NeuralNetwork::read(TextFileReader const& _file) throw() { TextFileReader file = _file; Text text; int line = 0; int numLayers = -1; float learnRate, actFuncOffset; IntArray nodes; while(file.isEof() == false) { text = file.readLine(); if(line == 0) { // should be the format/version string if(text.contains("NeuralNetworkSimple:v1") == false) { printf("NeuralNetwork::read wrong version type\n"); return; } } else if(line == 1) { // should be learn rate and act func offset sscanf(text.getArray(), "learnRate: %f actFuncOffset: %f", &learnRate, &actFuncOffset); } else if(line == 2) { // should be the number of layers sscanf(text.getArray(), "Layers:%d", &numLayers); if(numLayers < 2) { printf("NeuralNetwork::read invalid number of layers\n"); return; } nodes = IntArray::withSize(numLayers, false); } else if(numLayers > 0) { int layer, numNodes; sscanf(text.getArray(), "Layer %d:%d", &layer, &numNodes); numLayers--; nodes[layer] = numNodes; if(numLayers == 0) { if(nodes == getStructure()) { setLearnRate(learnRate); setActFuncOffset(actFuncOffset); } else { setInternal(new NeuralNetworkSimpleInternal(nodes, learnRate, actFuncOffset)); } } } else { // it's a weight or a threshold int layer, node, index; float value; sscanf(text.getArray(), "%d %d %d %f", &layer, &node, &index, &value); if(index < 0) setThreshold(layer, node, value); else setWeight(layer, node, index, value); } line++; } }
void KVStore::setInternal(const std::string& key, const std::initializer_list<std::string>& values) { setInternal(key, std::vector<std::string>(values)); }
void KVStore::setInternal(const std::string& key, const std::string& value) { setInternal(key, value.c_str()); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Settings::loadCommandLine(int argc, char** argv) { for(int i = 1; i < argc; ++i) { // strip off the '-' character string key = argv[i]; if(key[0] != '-') return true; // stop processing here, ignore the remaining items key = key.substr(1, key.length()); // Take care of the arguments which are meant to be executed immediately // (and then Stella should exit) if(key == "help") { usage(); return false; } else if(key == "listrominfo") { setExternal(key, "true"); return true; } else if(key == "debug") // this doesn't make Stella exit { setExternal(key, "true"); return true; } else if(key == "holdreset") // this doesn't make Stella exit { setExternal(key, "true"); return true; } else if(key == "holdselect") // this doesn't make Stella exit { setExternal(key, "true"); return true; } else if(key == "holdbutton0") // this doesn't make Stella exit { setExternal(key, "true"); return true; } if(++i >= argc) { cerr << "Missing argument for '" << key << "'" << endl; return false; } string value = argv[i]; // Settings read from the commandline must not be saved to // the rc-file, unless they were previously set if(int idx = getInternalPos(key) != -1) setInternal(key, value, idx); // don't set initialValue here else setExternal(key, value); } return true; }
void MonoLed::set( bool on ) { stopBlink(); setInternal( on ); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Settings::validate() { string s; int i; s = getString("video"); if(s != "soft" && s != "gl") setInternal("video", "soft"); #ifdef DISPLAY_OPENGL s = getString("gl_filter"); if(s != "linear" && s != "nearest") setInternal("gl_filter", "nearest"); float f = getFloat("gl_aspect"); if(f < 1.1 || f > 2.0) setInternal("gl_aspect", "2.0"); #endif #ifdef SOUND_SUPPORT i = getInt("fragsize"); if(i != 256 && i != 512 && i != 1024 && i != 2048 && i != 4096) #ifdef WIN32 setInternal("fragsize", "2048"); #else setInternal("fragsize", "512"); #endif i = getInt("volume"); if(i < 0 || i > 100) setInternal("volume", "100"); i = getInt("freq"); if(i < 0 || i > 48000) setInternal("freq", "31400"); i = getInt("tiafreq"); if(i < 0 || i > 48000) setInternal("tiafreq", "31400"); #endif i = getInt("zoom"); if(i < 1 || i > 6) setInternal("zoom", "2"); i = getInt("paddle"); if(i < 0 || i > 3) setInternal("paddle", "0"); i = getInt("pthresh"); if(i < 400) setInternal("pthresh", "400"); else if(i > 800) setInternal("pthresh", "800"); s = getString("palette"); if(s != "standard" && s != "original" && s != "z26") setInternal("palette", "standard"); i = getInt("ppblend"); if(i < 0) setInternal("ppblend", "0"); if(i > 100) setInternal("ppblend", "100"); s = getString("ssname"); if(s != "romname" && s != "md5sum") setInternal("ssname", "romname"); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Settings::Settings(OSystem* osystem) : myOSystem(osystem) { // Add this settings object to the OSystem myOSystem->attach(this); // Add options that are common to all versions of Stella setInternal("video", "soft"); setInternal("dirtyrects", "true"); setInternal("ppblend", "77"); setInternal("gl_filter", "nearest"); setInternal("gl_aspect", "2.0"); setInternal("gl_fsmax", "false"); setInternal("gl_lib", ""); setInternal("zoom", "2"); setInternal("fullscreen", "false"); setInternal("center", "true"); setInternal("grabmouse", "false"); setInternal("palette", "standard"); setInternal("debugheight", "0"); setInternal("sound", "true"); setInternal("fragsize", "512"); setInternal("freq", "31400"); setInternal("tiafreq", "31400"); setInternal("volume", "100"); setInternal("clipvol", "true"); setInternal("keymap", ""); setInternal("joymap", ""); setInternal("joyaxismap", ""); setInternal("joyhatmap", ""); setInternal("paddle", "0"); setInternal("sa1", "left"); setInternal("sa2", "right"); setInternal("joymouse", "false"); setInternal("p1speed", "50"); setInternal("p2speed", "50"); setInternal("p3speed", "50"); setInternal("p4speed", "50"); setInternal("pthresh", "600"); setInternal("showinfo", "false"); setInternal("ssdir", ""); setInternal("ssname", "romname"); setInternal("sssingle", "false"); setInternal("romdir", ""); setInternal("rombrowse", "false"); setInternal("lastrom", ""); setInternal("modtime", ""); // romdir last modification time setInternal("tiadefaults", "false"); }
void nTexture::setData(nVec2ui size, nColor *d) { if(!internal.isSuccess()) { setInternal(new TextureInternal()); } internal.getValue()->setData(size, d); }
void NeuralPattern::read(TextFileReader const& _file) throw() { TextFileReader file = _file; Text text; int line = 0; int numInputs = -1, numOutputs = -1; NumericalArray<float> inputVector; NumericalArray<float> outputVector; while((text = file.readLine()).size() != 0) { if(line == 0) { // should be the format/version string if(text.contains("NeuralPatternSimple:v1") == false) { printf("NeuralPattern::read wrong version type\n"); return; } } else if(numInputs < 0) { // should be the number of inputs sscanf(text.getArray(), "Inputs:%d", &numInputs); if(numInputs < 1) { printf("NeuralPattern::read invalid number of inputs\n"); return; } //printf("ins: %d\n", numInputs); inputVector = NumericalArray<float>::withSize(numInputs); } else if(numInputs > 0) { int index; float value; sscanf(text.getArray(), "%d %f", &index, &value); numInputs--; //printf("in[%3d] = %f\n", index, value); inputVector[index] = value; } else if(numOutputs < 0) { // should be the number of outputs sscanf(text.getArray(), "Outputs:%d", &numOutputs); if(numOutputs < 1) { printf("NeuralPattern::read invalid number of numOutputs\n"); return; } //printf("outs: %d\n", numOutputs); outputVector = NumericalArray<float>::withSize(numOutputs); } else if(numOutputs > 0) { int index; float value; sscanf(text.getArray(), "%d %f", &index, &value); numOutputs--; //printf("out[%3d] = %f\n", index, value); outputVector[index] = value; } if((numInputs == 0) && (numOutputs == 0)) { //printf("CREATING PATTERN\n"); setInternal(new NeuralPatternSimpleInternal(inputVector, outputVector)); return; } line++; } }
inline void operator=(const rgba_t &rgba) { setInternal(rgba); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SettingsWinCE::SettingsWinCE(OSystem* osystem) : Settings(osystem) { setInternal("romdir", (string) getcwd() + "\\Roms\\"); setInternal("wince_orientation", "0"); }
bool MemoryCacheImpl::replace(const std::string& key, GenericObject& value, const int& expireSeconds) { std::string valueStr = value.getSerilaizedState(); bool status = setInternal(key, valueStr, expireSeconds, 3); return status; }