double Note2FreqTable::operator[](string str) const { MapT::const_iterator iter = m_rep.find(str); assert(iter != m_rep.end()); return iter->second; }
static void load_and_init_with_map(const char* file, double* cpu_times, MapT& M) { FILE* f = fopen(file,"r"); if(f == NULL){ fprintf(stderr, "Could not open %s file: %s", file, strerror(errno)); exit(-1); } double nanosec; char ops[48]; char line[512]; std::string tmp = ""; while(fgets(line,sizeof(line),f)){ unsigned op; if (sscanf(line, "%47[^:]:\t%lf nanoseconds", ops, &nanosec) == 2) { tmp = ops; auto ite = M.find(ops); if (ite != M.end()) { op = ite->second; cpu_times[op] = nanosec; } else continue; } } fclose(f); }
bool Cstore::VarRef::getValue(string& value, vtw_type_e& def_type) { vector<string> result; MapT<string, bool> added; def_type = ERROR_TYPE; for (size_t i = 0; i < _paths.size(); i++) { if (_paths[i].first.size() == 0) { // empty path continue; } if (added.find(_paths[i].first.back()) != added.end()) { // already added continue; } if (_paths[i].second == ERROR_TYPE && !_cstore->cfgPathExists(_paths[i].first, _active)) { // path doesn't exist => empty string added[""] = true; result.push_back(""); continue; } if (_paths[i].second != ERROR_TYPE) { // set def_type. all types should be the same if multiple entries exist. def_type = _paths[i].second; } added[_paths[i].first.back()] = true; result.push_back(_paths[i].first.back()); } if (result.size() == 0) { // got nothing return false; } if (result.size() > 1 || def_type == ERROR_TYPE) { /* if no type is available or we are returning "joined" multiple values, * treat it as text type. */ def_type = TEXT_TYPE; } value = ""; for (size_t i = 0; i < result.size(); i++) { if (i > 0) { value += " "; } value += result[i]; } return true; }
ValueT get_value_or(const MapT &map, const KeyT &key, ValueT def) { typename MapT::const_iterator it(map.find(key)); return it != map.end() ? it->second : def; }