static void ClearStateMap(mapType &map) { for (typename mapType::iterator i = map.begin(); i != map.end(); i++) { SafeRelease(i->second.first); } map.clear(); }
int check_keys( hashType& h, mapType& m ) { set<int> collection; int res = 0; // (a) check sizes EXAM_CHECK_ASYNC_F( h.size() == m.size(), res ); // (b) iterate over multi_map for ( mapType::iterator i = m.begin(); i != m.end(); ++i ) { // look up that key in hash-table and keep all data in the set pair<hashType::iterator,hashType::iterator> range = h.equal_range( i->first ); for ( hashType::iterator j = range.first; j != range.second; ++j ) { collection.insert( j->second ); } } // (c) we should have seen as many elements as there are in the hash-table #if 0 if (collection.size() == h.size()) cout << " OK" << endl; else { // if not, please report cout << " FAILED: " << endl; int lastKey = -1; // iterate over all elements in multi_map for (mapType::iterator mIter = m.begin(); mIter != m.end(); mIter++) { // new key? print a new status line if (mIter->first != lastKey) { cout << endl << "Key : " << mIter->first << endl; lastKey = mIter->first; // print all hashed values for that key cout << " data in hash: "; pair<hashType::iterator,hashType::iterator> range = h.equal_range(mIter->first); for (hashType::iterator h = range.first; h != range.second; h++) { assert (h->first == lastKey); cerr << h->second << ", "; // print all data for that key in Hash-Table } cout << endl << " data in map: "; } // and print all member in multi-map until the next key occurs cout << mIter->second << ", " ; // print all data for that key in Map } } #endif EXAM_CHECK_ASYNC_F( collection.size() == h.size(), res ); return res; }
// return type?!? bool check_interface(mapType map_f, mapType map_c) { bool eqv = false; // check to ensure neither map is empty if (map_f.size() == 0 || map_c.size() == 0) { // Could make WARNING: in red std::cout << "WARNING: One or both of the maps are of size 0" << std::endl; std::cout << "map_f: size " << map_f.size() << ", map_c: size " << map_c.size() << std::endl; return false; } mapType::iterator itr; for (itr = map_f.begin(); itr != map_f.end(); ++itr) { std::string bind_func_name = itr->second->get_binding_label(); std::string c_func_name; mapType::iterator got_it = map_c.find(bind_func_name); if (got_it != map_c.end()) { c_func_name = got_it->first; if (compare_decl(itr->second, got_it->second) == true) { std::cout << "check_interface(): function declarations match" << std::endl; eqv = true; } else { std::cerr << "Error: Function names matches but function declarations do not match" << std::endl; return false; } } else { std::cout << "Error: Matching function name not found" << std::endl; } } return eqv; }