Пример #1
0
void Variables::leaveScope(bool insideLoop)
{
    if (insideLoop) {
        // read variables are read again in subsequent run through loop
        std::set<unsigned int> const & currentVarReadInScope = _varReadInScope.back();
        for (std::set<unsigned int>::const_iterator readIter = currentVarReadInScope.begin();
             readIter != currentVarReadInScope.end();
             ++readIter) {
            read(*readIter, nullptr);
        }
    }

    std::list<std::set<unsigned int> >::reverse_iterator reverseReadIter = _varReadInScope.rbegin();
    ++reverseReadIter;
    if (reverseReadIter != _varReadInScope.rend()) {
        // Transfer read variables into previous scope

        std::set<unsigned int> const & currentVarAddedInScope = _varAddedInScope.back();
        std::set<unsigned int>  & currentVarReadInScope = _varReadInScope.back();
        for (std::set<unsigned int>::const_iterator addedIter = currentVarAddedInScope.begin();
             addedIter != currentVarAddedInScope.end();
             ++addedIter) {
            currentVarReadInScope.erase(*addedIter);
        }
        std::set<unsigned int> & previousVarReadInScope = *reverseReadIter;
        previousVarReadInScope.insert(currentVarReadInScope.begin(),
                                      currentVarReadInScope.end());
    }
    _varReadInScope.pop_back();
    _varAddedInScope.pop_back();
}
gfx::Color PerlinCity::noise(const std::list<gfx::VolumeGray8Sptr> &op,
    const math::vec3d &tt)
{
  float ns = 0.0f,
        wt = 1.0f;

  for(std::list<gfx::VolumeGray8Sptr>::const_reverse_iterator ii = op.rbegin(), ee = op.rend();
      (ii != ee); ++ii)
  {
    gfx::VolumeGray8 *vv = ii->get();
    ns += wt * math::abs((vv->getAveragePixel(tt.x(), tt.y(), tt.z()) - 0.5f));
    wt *= 0.5f;
  }
  //ns = ns*ns;

  //ns = ns + 0.5f;
  if(ns < 0.0f)
  {
    ns = -ns;
  }
  else if(ns > 1.0f)
  {
    ns = 2.0f - ns;
  }

  return gfx::Color(ns, ns, ns);
  //return m_gradient.getColor(ns);
}
Пример #3
0
	void HeapPage::freeBlocks(std::list<HeapBlock>& newBlocks, std::list<HeapBlock>& newReleasedBlocks) {
		// Copy new blocks.
		blocks = newBlocks;

		// Check if we can join some values.
		IntPtr pageHighAddress = reinterpret_cast<IntPtr>(&memory[pagepointer]);
		std::list<HeapBlock>::reverse_iterator current = newBlocks.rbegin();

		// Start looking from the end of new blocks.
		// Use the new blocks listing, not the instance list.
		while (current != newBlocks.rend() && current->isReleased()) {
			const IntPtr blockHighAddress = reinterpret_cast<IntPtr>(current->getHandle()) + current->getSize();

			// If both are pointing to the same memory location,
			// we can join this block with the free memory region
			// of the page.
			if (blockHighAddress == pageHighAddress) {
				// Compute new high address and move page 
				// pointer back.
				pageHighAddress -= current->getSize();
				pagepointer -= current->getSize();

				// Remove from new released block listing.
				newReleasedBlocks.remove(*current);
				blocks.remove(*current);

				current++;
			} else {
				// If we can't join the first block to the free memory region,
				// there is no point going trough other blocks.
				break;
			}
		}
	}
Пример #4
0
void Preprocessor::sortRegions (std::list<RegionIterator>& regions)
{
	for ( std::list<RegionIterator>::iterator i = regions.begin(); i != regions.end(); ++i )
	{
		if ( i == regions.begin() )
			continue;

		// Get current element
		RegionIterator value = *i;

		// Get previous element
		std::list<RegionIterator>::reverse_iterator j = regions.rbegin();
		advance(j, distance(i, regions.end()));

		// Shift elements until finding final position
		while ( j != regions.rend() && *value < *(*j) )
		{
			std::list<RegionIterator>::reverse_iterator k = j;
			--k;
			*k = *j;

			++j;
		}

		// Insert current element into its final position
		std::list<RegionIterator>::reverse_iterator k = j;
		--k;
		*k = value;
	}
};
Пример #5
0
void
test_ns::matrix::
find_one_puddle_and_update(int entry_h, const entry_pos_t& entry_pos,
        entry_pos_set_t& puddle_pos, entry_pos_set_t& leaks_pos,
        std::list<puddle>& puddles,
        size_t& yet_not_found_positions) const {
    entry_pos_set_t searched_entries;
    entry_pos_set_t below_level_entries;
    bool is_puddle = find_one_puddle(entry_h, entry_pos, leaks_pos,
            searched_entries, below_level_entries);
    yet_not_found_positions -= searched_entries.size();
    if (is_puddle) {
        for (const auto & e : searched_entries) {
            puddle_pos.insert(e);
        }
        if (!below_level_entries.empty()) {
            for (auto const & below_entry : below_level_entries) {
                for (auto i = puddles.rbegin(); i != puddles.rend(); ++i) {
                    const auto & puddle = *i;
                    auto & entries = puddle.entries_;
                    if (entries.find(below_entry) != entries.end()) {
                        puddles.erase(std::prev (i.base()));
                        break;
                    }
                }
            }
        }
        puddle a_puddle{searched_entries, entry_h};
        puddles.push_back(std::move(a_puddle));
    } else {
        for (const auto & e : searched_entries) {
            leaks_pos.insert(e);
        }
    }
}
std::vector< double > guessLambdaModifiers(
    double initialAdjustmentParameter,
    const std::vector< double > &targetBitrateVector,
    const std::list< MetaLogEntry< std::vector< double > > >& metaLogEntryList )
{
  assert( !targetBitrateVector.empty( ) );
  assert( !metaLogEntryList.empty( ) );
  
  double cumulativeDelta( 0.0 );
  std::vector< double > resultVector;
  for( unsigned char i( 0 ); i < targetBitrateVector.size( ); ++i )
  {
    // Populate pointList with up to two of the previous points
    std::list< Point > pointList;
    std::list< MetaLogEntry< std::vector< double > > >::const_reverse_iterator j( metaLogEntryList.rbegin( ) );
    pointList.push_front( pointFromFullMetaLogEntry( i, *j ) );
    ++j;
    if( j != metaLogEntryList.rend( ) ) pointList.push_front( pointFromFullMetaLogEntry( i, *j ) );
    
    // Calculate the new Lambda-modifier guess and add it to the result vector
    const double newLambdaModifier( guessLambdaModifier(
        initialAdjustmentParameter,
        targetBitrateVector[ i ],  // target bitrate
        pointList,
        interDampeningFactor( 50.0, cumulativeDelta ) ) );
    resultVector.push_back( newLambdaModifier );
    
    // Increment the cumulativeDelta
    const double oldLambdaModifier( pointList.back( ).lambdaModifier );
    cumulativeDelta += std::abs( newLambdaModifier - oldLambdaModifier ) / oldLambdaModifier;
  }
  
  return resultVector;
}
double guessLambdaModifier(
    double initialAdjustmentParameter,
    double targetBitrate,
    const std::list< Point >& pointList,
    double interDampeningFactor )
{
  assert( ( double )0.0 < interDampeningFactor );
  assert( interDampeningFactor <= ( double )1.0 );
  assert( !pointList.empty( ) );
  
  double preliminaryResult;
  
  if( 1 == pointList.size( ) )  // If there is only one prevous point, then we cannot interpolate, so we call incrementLambdaModifier
  {
    preliminaryResult = incrementLambdaModifier( initialAdjustmentParameter, targetBitrate, pointList.back( ) );
  }
  else  // If there are at least two previous points, then we may be able to interpolate
  {
    std::list< Point >::const_reverse_iterator i( pointList.rbegin( ) );
    Point point1 = *i;
    ++i;
    Point point2 = *i;
    
    // If the slope is either horizontal or vertical, we cannot interpolate
    if( point1.lambdaModifier == point2.lambdaModifier || point1.bitrate == point2.bitrate )
    {
      preliminaryResult = incrementLambdaModifier( initialAdjustmentParameter, targetBitrate, pointList.back( ) );
    }
    else  // If the slope is not horizontal and not vertical, we can interpolate
    {
      preliminaryResult = polateLambdaModifier( targetBitrate, point1, point2 );
    }
  }
  
  double previousResult( pointList.back( ).lambdaModifier );
  
  // Apply "intra dampening"
  {
    double intermediate( std::log( ( double )1.0 + std::abs( preliminaryResult - previousResult ) / previousResult ) );
    assert( ( double )0.0 <= intermediate );
    if( ( preliminaryResult - previousResult ) < 0.0 )
    {
      preliminaryResult = previousResult * ( ( double )1.0 - intermediate );
    }
    else
    {
      preliminaryResult = previousResult * ( ( double )1.0 + intermediate );
    }
  }
  
  // Apply "inter dampening factor".  If necessary, reduce the factor until a positive result is acheived.
  double result;
  do
  {
    result = previousResult + interDampeningFactor * ( preliminaryResult - previousResult );
    interDampeningFactor /= ( double )2.0;
  } while( result <= ( double )0.0 );
  return result;
}
Пример #8
0
	cocos2d::Layer* GetGUILayer()
	{
		Ak_CScene* pCurScene = *(g_sceneList.rbegin());
		if (!pCurScene)
			return NULL;

		return pCurScene->GetGUILayer();
	}
Пример #9
0
void RenderChatText()
{
	// View transformation
	gGraphicsDevice->SetTransform(D3DTS_VIEW, &gOrthoViewMatrix);
	
	// Perspective transformation
	gGraphicsDevice->SetTransform(D3DTS_PROJECTION, &gScreenProjectionMatrix);

	// Render the texture
	gGraphicsDevice->BeginScene();
	{
		// render the user list
		size_t index = 0;
		int y = kFontSize / 4;
		for (auto iter=gChatUsers.rbegin(); iter != gChatUsers.rend() && index < gMaxChatLines; ++iter)
		{
			std::shared_ptr<ChatUser> user = *iter;
			RenderString(gWindowWidth-kUserListWidth, y, user->nameColorARGB, *user->font, user->username);

			y += user->font->pixelHeight + kLineSpacing;
			index++;
		}

		y = kFontSize / 4;

		// render the input text if showing
		if (gInputText != nullptr)
		{
			int x = RenderChatLine(kMessagesLeft, y, gInputText, KWhiteColor) + 2;
			RenderString(x, y, KWhiteColor, gNormalFont, "_");
			y += gInputText->font->pixelHeight + kLineSpacing;
		}

		// render the history
		for (auto iter=gChatLines.rbegin(); iter != gChatLines.rend(); ++iter)
		{
			std::shared_ptr<ChatLine> line = *iter;
			RenderChatLine(kMessagesLeft, y, line, KBlackColor);

			y += line->font->pixelHeight + kLineSpacing;
		}

		gGraphicsDevice->SetTexture(0, nullptr);
	}
	gGraphicsDevice->EndScene();
}
Пример #10
0
//*****************************************************************************
//
static bool callvote_CheckForFlooding( FString &Command, FString &Parameters, ULONG ulPlayer )
{
	NETADDRESS_s	Address = SERVER_GetClient( ulPlayer )->Address;
	ULONG			ulVoteType = callvote_GetVoteType( Command );
	time_t tNow;
	time( &tNow );

	// Remove old votes that no longer affect flooding.
	while ( g_PreviousVotes.size( ) > 0 && (( tNow - g_PreviousVotes.front( ).tTimeCalled ) > VOTE_LONGEST_INTERVAL * MINUTE ))
		g_PreviousVotes.pop_front( );

	// [BB] If the server doesn't want to limit the number of votes, there is no check anything.
	// [TP] sv_limitcommands == false also implies limitless voting.
	if ( sv_limitnumvotes == false || sv_limitcommands == false )
		return true;

	// Run through the vote cache (backwards, from recent to old) and search for grounds on which to reject the vote.
	for( std::list<VOTE_s>::reverse_iterator i = g_PreviousVotes.rbegin(); i != g_PreviousVotes.rend(); ++i )
	{
		// One *type* of vote per voter per ## minutes (excluding kick votes if they passed).
		if ( !( callvote_IsKickVote ( i->ulVoteType ) && i->bPassed ) && NETWORK_CompareAddress( i->Address, Address, true ) && ( ulVoteType == i->ulVoteType ) && (( tNow - i->tTimeCalled ) < VOTER_VOTETYPE_INTERVAL * MINUTE ))
		{
			int iMinutesLeft = static_cast<int>( 1 + ( i->tTimeCalled + VOTER_VOTETYPE_INTERVAL * MINUTE - tNow ) / MINUTE );
			SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "You must wait %d minute%s to call another %s vote.\n", iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" ), Command.GetChars() );
			return false;
		}

		// One vote per voter per ## minutes.
		if ( NETWORK_CompareAddress( i->Address, Address, true ) && (( tNow - i->tTimeCalled ) < VOTER_NEWVOTE_INTERVAL * MINUTE ))
		{
			int iMinutesLeft = static_cast<int>( 1 + ( i->tTimeCalled + VOTER_NEWVOTE_INTERVAL * MINUTE - tNow ) / MINUTE );
			SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "You must wait %d minute%s to call another vote.\n", iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" ));
			return false;
		}

		// Specific votes ("map map30") that fail can't be re-proposed for ## minutes.
		if (( ulVoteType == i->ulVoteType ) && ( !i->bPassed ) && (( tNow - i->tTimeCalled ) < VOTE_LITERALREVOTE_INTERVAL * MINUTE ))
		{
			int iMinutesLeft = static_cast<int>( 1 + ( i->tTimeCalled + VOTE_LITERALREVOTE_INTERVAL * MINUTE - tNow ) / MINUTE );

			// Kickvotes (can't give the IP to clients!).
			if ( callvote_IsKickVote ( i->ulVoteType ) && ( !i->bPassed ) && NETWORK_CompareAddress( i->KickAddress, g_KickVoteVictimAddress, true ))
			{
				SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "That specific player was recently on voted to be kicked or forced to spectate, but the vote failed. You must wait %d minute%s to call it again.\n", iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" ));
				return false;
			}

			// Other votes.
			if ( ( callvote_IsKickVote ( i->ulVoteType ) == false ) && ( stricmp( i->fsParameter.GetChars(), Parameters.GetChars() ) == 0 ))
			{
				SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "That specific vote (\"%s %s\") was recently called, and failed. You must wait %d minute%s to call it again.\n", Command.GetChars(), Parameters.GetChars(), iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" ));
				return false;
			}
		}
	}

	return true;
}
Пример #11
0
void ChunksCache::MatchLimit(bool removeAll) {
	std::list<CacheEntry*>::reverse_iterator rit;
	while (m_entries.size() && (removeAll || m_size > m_limit)) {
		rit = m_entries.rbegin();
		m_size -= (*rit)->size;
		delete(*rit);
		m_entries.pop_back();
	}
}
Пример #12
0
static std::list<TokenRec>::reverse_iterator searchBackToken(int id){
  std::list<TokenRec>::reverse_iterator iii=TokenList.rbegin();
  for ( ; iii!=TokenList.rend();iii++){
    if (id==iii->id){
      break;
    }
  }
  return iii;
}
Пример #13
0
	/*
	 * Erases the last inactive element in the cache.
	 */
	bool erase_last() {
		for (auto rit = elements.rbegin(); rit != elements.rend(); ++rit) {
			if (rit->active_readers == 0) {
				erase(rit->key);
				return true;
			}
		}
		return false;
	}
Пример #14
0
void CRealTextParser::PopTag(std::list<Tag>& p_rlistTags, const std::wstring& p_crszTagName)
{
    for (std::list<Tag>::reverse_iterator riter = p_rlistTags.rbegin(); riter != p_rlistTags.rend(); ++riter) {
        if (riter->m_szName == p_crszTagName) {
            p_rlistTags.erase((++riter).base());
            return;
        }
    }
}
Пример #15
0
	void PopScene()
	{
		cocos2d::Director::getInstance()->popScene();

		Ak_CScene* pScene = *(g_sceneList.rbegin());
		pScene->Destroy();
		delete pScene;
		g_sceneList.pop_back();
	}
Пример #16
0
	virtual void HandleSFEvents (std::list<sf::Event>& sfEvents) {
		for (typename std::list<T*>::reverse_iterator itState = stateList.rbegin();
				itState != stateList.rend(); ++itState) {
			if (!(*itState)->off) {
				(*itState)->HandleSFEvents(sfEvents);
				break;
			}
		}
	}
Пример #17
0
	void DrawScreenSpace (sf::RenderWindow& rwin) {
		for (typename std::list<T*>::reverse_iterator itState = stateList.rbegin();
				itState != stateList.rend(); ++itState) {
			if (!(*itState)->off) {
				(*itState)->DrawScreenSpace(rwin);
				break;
			}
		}
	}
Пример #18
0
	bool top_tags(const char* str1, const char* str2)
	{
		std::list<std::string>::reverse_iterator i = tag_stack.rbegin();
		if (i == tag_stack.rend()) return false;
		if (!string_equal_nocase(i->c_str(), str2)) return false;
		++i;
		if (i == tag_stack.rend()) return false;
		if (!string_equal_nocase(i->c_str(), str1)) return false;
		return true;
	}
Пример #19
0
	void Pop (int cntToPop) {
		int i = 0;
		for (typename std::list<T*>::reverse_iterator itState = stateList.rbegin();
				itState != stateList.rend(); itState++) {
			(*itState)->pop = true;

			if (++i == cntToPop)
				break;
		}
	}
Пример #20
0
T KernelFunction::findDecl(std::list<T> list, const clang::IdentifierInfo* ID) {
	typedef typename std::list<T>::reverse_iterator iterator;

	for (iterator it = list.rbegin(); it != list.rend(); ++it) {
		if ((*it)->ID == ID && (*it)->Parameter->isOccupied()) {
			return *it;
		}
	}

	return NULL;
}
Пример #21
0
	tick_t _d_last(const std::list<tick_t>& list) const {
		tick_t res = 0;
		if (list.size() < 2) {
			return res;
		}
		auto last = list.rbegin();
		tick_t cpu_l = (*last);
		last++;
		tick_t cpu_ll = (*last);
		return (cpu_l - cpu_ll);
	}
Пример #22
0
void Sip_Request::add_routes(const std::list<Sip_Uri> &routes)
{
    std::list<Sip_Uri>::const_reverse_iterator i;
    std::list<Sip_Uri>::const_reverse_iterator first = routes.rend();

    for( i = routes.rbegin(); i != first; ++i )
    {
        const Sip_Uri &route = *i;
        add_route( route.get_string() );
    }
}
Пример #23
0
		T toPop(std::list<T> &lst)
{
	if (lst.begin() == lst.end())
	{
		T ret;
		return ret;
	}
	T ret = (*lst.rbegin());
	lst.pop_back();
	return ret;
}
Пример #24
0
T KernelFunction::findArray(std::list<T> list, const clang::StringRef name) {
	typedef typename std::list<T>::reverse_iterator iterator;

	for (iterator it = list.rbegin(); it != list.rend(); ++it) {
		if ((*it)->ID->getName() == name) {
			return (*it);
		}
	}

	return NULL;
}
void PushLevelToList(long start, long end, long minGap, std::list<std::pair<long, long>>& outLanes)
{
	long gap = -1;
	if(!outLanes.empty())
	{
		gap = start - outLanes.rbegin()->second - 1;
	}

	if(gap >= 0 && gap < minGap)
	{
		outLanes.rbegin()->second = end;
		//std::pair<long, long> lastLevel = *outLanes.rbegin();
		//lastLevel.second = last;
					
		//outLanes.pop_back();
		//outLanes.push_back(lastLevel);
	}
	else
		outLanes.push_back(std::pair<long, long>(start, end));
}
Пример #26
0
void reverse_list(std::list<int> & l) {
	unsigned int temp, i;
	unsigned int middle = l.size()/2;
	std::list<int>::iterator it = l.begin();
	std::list<int>::reverse_iterator rit = l.rbegin();
	for (i=0;i<middle;i++) {
		temp = *it;
		*it = *rit;
		*rit = temp;
		rit++, it++;
	}
}
Пример #27
0
void reverse_list(std::list<int>& v){
    int oldi=0;
    std::list<int>::reverse_iterator ri=v.rbegin();
    std::list<int>::iterator i=v.begin();
    for (int j=0;j<v.size()/2;j++){
        oldi=*i;
        *i=*ri;
        *ri=oldi;
        ++ri;
        i++;
    }
}
Пример #28
0
void reverse( std::list<double>  &d)
{
  int size = d.size();
  std::list<double>::iterator fr = d.begin();
  std::list<double>::reverse_iterator ba = d.rbegin();
  for(int i=0; i<size/2;i++,fr++,ba++) {
    double temp;
    temp = *fr;
    *fr = *ba; 
    *ba = temp;
  }
}
Пример #29
0
	void Update (float dT) {
	// there was some bug with this somewhere..lol.. => safe and ugly solution
	//		stateList.back()->Update(dT);

		for (typename std::list<T*>::reverse_iterator itState = stateList.rbegin();
				itState != stateList.rend(); ++itState) {
			if (!(*itState)->off) {
				(*itState)->Update(dT);
				break;
			}
		}
	}
Пример #30
0
void
CheckDrive(
	frc::DifferentialDrive& drive,
        std::list<Packet*>&     packets,
        double                  magnitude,
        double                  curve,
        const MotorDrivePacket& expRightPacket,
        const MotorDrivePacket& expLeftPacket,
        bool squaredInputs
        )
{
    drive.ArcadeDrive(
            magnitude,
            curve,
            squaredInputs
            );

    bool rightDrivePacketFound = false;
    bool leftDrivePacketFound = false;

    RedBotSpeedController& leftController = dynamic_cast<RedBotSpeedController&>(drive.getLeftController());
    RedBotSpeedController& rightController = dynamic_cast<RedBotSpeedController&>(drive.getRightController());

    packets.push_back(leftController.getNextPacket());
    packets.push_back(rightController.getNextPacket());

    std::list<Packet*>::const_reverse_iterator packetIter = packets.rbegin();

    for (int i = 0; i < 2; i++)
    {
        Packet* packet = *(packetIter++);
        MotorDrivePacket* mDrivePacket = dynamic_cast<MotorDrivePacket*>(packet);

        CHECK(NULL != mDrivePacket);

        if (mDrivePacket->getMotor() == MotorDrivePacket::MOTOR_RIGHT)
        {
            rightDrivePacketFound = true;
            CHECK_EQUAL(expRightPacket.getSpeed(), mDrivePacket->getSpeed());
            CHECK_EQUAL(expRightPacket.getDirection(), mDrivePacket->getDirection());
        }
        else
        {
            leftDrivePacketFound = true;
            CHECK_EQUAL(expLeftPacket.getSpeed(), mDrivePacket->getSpeed());
            CHECK_EQUAL(expLeftPacket.getDirection(), mDrivePacket->getDirection());
        }
    }

    CHECK(rightDrivePacketFound);
    CHECK(leftDrivePacketFound);
}