Пример #1
0
const TAO_Control_Registry::NameList&
TAO_Control_Registry::names (void)
{
  if (this->name_cache_.length () == 0)
    {
      ACE_WRITE_GUARD_RETURN (TAO_SYNCH_RW_MUTEX,
                              guard,
                              this->mutex_,
                              this->name_cache_);

      if (this->name_cache_.length () == 0)
        {
          CORBA::ULong length = 0;
          Map::iterator itr (this->map_);
          Map::value_type* entry = 0;

          while (itr.next (entry))
            {
              this->name_cache_.length (length + 1);
              this->name_cache_[length++] =
                        CORBA::string_dup (entry->key ().c_str ());
              itr.advance ();
            }
        }
    }

  return this->name_cache_;
}
void NetworkAdapterList::DoRunCallbacks(Map& aMap)
{
    AutoMutex a(iListenerLock);
    Map::iterator it = aMap.begin();
    while (it != aMap.end()) {
        it->second();
        it++;
    }
}
Пример #3
0
TAO_Control_Registry::~TAO_Control_Registry (void)
{
  ACE_WRITE_GUARD (TAO_SYNCH_RW_MUTEX, guard, this->mutex_);

  Map::iterator itr (this->map_);
  Map::value_type* entry = 0;

  while (itr.next (entry))
    {
      delete entry->item ();
      itr.advance ();
    }
}
Пример #4
0
    bool testBasics() {
        typedef HashMap<AString, int, StringPolicy> Map;
        Map map;

        if (!check(map.init(), "initialized"))
            return false;

        Map::Result r = map.find("cat");
        if (!check(!r.found(), "cat not found"))
            return false;

        Map::Insert i = map.findForAdd("cat");
        if (!check(!i.found(), "cat not found for add"))
            return false;
        if (!check(map.add(i, AString("cat"), 5), "cat added"))
            return false;
        if (!check(r->value == 5, "cat is 5"))
            return false;

        Map::iterator iter = map.iter();
        if (!check(iter->key.compare("cat") == 0, "iterator got key cat"))
            return false;
        if (!check(iter->value == 5, "iterator got value 5"))
            return false;
        iter.next();
        if (!check(iter.empty(), "iterator should be finished"))
            return false;

        i = map.findForAdd("cat");
        if (!check(i.found(), "cat found through insert"))
            return false;

        r = map.find("dog");
        if (!check(!r.found(), "dog not found"))
            return false;

        r = map.find("cat");
        if (!check(r.found(), "cat found"))
            return false;
        if (!check(r->value == 5, "cat is 5"))
            return false;
        map.remove(r);

        r = map.find("cat");
        if (!check(!r.found(), "cat ran away"))
            return false;

        return true;
    }
QModelIndex Model::parent( const QModelIndex & index ) const {
   dgd_scopef(trace_vrml_scene_map);

   dgd_logger << dgd_expand(index.row()) << std::endl
              << dgd_expand(index.column()) << std::endl
              << dgd_expand(index.internalPointer()) << std::endl;

   QModelIndex rc;

   if( !index.isValid() ) {
      dgd_logger << "index not valid" << std::endl;
      return rc;
   }

   void *object = index.internalPointer();
   if( object == NULL ) {
      dgd_logger << "object == NULL" << std::endl;
      return rc;
   }

   Item *item = static_cast<Item*>( object );
   if( item == NULL ) {
      dgd_logger << "item == NULL" << std::endl;
      return rc;
   }

   if( item->node().node() == NULL ) {
      dgd_logger << "item->parent() == NULL" << std::endl;
      return rc;
   }

   Map::iterator iter = m_scene_map->find( item->parent() );
   if( iter == m_scene_map->end() ) {
      dgd_logger << "iter == m_scene_map->end()" << std::endl;
      return rc;   
   }

   dgd_logger << dgd_expand(iter->row()) << std::endl
              << dgd_expand(&*iter) << std::endl;

   return this->createIndex( iter->row(), 0, &*iter );
}
Пример #6
0
void Car::apply_physics(Map &map)
{
	if(m_physicTimer.ticked())
	{
		//float currentSpeed = norm(m_speedVector);

		sf::Transformable::rotate(m_rotation/**(currentSpeed / m_maxSpeed)*/);
		float rotation = getRotation();
		float accelFactor = m_physicTimer.getFullWaitedDuration().asSeconds();

		//calculate the new speed with the acceleration
		m_speed += accelFactor*m_acceleration;
		if(m_speed > m_maxSpeed)
		{
			m_speed = m_maxSpeed;
			//std::cout<< "max attained\n";
		}
		else if(m_speed < -m_maxSpeed)
		{
			m_speed = -m_maxSpeed;
			//std::cout<< "min attained\n";
		}

		sf::Vector2f posOffset(
		m_speed*accelFactor*std::cos(rotation*M_PI/180)
		, m_speed*accelFactor*std::sin(rotation*M_PI/180)
		);

		//calculate the new position with the speed
		move(posOffset);


		//collisions tests
		bool collided = false;
		int i = 0;
		collision::LineHitBox lineBox;
		for(Map::iterator it = map.begin(); it != map.end() && !collided; it++)
		{	
			collided = collision::collision(getHitBox(), it->getHitBox(), lineBox);
		}
		if(collided)
		{
			move(-posOffset); //return to position before collision
			posOffset = collision::bounceVector(
			posOffset
			,collision::normale(lineBox, getPosition())
			);

			move(posOffset);
			setRotation(angle(posOffset));
			m_speed /= 4;
			std::cout<< getPosition().x<< " ; "<< getPosition().y<< '\n';
		}


		m_acceleration = 0;
		m_physicTimer.restart();

	}

	//draw the speed at the right place
	m_speedIndicator.setPosition(getPosition() - sf::Vector2f(400, 300));
	std::stringstream stream;
	stream<< int(m_speed);
	std::string indicatorString;
	stream>> indicatorString;

	m_speedIndicator.setString(indicatorString);
}
Пример #7
0
static void makeGraph(const char* input) {
   std::vector<GNode> nodes;
   //Create local computation graph.
   typedef Galois::Graph::LC_CSR_Graph<Node, EdgeDataType> InGraph;
   typedef InGraph::GraphNode InGNode;
   InGraph in_graph;
   //Read graph from file.
   Galois::Graph::readGraph(in_graph, input);
   std::cout << "Read " << in_graph.size() << " nodes\n";
   //A node and a int is an element.
   typedef std::pair<InGNode, EdgeDataType> Element;
   //A vector of element is 'Elements'
   typedef std::vector<Element> Elements;
   //A vector of 'Elements' is a 'Map'
   typedef std::vector<Elements> Map;
   //'in_edges' is a vector of vector of pairs of nodes and int.
   Map edges(in_graph.size());
   //
   int numEdges = 0;
   for (InGraph::iterator src = in_graph.begin(), esrc = in_graph.end(); src != esrc; ++src) {
      for (InGraph::edge_iterator dst = in_graph.edge_begin(*src, Galois::MethodFlag::NONE), edst = in_graph.edge_end(*src, Galois::MethodFlag::NONE); dst != edst; ++dst) {
         if (*src == *dst) {
#if BORUVKA_DEBUG
            std::cout<<"ERR:: Self loop at "<<*src<<std::endl;
#endif
            continue;
         }
         EdgeDataType w = in_graph.getEdgeData(dst);
         Element e(*src, w);
         edges[in_graph.getEdgeDst(dst)].push_back(e);
         numEdges++;
      }
   }
#if BORUVKA_DEBUG
   std::cout<<"Number of edges "<<numEdges<<std::endl;
#endif
   nodes.resize(in_graph.size());
   for (Map::iterator i = edges.begin(), ei = edges.end(); i != ei; ++i) {
      Node n(nodeID);
      GNode node = graph.createNode(n);
      graph.addNode(node);
      nodes[nodeID] = node;
      nodeID++;
   }

   int id = 0;
   numEdges = 0;
   EdgeDataType edge_sum = 0;
   int numDups = 0;
   for (Map::iterator i = edges.begin(), ei = edges.end(); i != ei; ++i) {
      GNode src = nodes[id];
      for (Elements::iterator j = i->begin(), ej = i->end(); j != ej; ++j) {
         Graph::edge_iterator it = graph.findEdge(src, nodes[j->first], Galois::MethodFlag::NONE);
         if (it != graph.edge_end(src, Galois::MethodFlag::NONE)) {
            numDups++;
            EdgeDataType w = (graph.getEdgeData(it));
            if (j->second < w) {
               graph.getEdgeData(it) = j->second;
               edge_sum += (j->second-w);
            }
         } else {
            graph.getEdgeData(graph.addEdge(src, nodes[j->first], Galois::MethodFlag::NONE)) = j->second;
            edge_sum += j->second;
         }
         numEdges++;
         assert(edge_sum < std::numeric_limits<EdgeDataType>::max());
      }
      id++;
   }
#if BORUVKA_DEBUG
   std::cout << "Final num edges " << numEdges << " Dups " << numDups << " sum :" << edge_sum << std::endl;
#endif
}
Пример #8
0
static void makeGraph(GraphType &graph, const char* input) {
   std::vector<SGNode> nodes;
   //Create local computation graph.
   typedef Galois::Graph::LC_CSR_Graph<Node, edgedata> InGraph;
   typedef InGraph::GraphNode InGNode;
   InGraph in_graph;
   //Read graph from file.
   Galois::Graph::readGraph(in_graph, input);
   std::cout << "Read " << in_graph.size() << " nodes\n";
   //A node and a int is an element.
   typedef std::pair<InGNode, edgedata> Element;
   //A vector of element is 'Elements'
   typedef std::vector<Element> Elements;
   //A vector of 'Elements' is a 'Map'
   typedef std::vector<Elements> Map;
   //'in_edges' is a vector of vector of pairs of nodes and int.
   Map edges(in_graph.size());
   //
   int numEdges = 0;
   // Extract edges from input graph
   for (InGraph::iterator src = in_graph.begin(), esrc = in_graph.end();
        src != esrc; ++src) {
      for (InGraph::edge_iterator
             dst = in_graph.edge_begin(*src, Galois::MethodFlag::NONE),
             edst = in_graph.edge_end(*src, Galois::MethodFlag::NONE);
           dst != edst; ++dst) {
         edgedata w = in_graph.getEdgeData(dst);
         Element e(*src, w);
         edges[in_graph.getEdgeDst(dst)].push_back(e);
         numEdges++;
      }
   }
   //#if BORUVKA_DEBUG
   std::cout<<"Number of edges "<<numEdges<<std::endl;
   //#endif
   // Create nodes in output graph
   nodes.resize(in_graph.size());
   int nodeID = 0;
   for (Map::iterator i = edges.begin(), ei = edges.end(); i != ei; ++i) {
      Node n;
      n.id = nodeID;
      assert(!n.seen);
      SGNode node = graph.createNode(n);
      graph.addNode(node);
      nodes[nodeID] = node;
      nodeID++;
   }

   int id = 0;
   numEdges = 0;
   for (Map::iterator i = edges.begin(), ei = edges.end(); i != ei; ++i) {
      SGNode src = nodes[id];
      for (Elements::iterator j = i->begin(), ej = i->end(); j != ej; ++j) {
         typename GraphType::edge_iterator
           it = graph.findEdge(src, nodes[j->first], Galois::MethodFlag::NONE);
         if ( it != graph.edge_end(src, Galois::MethodFlag::NONE) ) {
           assert(graph.getEdgeData(it) == j->second);
           continue;
         }
         it = graph.addEdge(src, nodes[j->first], Galois::MethodFlag::NONE);
         graph.getEdgeData(it) = j->second;
         numEdges++;
      }
      id++;
   }
   
   //#if BORUVKA_DEBUG
   std::cout << "Final num edges " << numEdges << std::endl;
   //#endif
}