// puts animal on the grid void World::PutCreature(Animal* animal, const sf::Vector2i& dst) { if (creatures.at(dst) != nullptr) throw NotEmpty(); creatures.at(dst) = animal; }
// write output to .clu file - with 1 added to cluster numbers, and empties removed. void SaveOutput(Array<int> &OutputClass, double* OutputArray) { int p, c; int MaxClass = 0; Array<int> NotEmpty(MaxPossibleClusters); Array<int> NewLabel(MaxPossibleClusters); // find non-empty clusters for(c=0;c<MaxPossibleClusters;c++) NewLabel[c] = NotEmpty[c] = 0; for(p=0; p<OutputClass.size(); p++) NotEmpty[OutputClass[p]] = 1; // make new cluster labels so we don't have empty ones NewLabel[0] = 1; MaxClass = 1; for(c=1;c<MaxPossibleClusters;c++) { if (NotEmpty[c]) { MaxClass++; NewLabel[c] = MaxClass; } } // print file //sprintf(fname, "%s.clu.%d", FileBase, ElecNo); //fp = fopen_safe(fname, "w"); //fprintf(fp, "%d\n", MaxClass); int q = 0; for (p=0; p<OutputClass.size(); p++) OutputArray[q++] = (int)NewLabel[OutputClass[p]]; // fprintf(fp, "%d\n", NewLabel[OutputClass[p]]); //fclose(fp); }
void Take(std::list<T> & list) { std::unique_lock<std::mutex> locker(m_mutex); m_notEmpty.wait( locker , [this]{return m_stop || NotEmpty();}); if( m_stop ) { return; } list = std::move(m_queue); m_notFull.notify_one(); }
// moves animal from where it is to dst void World::MoveCreature(Animal* animal, const sf::Vector2i& dst) { if (creatures.at(dst) != nullptr) throw NotEmpty(); auto src = animal->GetLocation(); creatures.at(src) = nullptr; creatures.at(dst) = animal; animal->SetLocation(dst,lockey); }
void Take( T & t ) { std::unique_lock<std::mutex> locker(m_mutex); m_notEmpty.wait( locker , [this]{ return m_stop || NotEmpty();}); if(m_stop) { return; } t = m_queue.front(); m_queue.pop_front(); m_notFull.notify_one(); }
void Take(std::list<T> & list) { std::unique_lock<std::mutex> locker(m_mutex); m_notEmpty.wait( locker , [this]{return m_stop || NotEmpty();}); if( m_stop ) { return; } list = m_queue; for(int i = 0 ; i < list.size() ; i++) { m_queue.pop_back(); } m_notFull.notify_one(); }
nsFrameList nsFrameList::RemoveFramesAfter(nsIFrame* aAfterFrame) { if (!aAfterFrame) { nsFrameList result; result.InsertFrames(nullptr, nullptr, *this); return result; } NS_PRECONDITION(NotEmpty(), "illegal operation on empty list"); #ifdef DEBUG_FRAME_LIST NS_PRECONDITION(ContainsFrame(aAfterFrame), "wrong list"); #endif nsIFrame* tail = aAfterFrame->GetNextSibling(); // if (!tail) return EmptyList(); -- worth optimizing this case? nsIFrame* oldLastChild = mLastChild; mLastChild = aAfterFrame; aAfterFrame->SetNextSibling(nullptr); return nsFrameList(tail, tail ? oldLastChild : nullptr); }