示例#1
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);
  }
}
示例#2
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();
}
示例#3
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();
}
示例#4
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();
}
示例#5
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();
}
示例#6
0
bool 
compare_container_of_containers( 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() && compare(*i, *j) )
    {
        ++i;
        ++j;
    }

    return i == lhs.end() && j == rhs.end();
}
示例#7
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;
		}
	}	
}
示例#8
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());
				}
			}
		}
	}
}
示例#9
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_;
        }
    }
}
示例#10
0
文件: main.cpp 项目: 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 ;
}
示例#11
0
void HazardModule::PurgeAllHazardsProcessContainer(CONTAINER& container)
{
	typename CONTAINER::iterator iter = container.begin();
	while (iter != container.end())
	{
		iter = ExpireAndDeleteHazardInstance(container, iter);
	}
}
示例#12
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);	
	}
}
示例#13
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;
}
示例#14
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);
	}
}
示例#15
0
void
clear_map_pointers( CONTAINER& container )
{
    typename CONTAINER::iterator i = container.begin();
    while ( i != container.end() )
    {
        delete i->second;
        ++i;
    }

    container.clear();
}
示例#16
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;
		}
	}
}
示例#17
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);
}
示例#18
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_;
                }
            }
        }
    }
}
示例#19
0
bool contains(const CONTAINER& cont, const VALUE& val)
{
    return std::find(cont.begin(), cont.end(), val) != cont.end();
}
示例#20
0
文件: wire.hpp 项目: r-lyeh/wire
 strings( const CONTAINER &other ) : std::deque< string >( other.begin(), other.end() )
 {}
示例#21
0
 bool operator()( const CONTAINER& lhs, const CONTAINER& rhs )
 {
     std::lexicographical_compare( lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), PREDICATE );
 }
示例#22
0
	/**
	 * Binds a function to this dispatcher.
	 * @{
	 */
	BindHandler bind(std::function<void(EVENT &)> f){
		listeners.emplace_back(std::move(f));
		return std::prev(listeners.end());
	}
示例#23
0
 virtual literator    end(const any& container)      const
 {
     CONTAINER* c = anycast<CONTAINER*>(container);
     return literator(new vector_literator<CONTAINER,ELEMENT>(c,c->end()));
 }
示例#24
0
void MapTestDriver<CONTAINER>::testCase1()
{
    // ------------------------------------------------------------------------
    // SUPPORT REFERENCES AS 'mapped_type'
    //
    // Concerns:
    //: 1 All bsl map-like containers (map, multimap, unordered_map,
    //:   unordered_multimap) accept references as 'mapped_type'.
    //:
    //: 2 Container does not make a copy of the referenced object on insertion.
    //:
    //: 3 The mapped value copy-assignment operator assigns to the original
    //:   object and does not rebind the reference.
    //:
    //: 4 The container copy-assignment operator does not copy mapped values.
    //:
    //: 5 The container copy constructor does not copy mapped values.
    //:
    //: 6 The erase operation does not destroy the referenced object.
    //
    // Plan:
    //: 1 Create the value type containing a reference as a 'mapped_type' and
    //:   insert it into the container.  (C-1)
    //:
    //: 2 Verify that the container inserts the reference and does not make a
    //:   copy of the referenced object.  (C-2)
    //:
    //: 3 Assign diffenent value to the mapped value and verify that the
    //:   referenced object is changed.  (C-3)
    //:
    //: 4 Copy-construct new container and verify that the mapped value in the
    //:   new container references original object.  (C-4)
    //:
    //: 5 Assign the original container to a different container and verify
    //:   that the mapped value in the new container references original
    //:   object.  (C-4)
    //:
    //: 5 Erase the container entry and verify that the original object is not
    //:   destroyed.  (C-4)
    //
    // Testing:
    //   CONCERN: Support references as 'mapped_type' in map-like containers.
    // ------------------------------------------------------------------------
    if (verbose) {
        cout << "\tTesting with: " << bsls::NameOf<ValueType>().name() << endl;
    }

    BSLMF_ASSERT(false == bsl::is_reference<KeyType>::value);
    BSLMF_ASSERT(true  == bsl::is_reference<MappedType>::value);

    bslma::TestAllocator scratch("scratch", veryVeryVeryVerbose);

    bsls::ObjectBuffer<typename bsl::remove_const<KeyType>::type> tempKey;
    TTF::emplace(tempKey.address(), 1, &scratch);
    bslma::DestructorGuard<typename bsl::remove_const<KeyType>::type>
                                                   keyGuard(tempKey.address());

    bsls::ObjectBuffer<typename bsl::remove_reference<MappedType>::type>
                                                                    tempMapped;
    TTF::emplace(tempMapped.address(), 2, &scratch);
    bslma::DestructorGuard<typename bsl::remove_reference<MappedType>::type>
                                             mappedGuard(tempMapped.address());

    bsls::ObjectBuffer<typename bsl::remove_reference<MappedType>::type>
                                                                   tempMapped2;
    TTF::emplace(tempMapped2.address(), 18, &scratch);
    bslma::DestructorGuard<typename bsl::remove_reference<MappedType>::type>
                                           mappedGuard2(tempMapped2.address());

    CONTAINER mX;  const CONTAINER& X = mX;

    ValueType tempPair(tempKey.object(), tempMapped.object());

    mX.insert(MoveUtil::move(tempPair));

    Iter ret = mX.find(tempKey.object());

    ASSERT(ret != mX.end());

    // Reference still refers to the original object.
    ASSERT(bsls::Util::addressOf(ret->second) == tempMapped.address());

    // Assign different value to the mapped.
    ret->second = tempMapped2.object();

    // Reference still refers to the original object.
    ASSERT(bsls::Util::addressOf(ret->second) == tempMapped.address());
    ASSERT(tempMapped.object() == tempMapped2.object());

    // Copy-construct container.
    {
        CONTAINER mY(X);  const CONTAINER& Y = mY;

        CIter ret = Y.find(tempKey.object());

        ASSERT(ret != Y.end());

        // Reference still refers to the original object.
        ASSERT(bsls::Util::addressOf(ret->second) == tempMapped.address());
    }

    // Copy-assign container.
    {
        CONTAINER mY;  const CONTAINER& Y = mY;

        mY = X;

        CIter ret = Y.find(tempKey.object());

        ASSERT(ret != Y.end());

        // Reference still refers to the original object.
        ASSERT(bsls::Util::addressOf(ret->second) == tempMapped.address());
    }

    // Erasing the value.
    mX.erase(tempKey.object());

    ret = mX.find(tempKey.object());

    ASSERT(ret == mX.end());

    ASSERT(tempMapped.object() == tempMapped2.object());

    cout<< "here3\n";
}