Ejemplo n.º 1
0
Archivo: coam.cpp Proyecto: isub/coam
int MainWork ()
{
	int iRetVal = 0;
	std::vector<SSubscriberRefresh> vectSubscriberList;
	std::vector<SSubscriberRefresh>::iterator iterSubscr;

	do {
		/* загружаем список абонентов */
		iRetVal = CreateSubscriberList (&vectSubscriberList);
		if (iRetVal) {
			break;
		}
		if (vectSubscriberList.size() > 1000) {
			iRetVal = CreateSessionListFull(g_mmapSessionListFull);
			if (iRetVal) {
				g_mmapSessionListFull.clear();
			}
		}
		/* обходим список абонентов */
		iterSubscr = vectSubscriberList.begin();
		while (iterSubscr != vectSubscriberList.end()) {
			/* обрабатыаем учетную запись абонента */
			iRetVal = ThreadManager (*iterSubscr);
			if (iRetVal) {
				break;
			}
			++iterSubscr;
		}
	} while (0);

	g_mmapSessionListFull.clear();

	return iRetVal;
}
Ejemplo n.º 2
0
	virtual void ReadAliases()
	{
		ConfigReader MyConf(ServerInstance);

		AllowBots = MyConf.ReadFlag("fantasy", "allowbots", "no", 0);

		std::string fpre = MyConf.ReadValue("fantasy","prefix",0);
		fprefix = fpre.empty() ? '!' : fpre[0];

		Aliases.clear();
		for (int i = 0; i < MyConf.Enumerate("alias"); i++)
		{
			Alias a;
			std::string txt;
			txt = MyConf.ReadValue("alias", "text", i);
			a.AliasedCommand = txt.c_str();
			a.ReplaceFormat = MyConf.ReadValue("alias", "replace", i, true);
			a.RequiredNick = MyConf.ReadValue("alias", "requires", i);
			a.ULineOnly = MyConf.ReadFlag("alias", "uline", i);
			a.ChannelCommand = MyConf.ReadFlag("alias", "channelcommand", "no", i);
			a.UserCommand = MyConf.ReadFlag("alias", "usercommand", "yes", i);
			a.OperOnly = MyConf.ReadFlag("alias", "operonly", i);
			a.format = MyConf.ReadValue("alias", "format", i);
			a.CaseSensitive = MyConf.ReadFlag("alias", "matchcase", i);
			Aliases.insert(std::make_pair(txt, a));
		}
	}
Ejemplo n.º 3
0
/// Reads in the file with the grouping information
bool DiffractionFocussing::readGroupingFile(
    std::string groupingFileName,
    std::multimap<int64_t, int64_t> &detectorGroups) {
  std::ifstream grFile(groupingFileName.c_str());
  if (!grFile) {
    g_log.error() << "Unable to open grouping file " << groupingFileName
                  << std::endl;
    return false;
  }

  detectorGroups.clear();
  std::string str;
  while (getline(grFile, str)) {
    if (str.empty() || str[0] == '#')
      continue;
    std::istringstream istr(str);
    int n, udet, sel, group;
    double offset;
    istr >> n >> udet >> offset >> sel >> group;
    // Check the line wasn't badly formatted - return a failure if it is
    // if ( ! istr.good() ) return false;
    // only allow groups with +ve ids
    if ((sel) && (group > 0)) {
      detectorGroups.insert(std::make_pair(group, udet));
    }
  }
  return true;
}
Ejemplo n.º 4
0
	virtual void OnRehash(User *user)
	{
		ConfigReader MyConf(ServerInstance);
		std::string snomasks;
		std::string channel;

		logstreams.clear();

		for (int i = 0; i < MyConf.Enumerate("chanlog"); i++)
		{
			channel = MyConf.ReadValue("chanlog", "channel", i);
			snomasks = MyConf.ReadValue("chanlog", "snomasks", i);

			if (channel.empty() || snomasks.empty())
			{
				ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Malformed chanlog tag, ignoring");
				continue;
			}

			for (std::string::const_iterator it = snomasks.begin(); it != snomasks.end(); it++)
			{
				logstreams.insert(std::make_pair(*it, channel));
				ServerInstance->Logs->Log("m_chanlog", DEFAULT, "Logging %c to %s", *it, channel.c_str());
			}
		}

	}
Ejemplo n.º 5
0
static bool BuildPersistentCache()
{
    if (next_persistent_id)
        return true;
    if (!Core::getInstance().isWorldLoaded())
        return false;

    stl::vector<df::historical_figure*> &hfvec = df::historical_figure::get_vector();

    // Determine the next entry id as min(-100, lowest_id-1)
    next_persistent_id = -100;

    if (hfvec.size() > 0 && hfvec[0]->id <= -100)
        next_persistent_id = hfvec[0]->id-1;

    // Add the entries to the lookup table
    persistent_index.clear();

    for (size_t i = 0; i < hfvec.size() && hfvec[i]->id <= -100; i++)
    {
        if (!hfvec[i]->name.has_name || hfvec[i]->name.first_name.empty())
            continue;

        persistent_index.insert(T_persistent_item(hfvec[i]->name.first_name, -hfvec[i]->id));
    }

    return true;
}
Ejemplo n.º 6
0
void GroupTransformer::putData(RddPartition* output,
    std::multimap<PbMessagePtr, PbMessagePtr, idgs::store::less>& localCache) {
  if (!localCache.empty()) {
    PbMessagePtr key;
    std::vector<PbMessagePtr> values;
    for (auto it = localCache.begin(); it != localCache.end(); ++it) {
      if (idgs::store::equals_to()(const_cast<PbMessagePtr&>(it->first), key)) {
        values.push_back(it->second);
      } else {
        if (!values.empty()) {
          output->put(key, values);
          values.clear();
        }
        values.clear();
        key = it->first;
        values.push_back(it->second);
      }
    }
    if (!values.empty()) {
      output->put(key, values);
      values.clear();
    }

    localCache.clear();
  }
}
Ejemplo n.º 7
0
/// @brief distribute matched phrase by names
/// @param phrases vector with matched phrases [in]
/// @param phraseByCls classID to phrase_matched multimap [out]
// this impementatin doesn't use getClasses (by ids) since huge multimap overhead
void PhraseSearcher::getClasses(const vector<phrase_matched> &phrases, 
                                std::multimap<string, phrasecls_matched> &phraseByCls) const
{
  phraseByCls.clear();
  
  phrasecls_matched mi;
  phrase_record *phrec;
  phrase_classes_list *pclassList;
  
  for (vector<phrase_matched>::const_iterator it = phrases.begin();
       it != phrases.end();
       it++) 
  {
    phrec = m_pimpl->m_phrase_offsets[ it->phrase_id ];
    pclassList = __phrase_header_jump_to_classes(phrec);
    
    mi.phrase_id = it->phrase_id;
    mi.match_flags = it->match_flags;
    
    for (unsigned i = 0; i < pclassList->n; i++) {
      mi.baserank = pclassList->clse[i].phrase_rank;
      phraseByCls.insert(pair<string, phrasecls_matched>(m_pQCIndex->getName(pclassList->clse[i].clsid), mi));
    }
  }
}
Ejemplo n.º 8
0
CServerDefinitions::CServerDefinitions() : defaultPriority( 0 )
{
	Console.PrintSectionBegin();
	Console << "Loading server scripts..." << myendl;
	Console << "   o Clearing AddMenuMap entries(" << g_mmapAddMenuMap.size() << ")" << myendl;
	g_mmapAddMenuMap.clear();
	ScriptListings.resize( NUM_DEFS );
	ReloadScriptObjects();
	Console.PrintSectionBegin();
}
Ejemplo n.º 9
0
void IOracle::sortedColumns(
    std::multimap<Double, Column const *, std::greater<Double>> & result) const {
  result.clear();
//	MY_PRINT(_columns.size());
  for (auto const & column : _columns) {
//		column.print();
    ASSERT_CHECK(column.check(*_dual));
    result.insert(std::make_pair(column.reducedCost(), &column));
  }
}
Ejemplo n.º 10
0
bool MDFN_SaveSettings(void)
{
 std::multimap <uint32, MDFNCS>::iterator sit;
 std::list<MDFNCS *> SortedList;
 std::list<MDFNCS *>::iterator lit;

 FILE *fp;

 if(!(fp = fopen(fname.c_str(), "wb")))
  return(0);

 trio_fprintf(fp, ";VERSION %s\n", MEDNAFEN_VERSION);

 trio_fprintf(fp, _(";Edit this file at your own risk!\n"));
 trio_fprintf(fp, _(";File format: <key><single space><value><LF or CR+LF>\n\n"));

 for(sit = CurrentSettings.begin(); sit != CurrentSettings.end(); sit++)
 {
  SortedList.push_back(&sit->second);
  //trio_fprintf(fp, ";%s\n%s %s\n\n", _(sit->second.desc->description), sit->second.name, sit->second.value);
  //free(sit->second.name);
  //free(sit->second.value);
 }

 SortedList.sort(compare_sname);

 for(lit = SortedList.begin(); lit != SortedList.end(); lit++)
 {
  if((*lit)->desc->type == MDFNST_ALIAS)
   continue;

  trio_fprintf(fp, ";%s\n%s %s\n\n", _((*lit)->desc->description), (*lit)->name, (*lit)->value);
  free((*lit)->name);
  free((*lit)->value);
 }

 if(UnknownSettings.size())
 {
  trio_fprintf(fp, "\n;\n;Unrecognized settings follow:\n;\n\n");
  for(unsigned int i = 0; i < UnknownSettings.size(); i++)
  {
   trio_fprintf(fp, "%s %s\n\n", UnknownSettings[i].name, UnknownSettings[i].value);

   free(UnknownSettings[i].name);
   free(UnknownSettings[i].value);
  }
 }


 CurrentSettings.clear();	// Call after the list is all handled
 UnknownSettings.clear();
 fclose(fp);
 return(1);
}
Ejemplo n.º 11
0
void node_t::cmp_scores(std::multimap<double,int> &scores, descriptor_t *data)
{
	scores.clear();
	for (unsigned i=0; i<nb_branches; i++) {
		if (clusters[i]) {
			double d = clusters[i]->mean.distance(data);
			//if (!finite(d)) std::cout << "dist= " << d << std::endl;
			scores.insert(std::pair<double,int>(d,i));
		}
	}
}
Ejemplo n.º 12
0
//o--------------------------------------------------------------------------o
//|	Function/Class	-	bool CServerDefinitions::Reload( void )
//|	Date			-	04/17/2002
//|	Developer(s)	-	EviLDeD
//|	Company/Team	-	UOX3 DevTeam
//|	Status			-	
//o--------------------------------------------------------------------------o
//|	Description		-	Reload the dfn files.
//|	Modification	-	04042004 - EviLDeD - Added the code to clear out the 
//|									Auto-AddMenu items so there isn't any duplication in the
//|									multimap
//o--------------------------------------------------------------------------o
//|	Returns				-	[TRUE] if succesfull
//o--------------------------------------------------------------------------o	
bool CServerDefinitions::Reload( void )
{
	// We need to clear out the AddMenuItem Map
	g_mmapAddMenuMap.clear();
	//
	Cleanup();
	ScriptListings.clear();
	ScriptListings.resize( NUM_DEFS );
	ReloadScriptObjects();
	return true;
}
Ejemplo n.º 13
0
	void UpdateHashToFunctionMap() {
		lock_guard guard(functions_lock);
		hashToFunction.clear();
		// Really need to detect C++11 features with better defines.
#if !defined(__SYMBIAN32__) && !defined(IOS)
		hashToFunction.reserve(functions.size());
#endif
		for (auto iter = functions.begin(); iter != functions.end(); iter++) {
			AnalyzedFunction &f = *iter;
			if (f.hasHash && f.size > 16) {
				hashToFunction.insert(std::make_pair(f.hash, &f));
			}
		}
	}
Ejemplo n.º 14
0
static void cancel_timers(std::multimap<int,int> &timers)
{
    using Lua::Core::State;

    Lua::StackUnwinder frame(State);
    lua_rawgetp(State, LUA_REGISTRYINDEX, &DFHACK_TIMEOUTS_TOKEN);

    for (auto it = timers.begin(); it != timers.end(); ++it)
    {
        lua_pushnil(State);
        lua_rawseti(State, frame[1], it->second);
    }

    timers.clear();
}
Ejemplo n.º 15
0
template <typename PointT> void
pcl::SupervoxelClustering<PointT>::getSupervoxelAdjacency (std::multimap<uint32_t, uint32_t> &label_adjacency) const
{
  label_adjacency.clear ();
  for (typename HelperListT::const_iterator sv_itr = supervoxel_helpers_.cbegin (); sv_itr != supervoxel_helpers_.cend (); ++sv_itr)
  {
    uint32_t label = sv_itr->getLabel ();
    std::set<uint32_t> neighbor_labels;
    sv_itr->getNeighborLabels (neighbor_labels);
    for (std::set<uint32_t>::iterator label_itr = neighbor_labels.begin (); label_itr != neighbor_labels.end (); ++label_itr)
      label_adjacency.insert (std::pair<uint32_t,uint32_t> (label, *label_itr) );
    //if (neighbor_labels.size () == 0)
    //  std::cout << label<<"(size="<<sv_itr->size () << ") has "<<neighbor_labels.size () << "\n";
  }
}
Ejemplo n.º 16
0
	void ForgetFunctions(u32 startAddr, u32 endAddr) {
		lock_guard guard(functions_lock);

		// It makes sense to forget functions as modules are unloaded but it breaks
		// the easy way of saving a hashmap by unloading and loading a game. I added
		// an alternative way.

		// Most of the time, functions from the same module will be contiguous in functions.
		FunctionsVector::iterator prevMatch = functions.end();
		size_t originalSize = functions.size();
		for (auto iter = functions.begin(); iter != functions.end(); ++iter) {
			const bool hadPrevMatch = prevMatch != functions.end();
			const bool match = iter->start >= startAddr && iter->start <= endAddr;

			if (!hadPrevMatch && match) {
				// Entering a range.
				prevMatch = iter;
			} else if (hadPrevMatch && !match) {
				// Left a range.
				iter = functions.erase(prevMatch, iter);
				prevMatch = functions.end();
			}
		}
		if (prevMatch != functions.end()) {
			// Cool, this is the fastest way.
			functions.erase(prevMatch, functions.end());
		}

		RestoreReplacedInstructions(startAddr, endAddr);

		if (functions.empty()) {
			hashToFunction.clear();
		} else if (originalSize != functions.size()) {
			UpdateHashToFunctionMap();
		}
	}
Ejemplo n.º 17
0
Archivo: main.cpp Proyecto: CCJY/coliru
 void clear() { m_functions.clear(); }
Ejemplo n.º 18
0
void World::ClearPersistentCache()
{
    next_persistent_id = 0;
    persistent_index.clear();
}
Ejemplo n.º 19
0
 void mem_alloc_clear_stats()
 {
     for (auto& item : stats)
         free(item.second.StackTrace);
     stats.clear();
 }
Ejemplo n.º 20
0
/*
 * dissect/print packet
 */
void
got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet)
{

	static int count = 1;                   /* packet counter */
	
	/* declare pointers to packet headers */
	const struct sniff_ethernet *ethernet;  /* The ethernet header [1] */
	const struct sniff_ip *ip;              /* The IP header */
	const struct sniff_tcp *tcp;            /* The TCP header */
	//const char *payload;                    /* Packet payload */
	//const u_char *payload;

	int size_ip;
	int size_tcp;
	int size_payload;
	
	//printf("\nPacket number %d:\n", count);
	count++;
	
	/* define ethernet header */
	ethernet = (struct sniff_ethernet*)(packet);
	
	/* define/compute ip header offset */
	ip = (struct sniff_ip*)(packet + SIZE_ETHERNET);
	size_ip = IP_HL(ip)*4;
	if (size_ip < 20) {
		printf("   * Invalid IP header length: %u bytes\n", size_ip);
		return;
	}

	/* print source and destination IP addresses */
	//printf("       From: %s\n", inet_ntoa(ip->ip_src));
	//printf("         To: %s\n", inet_ntoa(ip->ip_dst));
	
	/* determine protocol */	
	switch(ip->ip_p) {
		case IPPROTO_TCP:
			//printf("   Protocol: TCP\n");
			break;
		case IPPROTO_UDP:
			printf("   Protocol: UDP\n");
			return;
		case IPPROTO_ICMP:
			printf("   Protocol: ICMP\n");
			return;
		case IPPROTO_IP:
			printf("   Protocol: IP\n");
			return;
		default:
			printf("   Protocol: unknown\n");
			return;
	}

	
	/* define/compute tcp header offset */
	tcp = (struct sniff_tcp*)(packet + SIZE_ETHERNET + size_ip);
	size_tcp = TH_OFF(tcp)*4;
	if (size_tcp < 20) {
		printf("   * Invalid TCP header length: %u bytes\n", size_tcp);
		return;
	}
	std::string flags;
	if (tcp->th_flags & TH_FIN) 
		flags = flags + "F";
	if (tcp->th_flags & TH_SYN) 
                flags = flags + "S";
	if (tcp->th_flags & TH_RST) 
                flags = flags + "R";
	if (tcp->th_flags & TH_ACK) 
                flags = flags + "A";
	if (tcp->th_flags & TH_URG) 
                flags = flags + "U";
	if (tcp->th_flags & TH_ECE) 
                flags = flags + "E";
	if (tcp->th_flags & TH_CWR) 
                flags = flags + "C";

	chars v;
	chars buffer;
	std::multimap<u_int,chars> temp_map; //to sort

	std::cout << "Packet# " << count << " S " << ntohl(tcp->th_seq) << " A " << ntohl(tcp->th_ack) << " Flags " << flags <<"\n";

	if ((tcp->th_flags & TH_ACK) != 0) {
		const u_char *payload = (const u_char *) (packet + SIZE_ETHERNET + size_ip + size_tcp);
		size_payload = ntohs(ip->ip_len)- (size_ip + size_tcp);
		std::copy(payload, payload + size_payload, std::back_inserter(v));
		//std::reverse(v.begin(),v.end()); // byte order thing
		std::pair<u_int,chars> temp(ntohl(tcp->th_seq),v); // create record
		dict.insert(std::pair<u_int,record>(ntohl(tcp->th_ack),temp));
		//std::cout << "Packet# " << count << " " << ntohl(tcp->th_seq) << "\n";
		//std::cout << "Packet# " << count << " " << inet_ntoa(ip->ip_src) << "\n";
	}

	  if (((tcp->th_flags & TH_FIN) != 0) && ((tcp->th_flags & TH_ACK) != 0)) {
		std::set<u_int> temp = get_keys(dict);
		u_int last_key = ntohl(tcp->th_ack);
		std::cout << "*********************************************\n";
		std::set<u_int>::iterator it = temp.begin();
		for(;it != temp.end(); ++it)
			std::cout << "Key " << *it << " Count " << dict.count(*it) <<"\n";
		u_int image_key = get_max_key(dict,temp);
		std::cout << "Image key " << image_key << "\n";

		std::multimap<u_int,record>::iterator itt;
		std::cout << "*********************************************\n";
		for(itt=dict.begin(); itt!= dict.end(); ++itt) {
			if ((*itt).first == image_key) {
				std::pair<u_int,chars> temp_record = (*itt).second;
				temp_map.insert(std::pair<u_int,chars>(temp_record.first,temp_record.second));
			}
		}

		std::multimap<u_int,chars>::iterator ittt;
		for(ittt = temp_map.begin(); ittt!=temp_map.end(); ++ittt) {
			buffer.insert(buffer.end(), (*ittt).second.begin(), (*ittt).second.end());
		}

		std::ofstream myfile;
		myfile.open("image.jpg", std::ios::out | std::ios::binary);
		myfile.write(&buffer[0], buffer.size());
		std::cout << buffer.size() << "\n";
		std::cout << "For FIN packet " << "S: " << ntohl(tcp->th_seq) << " A: " << ntohl(tcp->th_ack) << "\n";
		dict.clear();
		conn.set("server_ip",inet_ntoa(ip->ip_src));
		//exit(0);
	}
return;
}
Ejemplo n.º 21
0
JNIEXPORT void JNICALL Java_jp_kanagawa_kawasaki_photokuri_PhotoKuri_clearGray(JNIEnv * env, jobject  obj, jobject bitmapcolor,jobject bitmapgray,jobject bitmapover,jobject bitmapunder,jobject bitmaplaplac,double sgm)
{
    AndroidBitmapInfo  infocolor;
    void*              pixelscolor;
    void*              save_pixelscolor;
    AndroidBitmapInfo  infogray;
    void*              pixelsgray;
    void*              save_pixelsgray;
    AndroidBitmapInfo  infoover;
    void*              pixelsover;
    void*              save_pixelsover;
    AndroidBitmapInfo  infounder;
    void*              pixelsunder;
    void*              save_pixelsunder;
    AndroidBitmapInfo  infolaplac;
    void*              pixelslaplac;
    void*              save_pixelslaplac;
    int                ret;

    if ((ret = AndroidBitmap_getInfo(env, bitmapcolor, &infocolor)) < 0) {
        return;
    }
    if ((ret = AndroidBitmap_getInfo(env, bitmapgray, &infogray)) < 0) {
        return;
    }
    if ((ret = AndroidBitmap_getInfo(env, bitmapover, &infoover)) < 0) {
        return;
    }
    if ((ret = AndroidBitmap_getInfo(env, bitmapunder, &infounder)) < 0) {
        return;
    }
    if ((ret = AndroidBitmap_getInfo(env, bitmaplaplac, &infolaplac)) < 0) {
        return;
    }
    if (infocolor.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
    	return;
    }
    if (infogray.format != ANDROID_BITMAP_FORMAT_A_8) {
        return;
    }
    if (infoover.format != ANDROID_BITMAP_FORMAT_A_8) {
        return;
    }
    if (infounder.format != ANDROID_BITMAP_FORMAT_A_8) {
        return;
    }
    if ((ret = AndroidBitmap_lockPixels(env, bitmapcolor, &pixelscolor)) < 0) {
    }
    if ((ret = AndroidBitmap_lockPixels(env, bitmapgray, &pixelsgray)) < 0) {
    }
    if ((ret = AndroidBitmap_lockPixels(env, bitmapover, &pixelsover)) < 0) {
    }
    if ((ret = AndroidBitmap_lockPixels(env, bitmapunder, &pixelsunder)) < 0) {
    }
    if ((ret = AndroidBitmap_lockPixels(env, bitmaplaplac, &pixelslaplac)) < 0) {
    }

    //Save
    save_pixelscolor=pixelscolor;
    save_pixelsgray=pixelsgray;
    save_pixelsover=pixelsover;
    save_pixelsunder=pixelsunder;
    save_pixelslaplac=pixelslaplac;

	//pixelscolor=save_pixelscolor;
	graydone(infocolor, pixelscolor, infogray, pixelsgray);
	pixelscolor=save_pixelscolor;
	graydone(infocolor, pixelscolor, infoover, pixelsover);
	pixelscolor=save_pixelscolor;
	graydone(infocolor, pixelscolor, infounder, pixelsunder);
    pixelscolor=save_pixelscolor;
    graydone(infocolor, pixelscolor, infolaplac, pixelslaplac);
    pixelscolor=save_pixelscolor;
    AndroidBitmap_unlockPixels(env, bitmapcolor);

    /*http://imagingsolution.blog107.fc2.com/blog-entry-165.html���sigma��0.8���̗p*/
	double sigma=sgm;
	DifferenceOfGaussianFunc *differenceOfGaussianFunc;
	differenceOfGaussianFunc = new DifferenceOfGaussianFunc(sigma,1);
	pixelsgray=save_pixelsgray;
	gaussian(differenceOfGaussianFunc,infogray,pixelsgray);
	/*Over*/
	sigma=sgm+0.2;
	DifferenceOfGaussianFunc *differenceOfGaussianFuncOver;
	differenceOfGaussianFuncOver = new DifferenceOfGaussianFunc(sigma,1);
	pixelsover=save_pixelsover;
	gaussian(differenceOfGaussianFuncOver,infoover,pixelsover);
	/*Under*/
	sigma=sgm-0.2;
	DifferenceOfGaussianFunc *differenceOfGaussianFuncUnder;
	differenceOfGaussianFuncUnder = new DifferenceOfGaussianFunc(sigma,1);
	pixelsunder=save_pixelsunder;
	gaussian(differenceOfGaussianFuncUnder,infounder,pixelsunder);
	/*Laplac*/
	sigma=sgm;
	DifferenceOfGaussianFunc *differenceOfGaussianFuncLaplac;
	differenceOfGaussianFuncLaplac = new DifferenceOfGaussianFunc(sigma,1);
	pixelslaplac=save_pixelslaplac;
	gaussian(differenceOfGaussianFuncLaplac,infolaplac,pixelslaplac);

    lenamap = (char *)malloc(infogray.height * infogray.width);
    memset(lenamap,'x',infogray.height * infogray.width);
    cntr.clear();
    pixelsgray=save_pixelsgray;

    for (int y=1;y<infogray.height-1;y++) {
        for (int x=1;x<infogray.width-1;x++) {
        	if(strncmp(lenamap+(infogray.width*y)+x, "o", 1) != 0){
        		strncpy(lenamap+(infogray.width*y)+x,"o",1);
        		find_maximal(x,y,pixelsgray,pixelsover,pixelsunder,infogray);
        	}
        }
        pixelsgray = (char *) pixelsgray + infogray.stride;
    }

	/* test */
    pixelsgray=save_pixelsgray;
    std::multimap<int,int>::iterator it = cntr.begin();
    for (int y=1;y<infogray.height-1;y++) {
    	uint8_t * grayline = (uint8_t *) pixelsgray;
    	/*for(int x=1;x<infogray.width-1;x++){
    		grayline[x]=255;
    	}*/
    	//g(differenceOfGaussianFuncUnder,infounder,pixelsunder,(*it).first,(*it).second);
	    	if(y==(*it).first){
		    	while(y==(*it).first){
		    		if(0==g(differenceOfGaussianFuncUnder,infounder,pixelsunder,(*it).first,(*it).second)){
		    			grayline[(*it).second]=255;
		    		}else{
		    			grayline[(*it).second]=0;
		    		}
		    		it++;
		    	}
			}else{
				++it;
			}


		pixelsgray = (char *) pixelsgray + infogray.stride;
    }
    make_orientation(infolaplac,pixelslaplac,cntr);

    AndroidBitmap_unlockPixels(env, bitmapgray);
    AndroidBitmap_unlockPixels(env, bitmapover);
    AndroidBitmap_unlockPixels(env, bitmapunder);
    //free(lenamap);������
}
Ejemplo n.º 22
0
bool gpl::xml::getXPathResultSet(std::multimap<std::string, std::string>& resultSet)
{
	resultSet.clear();
	//added by shandy 20041208
	if (m_xml->resource == NULL)
		return true;

	std::vector<std::string> strVector;
	std::string str, name;
	int i;
	xmlNodeSetPtr tmpPtr = 0;

	//cout<<"resource->type:"<<m_xml->resource->type<<endl;
	switch (m_xml->resource->type)
	{
	case XPATH_UNDEFINED://Object is uninitialized
		return false;
		break;
	case XPATH_NODESET://Object is a Node Set
		tmpPtr = m_xml->resource->nodesetval;
		if (tmpPtr == NULL)
			break;
		for (i = 0; i < tmpPtr->nodeNr; i++)
			m_xml->getDumpNode(tmpPtr->nodeTab[i], resultSet);
		break;
	case XPATH_XSLT_TREE://Object is an XSLT value tree
		return false;
		break;
	case XPATH_BOOLEAN://Object is a Boolean
		str = m_xml->getStringByXmlCharPtr(xmlXPathCastBooleanToString(m_xml->resource->boolval), 1);
		resultSet.insert(std::multimap<std::string, std::string>::value_type(std::string("boolean"), str));
		break;
	case XPATH_NUMBER://Object is a number
		str = m_xml->getStringByXmlCharPtr(xmlXPathCastNumberToString(m_xml->resource->floatval), 1);
		resultSet.insert(std::multimap<std::string, std::string>::value_type(std::string("number"), str));
		break;
	case XPATH_STRING://Object is a string
		if (m_xml->resource->stringval != NULL)
		{
			std::string str = m_xml->getStringByXmlCharPtr(m_xml->resource->stringval);
			resultSet.insert(std::multimap<std::string, std::string>::value_type(std::string("string"), str));
		}
		break;
	case XPATH_POINT://Object is a point
		//fprintf(output, " : index %d in node", m_xml->resource->index);
		m_xml->getDumpNode((xmlNodePtr)m_xml->resource->user, resultSet);
		break;
	case XPATH_RANGE:
		if ((m_xml->resource->user2 == NULL) ||
			((m_xml->resource->user2 == m_xml->resource->user) && (m_xml->resource->index == m_xml->resource->index2)))
		{
			//Object is a collapsed range 
			//if (m_xml->resource->index >= 0)
			//    fprintf(output, "index %d in ", m_xml->resource->index);
			//fprintf(output, "node\n");
			m_xml->getDumpNode((xmlNodePtr)m_xml->resource->user, resultSet);
		}
		else
		{
			//Object is a range from 
			//if (m_xml->resource->index >= 0)
			//    fprintf(output, "index %d in ", m_xml->resource->index);
			m_xml->getDumpNode((xmlNodePtr)m_xml->resource->user, resultSet);
			// to 
			//if (m_xml->resource->index2 >= 0)
			//    fprintf(output, "index %d in ", m_xml->resource->index2);
			m_xml->getDumpNode((xmlNodePtr)m_xml->resource->user2, resultSet);
		}
		break;
	case XPATH_LOCATIONSET://Object is a Location Set
		return false;
		break;
	case XPATH_USERS://Object is user defined
		return false;
		break;
	}
	return true;
}
Ejemplo n.º 23
0
int readFile(const string &filename,
                 std::vector<Interaction> &vecInteractions,
                 std::multimap<size_t, size_t> &mapUserID2Index,
                 std::multimap<size_t, size_t> &mapAdID2Index,
                 std::map<size_t, std::set<size_t> > &mapUserID2AdIDSet){
    //init
    vecInteractions.clear();
    mapUserID2Index.clear();
    mapAdID2Index.clear();

#ifdef DEBUG
    time_t t1, t2;
    t1 = time(NULL);
    std::cout<<"start loading file\n";
    std::cout.flush();
#endif

    //file descriptor
    int fd;
    //file info
    struct stat fileState;
    int status;
    size_t fileSize;

    //the memory-mapped thing itself
    void *mapped;

    //open file for reading
    try{
        fd = open(filename.c_str(), O_RDONLY);
        if(fd < 0){
            throw("failed to open file\n");
        }
    }catch(const char* msg){
        std::cout<<msg<<std::endl;
        std::cout.flush();
        return -1;
    }
    status = fstat(fd, & fileState);
    if(status){
        std::cout<<"failed to get file status\n";

    }
    fileSize = fileState.st_size;

    //memory-map the file
    try{
        //mapped = mmap(0, fileSize, PROT_READ, MAP_PRIVATE| MAP_POPULATE, fd, 0);
        mapped = mmap(0, fileSize, PROT_READ | MAP_POPULATE | MAP_HUGETLB, MAP_SHARED, fd, 0);
        if(mapped == MAP_FAILED){
            throw("failed to map file\n");
        }

    }catch(const char* msg){
        std::cout<<msg<<std::endl;
        std::cout.flush();
        return -1;
    }
    madvise(mapped, fileSize, MADV_SEQUENTIAL|MADV_WILLNEED);




#ifdef DEBUG
    std::cout<<"start conuting line\n";
#endif

    //count line num
    char *ptr = (char*)mapped;
    size_t nChrCnt = 0;
    size_t nLineNum = 0;

    for(; nChrCnt < fileSize; ++nChrCnt){
        if(*ptr == '\n'){
            ++nLineNum;
        }
        ++ptr;
    }

    nChrCnt = 0;
    ptr = static_cast<char*>(mapped);

    vecInteractions.resize(nLineNum);

#ifdef DEBUG
    t2 = time(NULL);
    std::cout << "line num " << nLineNum << " time used " << t2-t1 << "sec \n";
    std::cout.flush();
#endif




    //map userid to its adList
    std::map<size_t, std::set<size_t> >::iterator iter;

    size_t nLineCnt = 0;
    while(1){
        int nEndPos = 0;
        while((nChrCnt < fileSize) && (ptr[nEndPos] != '\n')){
            ++nEndPos;
            ++nChrCnt;
        }

//        Interaction interaction(ptr, ptr+nEndPos);
//        vecInteractions.push_back(interaction);
//        mapUserID2Index.insert(std::pair<size_t, size_t>(interaction.userID, nCnt));
//        mapAdID2Index.insert(std::pair<size_t, size_t>(interaction.adID, nCnt));

        vecInteractions[nLineCnt].init(ptr, ptr+nEndPos);
        mapUserID2Index.insert(std::pair<size_t, size_t>(vecInteractions[nLineCnt].userID, nLineCnt));
        mapAdID2Index.insert(std::pair<size_t, size_t>(vecInteractions[nLineCnt].adID, nLineCnt));
        iter = mapUserID2AdIDSet.find(vecInteractions[nLineCnt].userID);
        if(iter != mapUserID2AdIDSet.end()){
            (iter->second).insert(vecInteractions[nLineCnt].adID);
        }else{
            std::set<size_t> adIDset;
            adIDset.insert(vecInteractions[nLineCnt].adID);
            mapUserID2AdIDSet.insert(std::pair<size_t, std::set<size_t> >(vecInteractions[nLineCnt].userID, adIDset));
        }

#ifdef DEBUG
        if(nLineCnt%1000000 == 0){
            t2 = time(NULL);
            std::cout << (double)nLineCnt*100/nLineNum << "% loaded. used time " << t2-t1 << "sec \n";
            std::cout.flush();
        }
#endif

        ++nEndPos;
        ++nChrCnt;
        ++nLineCnt;

        if(nChrCnt >= fileSize){
            break;
        }
        ptr = ptr + nEndPos;
    }

    //close file and file mapping
    try{
        if(munmap(mapped, fileSize)){
            throw("failed to unmapping file\n");
        }
        if(close(fd)){
            throw("failed to close file\n");
        }
    }catch(const char *msg){
        std::cout<<msg<<std::endl;
        std::cout.flush();
        return -1;
    }

#ifdef DEBUG
    t2 = time(NULL);
    std::cout<<"loading compeleted, used "<< t2-t1 << "sec \n";
#endif

    return 0;

}
Ejemplo n.º 24
0
void LoadSettings()
{
	// The path to the configuration file.
	char szCurDir[MAX_PATH];
	GetCurrentDirectory(sizeof(szCurDir), szCurDir);
	string scPluginCfgFile = string(szCurDir) + "\\flhook_plugins\\event.cfg";

	INI_Reader ini;
	set_mapCargoMissions.clear();
	set_mapNpcMissions.clear();
	if (ini.open(scPluginCfgFile.c_str(), false))
	{
		while (ini.read_header())
		{	
			if (ini.is_header("General"))
			{
				while (ini.read_value())
				{
					if (ini.is_value("debug"))
					{ 
						set_iPluginDebug = ini.get_value_int(0);
					}
					else if (ini.is_value("cargo"))
					{
						CARGO_MISSION mis;
						mis.nickname = ini.get_value_string(0);
						mis.base = CreateID(ini.get_value_string(1));
						mis.item = CreateID(ini.get_value_string(2));
						mis.required_amount = ini.get_value_int(3);
						set_mapCargoMissions.insert(multimap<uint, CARGO_MISSION>::value_type(mis.base, mis));
					}
					else if (ini.is_value("npc"))
					{
						NPC_MISSION mis;
						mis.nickname = ini.get_value_string(0);
						mis.system = CreateID(ini.get_value_string(1));
						mis.sector = ini.get_value_string(2);
						pub::Reputation::GetReputationGroup(mis.reputation, ini.get_value_string(3));
						mis.required_amount = ini.get_value_int(4);
						set_mapNpcMissions.insert(multimap<uint, NPC_MISSION>::value_type(mis.reputation, mis));
					}
				}
			}
			ini.close();
		}

		if (set_iPluginDebug&1)
		{
			ConPrint(L"CargoMissionSettings loaded [%d]\n",set_mapCargoMissions.size());
			ConPrint(L"NpcMissionSettings loaded [%d]\n",set_mapNpcMissions.size());
		}
		ini.close();
	}
	
	// Read the last saved event status
	char szDataPath[MAX_PATH];
	GetUserDataPath(szDataPath);
	string scStatsPath = string(szDataPath) + "\\Accts\\MultiPlayer\\event_stats.txt";	
	if (ini.open(scStatsPath.c_str(), false))
	{
		while (ini.read_header())
		{	
			if (ini.is_header("Missions"))
			{
				while (ini.read_value())
				{
					if (ini.is_value("cargo"))
					{
						string nickname = ini.get_value_string(0);
						int curr_amount = ini.get_value_int(2);

						for (multimap<uint, CARGO_MISSION>::iterator i = set_mapCargoMissions.begin();
							i != set_mapCargoMissions.end(); ++i)
						{
							if (i->second.nickname == nickname)
							{
								i->second.curr_amount = curr_amount;
							}
						}
					}
					else if (ini.is_value("npc"))
					{
						NPC_MISSION mis;
						string nickname = ini.get_value_string(0);
						int curr_amount = ini.get_value_int(2);

						for (multimap<uint, NPC_MISSION>::iterator i = set_mapNpcMissions.begin();
							i != set_mapNpcMissions.end(); ++i)
						{
							if (i->second.nickname == nickname)
							{
								i->second.curr_amount = curr_amount;
							}
						}
					}
				}
			}
		}
		ini.close();
	}
}
Ejemplo n.º 25
0
int main(int argc, char **argv)
{
	long int i, N;
	bool already_invaded;
	short int L, j, k, l;
	double pc = 0.49;
	L = atoi(argv[1]);

	N = L*L;

	for(j=-L/2; j < L/2; j++)
	{
		for(k=-L/2+1; k < L/2+1; k++)
		{
			Site loc = std::make_pair(j, k);
			unitCell_Square cell;
			lattice.insert(std::make_pair(loc, cell));
		}
	}

	Site start = std::make_pair(0,0);
	lattice[start].is_invaded = true;
	add_new_Bonds(start);
	try
	{
		for (i=0; i<N;)
		{
    		std::multimap<double, Bond>::iterator weakest;
    		weakest = accessible_Bonds.begin();
    		already_invaded = invade_bond(weakest->second);
    		if(!already_invaded)
    		{
    			i++;
    		}
    		accessible_Bonds.erase(weakest);
		}
		std::multimap<double, Bond>::iterator weakest = accessible_Bonds.begin();
		cluster.push_back(weakest->second);
	}
	catch (std::exception& e) {}

	std::ofstream toFile1("fractures.txt", std::ios::trunc);
	std::ofstream toFile2("trapped.txt", std::ios::trunc);
	toFile1 << cluster.size() << "\n";
	toFile2 << trappedBonds.size() << "\n";
	toFile1 << "Invasion for: temp" << "\n";
	toFile2 << "Trapping for: temp" << "\n";
	toFile1.precision(17);
	toFile2.precision(17);

	Bond current_Line;
	while (!cluster.empty())
	{
		current_Line = cluster.front();
		cluster.pop_front();
		toFile1 << get_strength(current_Line) << "\t";
		toFile1 <<  current_Line.first.first << "\t";
		toFile1 <<  current_Line.first.second << "\t";
		Site other_end = get_end(current_Line);
		toFile1 <<  other_end.first << "\t";
		toFile1 <<  other_end.second << "\n";
	}


	while (!trappedBonds.empty())
	{
		current_Line = trappedBonds.front();
		trappedBonds.pop_front();
		toFile2 << get_strength(current_Line) << "\t";
		toFile2 <<  current_Line.first.first << "\t";
		toFile2 <<  current_Line.first.second << "\t";
		Site other_end = get_end(current_Line);
		toFile2 <<  other_end.first << "\t";
		toFile2 <<  other_end.second << "\n";
	}

	toFile1.close();
	toFile2.close();


	accessible_Bonds.clear();
	for(j=-L/2; j < L/2; j++)
	{
		for(k=-L/2+1; k < L/2+1; k++)
		{
			for(l=0; l<2; l++)
			{
				Site loc = std::make_pair(j, k);
				Bond bond = std::make_pair(loc, l);
				accessible_Bonds.insert(std::make_pair(lattice[loc].bonds[l], bond));
			}
		}
	}

	std::multimap<double, Bond>::iterator weakest = accessible_Bonds.begin();
	while(weakest->first < pc)
	{	
		lattice[weakest->second.first].is_open[weakest->second.second] = grow_clusters(weakest->second);
		accessible_Bonds.erase(weakest);
		weakest = accessible_Bonds.begin();
	}


	unitCell_Square * current_cell;
	for(j=-L/2; j < L/2; j++)
	{
		for(k=-L/2+1; k < L/2+1; k++)
		{
			current_cell = &lattice[std::make_pair(j,k)];
			current_cell->clusterN = find(current_cell->clusterN);
		}
	}
	long int bond_count = 0;
	for(lattice_iterator iter = lattice.begin(); iter != lattice.end(); iter++)
	{
		current_cell = &iter->second;
		if(current_cell->is_open[0])
		{
			bond_count++;
		}
		if(current_cell->is_open[1])
		{
			bond_count++;
		}
	}


	std::ofstream toFile3("clusters.txt", std::ios::trunc);
	toFile3 << bond_count << "\n";

	unitCell_Square Line;
	Site begin;
	Site other_end;
	std::map<unsigned int, unsigned int> cluster_sizes;
	while (!lattice.empty())
	{
		begin = lattice.begin()->first;
		Line = lattice.begin()->second;
		lattice.erase(begin);
		if(Line.is_open[0])
		{
			if(cluster_sizes.count(Line.clusterN) > 0)
			{
				cluster_sizes[Line.clusterN]++;
			}
			else
			{
				cluster_sizes.insert(std::make_pair(Line.clusterN,1));
			}
			toFile3 << Line.clusterN << "\t";
			toFile3 << begin.first << "\t";
			toFile3 << begin.second << "\t";
			other_end = get_end(std::make_pair(begin, 0));
			toFile3 <<  other_end.first << "\t";
			toFile3 <<  other_end.second << "\n";
		}
		if(Line.is_open[1])
		{
			if(cluster_sizes.count(Line.clusterN) > 0)
			{
				cluster_sizes[Line.clusterN]++;
			}
			else
			{
				cluster_sizes.insert(std::make_pair(Line.clusterN,1));
			}
			toFile3 << Line.clusterN << "\t";
			toFile3 << begin.first << "\t";
			toFile3 << begin.second << "\t";
			other_end = get_end(std::make_pair(begin, 1));
			toFile3 <<  other_end.first << "\t";
			toFile3 <<  other_end.second << "\n";
		}
	}

	toFile3.close();
	unsigned int largest_cluster = 0;
	unsigned int largest_cluster_size = 0;
	std::map<unsigned int, unsigned int>::iterator iter;
	for(iter = cluster_sizes.begin(); iter != cluster_sizes.end(); iter++)
	{
		if(iter->second > largest_cluster_size)
		{
			largest_cluster = iter->first;
			largest_cluster_size = iter->second;
		}
	}

	std::map<unsigned int, unsigned int> cluster_count;
	unsigned int size, begin2;
	while (!cluster_sizes.empty())
	{
		begin2 = cluster_sizes.begin()->first;
		size = cluster_sizes.begin()->second;
		cluster_sizes.erase(begin2);
		if(cluster_count.count(size) > 0)
			{
				cluster_count[size]++;
			}
			else
			{
				cluster_count.insert(std::make_pair(size, 1));
			}
	}

	std::ofstream toFile4("cluster_distribution.txt", std::ios::trunc);
	toFile4 << cluster_count.size() << "\t" << largest_cluster << "\t";
	toFile4 << cluster_map[largest_cluster].second.first << "\t" << cluster_map[largest_cluster].second.second << "\n";

	unsigned int count;
	while (!cluster_count.empty())
	{
		size = cluster_count.begin()->first;
		count = cluster_count.begin()->second;
		cluster_count.erase(size);
		toFile4 << size << "\t" << count << "\n";
	}

	toFile4.close();

    return 0;
}
Ejemplo n.º 26
0
	void Reset() {
		lock_guard guard(functions_lock);
		functions.clear();
		hashToFunction.clear();
	}