int main()
{
	typedef map<string, int> MAP;
	MAP removal;
	string removal_word = "Anna";
	removal.insert(MAP::value_type(removal_word, 47)); 
 	if (removal.erase(removal_word))
 		cout << "Ok," << removal_word << " removed" << endl;
	else
		cout << "oops" <<removal_word << "not found!" <<endl;
	
	return 0;
}
Ejemplo n.º 2
0
int main()
{
	// declare a map to handle the mesh
	MAP myMap;

	// add position attribute on vertices and get handler on it
	VertexAttribute<VEC3, MAP> position = myMap.addAttribute<VEC3, VERTEX, MAP>("position");
	const int nb = 2;
	Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(myMap, nb, nb, nb);
	cubic.embedIntoGrid(position, 10.0f, 10.0f, 10.0f);

	VolumeAttribute<VEC3,MAP> color = myMap.addAttribute<VEC3, VOLUME, MAP>("color");

	foreach_cell<VOLUME>(myMap, [&](Vol w)
	{
		color[w] = position[w.dart] + VEC3(0.5,0.5,0.5);
	});

	CGoGNout.toStd(false);
	CGoGNout.toFile("ls_map1.csv");
	myMap.dumpCSV();
	std::cout << "MAP 1 dumped in ls_map1.csv"<< std::endl;

	myMap.saveMapBin("ls_pipo.map");

	MAP myMap2;
	VertexAttribute<VEC3, MAP> position2 = myMap2.addAttribute<VEC3, VERTEX, MAP>("position");
	CellMarker<MAP,VERTEX> cm(myMap2);

	myMap2.loadMapBin("ls_pipo.map");

	if (!position2.isValid())
	{
		std::cout << "Attribute handlers are invalid after load or copy, get it agin"<< std::endl;
		// get it again (here attribute created in load)
		position2 = myMap2.getAttribute<VEC3, VERTEX, MAP>("position");
	}

	CGoGNout.toFile("ls_map2.csv");
	myMap2.dumpCSV();
	std::cout << "MAP 2 dumped in ls_map2.csv"<< std::endl;


	cm.update();
	if (cm.isMarked(myMap2.begin()))
		std::cout << "MARKED"<< std::endl;

	std::cout << " Volume Total =" << Algo::Geometry::totalVolume<PFP>(myMap2, position2)<< std::endl;

	return 0;
}
Ejemplo n.º 3
0
static void
unbind_test (MAP &map,
             size_t iterations,
             KEY *keys)
{
  // Remove system generated keys.
  size_t counter = iterations;
  for (VALUE i = 0; i < iterations; ++i)
    {
      ACE_ASSERT (map.unbind (keys[i]) != -1);
      --counter;
      ACE_ASSERT (map.current_size () == counter);
    }
}
Ejemplo n.º 4
0
static void
insert_test (MAP &map,
             size_t iterations,
             KEY *keys)
{
  // Add to the map, allowing keys to be created by the map.
  size_t counter = 0;
  for (VALUE i = 0; i < iterations; ++i)
    {
      ACE_ASSERT (map.bind_create_key (i, keys[i]) == 0);
      ++counter;
      ACE_ASSERT (map.current_size () == counter);
    }
}
Ejemplo n.º 5
0
void Topo3PrimalRender<PFP>::computeDartMiddlePositions(MAP& map, DartAttribute<VEC3, MAP>& posExpl)
{
	m_vbo0->bind();
	Geom::Vec3f* positionsPtr = reinterpret_cast<Geom::Vec3f*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY));

	for (Dart d = map.begin(); d != map.end(); map.next(d))
	{
		const Geom::Vec3f& v =(positionsPtr[m_attIndex[d]] + positionsPtr[m_attIndex[d]+1])*0.5f;
		posExpl[d] = PFP::toVec3f(v);
	}

	m_vbo0->bind();
	glUnmapBuffer(GL_ARRAY_BUFFER);
}
Ejemplo n.º 6
0
// [[Rcpp::export]]
SEXP map_getVal(SEXP m, SEXP k) {
    MAP* list = (MAP*)R_ExternalPtrAddr(m);
    if (!list) return R_NilValue;
    
    if (!Rf_isString(k)) 
        return R_NilValue;
    
    std::string keystr = as<std::string>(k);
    
    MAP::iterator it = list->find(keystr);
    if (it == list->end()) 
        return R_NilValue;
    else
        return local_ptr_toRObject(it->second);
}
Ejemplo n.º 7
0
 const std::string str() const {
   std::stringstream ss;
   // start with xs
   bool firstTime=true;
   for(const_iterator i(terms.begin());i!=terms.end();++i) {      
     if(!firstTime) { ss << " + "; }
     firstTime=false;
     simple_poly_term const &t(i->first);
     int count = i->second;
     if(count > 1) { ss << count; }
     ss << i->first.str();
   }
   
   return ss.str(); 
 }
Ejemplo n.º 8
0
		static void				Delete( CSocket& sock ){
			CSession* pSession = Find( sock );
			if( pSession ){
				m_Sessions.erase( sock.GetHandle() );
				delete pSession;
			}
		}
Ejemplo n.º 9
0
   // Return a root with variable v.
   // If root does not exist, create it.
 void ForceTree(const Variable & v,SFSGNode *& result) {
   if(!FindTree(v,result)) {
     result = new SFSGNode(v);
     pair<const Variable,SFSGNode *> pr(v,result);
     d_tree_map.insert(pr);
   };
 }; 
Character::Character(Graphics &graphics, const std::string &filePath, int sourceX, int sourceY, int width, int height, int posX, int posY, int pos_x_arg, int pos_y_arg, MAP& map):
Sprite(graphics,filePath,sourceX,sourceY,width,height,posX,posY),pos_x(pos_x_arg), pos_y(pos_y_arg){

	std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> d(0, map.max_x-1);
	int y=d(gen)%(map.max_y-1),x=d(gen);
	if (filePath == "images/thief.png"){
		while (!map.map[y][x].accessable() || ((x + y) % 2)){
			y = d(gen) % (map.max_y - 1);
			x = d(gen);
		}
	}
	else {
		while (!map.map[y][x].accessable() || !((x + y) % 2)){
			y = d(gen) % (map.max_y - 1);
			x = d(gen);
		}
	}
	map.switchFree(pair<int,int>(x,y));
	pos_x=x;
	pos_y=y;
	_x=posX+x*map.mov_x;
	_y=posY+y*map.mov_y;
}
Ejemplo n.º 11
0
 ///function to insert shuffled values one by one into the Map
 void insert_random() {
     long i = 0;
     while ( i < n ) {
         hashmap.insert ( PAIR ( data[i], 2 * data[i] ) );
         i++;
     }
 }
Ejemplo n.º 12
0
// [[Rcpp::export]]
SEXP map_AddKeyVal(SEXP m, SEXP k, SEXP val) {
    MAP* list = (MAP*)R_ExternalPtrAddr(m);
    if (!list) return R_NilValue;
    
    if (!Rf_isString(k)) 
        return R_NilValue;
    
    std::string keystr = as<std::string>(k);
    
    if (!__map_hasKey(m,k))
        list->insert(pair<string,unsigned long>(keystr,local_getPtr(val)));
    else 
        return R_NilValue; 
    
    return m;
    
}
Ejemplo n.º 13
0
static void createAOUT(void** work)
{
#ifdef WITH_HW
    map.openMap();
    DAC* dac = new DAC(map);
    *work = (void *) dac;
#endif
}
Ejemplo n.º 14
0
Traversor2FE<MAP>::Traversor2FE(const MAP& map, Face f) : m(map), start(f), m_QLT(NULL)
{
	const AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* quickTraversal = map.template getQuickIncidentTraversal<FACE,VERTEX>() ;
	if (quickTraversal != NULL)
	{
		m_QLT = &(quickTraversal->operator[](map.getEmbedding(f)));
	}
}
Ejemplo n.º 15
0
Traversor2VE<MAP>::Traversor2VE(const MAP& map, Vertex v) : m(map), start(v),m_QLT(NULL)
{
	const AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* quickTraversal = map.template getQuickIncidentTraversal<VERTEX,EDGE>() ;
	if (quickTraversal != NULL)
	{
		m_QLT = &(quickTraversal->operator[](map.getEmbedding(v)));
	}
}
Ejemplo n.º 16
0
void CUser::HealAreaCheck(int rx, int rz)
{
	MAP* pMap = GetMap();
	if (pMap == NULL) return;
	// 자신의 region에 있는 NpcArray을 먼저 검색하여,, 가까운 거리에 Monster가 있는지를 판단..
	if(rx < 0 || rz < 0 || rx > pMap->GetXRegionMax() || rz > pMap->GetZRegionMax())	{
		TRACE("#### CUser-HealAreaCheck() Fail : [nid=%d, name=%s], nRX=%d, nRZ=%d #####\n", m_iUserId, m_strUserID, rx, rz);
		return;
	}

	float fRadius = 10.0f;				// 30m

	__Vector3 vStart, vEnd;
	CNpc* pNpc = NULL ;      // Pointer initialization!
	float fDis = 0.0f;
	vStart.Set(m_curx, (float)0, m_curz);
	int send_index=0, result = 1, count = 0; 

	EnterCriticalSection( &g_region_critical );
	CRegion *pRegion = &pMap->m_ppRegion[rx][rz];
	int total_mon = pRegion->m_RegionNpcArray.GetSize();
	int *pNpcIDList = new int[total_mon];
	foreach_stlmap (itr, pRegion->m_RegionNpcArray)
		pNpcIDList[count++] = *itr->second;

	LeaveCriticalSection( &g_region_critical );

	for(int i = 0 ; i < total_mon; i++ ) {
		int nid = pNpcIDList[i];
		if( nid < NPC_BAND ) continue;
		pNpc = (CNpc*)g_pMain->m_arNpc.GetData(nid - NPC_BAND);

		if( pNpc != NULL && pNpc->m_NpcState != NPC_DEAD)	{
			if( m_bNation == pNpc->m_byGroup ) continue;
			vEnd.Set(pNpc->m_fCurX, pNpc->m_fCurY, pNpc->m_fCurZ); 
			fDis = pNpc->GetDistance(vStart, vEnd);

			if(fDis <= fRadius)	{	// NPC가 반경안에 있을 경우...
				pNpc->ChangeTarget(1004, this);
			}	
		}
	}

	if (pNpcIDList)
		delete [] pNpcIDList;
}
Ejemplo n.º 17
0
		static CSession*		New( const CSocket& sock, DWORD dwMask, IProtocol* pProtocol = NULL ){
			CSession*	pSession	= new CSession(sock, dwMask, pProtocol);
			if( pSession ){
				m_Sessions.insert( PAIR(sock.GetHandle(), pSession) );
				return pSession;
			}
			return NULL;
		}
void map_histogram(std::ostream &out, const MAP &map) {
  std::vector<int> hist;
  for (typename MAP::const_iterator i = map.begin(); i != map.end(); ++i) {
    size_t n = (*i).second.size();
    if (hist.size() <= n) {
      hist.resize(n + 1);
    }
    hist[n]++;
  }
  int total = map.size();
  std::string bar(50, '*');
  for (size_t i = 0; i < hist.size(); i++) {
    if (hist[i] > 0) {
      out << std::setw(5) << i << " : " << std::setw(5) << hist[i] << " " << bar.substr(50 - hist[i] * 50 / total) << std::endl;
    }
  }
}
Ejemplo n.º 19
0
 ///function to search all values of the array in rb hash tree
 void search_random() {
     long int i = 0;
     long ret;
     while ( i < n ) {
         ret = hashmap.find ( data[i] )->second;
         i++;
     }
     ///
 }
Ejemplo n.º 20
0
VMarkerForTraversor<MAP, ORBIT>::VMarkerForTraversor(MAP& map, bool forceDartMarker, unsigned int thread) :
    m_map(map),
    m_dmark(NULL),
    m_cmark(NULL)
{
    if(!forceDartMarker && map.isOrbitEmbedded(ORBIT))
        m_cmark = new CellMarkerStore<ORBIT>(map, thread) ;
    else
        m_dmark = new DartMarkerStore(map, thread) ;
}
Ejemplo n.º 21
0
static void deleteAOUT(void** work)
{
#ifdef WITH_HW
    DAC* dac = (DAC*) (*work);
    if (dac != 0){
        delete dac;
    }
    map.closeMap();
#endif
}
Ejemplo n.º 22
0
 typename _MapT<MAP>::ValIter
 eachValForKey (MAP& map, typename _MapT<MAP>::Key key)
 {
   typedef typename MAP::iterator Pos;
   typedef RangeIter<Pos> Range;
   
   std::pair<Pos,Pos> valuesForKey = map.equal_range(key);
   Range contents (valuesForKey.first, valuesForKey.second);
   return wrapIter (takePairSecond(contents));
 }
Ejemplo n.º 23
0
 bool GpXmlStateMachine::FindAttribute(MAP& attribs, const string& compstr, string& retstr)
 {
   bool                retval = false;
   MAP::const_iterator search = attribs.find(compstr);
   #ifdef DEBUG
   cout << "Searching for attribute: " << compstr;
   #endif
   if (search != attribs.end() )
   {
     retstr = attribs[compstr];
     #ifdef DEBUG
     cout << " Found value: " << retstr;
     #endif
     retval = true;
   }
   #ifdef DEBUG
   cout << "\n";
   #endif
   return retval;
 }
Ejemplo n.º 24
0
/**
 * @brief computeLengthEdges
 * Demonstrate usage of 2 attributes on 2 differents orbits.
 * @param map the map
 * @param pos attribute handler of position of vertices
 * @param len attribute handler of length of edges
 */
void computeLengthEdges(MAP& map,const VertexAttribute<VEC3, MAP>& pos, EdgeAttribute<float, MAP> len)
{
	// warning c++11 lambda syntax
	foreach_cell<EDGE>(map,[&](Edge e) // for all edge e of map do
	{
		VEC3 P1 = pos[e.dart]; // access with dart because of access to VertexAttribute with an edge
		VEC3 P2 = pos[map.phi1(e)]; // phi1 return a dart so no problem (and e can auto-cast in dart)
		VEC3 V = P2 - P1;
		len[e] = V.norm();
	});
}
Ejemplo n.º 25
0
void do_test_insertPoints()
{
	// test 1: Insert and check expected values:
	{
		MAP  pts;
		load_demo_9pts_map(pts);

		EXPECT_EQ(pts.size(),demo9_N);

		for (size_t i=0;i<demo9_N;i++)
		{
			float x,y,z;
			pts.getPoint(i,x,y,z);
			EXPECT_EQ(x,demo9_xs[i]);
			EXPECT_EQ(y,demo9_ys[i]);
			EXPECT_EQ(z,demo9_zs[i]);
		}
	}

	// test 2: Copy between maps
	{
		MAP  pts1;
		load_demo_9pts_map(pts1);

		MAP  pts2 = pts1;
		MAP  pts3 = pts1;

		EXPECT_EQ(pts2.size(),pts3.size());
		for (size_t i=0;i<demo9_N;i++)
		{
			float x2,y2,z2;
			float x3,y3,z3;
			pts2.getPoint(i,x2,y2,z2);
			pts3.getPoint(i,x3,y3,z3);
			EXPECT_EQ(x2,x3);
			EXPECT_EQ(y2,y3);
			EXPECT_EQ(z2,z3);
		}
	}

}
Ejemplo n.º 26
0
int Exploration::getCellData(POINT &p, const MAP &map) {

	if (!isAllocated(p, map))
		return EXPLORATION_UNKNOWN;

	double data = map.storage().cell(p);

	if (data == EXPLORATION_UNKNOWN)
		return EXPLORATION_UNKNOWN;

	return (data > CELL_THRESHOLD ? EXPLORATION_OCCUPIED : EXPLORATION_OPEN_SPACE);
}
Ejemplo n.º 27
0
  // this is gary's shift operation
  void operator*=(xy_term const &p2) {
    if(p2.ypowerend == p2.ypower) {
      // I don't think the STL strictly would allow this,
      // but it doesn't hurt!      
      for(const_iterator i(terms.begin());i!=terms.end();++i) {      
	simple_poly_term &t((simple_poly_term &)i->first); // ouch ;)
	t.xpower += p2.xpower;
	t.ypower += p2.ypower;
      }
    } else {
      // recursive case (this is an ugly hack)
      simple_poly p(*this);

      for(unsigned int i=p2.ypower;i!=p2.ypowerend-1;++i) {
	*this += p;
	p *= xy_term(0,1);
      }
      
      *this += p;
    }
  }
void Character::move(int where_move,MAP& map){
	int mov=88;
	map.switchFree(pair<int,int>(pos_x,pos_y));
	if(where_move==1) {
		_y-=mov;
		pos_y--;
	}
	if(where_move==2) {
		_x+=mov;
		pos_x++;
	}
	if(where_move==3) {
		_y+=mov;
		pos_y++;
	}
	if(where_move==4) {
		_x-=mov;
		pos_x--;
	}
	map.switchFree(pair<int,int>(pos_x,pos_y));
}
Ejemplo n.º 29
0
void Topo3PrimalRender<PFP>::updateColors(MAP& map, const VertexAttribute<VEC3, MAP>& colors)
{
	m_vbo2->bind();
	Geom::Vec3f* colorBuffer =  reinterpret_cast<Geom::Vec3f*>(glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE));
	unsigned int nb=0;

	for (Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if (nb < m_nbDarts)
		{
			colorBuffer[m_attIndex[d]] = colors[d];
			nb++;
		}
		else
		{
			CGoGNerr << "Error buffer too small for color picking (change the selector parameter ?)" << CGoGNendl;
			break;
		}
	}
	glUnmapBuffer(GL_ARRAY_BUFFER);
}
Ejemplo n.º 30
0
Archivo: main.cpp Proyecto: Tytan/CDR
void command_add_dynamic(string& command, MAP &map) {
	vector<dynamic_object> objs;
	command = command.substr(2);
#if DEBUG
	cerr << "Objects this time :" << endl;
#endif
	while (command.find(';') != string::npos) {
		dynamic_object obj;
		sscanf(command.c_str(), "%i;%i;%i", &obj.x, &obj.y, &obj.r);
		objs.push_back(obj);
		command = command.substr(command.find(';')+1);
		command = command.substr(command.find(';')+1);
		command = command.substr(command.find(';')+1);
#if DEBUG
		cerr << obj.x << ":" << obj.y << ":" << obj.r << endl;
#endif
	}
	map.clear_dynamic_barriers();
	for (auto &obj: objs) {
		map.add_dynamic_circle(obj.x, obj.y, obj.r);
	}
}