• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ unordered_map类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中unordered_map的典型用法代码示例。如果您正苦于以下问题:C++ unordered_map类的具体用法?C++ unordered_map怎么用?C++ unordered_map使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了unordered_map类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

/****************************** MAIN *****************************/
int main (int argc, char **argv)
{
	int c;
	while (1) {
		static struct option long_options[] =
		{
			//These options don’t set a flag.
			//We distinguish them by their indices. 
			{"help",   	no_argument, 		0, 		'h'},
			{"threads",   	required_argument, 	0, 		't'},
			{"name",   	required_argument, 	0, 		'n'},
			{0, 		0, 			0, 		0}
		};
		//getopt_long stores the option index here. 
		int option_index = 0;

		c = getopt_long (argc, argv, "h:t:o:p:r:",long_options, &option_index);

		//Detect the end of the options.
		if (c == -1) { 
			break;
		}

		switch (c) {
			case 'h':
				print_help();
				return 0;
			case 't':
				num_threads = atoi(optarg);
				break;
			case 'n':
				name = optarg;
				break;
		}
		
	}

	init_system();

	string aux_model;
	string id;
	string idrelated;
	string sample;
	int threshold;
	string func = "";;
	string line = "";
	int func_id;
	unordered_map<string,unsigned long>::const_iterator it_func_id;
	unordered_map<string,unsigned long>::const_iterator it_func_value_id;
	while (getline(std::cin, line)) {
		if(!line.empty()){
			istringstream iss(line);

			iss >> func >> id;

			it_func_id = APIID.find(func);

			if (it_func_id != APIID.end()){

				switch(it_func_id->second) {	
					case 0:
						if(exist_sample(id)) {
							cout << "[\"Err\",\"duplicated sample\"]" << endl;
						}else{
							iss >> sample;
							string ok = add_sample(id,&sample);
							
							save_sample(id,&sample);
							
							cout << ok << endl;
						}
						break;
					case 1:
						it_func_value_id = APIVALUEID.find(id);
						if(it_func_value_id == APIVALUEID.end()){
							cout << "[\"Err\",\"missmatch function\"]" << endl;
						}else{
							iss >> id;
							if(!exist_sample(id)) {
								cout << "[\"Err\",\"missing sample\"]" << endl;
							}else{
								iss >> threshold;
								switch(it_func_value_id->second) {	
									case 0: get_value_snps(id,threshold);
										break;
									case 1: get_value_ides(id,threshold);
										break;
								}
							}
						}

						break;
					case 3:
						it_func_value_id = APIVALUEID.find(id);
						if(it_func_value_id == APIVALUEID.end()){
							cout << "[\"Err\",\"missmatch function\"]" << endl;
						}else{
							iss >> threshold;
							switch(it_func_value_id->second) {	
//.........这里部分代码省略.........
开发者ID:TrienDo,项目名称:findNeighbour,代码行数:101,代码来源:findNeighbour.cpp


示例2: begin

 unordered_map<int,int>::iterator begin (int s) {return g.find(s)->second.begin();}
开发者ID:robertu94,项目名称:hackpack,代码行数:1,代码来源:escape.cpp


示例3: main


//.........这里部分代码省略.........
	      pvm_upkstr(word);
	      pvm_upkstr(tree);
	      string sword = string(word);
	      string stree = string(tree);
	      //	      log << "Unpacked " << sword << " \t" << sword.size() << " and " << stree << " \t" << stree.size() << endl;
	      tree_list[sword] = stree;
	    }
	}
      // Wait for a NEXT request
      //      log << "Waiting for NEXT" << endl;
      int recbuf=pvm_recv(-1,NEXT);
      log << "Received NEXT with " << recbuf << endl;
      int tid;
      pvm_bufinfo(recbuf,NULL,NULL,&tid);
      pvm_initsend(PvmDataDefault);
      int block_size = BLOCK_SIZE;
      if (word_list.size() < BLOCK_SIZE)
	block_size = word_list.size();
      log << "Sending data block of size " << block_size << endl;
      pvm_pkint(&block_size,1,1);
      for (int ct = 0; ct < block_size; ct++)
	{
	  string sword = word_list.back();
	  //	  log << "Pack " << sword << endl;
	  pvm_pkstr((char *) sword.c_str() );
	  word_list.pop_back();
	}
      int sbuf = pvm_send(tid,DATA);
      log << "send DATA with " << sbuf << endl;
    }
  // See if DATA is pending
  while (pvm_probe(-1,DATA))
    {
      int recbuf=pvm_recv(-1,DATA);
      log << "got DATA with " << recbuf << endl;
      int block_size;
      pvm_upkint(&block_size,1,1);
      log << "Recieving data block of size " << block_size << endl;
      for (int ct = 0; ct < block_size; ct++)
	{
	  pvm_upkstr(word);
	  pvm_upkstr(tree);
	  string sword = string(word);
	  string stree = string(tree);
	  //	  log << "Unpacked " << sword << " \t" << sword.size() << " and " << stree << " \t" << stree.size() << endl;
	  tree_list[sword] = stree;
	}
    }

  // Syncing up after end of data
  for (int ct = 0; ct < task_count; ct++)
    {
      // Sending empty data twice to be sure to be received and unblock receive
      pvm_initsend(PvmDataDefault);
      int null = 0;
      pvm_pkint(&null,1,1);
      pvm_send(tids[ct],DATA);
      pvm_initsend(PvmDataDefault);
      pvm_send(tids[ct],DATA);
      log << "Send empty DATA to " << tids[ct] << endl;
      // Waiting for last message
      int recbuf=pvm_recv(tids[ct],FINAL);
      log << "got FINAL with " << recbuf << endl;
      int block_size;
      pvm_upkint(&block_size,1,1);
      log << "Recieving data block of size " << block_size << endl;
      for (int ct2 = 0; ct2 < block_size; ct2++)
  	{
  	  pvm_upkstr(word);
  	  pvm_upkstr(tree);
  	  string sword = string(word);
  	  string stree = string(tree);
  	  log << "Unpacked " << sword << " \t" << sword.size() << " and " << stree << " \t" << stree.size() << endl;
  	  tree_list[sword] = stree;
  	}
      int tid;
      pvm_bufinfo(recbuf,NULL,NULL,&tid);
      pvm_initsend(PvmDataDefault);
      int sbuf = pvm_send(tids[ct],DIE);
      log << "send DIE with " << sbuf << endl;
    }
  time(&end_time);
  log << "Matching took " << difftime(end_time,begin_time) << " seconds" << endl;
  log << "Start writing output" << endl;
  ofstream ofile;
  int wordcount = 0;
  ofile.open(OUTPUT_FILE);
  for (unordered_map<string,int>::iterator it = frequency_list.begin(); it != frequency_list.end(); it++)
    {
      //      log << it->first << "\t" << tree_list[it->first] << "\t" << it->second << endl;
      ofile << it->first << "\t" << tree_list[it->first] << "\t" << it->second << endl;
    }
  ofile.close();
  log << "Finished writing output" << endl;
  log.close();
  free(word);
  free(tree);
  log << "Exiting" << endl;
  pvm_exit();
}
开发者ID:daherb,项目名称:PVM-Silben,代码行数:101,代码来源:master.cpp


示例4: parseVecReport

void parseVecReport(string fileName,unordered_map<string,string>& htabVecMessages,unordered_map<string,set<string>>& htabLines,bool isVec6){
	string line;
	bool isMsg = false;
	ifstream infile(fileName);
	if(infile.is_open()){
		while(getline(infile,line)){
			if(line.find("error") != string::npos){
				cout<<endl<<line;
				infile.close();
				exit(0);
			}		
			else if(line.find("warning") != string::npos)
				continue;
			else{
              			vector<string> vecTemp = splitStringByDelimiter(line,':');
				if(vecTemp.size() < 3){
                  			if(!isMsg){
                                        	cerr<<endl<<endl<<"The following line(s) from the vec report have not been processed:"<<endl;
                                        	isMsg = true;
                                	}
                                	cerr<<endl<<line;				
				}
				else{
					string strFileName = vecTemp[0].substr(0,vecTemp[0].find_first_of("("));
					string strLineNb = vecTemp[0].substr(vecTemp[0].find("(")+1,vecTemp[0].find(")")-vecTemp[0].find("(")-1);
					string strKey = strFileName + ";" + strLineNb;
                                	string strReason;
                                	for(int j=2;j<vecTemp.size();j++){
						if(isVec6){
							strReason += trimWhiteSpaces(vecTemp[j]);
						}
						else{
							string trimmedString = trimWhiteSpaces(vecTemp[j]);
							vector<string> vecInner = splitStringByDelimiter(trimmedString,' ');
							if(vecInner.size() > 0){
								if(htabVecMessages.find(vecInner[0]) != htabVecMessages.end()){
									strReason += htabVecMessages.at(vecInner[0]);
									if(vecInner.size() == 2)
										strReason += vecInner[1];	
								}
								else{
									strReason += trimmedString;
								}
							}
						}
                                        	if(j==vecTemp.size()-1)
                                                	strReason+=";";
                                        	else
                                                	strReason+=" - ";
                                	}
					if(htabLines.find(strKey) != htabLines.end()){
						set<string> reasons = htabLines.at(strKey);
						if(reasons.find(strReason) == reasons.end()){
							reasons.insert(strReason);
						}
						htabLines.at(strKey) = reasons;
					}				
					else{
						set<string> reasons;
						reasons.insert(strReason);
						htabLines.insert(make_pair<string,set<string>>(strKey,reasons));
					}							
				}
			}	
		}
		infile.close();
	}		
}
开发者ID:sreesurendran,项目名称:compilers,代码行数:68,代码来源:intelvecrep_parse_embed_comments_external_dict.cpp


示例5: manageEquipmentEvent

static void manageEquipmentEvent(color_ostream& out) {
    if (!df::global::world)
        return;
    multimap<Plugin*,EventHandler> copy(handlers[EventType::INVENTORY_CHANGE].begin(), handlers[EventType::INVENTORY_CHANGE].end());

    unordered_map<int32_t, InventoryItem> itemIdToInventoryItem;
    unordered_set<int32_t> currentlyEquipped;
    for ( auto a = df::global::world->units.all.begin(); a != df::global::world->units.all.end(); a++ ) {
        itemIdToInventoryItem.clear();
        currentlyEquipped.clear();
        df::unit* unit = *a;
        /*if ( unit->flags1.bits.dead )
            continue;
        */

        auto oldEquipment = equipmentLog.find(unit->id);
        bool hadEquipment = oldEquipment != equipmentLog.end();
        vector<InventoryItem>* temp;
        if ( hadEquipment ) {
            temp = &((*oldEquipment).second);
        } else {
            temp = new vector<InventoryItem>;
        }
        //vector<InventoryItem>& v = (*oldEquipment).second;
        vector<InventoryItem>& v = *temp;
        for ( auto b = v.begin(); b != v.end(); b++ ) {
            InventoryItem& i = *b;
            itemIdToInventoryItem[i.itemId] = i;
        }
        for ( size_t b = 0; b < unit->inventory.size(); b++ ) {
            df::unit_inventory_item* dfitem_new = unit->inventory[b];
            currentlyEquipped.insert(dfitem_new->item->id);
            InventoryItem item_new(dfitem_new->item->id, *dfitem_new);
            auto c = itemIdToInventoryItem.find(dfitem_new->item->id);
            if ( c == itemIdToInventoryItem.end() ) {
                //new item equipped (probably just picked up)
                InventoryChangeData data(unit->id, NULL, &item_new);
                for ( auto h = copy.begin(); h != copy.end(); h++ ) {
                    EventHandler handle = (*h).second;
                    handle.eventHandler(out, (void*)&data);
                }
                continue;
            }
            InventoryItem item_old = (*c).second;

            df::unit_inventory_item& item0 = item_old.item;
            df::unit_inventory_item& item1 = item_new.item;
            if ( item0.mode == item1.mode && item0.body_part_id == item1.body_part_id && item0.wound_id == item1.wound_id )
                continue;
            //some sort of change in how it's equipped

            InventoryChangeData data(unit->id, &item_old, &item_new);
            for ( auto h = copy.begin(); h != copy.end(); h++ ) {
                EventHandler handle = (*h).second;
                handle.eventHandler(out, (void*)&data);
            }
        }
        //check for dropped items
        for ( auto b = v.begin(); b != v.end(); b++ ) {
            InventoryItem i = *b;
            if ( currentlyEquipped.find(i.itemId) != currentlyEquipped.end() )
                continue;
            //TODO: delete ptr if invalid
            InventoryChangeData data(unit->id, &i, NULL);
            for ( auto h = copy.begin(); h != copy.end(); h++ ) {
                EventHandler handle = (*h).second;
                handle.eventHandler(out, (void*)&data);
            }
        }
        if ( !hadEquipment )
            delete temp;

        //update equipment
        vector<InventoryItem>& equipment = equipmentLog[unit->id];
        equipment.clear();
        for ( size_t b = 0; b < unit->inventory.size(); b++ ) {
            df::unit_inventory_item* dfitem = unit->inventory[b];
            InventoryItem item(dfitem->item->id, *dfitem);
            equipment.push_back(item);
        }
    }
}
开发者ID:HarryFromMarydelDE,项目名称:dfhack,代码行数:82,代码来源:EventManager.cpp


示例6: encstrpath1

void asferknnclustering::kNNClustering(string distancemetric)
{
        bool converged=false;

        asferstringdistance asd;

	int max_no_of_points=0;
	int max_cluster_id=0;

	//training labelled dataset
        ifstream input1;
        char line1[256];
        char line2[256];
        string encstrpath1(asferroot);
        encstrpath1.append("/asfer.enterprise.encstr.kNN");
        input1.open(encstrpath1.c_str(), ifstream::in);
	labelled_points.clear();
	
	int i=0;
        while (!input1.eof())
        {
               input1.getline(line1,256);
               string encstrtr(line1);
	       if(encstrtr != "")
	       {
			cout<<"training dataset : encstrtr = "<<encstrtr<<endl;
			labelled_points[encstrtr] = i % MAX_NO_CLUSTERS;
	       		i++;
	       }
        }
	
	cout<<"Before kNN clustering"<<endl;
	printClusters();
                                            
       	//kNN clustering classification 
        ifstream input2;
        string encstrpath2(asferroot);
        encstrpath2.append("/asfer.enterprise.encstr");
        input2.open(encstrpath2.c_str(), ifstream::in);

        while (!input2.eof()) //for each unlabelled encoded string 
        {
                input2.getline(line2,256);
                string encstrtr(line2);
		if(encstrtr != "")
		{
			int editdistance_radius=8;
	      		unordered_map<string,int> kNearestNeighbours; // <encoded_string,cluster_id>
 
			printClusters();
			for(unordered_map<string,int>::iterator it1 = labelled_points.begin(); it1 != labelled_points.end(); it1++) // for each labelled encoded string
			{
				//compute distance to all labelled points from this unlabelled point
				//and create a map of k Nearest neighbours that are with in a
				//radius edit distance
	       			int ed;
				cout<<"kNNClustering iteration: encstrtr = "<<encstrtr<<endl;
				if(it1->first != "")
				{
					ed = asd.editDistanceWagnerFischer(encstrtr, it1->first);
					if(ed < editdistance_radius)
					{
						kNearestNeighbours[it1->first] = it1->second;
					}
				}
			}	
			
			//find the cluster id label that is
			//in majority in above k Nearest Neighbours
			unordered_map<int,int> labelMajority; // <cluster_id, no_of_points_in_cluster>
			for(unordered_map<string,int>::iterator it2 = kNearestNeighbours.begin(); it2 != kNearestNeighbours.end(); it2++)
			{
				//if(it2->first != "")
					labelMajority[it2->second]++;
			}
			
			for(unordered_map<int,int>::iterator it3 = labelMajority.begin(); it3 != labelMajority.end(); it3++)
			{
				if(it3->second > max_no_of_points)
				{
					max_no_of_points = it3->second;
					max_cluster_id = it3->first;
				}
			}
			//label with max_cluster_id
			labelled_points[encstrtr]=max_cluster_id;
			max_no_of_points=0;
			max_cluster_id=0;
        	}
	}
	printClusters();
}
开发者ID:shrinivaasanka,项目名称:asfer-github-code,代码行数:92,代码来源:asferkNNclustering.cpp


示例7: createTupleTable

vector<vector<int>> createTupleTable(unordered_map<int, vector<Pair>> clauseAnswers, vector<Relationship> relationships, unordered_map<string, int> *synIndexMap) {
	//// cout << "Begin creating tuple table" << endl;

	vector<vector<int>> tupleTable;
	vector<int> emptyTuple;
	tupleTable.push_back(emptyTuple);

	for(int i=0; i<int(relationships.size()); i++) {

		if (AbstractWrapper::GlobalStop) {
			// cout<< "Timeout detected! Stopping QueryProcessor Tuple!" << endl;
			return tupleTable;
		}

		//// cout << "Adding relationship " << i << " to tuple table" << endl;

		vector<Pair> clauseAns = clauseAnswers.at(i);
		//Initialize variables
		Relationship r = relationships.at(i);
		Relationship::RelType rt = r.getRelType();
		//// cout << "Relation Type being added to tuple table: " << rt << endl;
		string token1;
		string token2;
		Relationship::TokenType type1;
		Relationship::TokenType type2;

		if(rt == Relationship::PATTERN) {
			type1 = r.getToken1Type();
			if(type1 == Relationship::SYNONYM) {
				token1 = r.getPatternSyn();
				token2 = r.getToken1();
				type2 = r.getToken1Type();
			}
			else {
				token1 = r.getPatternSyn();
				token2 = r.getPatternSyn();
				type1 = Relationship::SYNONYM;
				type2 = Relationship::INVALIDTOKEN;
			}
		}
		else {
			token1 = r.getToken1();
			token2 = r.getToken2();
			type1 = r.getToken1Type();
			type2 = r.getToken2Type();
		}
		bool ignore1 = false;
		bool ignore2 = false;

		if(type1 != Relationship::SYNONYM)
			ignore1 = true;
		if(type2 != Relationship::SYNONYM || (token1==token2))
			ignore2 = true;

		//Case 1: both are Synonyms
		if(!ignore1 && !ignore2) {
			//// cout << "Case 1" << endl;
			bool tk1InMap = false;
			bool tk2InMap = false;

			if(synIndexMap->find(token1) != synIndexMap->end())
				tk1InMap = true;
			else {
				//// cout << "Adding " << token1 << " to synMap with index " << synIndexMap->size() << endl;
				synIndexMap->insert(make_pair(token1, synIndexMap->size()));
			}
			
			if(synIndexMap->find(token2) != synIndexMap->end())
				tk2InMap = true;
			else {
				//// cout << "Adding " << token2 << " to synMap with index " << synIndexMap->size() << endl;
				synIndexMap->insert(make_pair(token2, synIndexMap->size()));
			}
			// Check if clause has no answer, return empty tuple table
			if(clauseAns.size()==0) {
				//// cout << "empty clause detected, returning empty table" << endl;
				tupleTable.clear();
				break;
			}

			vector<vector<int>> newTable;

			//Case 1.1: Both Synonyms are new
			if(!tk1InMap && !tk2InMap) {
				//// cout << "Case 1.1" << endl;
				for(int x=0; x<int(tupleTable.size()); x++) {
					for(int y=0; y<int(clauseAns.size()); y++) {
						vector<int> tuple;
						vector<int> tuple1 = tupleTable.at(x);
						Pair tuple2 = clauseAns.at(y);
						tuple.insert(tuple.begin(), tuple1.begin(), tuple1.end());
						//// cout << tuple2.ans1 << " " << tuple2.ans2 << endl; 
						tuple.push_back(tuple2.ans1);
						tuple.push_back(tuple2.ans2);
						
						newTable.push_back(tuple);
					}
				}
			}
			//Case 1.2: First Synonym is new
//.........这里部分代码省略.........
开发者ID:gongfuPanada,项目名称:Static-Code-Analyzer,代码行数:101,代码来源:QueryProcessor.cpp


示例8: update_predefined_parameters

  ////////////////////////////////////////////////////////////////////////////////
  // OTHERS
  void update_predefined_parameters(
    unordered_map<wstring, pair<wstring, int> > const& params) {

    unordered_map<wstring, pair<wstring, int> >::const_iterator i;


    ////////////////////////////////////////////////////////////////////////////////
    // SIZE

    if ((i=params.find(pre_edge_width))!=params.end()) {
      wstring const& s = i->second.first;
      try {
        float const v = boost::lexical_cast<float>(s);
        if (v>0.0f) sociarium_project_draw::set_edge_width(v);
      } catch (...) {}
    } else {
      sociarium_project_draw::set_edge_width(
        sociarium_project_draw::get_default_edge_width());
    }

    if ((i=params.find(pre_node_size))!=params.end()) {
      wstring const& s = i->second.first;
      try {
        float const v = boost::lexical_cast<float>(s);
        if (v>0.0f) sociarium_project_draw::set_node_size(v);
      } catch (...) {}
    } else {
      sociarium_project_draw::set_node_size(
        sociarium_project_draw::get_default_node_size());
    }

    if ((i=params.find(pre_coordinates_size))!=params.end()) {
      wstring const& s = i->second.first;
      try {
        float const v = boost::lexical_cast<float>(s);
        if (v>0.0f) sociarium_project_draw::set_coordinates_size(v);
      } catch (...) {}
    }

    if ((i=params.find(pre_grid_interval))!=params.end()) {
      wstring const& s = i->second.first;
      try {
        float const v = boost::lexical_cast<float>(s);
        if (v>0.0f) sociarium_project_layout::set_grid_interval(v);
      } catch (...) {}
    }


    ////////////////////////////////////////////////////////////////////////////////
    // FORCE DIRECTION

    if ((i=params.find(pre_force_scale))!=params.end()) {
      wstring const& s = i->second.first;
      try {
        float const v = boost::lexical_cast<float>(s);
        if (v>0.0f) sociarium_project_force_direction::set_force_scale(v);
      } catch (...) {}
    }

    if ((i=params.find(pre_kk_force_NN))!=params.end()) {
      wstring const& s = i->second.first;
      try {
        float const v = boost::lexical_cast<float>(s);
        if (v>0.0f) sociarium_project_force_direction::set_kk_force_CC(v);
      } catch (...) {}
    }

    if ((i=params.find(pre_kk_force_CC))!=params.end()) {
      wstring const& s = i->second.first;
      try {
        float const v = boost::lexical_cast<float>(s);
        if (v>0.0f) sociarium_project_force_direction::set_kk_force_CC(v);
      } catch (...) {}
    }

    if ((i=params.find(pre_spring_force_CN))!=params.end()) {
      wstring const& s = i->second.first;
      try {
        float const v = boost::lexical_cast<float>(s);
        if (v>0.0f) sociarium_project_force_direction::set_spring_force_CN(v);
      } catch (...) {}
    }

    if ((i=params.find(pre_spring_force_NN))!=params.end()) {
      wstring const& s = i->second.first;
      try {
        float const v = boost::lexical_cast<float>(s);
        if (v>0.0f) sociarium_project_force_direction::set_spring_force_NN(v);
      } catch (...) {}
    }

    if ((i=params.find(pre_spring_length_CN))!=params.end()) {
      wstring const& s = i->second.first;
      try {
        float const v = boost::lexical_cast<float>(s);
        if (v>0.0f) sociarium_project_force_direction::set_spring_length_CN(v);
      } catch (...) {}
    }
//.........这里部分代码省略.........
开发者ID:kiyoya,项目名称:sociarium,代码行数:101,代码来源:update_predefined_parameters.cpp


示例9: update_texture_parameters

  ////////////////////////////////////////////////////////////////////////////////
  // TEXTURE
  void update_texture_parameters(
    unordered_map<wstring, pair<wstring, int> > const& params) {

    unordered_map<wstring, pair<wstring, int> >::const_iterator i;

    if ((i=params.find(pre_texture_folder))!=params.end()) {
      wstring path = i->second.first;
      if (!path.empty() && path[path.size()-1]!=L'\\') path += L'\\';
      sociarium_project_texture::set_texture_folder_path(path);
    } else
      sociarium_project_texture::set_texture_folder_path(L"");

    GLint wrap_s = GL_CLAMP_TO_EDGE_EXT;
    GLint wrap_t = GL_CLAMP_TO_EDGE_EXT;
    /* GL_REPEAT
     * GL_CLAMP
     * GL_CLAMP_TO_BORDER_EXT (unavailable??)
     * GL_CLAMP_TO_EDGE_EXT
     */

    if ((i=params.find(pre_texture_wrap_s))!=params.end()) {

      wstring const s = i->second.first;

      if (s==L"GL_CLAMP")
        wrap_s = GL_CLAMP;
      else if (s==L"GL_REPEAT")
        wrap_s = GL_REPEAT;
      else if (s==L"GL_CLAMP_TO_EDGE_EXT")
        wrap_s = GL_CLAMP_TO_EDGE_EXT;

      sociarium_project_texture::set_texture_parameter_wrap_s(wrap_s);
    }

    if ((i=params.find(pre_texture_wrap_t))!=params.end()) {

      wstring const s = i->second.first;

      if (s==L"GL_CLAMP")
        wrap_t = GL_CLAMP;
      else if (s==L"GL_REPEAT")
        wrap_t = GL_REPEAT;
      else if (s==L"GL_CLAMP_TO_EDGE_EXT")
        wrap_t = GL_CLAMP_TO_EDGE_EXT;

      sociarium_project_texture::set_texture_parameter_wrap_t(wrap_t);
    }

    if ((i=params.find(pre_node_texture))!=params.end()) {
      // Change default node texture.
      wstring const filename = i->second.first;
      sociarium_project_texture::set_default_node_texture_tmp(filename);
    } else {
      wstring const path_tmp
        = sociarium_project_texture::get_texture_folder_path();
      sociarium_project_texture::set_texture_folder_path(L"");
      sociarium_project_texture::set_default_node_texture_tmp(
        DEFAULT_NODE_TEXTURE_FILE);
      sociarium_project_texture::set_texture_folder_path(path_tmp);
    }

    if ((i=params.find(pre_edge_texture))!=params.end()) {
      // Change default edge texture.
      wstring const filename = i->second.first;
      sociarium_project_texture::set_default_edge_texture_tmp(filename);
    } else {
      wstring const path_tmp
        = sociarium_project_texture::get_texture_folder_path();
      sociarium_project_texture::set_texture_folder_path(L"");
      sociarium_project_texture::set_default_edge_texture_tmp(
        DEFAULT_EDGE_TEXTURE_FILE);
      sociarium_project_texture::set_texture_folder_path(path_tmp);
    }

    if ((i=params.find(pre_community_texture))!=params.end()) {
      // Change default community texture.
      wstring const filename = i->second.first;
      sociarium_project_texture::set_default_community_texture_tmp(filename);
    } else {
      wstring const path_tmp
        = sociarium_project_texture::get_texture_folder_path();
      sociarium_project_texture::set_texture_folder_path(L"");
      sociarium_project_texture::set_default_community_texture_tmp(
        DEFAULT_COMMUNITY_TEXTURE_FILE);
      sociarium_project_texture::set_texture_folder_path(path_tmp);
    }

    if ((i=params.find(pre_community_edge_texture))!=params.end()) {
      // Change default community edge texture.
      wstring const filename = i->second.first;
      sociarium_project_texture::set_default_community_edge_texture_tmp(filename);
    } else {
      wstring const path_tmp
        = sociarium_project_texture::get_texture_folder_path();
      sociarium_project_texture::set_texture_folder_path(L"");
      sociarium_project_texture::set_default_community_edge_texture_tmp(
        DEFAULT_COMMUNITY_EDGE_TEXTURE_FILE);
      sociarium_project_texture::set_texture_folder_path(path_tmp);
//.........这里部分代码省略.........
开发者ID:kiyoya,项目名称:sociarium,代码行数:101,代码来源:update_predefined_parameters.cpp


示例10: find

 unordered_map<int,int>::iterator find(int s, int d){
     return g.find(s)->second.find(d);}
开发者ID:robertu94,项目名称:hackpack,代码行数:2,代码来源:escape.cpp


示例11: end

 unordered_map<int,int>::iterator end (int s) {return g.find(s)->second.end();}
开发者ID:robertu94,项目名称:hackpack,代码行数:1,代码来源:escape.cpp


示例12: flush_creatures

void flush_creatures (){
    creatures_map.clear();
}
开发者ID:arthur-hav,项目名称:QuickRL,代码行数:3,代码来源:creatures.cpp


示例13: server_result

/******************************************************************************
Description: function for sending back the result
Input Value.:
Return Value:
******************************************************************************/
void server_result (int sock, string userID)
{
    if (debug) printf("result thread\n\n");

    int n, fd;
    char response[] = "ok";
    sem_t *sem_match = new sem_t(); // create a new semaphore in heap
    queue<string> *imgQueue = 0;    // queue storing the file names 

    //  Init semaphore and put the address of semaphore into map
    if (sem_init(sem_match, 0, 0) != 0)
    {
        errorSocket("ERROR semaphore init failed", sock);
    }
    // grap the lock
    pthread_mutex_lock(&sem_map_lock);
    sem_map[userID] = sem_match;
    pthread_mutex_unlock(&sem_map_lock);

    // reponse to the client
    if (!orbit)
    {
        n = write(sock, response, sizeof(response));
        if (n < 0)
        {
            error("ERROR writting to socket");
        }
    }
    else
    {
        MsgD.send(sock, response, sizeof(response));
    }

    struct sockaddr_in myaddr;
    int ret;
    char buf[1024];
    int serverPort = 9879;
    
    if (storm)
    {

        if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
            printf("socket create failed\n");
        if (debug) printf("socket created\n");

        /* bind it to all local addresses and pick any port number */

        memset((char *)&myaddr, 0, sizeof(myaddr));
        myaddr.sin_family = AF_INET;
        myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
        myaddr.sin_port = htons(serverPort);

        if (bind(fd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {
            perror("bind failed");
            goto stop;
        }       
        if (debug) printf("socket binded\n");
    }

    while(!global_stop) 
    {
        sem_wait(sem_match);
        // get the address of image queue
        if (imgQueue == 0)
        {
            imgQueue = queue_map[userID];
        }

        // check if the queue is empty
        if (imgQueue->empty())
        {
            sem_map.erase(userID);
            queue_map.erase(userID);
            user_map.erase(userID);
            delete(sem_match);
            delete(imgQueue);
            sem_destroy(sem_match);
            // if (orbit)
            // {
            //     MsgD.close(sock, 0);                
            // }
            printf("[server] client disconnected --- result\n");
            // pthread_exit(NULL); //terminate calling thread!
            return;
        }

        if (!storm)
        {
            if (debug) printf("\n----------- start matching -------------\n");
            string file_name = imgQueue->front(); 
            if (debug) printf("file name: [%s]\n", file_name.c_str());
            imgQueue->pop();

            // create a new thread to do the image processing

//.........这里部分代码省略.........
开发者ID:wuyangzhang,项目名称:asr,代码行数:101,代码来源:server-OpenCV.cpp


示例14: if

/******************************************************************************
Description.: There is a separate instance of this function 
              for each connection.  It handles all communication
              once a connnection has been established.
Input Value.:
Return Value: -
******************************************************************************/
void *serverThread (void * inputsock)
{
    int sock = *((int *)inputsock);
    int n;
    char buffer[100];
    string userID;
    char *threadType;
    char fail[] = "failed";

    // Receive the header
    bzero(buffer, sizeof(buffer));
    if (!orbit)
    {
        n = read(sock, buffer, sizeof(buffer));
        if (n < 0)
        {
            errorSocket("ERROR reading from socket", sock);
        } 
    }
    // below is orbit mode, using MFAPI
    else
    {
        MsgD.recv(sock, buffer, sizeof(buffer));
    }

    printf("[server] header content: %s\n\n",buffer);

    threadType = strtok(buffer, ",");
    userID = strtok(NULL, ",");

    // grap the lock
    pthread_mutex_lock(&user_map_lock);
    // confirm that this user does not log in
    if (user_map.find(userID) == user_map.end())
    {
        // put the new user into user map
        user_map[userID] = 1;
    }
    else
    {
        if (user_map[userID] == 1)
        {
            // increase user thread count
            user_map[userID] = 2;
        }
        else
        {
            // remember to unlock!
            pthread_mutex_unlock(&user_map_lock);
            // reponse to the client
            if (!orbit)
            {
                if (write(sock, "failed", sizeof("failed")) < 0)
                {
                    errorSocket("ERROR writting to socket", sock);
                }
                close(sock); 
            }
            else
            {
                MsgD.send(sock, fail, sizeof(fail));
            }
            printf("[server] User exist. Connection closed.\n\n");
            return 0;
        }
    }
    pthread_mutex_unlock(&user_map_lock);

    if (strcmp(threadType, "transmit") == 0) 
    {
        server_transmit(sock, userID);
    }
    else if (strcmp(threadType, "result") == 0) 
    {
        server_result(sock, userID);
    }
    else
    {
        if (!orbit)
        {
            close(sock); 
        }
        printf("[server] Command Unknown. Connection closed.\n\n");
    }

    return 0;
}
开发者ID:wuyangzhang,项目名称:asr,代码行数:94,代码来源:server-OpenCV.cpp


示例15: rmscache

void rmscache(const char *path)
{
    pthread_mutex_lock(&slock);
    scache.erase(path);
    pthread_mutex_unlock(&slock);
}
开发者ID:HiddenSelf,项目名称:baidudisk,代码行数:6,代码来源:cache.cpp


示例16: main

int main(int argc, char** argv) {
    log.execname(basename(argv[0]));
    log << "starting" << endl;
    vector<string> args(&argv[1], &argv[argc]);
    signal_action(SIGINT, signal_handler);
    signal_action(SIGTERM, signal_handler);
    if (args.size() > 2)
        usage();
    string host = get_cix_server_host(args, 0);
    in_port_t port = get_cix_server_port(args, 1);
    log << to_string(hostinfo()) << endl;
    try {
        log << "connecting to " << host << " port " << port << endl;
        client_socket server(host, port);
        log << "connected to " << to_string(server) << endl;
        for (;;) {
            string line, command, file;
            getline(cin, line);
            //get command and the files in the command
            if (line.find(" ") != string::npos) {
                command = line.substr(0, line.find(" "));
                file = line.substr(line.find(" ") + 1);
            } else {
                command = line;  //if first space is the end
            }

            if (cin.eof())
                throw cix_exit();
            if (SIGINT_throw_cix_exit)
                throw cix_exit();
            log << "command " << command << endl;
            log << "file " << file << endl;
            const auto& itor = command_map.find(command);
            cix_command cmd =
                    itor == command_map.end() ?
                            CIX_ERROR : itor->second;
            switch (cmd) {
            case CIX_EXIT:
                throw cix_exit();
                break;
            case CIX_GET:
                cix_get(server, file);
                break;
            case CIX_HELP:
                cix_help();
                break;
            case CIX_LS:
                cix_ls(server);
                break;
            case CIX_PUT:
                cix_put(server, file);
                break;
            case CIX_RM:
                cix_rm(server, file);
                break;
            default:
                log << line << ": invalid command" << endl;
                break;
            }
        }
    } catch (socket_error& error) {
        log << error.what() << endl;
    } catch (cix_exit& error) {
        log << "caught cix_exit" << endl;
    }
    log << "finishing" << endl;
    return 0;
}
开发者ID:kevinjesse,项目名称:UC-Santa-Cruz-Coursework,代码行数:68,代码来源:cix-client.cpp


示例17: mbl_mw_metawearboard_serialize

uint8_t* mbl_mw_metawearboard_serialize(const MblMwMetaWearBoard* board, uint32_t* size) {
    vector<uint8_t> serialized_state;

    serialized_state.push_back(SIGNAL_COMPONENT_SERIALIZATION_FORMAT);
    
    board->firmware_revision.serialize(serialized_state);

    serialized_state.push_back((uint8_t)board->module_number.size());
    serialized_state.insert(serialized_state.end(), board->module_number.begin(), board->module_number.end());

    {
        vector<uint8_t> sorted_keys;
        for (auto it : board->module_info) {
            sorted_keys.push_back(it.first);
        }
        sort(sorted_keys.begin(), sorted_keys.end());

        serialized_state.push_back((uint8_t)board->module_info.size());
        for (auto it : sorted_keys) {
            board->module_info.at(it).serialize(serialized_state);
        }
    }

    {
        uint8_t n_events= 0;
        vector<uint8_t> event_states;
        vector<ResponseHeader> sorted_keys;
        for (auto it : board->module_events) {
            sorted_keys.emplace_back(it.first.module_id, it.first.register_id, it.first.data_id);
        }
        sort(sorted_keys.begin(), sorted_keys.end());

        for (auto it : sorted_keys) {
            board->module_events.at(it)->serialize(event_states);
            n_events++;

            // serialize component signals after the main signal
            // rely on this ordering to restore the components vector
            if (MblMwDataSignal* signal= dynamic_cast<MblMwDataSignal*>(board->module_events.at(it))) {
                for(auto component: signal->components) {
                    component->serialize(event_states);
                    n_events++;
                }
            }
        }

        serialized_state.push_back(n_events);
        serialized_state.insert(serialized_state.end(), event_states.begin(), event_states.end());
    }

    {
        vector<uint8_t> sorted_keys;
        for (auto it : board->module_config) {
            sorted_keys.push_back(it.first);
        }
        sort(sorted_keys.begin(), sorted_keys.end());

        serialized_state.push_back((uint8_t)board->module_config.size());
        for (auto it : sorted_keys) {
            serialized_state.push_back(it);
            CONFIG_SERIALIZATION.at(it)(board, serialized_state);
        }
    }
    
    serialize_logging(board, serialized_state);
    
    *size = (uint32_t) serialized_state.size();
    uint8_t* state_bytes = (uint8_t*)malloc(sizeof(uint8_t) * (*size));
    memcpy(state_bytes, serialized_state.data(), *size);
    return state_bytes;
}
开发者ID:siddrajput,项目名称:Metawear-CppAPI,代码行数:71,代码来源:metawearboard.cpp


示例18: command_parse

void command_parse(SSL *ssl, char *command_line)
{
	char command[MAXLINE], arg[MAXLINE];
	char message[MAXLINE + 1];
	int n = sscanf(command_line, "%s%s", command, arg);
	if(strcmp(command, "signup") == 0) // signup a new user.
	{
		if(n != 2)
		{
			print 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ unordered_multimap类代码示例发布时间:2022-05-31
下一篇:
C++ unittest类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap