QStringList FindKeyOperation::findKey(const QVariant &in, const QString &key, const QString &prefix) { QStringList result; if (in.type() == QVariant::Map) { QVariantMap map = in.toMap(); for (QVariantMap::const_iterator i = map.begin(); i != map.end(); ++i) { QString pfx = prefix; if (!pfx.isEmpty()) pfx.append(QLatin1Char('/')); if (i.key() == key) { result << pfx + key; } else { pfx.append(i.key()); result.append(findKey(i.value(), key, pfx)); } } } else if (in.type() == QVariant::List) { QVariantList list = in.toList(); for (int pos = 0; pos < list.count(); ++pos) { QString pfx = prefix + QLatin1Char('[') + QString::number(pos) + QLatin1Char(']'); result.append(findKey(list.at(pos), key, pfx)); } } return result; }
int TCBSpline::findKey(int curTime,int startIndex, int endIndex) { if (curTime > keys[numKeys-1].ti) return -1; if (startIndex >= endIndex) return -1; if (curTime >= keys[startIndex].ti && curTime < keys[startIndex+1].ti) return startIndex; if (startIndex + 1 == endIndex) return startIndex; int mid = (startIndex+endIndex) >> 1; if (curTime >= keys[startIndex].ti && curTime < keys[mid].ti) { return findKey(curTime, startIndex, mid); } else if (curTime >= keys[mid].ti && curTime <= keys[endIndex].ti) { return findKey(curTime, mid, endIndex); } else { return keys[endIndex].ti; } }
bool rspfFgdcTxtDoc::open(const rspfFilename& file) { bool result = false; // Open the file: std::ifstream str( file.c_str(), std::ios_base::in ); if ( str.good() ) { std::string key = "Metadata_Standard_Version"; std::string value; if ( findKey( str, true, key, value ) ) { if ( value == FGDC_VERSION_001_1998 ) { result = true; m_kwl->addPair( FGDC_VERSION_KW, value ); m_kwl->addPair( FGDC_FILE_KW, file.string() ); // Store for getAltitudeDistanceUnits() method if key found. key = "Altitude_Distance_Units"; if ( findKey( str, false, key, value ) ) { m_kwl->addPair( ALTITUDE_DISTANCE_UNITS_KW, value ); } } } } return result; }
bool FindKeyOperation::test() const { QVariantMap testMap; QVariantMap subKeys; QVariantMap cur; cur.insert(QLatin1String("testint"), 53); subKeys.insert(QLatin1String("subsubkeys"), cur); subKeys.insert(QLatin1String("testbool"), true); testMap.insert(QLatin1String("subkeys"), subKeys); subKeys.clear(); testMap.insert(QLatin1String("subkeys2"), subKeys); testMap.insert(QLatin1String("testint"), 23); testMap.insert(QLatin1String("testbool"), true); QStringList result; result = findKey(testMap, QLatin1String("missing")); if (!result.isEmpty()) return false; result = findKey(testMap, QLatin1String("testint")); if (result.count() != 2 || !result.contains(QLatin1String("testint")) || !result.contains(QLatin1String("subkeys/subsubkeys/testint"))) return false; result = findKey(testMap, QLatin1String("testbool")); if (result.count() != 2 || !result.contains(QLatin1String("testbool"))) return false; return true; }
Xmpdatum& XmpData::operator[](const std::string& key) { XmpKey xmpKey(key); iterator pos = findKey(xmpKey); if (pos == end()) { add(Xmpdatum(xmpKey)); pos = findKey(xmpKey); } return *pos; }
Iptcdatum& IptcData::operator[](const std::string& key) { IptcKey iptcKey(key); iterator pos = findKey(iptcKey); if (pos == end()) { add(Iptcdatum(iptcKey)); pos = findKey(iptcKey); } return *pos; }
void CfgFile::addBlock(const std::string &sBlock, const blockMap &block) { if (findBlock(sBlock) == 0) { std::ofstream f; copyFirstPart(f, cfgfile.tellg()); for (auto item : block) { std::string sValue = item.second; if (sValue.find_first_of("\n\r") != std::string::npos) throw std::invalid_argument("I can't write a string containing a 'new line' to the config file!"); escapeString(sValue, "\"#", '\\'); if (sValue.find_first_of(" \t") != std::string::npos) sValue = "\"" + sValue + "\""; f << '\t' << item.first << " = " << sValue << "\n"; } findKey(""); copySecondPart(f, cfgfile.tellg()); } else { cfgfile.seekg(biggestBlockPosition); if (findKey("") != 2) throw std::logic_error( "unhandled return value of findKey(). Or something is very wrong with your cfg file."); // now we are at eof, but empty lines or comments at the end of the file do not matter cfgfile.unget(); if (cfgfile.get() != '\n') cfgfile << '\n'; cfgfile.clear(); cfgfile << "\n[" << sBlock << "]\n"; for (auto item : block) { std::string sValue = item.second; if (sValue.find_first_of("\n\r") != std::string::npos) throw std::invalid_argument("I can't write a string containing a 'new line' to the config file!"); escapeString(sValue, "\"#", '\\'); if (sValue.find_first_of(" \t") != std::string::npos) sValue = "\"" + sValue + "\""; cfgfile << '\t' << item.first << " = " << sValue << "\n"; } cfgfile.flush(); } }
bool FindKeyOperation::test() const { QVariantMap testMap; QVariantMap subKeys; QVariantMap cur; cur.insert(QLatin1String("testint"), 53); subKeys.insert(QLatin1String("subsubkeys"), cur); subKeys.insert(QLatin1String("testbool"), true); testMap.insert(QLatin1String("subkeys"), subKeys); subKeys.clear(); testMap.insert(QLatin1String("subkeys2"), subKeys); testMap.insert(QLatin1String("testint"), 23); testMap.insert(QLatin1String("testbool"), true); subKeys.clear(); QVariantList list1; list1.append(QLatin1String("ignore this")); list1.append(QLatin1String("ignore this2")); QVariantList list2; list2.append(QLatin1String("somevalue")); subKeys.insert(QLatin1String("findMe"), QLatin1String("FindInList")); list2.append(subKeys); list2.append(QLatin1String("someothervalue")); list1.append(QVariant(list2)); testMap.insert(QLatin1String("aList"), list1); QStringList result; result = findKey(testMap, QLatin1String("missing")); if (!result.isEmpty()) return false; result = findKey(testMap, QLatin1String("testint")); if (result.count() != 2 || !result.contains(QLatin1String("testint")) || !result.contains(QLatin1String("subkeys/subsubkeys/testint"))) return false; result = findKey(testMap, QLatin1String("testbool")); if (result.count() != 2 || !result.contains(QLatin1String("testbool"))) return false; result = findKey(testMap, QLatin1String("findMe")); if (result.count() != 1 || !result.contains(QLatin1String("aList[2][1]/findMe"))) return false; return true; }
//arguments to output to file(input file, output file, frequency data file) //arguments to output to console(input file, frequency data file) int main(int argc, char* argv[]) { float given[26], found[26]; int key; if (argc != 4 && argc != 3) { printf ("Arguments to output to file: infile, outfile, data file\nArguments to output to console: infile, data file\n"); exit(1); } //prints to console if(argc == 3) { readFreq(given, argv[2]); calcFreq(found, argv[1]); key = findKey(given, found); decrypt(key, argv[1]); } else if (argc == 4) //prints to output file { readFreq(given, argv[3]); calcFreq(found, argv[1]); key = findKey(given, found); decryptToFile(key, argv[1], argv[2]); } return 0; }
JSONParser( const std::string& jsonStr ) : std::map< std::string, std::string >() { m_jsonStr = jsonStr; pos = 1; skipSpaces(); long keyCount = 0; std::string key; while ( pos < m_jsonStr.length() ) { if ( ( m_jsonStr[ 0 ] == '[' ) || keyCount ) { key = numToStr( keyCount++ ); } else { key = findKey(); } if ( pos >= m_jsonStr.length() ) { return; } std::string value = findValue( keyCount != 0 ); insert( std::pair< std::string, std::string >( key, value ) ); if ( keyCount && ( m_jsonStr[ pos ] == ',' || m_jsonStr[ pos ] == ']' ) ) { ++pos; skipSpaces(); } else { moveToEndChar(); } } }
/** * deleteRecord(key) locates the desired record. Normally, all reads are ultimately * followed by a write. In this case, the next record is read from the file without * saving the current record so that the next pass through the file will not find * this record, anymore. * Returns whether the record with the key was found (and presumably deleted). **/ int deleteRecord(KeyType key) { if ( findKey(key) ) { /* replace current record with next record */ atEnd = (fread(&rec, sizeof(rec), 1, sourceFile) < 1); return 1; } else return 0; }
const char* Map_GetValueFromKey(MAP_HANDLE handle, const char* key) { const char* result; /*Codes_SRS_MAP_02_040: [If parameter handle or key is NULL then Map_GetValueFromKey returns NULL.]*/ if ( (handle == NULL) || (key == NULL) ) { result = NULL; LogError("invalid parameter to Map_GetValueFromKey\r\n"); } else { MAP_HANDLE_DATA * handleData = (MAP_HANDLE_DATA *)handle; char** whereIsIt = findKey(handleData, key); if(whereIsIt == NULL) { /*Codes_SRS_MAP_02_041: [If the key is not found, then Map_GetValueFromKey returns NULL.]*/ result = NULL; } else { /*Codes_SRS_MAP_02_042: [Otherwise, Map_GetValueFromKey returns the key's value.] */ size_t index = whereIsIt - handleData->keys; result = handleData->values[index]; } } return result; }
char *stringValue(Val_t val) { s57key_t *key = findKey(val.key); strcpy(outstr, ""); switch (val.type) { case A: case S: strcpy(outstr, val.val.a); break; case E: if (findVal(key, val.val.e) == NULL) break; strcpy(outstr, findEnum(key, val.val.e)); break; case L: { strcpy(outstr, ""); Lst_t *lst = val.val.l; while (lst != NULL) { strcat(outstr, findEnum(key, lst->val)); lst = lst->next; if (lst != NULL) strcat(outstr, ";"); } } break; case I: sprintf(outstr, "%ld", val.val.i); break; case F: sprintf(outstr, "%g", val.val.f); break; } return outstr; }
BOOL CCmdLineParser::HasKey(LPCTSTR sKey) const { CValsMap::const_iterator it = findKey(sKey); if(it == m_valueMap.end()) return false; return true; }
LPCTSTR CCmdLineParser::GetVal(LPCTSTR sKey) const { CValsMap::const_iterator it = findKey(sKey); if (it == m_valueMap.end()) return 0; return it->second.c_str(); }
// If create is set to true, will create key if it does not exist bool CIniFile::SetValue(const string §ion, const string &key, const string &value, bool const create) { S32 sectionId = findSection(section); if(sectionId == noID) { if(create) sectionId = addSection(section); else return false; if(sectionId == noID) sectionId = findSection(section); if(sectionId == noID) // Fish in a tree? This should not be. return false; } S32 valueID = findKey(sectionId, key); if(valueID == noID) { if(!create) return false; sections[sectionId].keys.push_back(key); sections[sectionId].values.push_back(value); } else sections[sectionId].values[valueID] = value; return true; }
bool EditorBase::hasContainsKey(int p_key) { if (findKey(p_key) != -1) return true; else return false; }
RC insertKey (BTreeHandle *tree, Value *key, RID rid){ //printf("inserting(%d)\n", key->v.intV); RID res; int rt = findKey(tree,key,&res); if(rt==RC_OK){ return RC_IM_KEY_ALREADY_EXISTS; } Node* root = (Node*)tree->mgmtData; if(root->nval==0){ root->rids[0].page=rid.page; root->rids[0].slot=rid.slot; root->vals[0]=key->v.intV; root->vals[1]=0; root->nds[2]=NULL; root->nval++; incNumNodes(tree); incNumEntries(tree); //printTree(tree); //printf("\n\n\n\n\n\n"); return RC_OK; } Node *ret = insertNode(tree,root,key->v.intV,rid); if(ret != NULL){ tree->mgmtData = ret; //printf("new root: (%d,%d)\n", ret->vals[0],ret->vals[1]); incNumNodes(tree); } //printTree(tree); //printf("\n\n\n\n\n\n"); return RC_OK; }
/* inArray: Returns true if key is in array */ int inArray( Symbol *s ) { int index; char *key; Array *array; /* get the array */ array = getArray( s ); eMemTest( "inArray: array", array ); if (!array->isDynamic) { ePrintf( Runtime, "%s is a static array", s->name ); } /* get key */ key = popString(); index = findKey( array, s, key ); eFree( key ); /* found key? */ if (index == -1) { return 0; } else { return 1; } }
void Node::updateMeta() { QMutexLocker mutlock(&featMutex); if (MetaUpToDate) return; Feature::updateMeta(); IsWaypoint = (findKey("_waypoint_") != -1); IsPOI = false; for (int i=0; i<tagSize(); ++i) { if (!M_PREFS->getTechnicalTags().contains(tagKey(i))) { IsPOI = true; break; } } if (!IsPOI && !IsWaypoint) { int i=0; int prtReadonly=0, prtWritable=0; for (; i<sizeParents(); ++i) { if (getParent(i)->isReadonly()) ++prtReadonly; else ++prtWritable; } if (!ReadOnly) { if (prtReadonly && !prtWritable) setReadonly(true); } } MetaUpToDate = true; }
ValueType sMap<ValueType>::get(std::string key) { int index = findKey(key); if (index == -1 ) { throw -1;// Key not in map error ? } return array[index].value; }
bool IndexCursor::advance() { killCurrentOp.checkForInterrupt(); if ( ok() ) { // Advance one row further, and then check if we've went out of bounds. _advance(); } else { if ( tailable() ) { if ( _currKey < _endKey ) { // Read the most up-to-date minUnsafeKey from the namespace refreshMinUnsafeEndKey(); _advance(); } else { // reset _currKey, we may have accidentally // gone past _endKey when we did our last advance // and saw something we are not allowed to see. _currKey = _endKey; // Read the most up-to-date minUnsafeKey from the namespace refreshMinUnsafeEndKey(); findKey( _currKey.isEmpty() ? minKey : _currKey ); } } else { // Exhausted cursors that are not tailable never advance return false; } } // the key we are now positioned over may or may not be ok to read. // checkCurrentAgainstBounds() will decide. return checkCurrentAgainstBounds(); }
// Main method for decoder.c int main(int argc, char* argv[]){ FILE *fin; FILE *fout; int option; int key; char ch; // Applies all spots to 0 float given[26] = {0}; float found[26] = {0}; // Initial check for correct arguments, take from cipher.c if (argc != 5){ printf ("Parameters: cipher option, key, input file, output file\n"); printf ("Cipher option 1 : encryption\tCipher option 2 : decryption\n"); exit(1); } // Assign integer values to key and selection of encryption/decription option = atoi(argv[1]); key = atoi(argv[2]); // This invokes decription when user prompts input option as 2 if (option == 2){ // Process for decoding: // 1.Read file 2.Calcuate frequencies given // 3.Find the key for decoding and 4.Decode the file readFreq(given, "LetFreq.txt"); calcFreq(found, argv[3]); int key = findKey(given, found); decrypt(key, argv[3], argv[4]); } // This was made as a fail safe to using the makefile, it will // encrypt regardless of if it was before when the user wishes to do // such. Also this made developing much easier because I only needed // to run my file for it to execute the full encrypt/decrypt process else{ // Main files to receive code to encrypt and file to send output to fin = fopen(argv[3], "r"); fout = fopen(argv[4], "w"); // Checks if files exist if (fin == NULL || fout == NULL){ printf("File could not be opened\n"); exit(1); } // Prints encrypted text to the output file defined above while (fscanf(fin, "%c", &ch) != EOF){ fprintf(fout, "%c", encrypt(ch, key)); } // Seal off files after being written to or read from fclose(fin); fclose(fout); } return 0; }
static bool findKey (Tree pl, Tree key, Tree& val) { if (isNil(pl)) return false; if (left(hd(pl)) == key) { val = right(hd(pl)); return true; } if (isBefore(left(hd(pl)),key)) return findKey (tl(pl), key, val); return false; }
__int64 CCmdLineParser::GetLongLongVal(LPCTSTR sKey) const { CValsMap::const_iterator it = findKey(sKey); if (it == m_valueMap.end()) return 0; return _ttoi64(it->second.c_str()); }
/** * getRecord(key, &record) copies the record with matching key into the * address indicated by the second argument. * Returns whether a matching record exists. If false, specified record * is unchanged. **/ int getRecord(KeyType key, Customer * result) { if ( findKey(key) ) { memcpy(result, &rec, sizeof(rec)); return 1; } else return 0; }
/** * updateRecord(&record) changes the contents of the matching file record. * It is optimized so you can use getRecord to obtain data, change the data, * then use updateRecord to save the change. You can update the record * multiple times without incurring I/O as long as no access of other records * is occurring. This version does allow you to save multiple records and * update them in any order, although performance does suffer. updateRecord * simply searches to find the record if the one you are updating isn't the * current one. This flexibility comes at a price, however, as there is no * way to prevent you from updating the key and destroying another record. * To update the key value, you should use getRecord to save a local copy, * deleteRecord(key) to destroy the old record, change the key, and use * insertRecord to save the change as a new record. * Returns whether or not the updated record matches an existing record * in the file. **/ int updateRecord(Customer * r) { if ( KEY_COMPARE(r->KEY, rec.KEY) != 0 ) { if ( ! findKey(r->KEY) ) return 0; } memcpy(&rec, r, sizeof(rec)); /* can replace memcpy with packing and unpacking operations, if desired */ return 1; }
void KeyboardManager::onKeyReleased(const EventKeyboard::KeyCode keyCode, const Event* event) { auto key = findKey(keyCode); _pressedKeys &= ~static_cast<Keys>(key); if (onReleased != nullptr) { onReleased(key); } }
QString Node::toHtml() { QString D; int i; if ((i = findKey("_waypoint_")) != -1) D += "<p><b>"+QApplication::translate("MapFeature", "Waypoint")+"</b><br/>"; D += "<i>"+QApplication::translate("MapFeature", "coord")+": </i>" + COORD2STRING(position().y()) + " (" + Coord2Sexa(position().y()) + ") / " + COORD2STRING(position().x()) + " (" + Coord2Sexa(position().x()) + ")"; if ((i = findKey("_description_")) != -1) D += "<br/><i>"+QApplication::translate("MapFeature", "description")+": </i>" + tagValue(i); if ((i = findKey("_comment_")) != -1) D += "<br/><i>"+QApplication::translate("MapFeature", "comment")+": </i>" + tagValue(i); return Feature::toMainHtml(QApplication::translate("MapFeature", "Node"), "node").arg(D); }
TAnimationCurve<T> TAnimationCurve<T>::split(float start, float end) { Vector<TKeyframe<T>> keyFrames; start = Math::clamp(start, mStart, mEnd); end = Math::clamp(end, mStart, mEnd); if (Math::approxEquals(end - start, 0.0f)) return TAnimationCurve<T>(); UINT32 startKeyIdx = findKey(start); UINT32 endKeyIdx = findKey(end); keyFrames.reserve(endKeyIdx - startKeyIdx + 2); const KeyFrame& startKey = mKeyframes[startKeyIdx]; const KeyFrame& endKey = mKeyframes[endKeyIdx]; if (!Math::approxEquals(startKey.time, start)) { keyFrames.push_back(evaluateKey(startKey, mKeyframes[startKeyIdx + 1], start)); if (start > startKey.time) startKeyIdx++; } else { keyFrames.push_back(startKey); startKeyIdx++; } if(!Math::approxEquals(endKey.time, end)) { keyFrames.push_back(evaluateKey(endKey, mKeyframes[endKeyIdx + 1], end)); if (end < endKey.time) endKeyIdx--; } keyFrames.insert(keyFrames.begin() + 1, mKeyframes.begin() + startKeyIdx, mKeyframes.begin() + endKeyIdx + 1); for (auto& entry : keyFrames) entry.time -= start; return TAnimationCurve<T>(keyFrames); }