/** * Stats the given file. If <tt>throttleRate</tt> seconds have passed since * the last time stat() was called on this file, then the file will be * re-stat()ted, otherwise the cached stat information will be returned. * * @param filename The file to stat. * @param stat A pointer to a stat struct; the retrieved stat information * will be stored here. * @param throttleRate Tells this CachedFileStat that the file may only * be statted at most every <tt>throttleRate</tt> seconds. * @return 0 if the stat() call succeeded or if the cached stat information was used; * -1 if something went wrong while statting the file. In the latter * case, <tt>errno</tt> will be populated with an appropriate error code. * @throws SystemException Something went wrong while retrieving the * system time. stat() errors will <em>not</em> result in * SystemException being thrown. * @throws boost::thread_interrupted */ int stat(const string &filename, struct stat *buf, unsigned int throttleRate = 0) { boost::unique_lock<boost::mutex> l(lock); EntryMap::iterator it(cache.find(filename)); EntryPtr entry; int ret; if (it == cache.end()) { // Filename not in cache. // If cache is full, remove the least recently used // cache entry. if (maxSize != 0 && cache.size() == maxSize) { EntryList::iterator listEnd(entries.end()); listEnd--; string filename((*listEnd)->filename); entries.pop_back(); cache.erase(filename); } // Add to cache as most recently used. entry = EntryPtr(new Entry(filename)); entries.push_front(entry); cache[filename] = entries.begin(); } else { // Cache hit. entry = *it->second; // Mark this cache item as most recently used. entries.erase(it->second); entries.push_front(entry); cache[filename] = entries.begin(); } ret = entry->refresh(throttleRate); *buf = entry->info; return ret; }
void Code::generateCall(SymbolTableEntry* entry, EntryList& eList) { EntryList::iterator it; for(it = eList.begin(); it != eList.end(); it++) generate(cd_APARAM,NULL,NULL,*it); generate(cd_CALL,entry,NULL,NULL); }
void print() { std::map<int, double> totals; std::cerr << "Timings: " << std::endl; // print out all the entries. //std::sort(root_entries.begin(), root_entries.end(), cmp()); printEntries(std::cerr, root_entries, " ", -1.0); for (EntryList::const_iterator it = entries.begin(); it != entries.end(); ++it) { totals[(*it).id] += (*it).time; } std::cerr << std::endl; std::cerr << "Totals: " << std::endl; std::vector<std::pair<int, double> > sorted_totals; sorted_totals.reserve(totals.size()); for (std::map<int,double>::iterator it = totals.begin(); it != totals.end(); ++it) { sorted_totals.push_back(*it); } std::sort(sorted_totals.begin(), sorted_totals.end(), cmp()); for (std::vector<std::pair<int,double> >::iterator it = sorted_totals.begin(); it != sorted_totals.end(); ++it) { std::cerr << " "; std::string str = names[it->first]; if (str.empty()) { std::cerr << "(" << it->first << ")"; } else { std::cerr << str; } std::cerr << " - " << it->second << "s " << std::endl; } }
SnapshotEntrySeqMap BuddyCoreSnapshotI::getFriends(const ::MyUtil::IntSeq& ids, const Ice::Current& current) { SnapshotEntrySeqMap result; ServiceI& service = ServiceI::instance(); for (IntSeq::const_iterator it = ids.begin(); it != ids.end(); ++it) { EntryListHolderPtr owner = service.findObject<EntryListHolderPtr>( CATEGORY_ENTRY, *it); if (!owner) { continue; } EntryList ownerList = owner->getAll(); SnapshotEntrySeq ownerSnap; for (EntryList::iterator ownerIt = ownerList.begin(); ownerIt != ownerList.end(); ++ownerIt) { int ownerToId = ownerIt->to; uint32_t ownerDesc = ownerIt->desc; //MCE_INFO("Owner:"<<*it <<" Buddy:"<<ownerToId << " Desc:"<<ownerDesc); if (ownerDesc!=DESC_FRIEND) { continue; } SnapshotEntry entryOwner; entryOwner.toId = ownerToId; entryOwner.desc = BuddyDescHelper::translateDesc(ownerDesc); ownerSnap.push_back(entryOwner); } result[*it] = ownerSnap; } return result; }
void AssFile::Sort(EntryList &lst, CompFunc comp, std::set<AssDialogue*> const& limit) { AssEntryComp compE; compE.comp = comp; // Sort each block of AssDialogues separately, leaving everything else untouched for (entryIter begin = lst.begin(); begin != lst.end(); ++begin) { if (!is_dialogue(&*begin, limit)) continue; entryIter end = begin; while (end != lst.end() && is_dialogue(&*end, limit)) ++end; // used instead of std::list::sort for partial list sorting EntryList tmp; tmp.splice(tmp.begin(), lst, begin, end); tmp.sort(compE); lst.splice(end, tmp); begin = --end; } }
void MamdaOrderBookPriceLevel::MamdaOrderBookPriceLevelImpl::clearEntries ( EntryList& entries) { EntryList::iterator itr = entries.begin(); EntryList::iterator end = entries.end(); for (; itr != end; itr++) { delete *itr; } entries.clear(); }
void AssFile::Sort(EntryList<AssDialogue> &lst, CompFunc comp, std::set<AssDialogue*> const& limit) { if (limit.empty()) { lst.sort(comp); return; } // Sort each selected block separately, leaving everything else untouched for (auto begin = lst.begin(); begin != lst.end(); ++begin) { if (!limit.count(&*begin)) continue; auto end = begin; while (end != lst.end() && limit.count(&*end)) ++end; // sort doesn't support only sorting a sublist, so move them to a temp list EntryList<AssDialogue> tmp; tmp.splice(tmp.begin(), lst, begin, end); tmp.sort(comp); lst.splice(end, tmp); begin = --end; } }
void ConfigSection::remove_entry(const char* key) { E_ASSERT(key != NULL); int klen = strlen(key); unsigned int hh = do_hash(key, klen); EntryListIter it = entry_list.begin(); for(; it != entry_list.end(); ++it) { ConfigEntry* e = *it; if(hh == e->hash && strncmp(e->key, key, e->keylen) == 0) entry_list.erase(it); } }
Profile::EntryList Profile::list(List type) { EntryList parentList; if (m_parent) parentList = m_parent->list(type); EntryList list = parentList; for (EntryList::iterator it = list.begin(); it != list.end(); ++it) (*it).derived = true; QStringList &personalList = listByType(type); for (QStringList::const_iterator it = personalList.begin(); it != personalList.end(); ++it) list.append(Entry(*it, false)); return list; }
DB_Error DataBaseSqlite::AddUser(shared_ptr<User> user) { DB_Error ret = CreateTable("User"); if (ret == DB_OK) { EntryList entries = m_pTableComponent->GetTableFormat("User"); PDEBUG ("entry size: %lu\n", entries.size()); if (!entries.empty()) { string sql(INSERT_TABLE); sql += string("User") + VALUE + LPARENT; EntryList::iterator iter = entries.begin(); EntryList::iterator end = entries.end(); for (; iter != end;) { sql += "@" + iter->name; if (++iter != end) { sql += ", "; } } sql += string(RPARENT) + SEMI; SqliteCommand cmd(this, sql); // Ugly hard code!! PDEBUG ("Begin binding\n"); ret = cmd.Bind("@name", user->name()); ret = ret ? ret : cmd.Bind("@uuid", user->uuid()); int64 date = 0; if (user->has_reg_date()) { ret = user->reg_date(); } ret = ret ? ret : cmd.Bind("@reg_date", date); date = 0; if (user->has_last_login()) { date = user->last_login(); } ret = ret ? ret : cmd.Bind("@last_login", date); // Bind others ... ret = ret ? ret : cmd.Execute(); // Execute .... } } return ret; }
ConfigEntry* ConfigSection::find_entry(const char* key) { E_ASSERT(key != NULL); int klen = strlen(key); unsigned int hh = do_hash(key, klen); EntryListIter it = entry_list.begin(), it_end = entry_list.end(); for (; it != it_end; ++it) { ConfigEntry* e = *it; if (hh == e->hash && strncmp(e->key, key, e->keylen) == 0) return e; } return NULL; }
void print( std::ostream& o = std::cout ) const { o << "ED LOOKUP TABLE\n"; for ( typename EDTable::size_type ii=0; ii<table.size(); ++ii ) { o << "\tDIMENSION: " << ii << '\n'; for ( typename DimensionEntries::const_iterator jj=table[ii].begin() ; jj!=table[ii].end(); ++jj ) { (jj)->print(o); } } o << "\tCURRENT ENTRIES:\n"; for ( typename EntryList::const_iterator ii=entries.begin(); ii!=entries.end(); ++ii ) { o << *ii << '\n'; } }
void BuddyRelationLogic::addBuddyRelationData(Ice::Int id, const BuddyRelationDataPtr& data) { EntryList list; ostringstream info; for (RelationEntryList::iterator en = data->list.begin(); en != data->list.end(); ++en) { Entry entry(en->id, BuddyDescHelper::translateInt(en->desc)); list.push_back(entry); info << "<" << en->id << "/" << BuddyDescHelper::translateInt(en->desc) << "> "; } MCE_DEBUG("BuddyRelationLogic::addBuddyRelationData, id "<< id << " relations " << info.str()); sort(list.begin(), list.end(), less_entry()); EntryListHolderPtr holder = new EntryListHolder(id, list); writeObject(id, holder); }
void FillTask::handle() { ObjectResultPtr result = new ObjectResult(); for ( std::map<long, Ice::ObjectPtr>::const_iterator it = _buddyData->data.begin(); it!= _buddyData->data.end(); ++it ){ BuddyRelationDataPtr data = BuddyRelationDataPtr::dynamicCast(it->second); EntryList list; list.reserve(data->list.size()); for(RelationEntryList::iterator en = data->list.begin(); en != data->list.end(); ++en) { Entry entry(en->id, BuddyDescHelper::translateInt(en->desc)); list.push_back(entry); } sort(list.begin(), list.end(), less_entry()); EntryListHolderPtr holder = new EntryListHolder(it->first, list); result->data[it->first] = holder; } _logic->writeObjects(result); }
/*******************private interface***********************/ void BuddyRelationLogic::createRelation(const Relationship& relation, BuddyDesc desc) { BuddyRelationDataPtr data = BuddyRelationFactory::instance().create(relation.from); EntryList list; for(RelationEntryList::iterator en = data->list.begin(); en != data->list.end(); ++en) { Entry entry(en->id, BuddyDescHelper::translateInt(en->desc)); list.push_back(entry); } sort(list.begin(), list.end(), less_entry()); EntryListHolderPtr holder = new EntryListHolder(relation.from, list); Entry key; key.to = relation.to; key.desc = BuddyDescHelper::translateInt(desc); holder->add(key); writeObject(relation.from, holder); }
DB_Error DataBaseSqlite::CreateTable(const string& name) { DB_Error ret = DB_INVAL; EntryList entries = m_pTableComponent->GetTableFormat(name); PDEBUG ("entry size: %lu\n", entries.size()); if (!entries.empty()) { string sql(CREATE_TABLE); sql += IFNEXT + name + LPARENT; EntryList::iterator iter = entries.begin(); EntryList::iterator end = entries.end(); for (; iter != end;) { sql += iter->name + " " + g_SqlteKeywordMapping[iter->type]; if (iter->primary) { sql += PRIMARY_KEY; } if (++iter != end) { sql += ", "; } } sql += string(RPARENT) + SEMI; SqliteCommand cmd(this, sql); ret = cmd.Execute(); } PDEBUG ("Create %s, ret: %d\n", name.c_str(), ret); return ret; }
void KNewFileMenuSingleton::parseFiles() { //kDebug(1203); filesParsed = true; KNewFileMenuSingleton::EntryList::iterator templ = templatesList->begin(); const KNewFileMenuSingleton::EntryList::iterator templ_end = templatesList->end(); for (; templ != templ_end; ++templ) { QString iconname; QString filePath = (*templ).filePath; if (!filePath.isEmpty()) { QString text; QString templatePath; // If a desktop file, then read the name from it. // Otherwise (or if no name in it?) use file name if (KDesktopFile::isDesktopFile(filePath)) { KDesktopFile desktopFile( filePath); text = desktopFile.readName(); (*templ).icon = desktopFile.readIcon(); (*templ).comment = desktopFile.readComment(); QString type = desktopFile.readType(); if (type == "Link") { templatePath = desktopFile.desktopGroup().readPathEntry("URL", QString()); if (templatePath[0] != '/' && !templatePath.startsWith("__")) { if (templatePath.startsWith("file:/")) templatePath = KUrl(templatePath).toLocalFile(); else { // A relative path, then (that's the default in the files we ship) QString linkDir = filePath.left(filePath.lastIndexOf('/') + 1 /*keep / */); //kDebug(1203) << "linkDir=" << linkDir; templatePath = linkDir + templatePath; } } } if (templatePath.isEmpty()) { // No URL key, this is an old-style template (*templ).entryType = KNewFileMenuSingleton::Template; (*templ).templatePath = (*templ).filePath; // we'll copy the file } else { (*templ).entryType = KNewFileMenuSingleton::LinkToTemplate; (*templ).templatePath = templatePath; } } if (text.isEmpty()) { text = KUrl(filePath).fileName(); if (text.endsWith(".desktop")) text.truncate(text.length() - 8); } (*templ).text = text; /*kDebug(1203) << "Updating entry with text=" << text << "entryType=" << (*templ).entryType << "templatePath=" << (*templ).templatePath;*/ } else { (*templ).entryType = KNewFileMenuSingleton::Separator; } } }
void Code::generateFormals(EntryList& entrylist) { EntryList::iterator it; for(it = entrylist.begin(); it != entrylist.end(); it++) generate(cd_FPARAM,NULL,NULL,*it); }
void Code::generateVariables(EntryList& entrylist) { EntryList::iterator it; for(it = entrylist.begin(); it != entrylist.end(); it++) generate(cd_VAR,NULL,NULL,*it); }
SnapshotEntrySeqMap BuddyCoreSnapshotI::getEntry4CommonFriend( ::Ice::Int userId, const Ice::Current& current) { SnapshotEntrySeqMap result; ServiceI& service = ServiceI::instance(); EntryListHolderPtr owner = service.findObject<EntryListHolderPtr>( CATEGORY_ENTRY, userId); if (!owner) { return result; } EntryList ownerList = owner->getAll(); SnapshotEntrySeq ownerSnap; for (EntryList::iterator ownerIt = ownerList.begin(); ownerIt != ownerList.end(); ++ownerIt) { int ownerToId = ownerIt->to; uint32_t ownerDesc = ownerIt->desc; SnapshotEntry entryOwner; entryOwner.toId = ownerToId; entryOwner.desc = BuddyDescHelper::translateDesc(ownerDesc); ownerSnap.push_back(entryOwner); EntryListHolderPtr ownerBuddy = service.findObject<EntryListHolderPtr>( CATEGORY_ENTRY, ownerToId); if (!ownerBuddy) { continue; } if (ownerDesc == DESC_FRIEND) { EntryList buddyList = ownerBuddy->getAll(); SnapshotEntrySeq buddySnap; for (EntryList::iterator buddyIt = buddyList.begin(); buddyIt != buddyList.end(); ++buddyIt) { int buddyToId = buddyIt->to; uint32_t buddyDesc = buddyIt->desc; if (buddyDesc==DESC_FRIEND || buddyDesc == DESC_APPLY) { SnapshotEntry entryFF; entryFF.toId = buddyToId; entryFF.desc = BuddyDescHelper::translateDesc(buddyDesc); buddySnap.push_back(entryFF); } } result[ownerToId] = buddySnap; } if (ownerDesc == DESC_APPLY) { EntryList buddyList = ownerBuddy->getAll(); SnapshotEntrySeq buddySnap; for (EntryList::iterator buddyIt = buddyList.begin(); buddyIt != buddyList.end(); ++buddyIt) { int buddyToId = buddyIt->to; uint32_t buddyDesc = buddyIt->desc; if (buddyDesc==DESC_FRIEND) { SnapshotEntry entryAF; entryAF.toId = buddyToId; entryAF.desc = BuddyDescHelper::translateDesc(buddyDesc); buddySnap.push_back(entryAF); } } result[ownerToId] = buddySnap; } } result[userId] = ownerSnap; return result; }