Ejemplo n.º 1
0
void HazardModule::RemoveExpiredHazardsHelperProcessContainer(CONTAINER& container)
{
	// NOTE: in the future we may want to keep the array sorted based on
	// expiry time or something.
	const float nowTimeIndex = gEnv->pTimer->GetCurrTime();
	bool expiredFlag = false;
	typename CONTAINER::iterator iter = container.begin();
	while (iter != container.end())
	{
		expiredFlag = false;
		if (iter->GetExpireTimeIndex() >= 0)
		{
			if (iter->GetExpireTimeIndex() <= nowTimeIndex)
			{
				expiredFlag = true;
			}
		}

		if (expiredFlag)
		{
			iter = ExpireAndDeleteHazardInstance(container, iter);	
			expiredFlag = false;
		}
		else
		{
			++iter;
		}
	}	
}
Ejemplo n.º 2
0
Archivo: main.cpp Proyecto: CCJY/coliru
template< typename CONTAINER > std::clock_t geminate( CONTAINER& cntr )
{
    const auto start = std::clock() ;
    for( auto iter = cntr.begin() ; iter != cntr.end() ; ++iter, ++iter )
        iter = cntr.insert( iter, *iter ) ;
    return std::clock() - start ;
}
Ejemplo n.º 3
0
void HazardModule::ProcessCollisionsWithEntityProcessContainer(
	CONTAINER& container, Agent& agent,
	const char *signalFunctionName, const EntityId entityID)
{
	assert(signalFunctionName != NULL);
	
	HazardCollisionResult collisionResult;

	// NOTE: for now this will be quick and dirty. If the amount of hazards
	// becomes too big we should apply some spatial hashing schemes!
	typename CONTAINER::const_iterator hazardIter;
	typename CONTAINER::const_iterator hazardEndIter = container.end();
	for (hazardIter = container.begin() ; hazardIter != hazardEndIter ; ++hazardIter)
	{
		if (hazardIter->ShouldWarnEntityID(entityID))		
		{
			hazardIter->CheckCollision(agent, &collisionResult);
			if (collisionResult.m_CollisionFlag)			
			{
				if (hazardIter->IsAgentAwareOfDanger(agent, collisionResult.m_HazardOriginPos))
				{
					SendSignalToAgent(agent, signalFunctionName, 
						collisionResult.m_HazardOriginPos, hazardIter->GetNormal());
				}
			}
		}
	}
}
Ejemplo n.º 4
0
template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> void
ACE_Pair_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::minimum (CONTAINER &container,
                                                                                KEY *&key_to_remove,
                                                                                VALUE *&value_to_remove)
{
  // Starting values.
  ITERATOR iter = container.begin ();
  ITERATOR end = container.end ();
  ATTRIBUTES min = (*iter).int_id_.second ();
  key_to_remove = &(*iter).ext_id_;
  value_to_remove = &(*iter).int_id_;

  // The iterator moves thru the container searching for the entry
  // with the lowest ATTRIBUTES.
  for (++iter;
       iter != end;
       ++iter)
    {
      if (min > (*iter).int_id_.second ())
        {
          // Ah! an item with lower ATTTRIBUTES...
          min = (*iter).int_id_.second ();
          key_to_remove = &(*iter).ext_id_;
          value_to_remove = &(*iter).int_id_;
        }
    }
}
Ejemplo n.º 5
0
void HazardModule::PurgeAllHazardsProcessContainer(CONTAINER& container)
{
	typename CONTAINER::iterator iter = container.begin();
	while (iter != container.end())
	{
		iter = ExpireAndDeleteHazardInstance(container, iter);
	}
}
Ejemplo n.º 6
0
void HazardModule::StartRequestedRayCastsProcessContainer(CONTAINER& container)
{
	typename CONTAINER::iterator iter;
	typename CONTAINER::iterator iterEnd = container.end();
	for (iter = container.begin() ; iter != iterEnd ; ++iter)
	{	
		iter->StartRequestedRayCasts(this);	
	}
}
Ejemplo n.º 7
0
void HazardModule::RenderDebugProcessContainer(
	const CONTAINER& container, IPersistantDebug& debugRenderer) const
{
	typename CONTAINER::const_iterator iter;
	typename CONTAINER::const_iterator Enditer = container.end();
	for (iter = container.begin() ; iter != Enditer ; ++iter)
	{
		iter->DebugRender(debugRenderer);
	}
}
Ejemplo n.º 8
0
bool contains (const CONTAINER& cont, std::string which, std::string what)
{
    auto it = cont.find (which);
    if (it == cont.end ())
        return false;
    auto vec = it->second;
    if (std::find (begin (vec), end (vec), what) != end (vec))
        return true;
    return false;
}
Ejemplo n.º 9
0
void
clear_map_pointers( CONTAINER& container )
{
    typename CONTAINER::iterator i = container.begin();
    while ( i != container.end() )
    {
        delete i->second;
        ++i;
    }

    container.clear();
}
Ejemplo n.º 10
0
void test<CONTAINER,HANDLER>::insert(unsigned count, bool warm, bool write)
{
  CONTAINER container;
  if (warm) {
    container.push_back(0); container.push_back(0);
    typename CONTAINER::iterator iter = ++container.begin();
    for(unsigned ii = 0; ii != count; ++ii) {
      iter = _handler.insert(container, iter, 1);
      if (ii & 1) ++iter;
    }
    container.clear();
  }
  container.push_back(0); container.push_back(0);
  boost::timer::cpu_timer timer;
  timer.start();
  typename CONTAINER::iterator iter = ++container.begin();
  for(unsigned ii = 0; ii != count; ++ii) {
    iter = _handler.insert(container, iter, 1);
    if (ii & 1) ++iter;
  }
  timer.stop();
  if (write) {
    dump(timer, "middle insert", count, warm);
  }
}
Ejemplo n.º 11
0
void HazardModule::PurgeHazardsWithPendingRayRequestsProcessContainer(CONTAINER& container)
{
	typename CONTAINER::iterator iter = container.begin();
	while (iter != container.end())
	{		
		if (iter->HasPendingRayCasts())
		{
			iter = ExpireAndDeleteHazardInstance(container, iter);
		}
		else
		{
			++iter;
		}
	}
}
Ejemplo n.º 12
0
void fillContainer(T min, T max, CONTAINER& randContainer, ::boost::uint32_t seedVal = std::time(NULL))
{
    SLM_ASSERT("Wrong min/max value", min <= max);
    SLM_ASSERT("Container type not same as T", (::boost::is_same< T, typename CONTAINER::value_type>::value) );
    typedef typename ::boost::mpl::if_<
            ::boost::is_floating_point<T>,
            ::boost::uniform_real<>,
            ::boost::uniform_int<>
    >::type DistroType;

    ::boost::mt19937 seed(seedVal);
    DistroType dist(min, max);
    ::boost::variate_generator< ::boost::mt19937&, DistroType > random(seed, dist);
    std::generate(randContainer.begin(), randContainer.end(), random);
}
Ejemplo n.º 13
0
 vector_multimap_iterator (const CONTAINER& container, ITERATOR_TYPE iterType = ITERATOR_TYPE::BEGIN)
     : m_position (0)
     , m_container (container)
 {
     if (iterType == ITERATOR_TYPE::END)
         m_position = container.size ();
 }
Ejemplo n.º 14
0
template <class KEY, class VALUE, class CONTAINER> int
ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER>::cleanup (CONTAINER &container,
                                                      KEY *key,
                                                      VALUE *)
{
  return container.unbind (*key);
}
Ejemplo n.º 15
0
	bool IsLocationInUse(const CONTAINER& source)
	{
		if(source.size() > 0)
			return true;

		return false;
	}
Ejemplo n.º 16
0
template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> void
ACE_Refcounted_Recyclable_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::minimum (CONTAINER &container,
                                                                                                         KEY *&key_to_remove,
                                                                                                         VALUE *&value_to_remove)
{
  // Starting values.
  ITERATOR end = container.end ();
  ITERATOR iter = container.begin ();
  ATTRIBUTES min = (*iter).int_id_.second ();
  key_to_remove = 0;
  value_to_remove = 0;
  // Found the minimum entry to be purged?
  int found = 0;

  // The iterator moves thru the container searching for the entry
  // with the lowest ATTRIBUTES.
  for (;
       iter != end;
       ++iter)
    {
      // If the <min> entry isnt IDLE_AND_PURGABLE continue until you reach
      // the first entry which can be purged. This is the minimum with
      // which you will compare the rest of the purgable entries.
      if ((*iter).ext_id_.recycle_state () == ACE_RECYCLABLE_IDLE_AND_PURGABLE ||
          (*iter).ext_id_.recycle_state () == ACE_RECYCLABLE_PURGABLE_BUT_NOT_IDLE)
        {
          if (found == 0)
            {
              min = (*iter).int_id_.second ();
              key_to_remove = &(*iter).ext_id_;
              value_to_remove = &(*iter).int_id_;
              found = 1;
            }
          else
            {
              // Ah! an entry with lower ATTTRIBUTES...
              if (min > (*iter).int_id_.second ())
                {
                  min = (*iter).int_id_.second ();
                  key_to_remove = &(*iter).ext_id_;
                  value_to_remove = &(*iter).int_id_;
                }
            }
        }
    }
}
Ejemplo n.º 17
0
template <class KEY, class VALUE, class CONTAINER> int
ACE_Cleanup_Strategy<KEY, VALUE, CONTAINER>::cleanup (CONTAINER &container,
                                                      KEY *key,
                                                      VALUE *value)
{
  ACE_UNUSED_ARG (value);

  return container.unbind (*key);
}
Ejemplo n.º 18
0
void test<CONTAINER,HANDLER>::push_front(unsigned count, bool warm, bool write)
{
  CONTAINER container;
  if (warm) {
    for(unsigned ii = 0; ii != count; ++ii)
      _handler.push_front(container, 1);
    container.clear();
  }

  boost::timer::cpu_timer timer;
  timer.start();
  for(unsigned ii = 0; ii != count; ++ii)
    _handler.push_front(container, 1);
  timer.stop();
  if (write) {
    dump(timer, "push_front", count, warm);
  }
}
Ejemplo n.º 19
0
bool CBratSettings::LoadRecentFilesGeneric( CONTAINER &paths )
{
	long maxEntries = 0;

	{
		CSection section( mSettings, GROUP_WKS_RECENT );
		auto const &keys = mSettings.childKeys();
        maxEntries = keys.size();
		for ( auto const &key : keys )
		{
			auto value = ReadValue< typename CONTAINER::value_type >( section, q2t< std::string >( key ) );
			paths.push_back( value );
		};
	}

	assert__( paths.size() == maxEntries );			Q_UNUSED( maxEntries );		//for release builds

	return mSettings.status() == QSettings::NoError;
}
Ejemplo n.º 20
0
template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> int
ACE_Refcounted_Recyclable_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::clear_cache (CONTAINER &container,
                                                                                                             double purge_percent)
{
  // Check that the purge_percent is non-zero.
  if (purge_percent == 0)
    return 0;

  // Get the number of entries in the container which can be considered for purging.
  size_t const available_entries =
    container.current_size () - this->marked_as_closed_entries_;

  // Also whether the number of entries in the cache zero.
  // Oops! then there is no way out but exiting.
  if (available_entries <= 0)
    return 0;

  // Calculate the no of entries to remove from the cache depending
  // upon the <purge_percent>.
  size_t entries_to_remove
    = ACE_MAX (static_cast<size_t> (1),
               static_cast<size_t> (static_cast<double> (purge_percent)
                                    / 100 * available_entries));

  if (entries_to_remove >= available_entries  || entries_to_remove == 0)
    entries_to_remove = available_entries - 1;

  KEY *key_to_remove = 0;
  VALUE *value_to_remove = 0;

  for (size_t i = 0; i < entries_to_remove ; ++i)
    {
      this->minimum (container,
                     key_to_remove,
                     value_to_remove);

      // Simply verifying that the key is non-zero.
      // This is important for strategies where the minimum
      // entry cant be found due to constraints on the type of entry
      // to remove.
      if (key_to_remove == 0)
        return 0;

      if (this->cleanup_strategy_->cleanup (container,
                                            key_to_remove,
                                            value_to_remove) == -1)
        return -1;

      ++this->marked_as_closed_entries_;
    }

  return 0;
}
Ejemplo n.º 21
0
void test<CONTAINER,HANDLER>::iterate(unsigned count, bool warm, bool write)
{
  CONTAINER container;
  unsigned unused = 0;
  for(unsigned ii = 0; ii != count; ++ii)
    container.push_back(ii);
  if (warm) {
    for(typename CONTAINER::const_iterator iter = container.begin();
        iter != container.end();
        ++iter)
    {
      unused += *iter;
    }
  }
  boost::timer::cpu_timer timer;
  timer.start();
  for(typename CONTAINER::const_iterator iter = container.begin();
      iter != container.end();
      ++iter)
  {
    unused += *iter;
  }
  timer.stop();
  if (unused == 1234) { // won't happen
    std::cout << "YEAH RIGHT!";
  }
  if (write) {
    dump(timer, "iterate", count, warm);
  }
}
Ejemplo n.º 22
0
void HazardModule::ExpireHazardProcessContainer(
	CONTAINER& container, const HazardID hazardInstanceID)
{
	CRY_ASSERT_MESSAGE((m_UpdateLockCount == 0), "Not allowed to unregister hazards to the hazard module while it is updating!");

	int index = IndexOfInstanceID(container, hazardInstanceID);
	if (index < 0)
	{
		return;
	}

	ExpireAndDeleteHazardInstance(container, container.begin() + index);
}
Ejemplo n.º 23
0
template <class KEY, class VALUE, class CONTAINER, class ITERATOR, class ATTRIBUTES> int
ACE_Recyclable_Handler_Caching_Utility<KEY, VALUE, CONTAINER, ITERATOR, ATTRIBUTES>::clear_cache (CONTAINER &container,
                                                                                                  double purge_percent)
{
  // Check that the purge_percent is non-zero.
  if (purge_percent == 0)
    return 0;

  // Get the number of entries in the container.
  size_t current_map_size = container.current_size ();

  // Also whether the number of entries in the cache is just one!
  // Oops! then there is no way out but exiting. So return an error.
  //  if (current_map_size <= 1)
  if (current_map_size == 0)
    return 0;

  // Calculate the no of entries to remove from the cache depending
  // upon the <purge_percent>.
  size_t const entries_to_remove
    = ACE_MAX (static_cast<size_t> (1),
               static_cast<size_t> (static_cast<double> (purge_percent)
                                    / 100 * current_map_size));

  KEY *key_to_remove = 0;
  VALUE *value_to_remove = 0;

  for (size_t i = 0; i < entries_to_remove ; ++i)
    {
      this->minimum (container,
                     key_to_remove,
                     value_to_remove);

      // Simply verifying that the key is non-zero.
      // This is important for strategies where the minimum
      // entry cant be found due to constraints on the type of entry
      // to remove.
      if (key_to_remove == 0)
        return 0;

      if (this->cleanup_strategy_->cleanup (container,
                                            key_to_remove,
                                            value_to_remove) == -1)
        return -1;
    }

  return 0;
}
Ejemplo n.º 24
0
template <class KEY, class VALUE, class CONTAINER> int
ACE_Recyclable_Handler_Cleanup_Strategy<KEY, VALUE, CONTAINER>::cleanup (CONTAINER &container,
                                                                         KEY *key,
                                                                         VALUE *)
{
  VALUE value;

  if (container.unbind (*key, value) == -1)
    return -1;

  value.first ()->recycler (0, 0);

  value.first ()->close ();

  return 0;
}
Ejemplo n.º 25
0
template <class KEY, class VALUE, class CONTAINER> int
ACE_Handler_Cleanup_Strategy<KEY, VALUE, CONTAINER>::cleanup (CONTAINER &container,
                                                              KEY *key,
                                                              VALUE *value)
{
  // Remove the item from cache only if the handler isnt in use.
  if ((*value)->active () == 0)
    {
      (*value)->close ();

      if (container.unbind (*key) == -1)
        return -1;

    }

  return 0;
}
Ejemplo n.º 26
0
bool compare_map_weak_ptrs( const CONTAINER& lhs, const CONTAINER& rhs )
{
    typename CONTAINER::const_iterator i = lhs.begin();
    typename CONTAINER::const_iterator j = rhs.begin();
    while ( i != lhs.end() && j != rhs.end() && (i->second.lock().get() == 0 && j->second.lock().get() == 0 || i->second.lock() != 0 && j->second.lock() != 0 && *(i->second.lock()) == *(j->second.lock())) )
    {
        ++i;
        ++j;
    }

    return i == lhs.end() && j == rhs.end();
}
Ejemplo n.º 27
0
bool compare_pointer_types( const CONTAINER& lhs, const CONTAINER& rhs )
{
    typename CONTAINER::const_iterator i = lhs.begin();
    typename CONTAINER::const_iterator j = rhs.begin();
    while ( i != lhs.end() && j != rhs.end() && (*i == 0 && *j == 0 || *i != 0 && *j != 0 && (*(*i) == *(*j) && SWEET_TYPEID(*(*i)) == SWEET_TYPEID(*(*j)))) )
    {
        ++i;
        ++j;
    }

    return i == lhs.end() && j == rhs.end();
}
Ejemplo n.º 28
0
bool compare_map_pointers( const CONTAINER& lhs, const CONTAINER& rhs )
{
    typename CONTAINER::const_iterator i = lhs.begin();
    typename CONTAINER::const_iterator j = rhs.begin();
    while ( i != lhs.end() && j != rhs.end() && i->first == j->first && (i->second == 0 && j->second == 0 || i->second != 0 && j->second != 0 && *i->second == *j->second) )
    {
        ++i;
        ++j;
    }

    return i == lhs.end() && j == rhs.end();
}
Ejemplo n.º 29
0
bool compare( const CONTAINER& lhs, const CONTAINER& rhs )
{
    typename CONTAINER::const_iterator i = lhs.begin();
    typename CONTAINER::const_iterator j = rhs.begin();
    while ( i != lhs.end() && j != rhs.end() && *i == *j )
    {
        ++i;
        ++j;
    }

    return i == lhs.end() && j == rhs.end();
}
Ejemplo n.º 30
0
bool CBratSettings::SaveRecentFilesGeneric( const CONTAINER &paths )
{
	auto brathlFmtEntryRecentWksMacro = []( size_t index ) -> std::string
	{
		return KEY_WKS_RECENT + n2s<std::string>( index );
	};

	//

	{
		CSection section( mSettings, GROUP_WKS_RECENT );
		const size_t size = paths.size();
		for ( size_t i = 0; i < size; ++i )
			WriteValue( section, brathlFmtEntryRecentWksMacro( i ), paths[ (typename CONTAINER::size_type) i ] );
	}

	return mSettings.status() == QSettings::NoError;
}