int Bchart:: headPosFromItems(Item* lhs, Items& rhs) { int ansPriority = 9999; ECString lhsString(lhs->term()->name()); if(lhsString == "") lhsString = "S1"; int pos = -1; int ans = -1; Items::iterator ii = rhs.begin(); Item *subi; for( ; ii != rhs.end() ; ii++ ) { subi = (*ii); pos++; const Term* trm = subi->term(); int nextPriority = 12; if(trm) { ECString rhsString(subi->term()->name()); if(subi->term() == Term::stopTerm) continue; nextPriority = headPriority(lhsString, rhsString, ansPriority); } if(nextPriority <= ansPriority) { ans = pos; ansPriority = nextPriority; } } return ans; }
void RowCollection<Group,Hash>::getWholeRow(size_t rowId, Items& items, bool separateNull, uint32_t attrId, Items* pNullItems) { assert(_mode==RowCollectionModeRead); assert(separateNull || (pNullItems==NULL)); assert(items.empty()); if (pNullItems!=NULL) { assert(pNullItems->empty()); } boost::scoped_ptr<MyRowIterator> rowIterator(openRow(rowId)); items.reserve(_counts[rowId]); TypeId strType = _attributes[attrId].getType(); DoubleFloatOther type = getDoubleFloatOther(strType); while (!rowIterator->end()) { vector<Value> item(_attributes.size()); rowIterator->getItem(item); if (separateNull && isNullOrNan(item[attrId], type)) { if (pNullItems!=NULL) { pNullItems->push_back(item); } } else { items.push_back(item); } ++(*rowIterator); } }
int main() { string commandLine = "start"; while (commandLine != "exit") { cout << "$ "; getline(cin ,commandLine); if(commandLine != "exit") { string temp; for (istringstream tString1(commandLine); tString1 >> temp; ) { int type = 0; bool detectCon = false; vector<string> arr; detectCon = add_com(arr, temp, type); while (!detectCon && !tString1.eof()) { tString1 >> temp; detectCon = add_com(arr, temp, type); } Items* complCom = new Command(); Items* complCon; complCom->set_command(arr); if (type == 0 || type == -1) {complCon = new Always();} else if (type == 2) {complCon = new Failure();} else if (type == 1) {complCon = new Success();} complCon->set_before(complCom); } }
void InventoryImpl::draw() { Vector2f pos = Vector2f(400, 300); int num_items = items.size(); float step_angle = (2.0f * math::pi) / static_cast<float>(num_items); for(int i = 0; i < int(items.size()); ++i) { const InventoryItem& item = items[(i+current_item) % items.size()]; Vector2f draw_pos = pos + Vector2f(128.0f, 0.0f).rotate(step_angle * static_cast<float>(i) - math::pi/2.0f + add_angle); if (i == 0 && moving == 0) { slothighlight.draw(draw_pos); Fonts::current()->vera20->draw_center(Vector2f(draw_pos.x, draw_pos.y - 64), item.name); } else { slot.draw(draw_pos); } item.sprite.draw(draw_pos - Vector2f(32,32)); } }
void InventoryImpl::draw() { Vector pos = Vector(400, 300); // View::current()->screen_Player::currently->get_pos(); int num_items = items.size(); float step_angle = (2*M_PI) / num_items; for(int i = 0; i < int(items.size()); ++i) { const InventoryItem& item = items[(i+current_item)%items.size()]; Vector draw_pos = pos + Vector(128, 0).rotate(step_angle * i - M_PI/2 + add_angle); if (i == 0 && moving == 0) { slothighlight.draw(draw_pos); Fonts::vera20->draw_center(draw_pos.x, draw_pos.y - 64, item.name); } else { slot.draw(draw_pos); } item.sprite.draw(draw_pos - Vector(32,32)); } }
QStringList ShopTemplateManager::WriteItems(const Items &items, bool includeBuyoutTag, bool includeNoBuyouts) { Items sorted = items; QStringList result; // Sort to ensure that the template matches even if the item order is different. std::sort(sorted.begin(), sorted.end(), [](const std::shared_ptr<Item> &first, const std::shared_ptr<Item> &second) -> bool { return first->PrettyName() > second->PrettyName(); }); for (auto &item : sorted) { if (item->location().socketed()) continue; if (parent_->buyout_manager().Exists(*item)) { Buyout bo = parent_->buyout_manager().Get(*item); QString temp = QString::fromStdString(item->location().GetForumCode(parent_->league())); if (includeBuyoutTag) temp += BuyoutManager::Generate(bo); result << temp; } else if (includeNoBuyouts) { result << QString::fromStdString(item->location().GetForumCode(parent_->league())); } } return result; }
Items ShopTemplateManager::FindMatchingItems(const Items &items, QString keyword) { Items matched; for (auto &item : items) { if (IsMatchingItem(item, keyword)) { matched.push_back(item); } } return matched; }
void Items::MergeFrom(const Items& from) { GOOGLE_CHECK_NE(&from, this); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from._has_bit(0)) { set_ret(from.ret()); } } mutable_unknown_fields()->MergeFrom(from.unknown_fields()); }
static Items by_size(Items items, Size size) { Items results; for (auto &i : items) { if (i->size == size) { results.push_back(i); } } return results; }
inline bool Configuration::import(const char* key, const char* val) { for(Items::iterator i = items_.begin(); i != items_.end(); ++i) { ConfigItem* item = *i; if(item->set_maybe(key, val)) return true; } return false; }
inline ConfigItem* Configuration::find(const char* key) { for(Items::iterator i = items_.begin(); i != items_.end(); ++i) { ConfigItem* item = *i; if(item->equal_p(key)) return item; } return 0; }
virtual Items filter(Items items, ISpecification<Product> &spec) override { Items result; for (auto &p : items) { if (spec.is_satisfied(p)) { result.push_back(p); } } return result; }
static Items by_color_and_size(Items items, Color color, Size size) { Items results; for (auto &i : items) { if (i->size == size && i->color == color) { results.push_back(i); } } return results; }
static Items by_color(Items items, Color color) { Items results; for (auto &i : items) { if (i->color == color) { results.push_back(i); } } return results; }
DFhackCExport command_result mapitems (Core * c, vector <string> & parameters) { c->Suspend(); vector <df_item *> vec_items; Gui * g = c-> getGui(); Maps* m = c->getMaps(); Items* it = c->getItems(); if(!m->Start()) { c->con.printerr("No map to probe\n"); return CR_FAILURE; } if(!it->Start() || !it->readItemVector(vec_items)) { c->con.printerr("Failed to get items\n"); return CR_FAILURE; } int32_t cx,cy,cz; g->getCursorCoords(cx,cy,cz); if(cx != -30000) { df_block * b = m->getBlock(cx/16,cy/16,cz); if(b) { c->con.print("Item IDs present in block:\n"); auto iter_b = b->items.begin(); while (iter_b != b->items.end()) { df_item * itmz = it->findItemByID(*iter_b); string s; itmz->getItemDescription(&s); c->con.print("%d = %s\n",*iter_b, s.c_str()); iter_b++; } c->con.print("Items under cursor:\n"); auto iter_it = vec_items.begin(); while (iter_it != vec_items.end()) { df_item * itm = *iter_it; if(itm->x == cx && itm->y == cy && itm->z == cz) { string s; itm->getItemDescription(&s,0); c->con.print("%d = %s\n",itm->id, s.c_str()); } iter_it ++; } } } c->Resume(); return CR_OK; }
Items Item::getSubItems() const { // TODO Make this better UsdPrimSiblingRange primChildren = m_prim.GetChildren(); Items children; for ( const auto &child : primChildren ) { children.push_back( Item( child ) ); } return children; }
void RowCollection<Group,Hash>::flushOneRowInBuffer(size_t rowId, Items const& items) { assert(rowId<_counts.size()); vector<boost::shared_ptr<ChunkIterator> > chunkIterators(_attributes.size()); try { if (! isLastChunkFull(rowId)) { // only get chunk iterators if there exists a non-full last chunk. getChunkIterators(chunkIterators, rowId); } for (size_t v=0; v<items.size(); ++v) { vector<Value> const& item = items[v]; if (isLastChunkFull(rowId)) { // when the last chunk was full, get the iterators here (right before append) getChunkIterators(chunkIterators, rowId); } for (size_t i=0; i<_attributes.size(); ++i) { chunkIterators[i]->writeItem(item[i]); } ++ _counts[rowId]; if (isLastChunkFull(rowId)) { // after append, flush and clear the chunk iterators if the last chunk becomes full for (size_t i=0; i<_attributes.size(); ++i) { chunkIterators[i]->flush(); chunkIterators[i].reset(); } } else { for (size_t i=0; i<_attributes.size(); ++i) { ++ (*chunkIterators[i]); } } } if (items.size()>0 && !isLastChunkFull(rowId)) { assert(chunkIterators[0]); for (size_t i=0; i<_attributes.size(); ++i) { chunkIterators[i]->flush(); chunkIterators[i].reset(); } } else { assert(! chunkIterators[0]); } } catch (std::exception& e) { LOG4CXX_DEBUG(logger, "[RowCollection] std::exception in RowIterator::appendItems(): " << e.what()); throw; } catch (...) { LOG4CXX_DEBUG(logger, "[RowCollection] (...) exception in RowIterator::appendItem()" ); throw; } }
void ItemsList::SetNode(Items* argu){ if(nCount==0){ Items* inow; inow = argu; inow->SetPrev(pStart); inow->SetNext(pEnd); pStart->SetNext(inow); pEnd->SetPrev(inow); } else{ Items* inow; pListPrev = pStart; inow = pStart->GetNext(); while(inow->GetNext()!=NULL){ pListPrev = inow; inow = inow->GetNext(); } inow = argu; inow->SetPrev(pListPrev); pListPrev->SetNext(inow); inow->SetNext(pEnd); pEnd->SetPrev(inow); pEnd->SetNext(NULL); } nCount++; }
void ChartBase:: free_chart_items(Items& itms) { Item *temp; while( !itms.empty() ) { temp = itms.front(); //temp->check(); itms.pop_front(); //if(!temp->term()->terminal_p()) delete temp; } }
void Search::UpdateItemCounts(const Items &items) { unfiltered_item_count_ = items.size(); filtered_item_count_total_ = 0; for (auto &item : items_) filtered_item_count_total_ += item->count(); }
inline void Configuration::print(bool desc) { for(Items::iterator i = items_.begin(); i != items_.end(); ++i) { ConfigItem* item = *i; std::cout << item->name() << ": "; item->print_value(std::cout); std::cout << "\n"; if(desc) { if(const char* desc = item->description()) { std::cout << " " << desc << "\n"; } std::cout << "\n"; } } }
Item * ChartBase:: get_S() const { const Term * sterm = Term::rootTerm; Item *itm; Items il = regs[wrd_count_ - 1][0]; Items::iterator ili = il.begin(); for(; ili != il.end(); ili++ ) { itm = *ili; if( itm->term() == sterm ) return itm; } return NULL; }
StringsView::Items StringsView::items() const { Items options; if ( 0x0 != _model ) { typedef OptionsItemModel::Values Values; Values values ( _model->values() ); for ( Values::const_iterator iter = values.begin(); iter != values.end(); ++iter ) { options.push_back ( *iter ); } } return options; }
void Persist::saveItems(Items& library) { Items::iterator iterator; const char* fileName = Library::FILE_NAME.c_str(); std::ofstream file(fileName, std::ios::out); if (!file) { std::cerr << "Error while opening " << fileName << std::endl; exit(EXIT_FAILURE); } for (iterator = library.begin(); iterator != library.end(); ++iterator) { Item item = (*iterator).second; file.write(reinterpret_cast<const char*>(&item), sizeof(Item)); } file.close(); }
void InventoryImpl::update(float delta, const Controller& controller) { float step_angle = (2.0f * math::pi) / static_cast<float>(items.size()); if (fabsf(add_angle) > step_angle) { if (moving == 1) decr_current_item(); else if (moving == -1) incr_current_item(); moving = 0; add_angle = 0; } if (controller.get_axis_state(X_AXIS) < -0.5f) { if (moving == 1) { add_angle = -step_angle + add_angle; decr_current_item(); } moving = -1; } else if (controller.get_axis_state(X_AXIS) > 0.5f) { if (moving == -1) { add_angle = step_angle + add_angle; incr_current_item(); } moving = 1; } if (moving == -1) { add_angle -= 3 * delta; } else if (moving == 1) { add_angle += 3 * delta; } if (moving == 0) { if (controller.button_was_pressed(OK_BUTTON) || controller.button_was_pressed(CANCEL_BUTTON) || controller.button_was_pressed(INVENTORY_BUTTON)) { GameSession::current()->set_control_state(GameSession::GAME); } } }
void get_items_at(const Rectf& rect, std::vector<C>& out_items) const { // If rect overlaps with the given quadrant, recursivly check the quadrant if (m_nw.get() && rect.left < m_center.x && rect.top < m_center.y) { m_nw->get_items_at(rect, out_items); } if (m_ne.get() && rect.right > m_center.x && rect.top < m_center.y) { m_ne->get_items_at(rect, out_items); } if (m_sw.get() && rect.left < m_center.x && rect.bottom > m_center.y) { m_sw->get_items_at(rect, out_items); } if (m_se.get() && rect.right > m_center.x && rect.bottom > m_center.y) { m_se->get_items_at(rect, out_items); } // Check all overlapping items for(typename Items::const_iterator i = m_items.begin(); i != m_items.end(); ++i) { if (i->rect.is_overlapped(rect)) { out_items.push_back(i->data); } } }
void Client::processPersistentRequests(_Store& store) { // create a typedef for the vector holding the correct type of items typedef std::vector<typename _Store::Item> Items; // get the items that need to be reconstructed Items items = store.getBadItems(); if (items.size() > 0) logger_->debug("A total of %d persistent requests need to be re-processed", items.size()); // loop through the items and process them // (We don't have to care about the Status result of the processRequest function, // since processPersistentRequests() is called automatically by a thread, and this // thread doesn't perform any actions in case of failures.) for (typename Items::iterator it = items.begin(); it != items.end(); ++it) processRequest<typename _Store::ServiceType>( it->request, it->badTargetsMask, it->result); }
void Space::UpdateChunk( Vec2i index, float dt ) { // The chunk we're at Chunks::iterator it = chunks.find( index ); if( it != chunks.end() ) { Chunk &chunk = it->second; // Update our chunk and everything in it chunk.Update( dt ); // Check intersections Items items = chunk.GetItems(); for( Items::iterator it = items.begin(); it != items.end(); ++it ) { if( (*it)->BoundingBox().Intersects( satellite.BoundingBox() ) ) { Intersects( *it ); } } } else { //L_("couldn't find %d index chunk for updating\n"); } }
std::vector<PItem> SameAreaPeerAdapter::getAreaPeer(long key, int limit) { std::vector<PItem> recommend_list; std::vector<unsigned char> value; GetDistCacheData2(BIZ, key, value); if (!value.empty()) { Items items; items.ParseFromArray(value.data(), value.size()); for (::google::protobuf::RepeatedPtrField< ::xce::socialgraph::Item >::const_iterator iter = items.items().begin(); iter != items.items().end(); ++iter) { PItem pe; pe.uid_ = iter->id(); pe.gender_ = iter->field(); recommend_list.push_back(pe); } } if (limit > 0 && (int)recommend_list.size() > limit) { recommend_list.resize(limit); } return recommend_list; }
// Algorithm to calculate the edit operations to allow //_ replaceing items without model reset inline void replace(const Items &newItems, int from = 0) { using namespace kamd::utils::member_matcher; #if 0 QDBG << "===\nOld items {"; for (const auto& item: m_items) { QDBG << item; } QDBG << "}"; QDBG << "New items to be added at " << from << " {"; for (const auto& item: newItems) { QDBG << item; } QDBG << "}"; #endif // Based on 'The string to string correction problem // with block moves' paper by Walter F. Tichy // // In essence, it goes like this: // // Take the first element from the new list, and try to find // it in the old one. If you can not find it, it is a new item // item - send the 'inserted' event. // If you did find it, test whether the following items also // match. This detects blocks of items that have moved. // // In this example, we find 'b', and then detect the rest of the // moved block 'b' 'c' 'd' // // Old items: a[b c d]e f g // ^ // / // New items: [b c d]a f g // // After processing one block, just repeat until the end of the // new list is reached. // // Then remove all remaining elements from the old list. // // The main addition here compared to the original papers is that // our 'strings' can not hold two instances of the same element, // and that we support updating from arbitrary position. auto newBlockStart = newItems.cbegin(); // How many items should we add? // This should remove the need for post-replace-trimming // in the case where somebody called this with too much new items. const int maxToReplace = m_countLimit - from; if (maxToReplace <= 0) return; const auto newItemsEnd = newItems.size() <= maxToReplace ? newItems.cend() : newItems.cbegin() + maxToReplace; // Finding the blocks until we reach the end of the newItems list // // from = 4 // Old items: X Y Z U a b c d e f g // ^ oldBlockStart points to the first element // of the currently processed block in the old list // // New items: _ _ _ _ b c d a f g // ^ newBlockStartIndex is the index of the first // element of the block that is currently being // processed (with 'from' offset) while (newBlockStart != newItemsEnd) { const int newBlockStartIndex = from + std::distance(newItems.cbegin(), newBlockStart); const auto oldBlockStart = std::find_if( m_items.begin() + from, m_items.end(), member(&ResultSet::Result::resource) == newBlockStart->resource()); if (oldBlockStart == m_items.end()) { // This item was not found in the old cache, so we are // inserting a new item at the same position it had in // the newItems array d->q->beginInsertRows(QModelIndex(), newBlockStartIndex, newBlockStartIndex); m_items.insert(newBlockStartIndex, *newBlockStart); d->q->endInsertRows(); // This block contained only one item, move on to find // the next block - it starts from the next item ++newBlockStart; } else { // We are searching for a block of matching items. // This is a reimplementation of std::mismatch that // accepts two complete ranges that is available only // since C++14, so we can not use it. auto newBlockEnd = newBlockStart; auto oldBlockEnd = oldBlockStart; while (newBlockEnd != newItemsEnd && oldBlockEnd != m_items.end() && newBlockEnd->resource() == oldBlockEnd->resource()) { ++newBlockEnd; ++oldBlockEnd; } // We have found matching blocks // [newBlockStart, newBlockEnd) and [oldBlockStart, newBlockEnd) const int oldBlockStartIndex = std::distance(m_items.begin() + from, oldBlockStart); const int blockSize = std::distance(oldBlockStart, oldBlockEnd); if (oldBlockStartIndex != newBlockStartIndex) { // If these blocks do not have the same start, // we need to send the move event. // Note: If there is a crash here, it means we // are getting a bad query which has duplicate // results d->q->beginMoveRows(QModelIndex(), oldBlockStartIndex, oldBlockStartIndex + blockSize - 1, QModelIndex(), newBlockStartIndex); // Moving the items from the old location to the new one kamd::utils::slide( oldBlockStart, oldBlockEnd, m_items.begin() + newBlockStartIndex); d->q->endMoveRows(); } // Skip all the items in this block, and continue with // the search newBlockStart = newBlockEnd; } } // We have avoided the need for trimming for the most part, // but if the newItems list was shorter than needed, we still // need to trim the rest. trim(from + newItems.size()); // Check whether we got an item representing a non-existent file, // if so, schedule its removal from the database for (const auto &item: newItems) { if (item.resource().startsWith('/') && !QFile(item.resource()).exists()) { d->q->forgetResource(item.resource()); } } }