/** * Cartesian product */ std::vector<box> box_factory::cartesian_product(std::map<std::string, std::vector<capd::interval>> m) { // checking if the map is empty if(m.empty()) { return vector<box>{}; } unsigned long size = 1; for(auto it = m.cbegin(); it != m.cend(); it++) { size *= (it->second).size(); } std::vector<box> product; for(unsigned long i = 0; i < size; i++) { unsigned long index = i; std::map<std::string, capd::interval> tmp_m; for(auto it1 = m.cbegin(); it1 != m.cend(); it1++) { unsigned long mult = 1; for(auto it2 = --m.cend(); it2 != it1; it2--) { mult *= (it2->second).size(); } unsigned long tmp_index = index / mult; tmp_m.insert(make_pair(it1->first, (it1->second).at(tmp_index))); index -= tmp_index * mult; } product.push_back(box(tmp_m)); } return product; }
std::wstring CTestCaseData::GetErrorMessageText() const { static std::wstring res; res = L"unknown message"; auto it = mapEncodingNames.find(iEncoding); assert(it != mapEncodingNames.cend()); if (it != mapEncodingNames.cend()) { res = it->second; } return res; }
void print(const std::map<T, P>& container) { #ifdef _DEBUG for (auto it = container.cbegin(); it != container.cend();) { std::cerr << it->first << ": " << it->second; it++; if (it != container.cend()) std::cerr << ", "; } #endif }
const IdentifierInfo * Get( const char * name ) const { auto it = _identifiers.find(name); if (it == _identifiers.cend()) return nullptr; return it->second; }
// path lookup within registry Path path( const std::string &key ) { std::map<std::string, Path>::const_iterator it = g_pathRegistry.find( key ); if( it != g_pathRegistry.cend() ) return it->second; return Path(); }
void dump_as_list(const int fd) final { using t = typename std::map<TId, TValue>::value_type; std::vector<t> v; v.reserve(m_elements.size()); std::copy(m_elements.cbegin(), m_elements.cend(), std::back_inserter(v)); osmium::io::detail::reliable_write(fd, reinterpret_cast<const char*>(v.data()), sizeof(t) * v.size()); }
std::vector<std::tuple<K, V>> to_vec(std::map<K, V> m) { std::vector<std::tuple<K, V>> vec; for (auto it = m.cbegin(); it != m.cend(); ++it) { vec.emplace_back(std::make_tuple(it->first, it->second)); } return vec; }
int main(int argc, char** argv) { SkCommandLineFlags::SetUsage( "Usage: get_images_from_skps -s <dir of skps> -o <dir for output images> --testDecode " "-j <output JSON path>\n"); SkCommandLineFlags::Parse(argc, argv); const char* inputs = FLAGS_skps[0]; gOutputDir = FLAGS_out[0]; if (!sk_isdir(inputs) || !sk_isdir(gOutputDir)) { SkCommandLineFlags::PrintUsage(); return 1; } SkOSFile::Iter iter(inputs, "skp"); for (SkString file; iter.next(&file); ) { SkAutoTDelete<SkStream> stream = SkStream::NewFromFile(SkOSPath::Join(inputs, file.c_str()).c_str()); sk_sp<SkPicture> picture(SkPicture::MakeFromStream(stream)); SkDynamicMemoryWStream scratch; Sniffer sniff(file.c_str()); picture->serialize(&scratch, &sniff); } int totalUnknowns = 0; /** JSON results are written out in the following format: { "failures": { "skp1": 12, "skp4": 2, ... }, "totalFailures": 32, "totalSuccesses": 21, } */ Json::Value fRoot; for(auto it = gSkpToUnknownCount.cbegin(); it != gSkpToUnknownCount.cend(); ++it) { SkDebugf("%s %d\n", it->first.c_str(), it->second); totalUnknowns += it->second; fRoot["failures"][it->first.c_str()] = it->second; } SkDebugf("%d known, %d unknown\n", gKnown, totalUnknowns); fRoot["totalFailures"] = totalUnknowns; fRoot["totalSuccesses"] = gKnown; if (totalUnknowns > 0) { if (!FLAGS_failuresJsonPath.isEmpty()) { SkDebugf("Writing failures to %s\n", FLAGS_failuresJsonPath[0]); SkFILEWStream stream(FLAGS_failuresJsonPath[0]); stream.writeText(Json::StyledWriter().write(fRoot).c_str()); stream.flush(); } return -1; } return 0; }
static inline bbb::json convert(std::map<std::string, type, comp, alloc> &table) { std::map<std::string, bbb::json> json_map; for(auto it = table.cbegin(); it != table.cend(); ++it) { json_map.emplace(it->first, std::move(convert(it->second))); } return json_map; }
bool removeTexture(const sf::String & alias) { ConstTextureIterator texture = textures.find(alias); if (texture != textures.cend()) { textures.erase(texture); return true; } return false; }
bool removeFont(const sf::String & fontAlias) { std::map<sf::String, sf::Font>::const_iterator font = fonts.find(fontAlias); if (font != fonts.cend()) { fonts.erase(font); return true; } return false; }
std::vector<std::string> getScraperList() { std::vector<std::string> list; for(auto it = scraper_request_funcs.cbegin(); it != scraper_request_funcs.cend(); it++) { list.push_back(it->first); } return list; }
static names_vec get_matching_groups( nameFlags searchFlags ) { names_vec matching_groups; for( auto it = names.cbegin(), end = names.cend(); it != end; ++it ) { const nameFlags type = it->first; if( ( searchFlags & type ) == searchFlags ) { matching_groups.push_back( it ); } } return matching_groups; }
const std::string &name_by_dt( const damage_type &dt ) { auto iter = dt_map.cbegin(); while( iter != dt_map.cend() ) { if( iter->second == dt ) { return iter->first; } iter++; } static const std::string err_msg( "dt_not_found" ); return err_msg; }
std::vector<int> find_vertical_sum(Node* node) { void vertical_sum_rec(Node* node, int index); vertical_sum_rec(node, 0); std::vector<int> result; // this is still not supported //for (auto it:vert_sum) { for (auto it = vert_sum.cbegin(); it != vert_sum.cend(); ++it) result.push_back(it->second); return result; }
static optional<std::pair<const std::string&, const variable&>> is_builtin_variable(const id& vid) { typedef std::pair<std::string, std::reference_wrapper<const variable>> var_pair; static const std::map<id, var_pair> names { { gl_NumWorkGroups.variable_id, var_pair{ "gl_NumWorkGroups", gl_NumWorkGroups } }, { gl_WorkGroupID.variable_id, var_pair{ "gl_WorkGroupID", gl_WorkGroupID } }, { gl_LocalInvocationID.variable_id, var_pair{ "gl_LocalInvocationID", gl_LocalInvocationID } }, { gl_GlobalInvocationID.variable_id, var_pair{ "gl_GlobalInvocationID", gl_GlobalInvocationID } }, { gl_LocalInvocationIndex.variable_id, var_pair{ "gl_LocalInvocationIndex", gl_LocalInvocationIndex } } }; auto v = names.find(vid); if (v == names.cend()) return nullopt; return optional<std::pair<const std::string&, const variable&>>(in_place, v->second.first, v->second.second); }
//fills lst or const_lst (depending on which is null) with all borrowers with specified name static void findByName_helper(const std::map<unsigned int, Borrower>& borrowers, const std::string name, list<Borrower*const> *const lst, list<const Borrower*const> *const const_lst){ borrowers_citer iter = borrowers.cbegin(); while (iter != borrowers.cend()) { if (iter->second.getName() == name) { const_lst == NULL ? lst->push_back(const_cast<Borrower*>(&iter->second)) : const_lst->push_back(&iter->second); } iter++; } }
// assuming the namenode id is 0 void GetServerIDsFromHostMap(std::vector<int32_t> *server_ids, const std::map<int32_t, HostInfo>& host_map){ int32_t num_servers = host_map.size() - 1; server_ids->resize(num_servers); int32_t i = 0; for (auto host_info_iter = host_map.cbegin(); host_info_iter != host_map.cend(); host_info_iter++) { if (host_info_iter->first == 0) continue; (*server_ids)[i] = host_info_iter->first; ++i; } }
const std::string get_mime_type(const std::string & filePath) { const char *defMimeType = "application/octet-stream"; size_t extPos = filePath.rfind('.'); if (extPos == std::string::npos || (extPos == filePath.length() - 1)) return defMimeType; std::map<std::string, std::string>::const_iterator it = mimeTypes.find(filePath.substr(extPos + 1)); if (it == mimeTypes.cend()) return defMimeType; return it->second; }
std::string optionsToString(std::map<std::string, std::string> const &options) { if (!options.empty()) { std::ostringstream resultStream; auto optionsKvpIt = options.cbegin(); auto const &firstKvp = (*optionsKvpIt); resultStream << firstKvp.first << "='" << firstKvp.second << '\''; for (; optionsKvpIt != options.cend(); ++optionsKvpIt) { auto kvp = (*optionsKvpIt); resultStream << ", " << kvp.first << "='" << kvp.second << '\''; } return resultStream.str(); } else { return std::string(); } }
int MeshInfoSet::InitializeMeshNeiboNum(const std::map<MeshPair, int>& meshPair, std::map<int, std::vector<std::pair<int, int>>>& meshNeiboNum) { int rtn = 0; meshNeiboNum.clear(); for (map<MeshPair, int>::const_iterator it = meshPair.cbegin(); it != meshPair.cend(); ++it) { rtn = AddMeshNeiboNum(it->first.first, it->first.second, it->second, meshNeiboNum); CHECK_RTN(rtn); rtn = AddMeshNeiboNum(it->first.second, it->first.first, it->second, meshNeiboNum); CHECK_RTN(rtn); } for (map<int, vector<pair<int, int>>>::iterator it = meshNeiboNum.begin(); it != meshNeiboNum.end(); ++it) sort(it->second.begin(), it->second.end(), CmpPairByLagerSecond<int, int>); return 0; }
//Any literal that is larger than maxvar was newly introduced by the transformation, so should be mapped to nVars()+lit Lit mapFromPBLit(MiniSatPP::Lit lit, int maxopbvar, PCSolver& pcsolver, std::map<Atom, Atom>& opbinternal2pcsolver){ auto var = MiniSatPP::var(lit); if(var <= maxopbvar){ return mkLit(var, sign(lit)); }else{ auto it = opbinternal2pcsolver.find(var); if(it==opbinternal2pcsolver.cend()){ auto newv = pcsolver.newAtom(); opbinternal2pcsolver[var] = newv; var = newv; }else{ var = it->second; } return mkLit(var, sign(lit)); } }
void remove_vertex(const T x) { const auto iterator = vertices.find(x); if(iterator == vertices.cend()) return; const size_t i = iterator->second; vertices.erase(x); empty_spots.push(i); edges.at(i).clear(); for(auto& e : edges) e.erase(i); }
void garbage_collection() { for (auto i = rx_pkt_queue.cbegin(); i != rx_pkt_queue.cend(); /* NO INCREMENT*/) { if (i->second->id <= last_fw_id) { #ifdef VERBOSE printf("Erasing pkt with id=%u, last_fw_id %u\n", i->first, last_fw_id); #endif rx_pkt_queue.erase(i++); } else { ++i; } } }
/** * Function: wakeSleepingThreads * Iterates over all threads alive and wakes them up if needed. * If a thread is awaken it is added to the READY list. */ void wakeSleepingThreads() { uthread *curr; // Add waking threads to READY list for (auto th=livingThreads.cbegin(); th != livingThreads.cend(); ++th) { // curr is the current thread in the for loop curr = th->second; // If the thread is sleeping and it should wake up, wake it up if (curr->get_state() == uthread::state::SLEEPING && uthread_get_time_until_wakeup(curr->get_id())==SHOULD_WAKE) { curr->set_state(uthread::state::READY); readyThreads.push_back(curr->get_id()); } } }
bool getTokenKeyword(const std::string& token, const std::string& name, const std::map<std::string, int>& map, int& value) { if (token.size() < name.size() + 2 || token.substr(0, name.size()) != name || token[name.size()] != '=') return false; std::string t = token.substr(name.size()+1); if (t[0] == '\'' && t[t.size()-1] == '\'') t = t.substr(1, t.size()-2); auto p = map.find(t); if (p == map.cend()) return false; value = p->second; return true; }
bool check_types(const std::map<std::string, uint16_t>& expected) { // holds the type names we see at runtime std::map<std::string, uint16_t> found; // fetch all available type names auto types = uniform_type_info::instances(); for (auto tinfo : types) { found.insert(std::make_pair(tinfo->name(), tinfo->type_nr())); } // compare the two maps if (expected == found) { CAF_CHECKPOINT(); return true; } CAF_CHECK(false); using const_iterator = std::map<std::string, uint16_t>::const_iterator; using std::setw; using std::left; std::ostringstream oss; oss << left << setw(20) << ("found (" + tostr(found.size(), 1) + ")") << " | expected (" << expected.size() << ")"; CAF_PRINT(oss.str()); oss.seekp(0); oss << std::setfill('-') << setw(22) << "" << "|" << setw(22) << ""; CAF_PRINT(oss.str()); auto fi = found.cbegin(); auto fe = found.cend(); auto ei = expected.cbegin(); auto ee = expected.cend(); std::string dummy(20, ' '); auto out = [&](const_iterator& i, const_iterator last) -> std::string { if (i == last) { return dummy; } std::ostringstream tmp; tmp << left << setw(16) << i->first << "[" << tostr(i->second) << "]"; ++i; return tmp.str(); }; while (fi != fe || ei != ee) { CAF_PRINT(out(fi, fe) << " | " << out(ei, ee)); } return false; }
void check_martialarts() { for( auto style = martialarts.cbegin(); style != martialarts.cend(); ++style ) { for( auto technique = style->second.techniques.cbegin(); technique != style->second.techniques.cend(); ++technique ) { if( ma_techniques.find( *technique ) == ma_techniques.end() ) { debugmsg( "Technique with id %s in style %s doesn't exist.", technique->c_str(), style->second.name.c_str() ); } } for( auto weapon = style->second.weapons.cbegin(); weapon != style->second.weapons.cend(); ++weapon ) { if( !item::type_is_defined( *weapon ) ) { debugmsg( "Weapon %s in style %s doesn't exist.", weapon->c_str(), style->second.name.c_str() ); } } } }
int main() { const std::map< int, std::vector<double> > map = { { 247, { 1.2, 2.3, 3.4, 4.5 } }, { 106, { 5.6, 6.7, 7.8, 8.9, 9.1, 1.2, 2.3 } }, { 184, { 3.4, 4.5 } } }; { // option 1: range-based loops for( const auto& pair : map ) { std::cout << "key: " << pair.first << " value: [ " ; for( double d : pair.second ) std::cout << d << " " ; std::cout << "]\n" ; } } std::cout << "----------------\n" ; { // option 2: iterators for( auto map_iter = map.cbegin() ; map_iter != map.cend() ; ++map_iter ) { std::cout << "key: " << map_iter->first << " value: [ " ; for( auto vec_iter = map_iter->second.cbegin() ; vec_iter != map_iter->second.cend() ; ++vec_iter ) std::cout << *vec_iter << " " ; std::cout << "]\n" ; } } std::cout << "----------------\n" ; { // option 3: range-based loop for map, subscript operator for vector for( const auto& pair : map ) { std::cout << "key: " << pair.first << " value: [ " ; for( std::size_t i = 0 ; i < pair.second.size() ; ++i ) std::cout << pair.second[i] << " " ; std::cout << "]\n" ; } } // options 4, 5 ... }
DRAWABLE_PTR_CONTAINER_TEMPLATE_CPP const model_map ModelData::readModelList(GLFWwindow* window, const std::map<std::string, std::string>& fileNamesAndPaths, const DescriptorType descType){ model_map models; std::map<std::string, std::string>::const_iterator it; // Start to asynchronously load models for (it = fileNamesAndPaths.cbegin(); it != fileNamesAndPaths.cend(); ++it){ models.emplace(it->first, new ModelData(it->second, false, descType)); // Do not create voxel space, also } // Wait for individual models to load std::map<std::string, ModelData*>::const_iterator m_i; for (m_i = models.cbegin(); m_i != models.cend(); ++m_i){ Framework::GL::initObjectToDraw(m_i->second, window); } Framework::ModelUtils::updateModelTransforms(models); return models; }