コード例 #1
0
ファイル: two_sum_hash.cpp プロジェクト: wyqsnddd/courseWork
void readIntegerFile(std::string inputFile, std::multimap<sampleType, int> &mapSample ){
  std::ifstream integerReader;
  std::string line;
  integerReader.open(inputFile, std::ios::in);
  int lineCounter = 0;  
  int diff = 1;
  while(std::getline(integerReader, line)){
    // read in the integer 
    std::istringstream iss(line);
    sampleType intSample(0);
    iss>>intSample; 
    // add it to the hash table 
    // mapSample[key] = data;
    // mapSample[intSample] = lineCounter;
    mapSample.insert(std::pair<sampleType, int>(intSample, lineCounter));

    lineCounter++;

    if((lineCounter - mapSample.size()) == diff){
      std::cout<<"At line: "<<lineCounter<<" , key: "<<intSample<<" is not inserted. "<<"Map size is: "<< mapSample.size()<<std::endl;
      diff++;
    }

  }// end of while 
  std::cout<<"The hash table size is: "<<mapSample.size()<<std::endl;
  std::cout<<"line counter is: "<<lineCounter<<std::endl;
  std::cout<<std::endl;
  std::cout<<std::endl;
  std::cout<<std::endl;
  //  std::cout<<"If the above two are not equal, then it means there are : "<<lineCounter<<std::endl;
} // end of reader 
コード例 #2
0
ファイル: RxnRates.cpp プロジェクト: MrKingKong/cantera
Plog::Plog(const std::multimap<double, Arrhenius>& rates)
    : logP_(-1000)
    , logP1_(1000)
    , logP2_(-1000)
    , rDeltaP_(-1.0)
{
    size_t j = 0;
    rates_.reserve(rates.size());
    // Insert intermediate pressures
    for (const auto& rate : rates) {
        double logp = std::log(rate.first);
        if (pressures_.empty() || pressures_.rbegin()->first != logp) {
            // starting a new group
            pressures_[logp] = {j, j+1};
        } else {
            // another rate expression at the same pressure
            pressures_[logp].second = j+1;
        }

        j++;
        rates_.push_back(rate.second);
    }

    // Duplicate the first and last groups to handle P < P_0 and P > P_N
    pressures_.insert({-1000.0, pressures_.begin()->second});
    pressures_.insert({1000.0, pressures_.rbegin()->second});
}
コード例 #3
0
bool ltr_int_broadcast_pose(linuxtrack_full_pose_t &pose)
{
    pthread_mutex_lock(&send_mx);
    std::multimap<std::string, int>::iterator i;
    int res;
    bool checkSlaves = false;
    //Send updated pose to all clients
    //printf("Master: %g  %g  %g\n", pose.pose.raw_pitch, pose.pose.raw_yaw, pose.pose.raw_roll);
    for(i = slaves.begin(); i != slaves.end();) {
        res = ltr_int_send_data(i->second, &pose);
        if(res == -EPIPE) {
            ltr_int_log_message("Slave @socket %d left!\n", i->second);
            close(i->second);
            i->second = -1;
            slaves.erase(i++);
            checkSlaves = true;
        } else {
            ++i;
        }
    }
    if(checkSlaves && (slaves.size() == 0)) {
        no_slaves = true;
    }
    pthread_mutex_unlock(&send_mx);
    return true;
}
コード例 #4
0
 void mem_alloc_show_stats()
 {
     uint size = (uint)stats.size();
     auto strings = (StatsItem*)_alloca(size*sizeof(StatsItem));
     uint accumulator = 0, i = 0;
     for (auto& pair : stats)
     {
         strings[i] = pair.second;
         i++;
         accumulator += pair.second.Calls;
     }
     struct predicate
     {
         static inline bool compare(const StatsItem& a, const StatsItem& b)
         {
             return a.Calls < b.Calls;
         }
     };
     std::sort(strings, strings+size, predicate::compare);
     for (i = 0; i < size; i++)
     {
         auto& item = strings[i];
         Msg("%d(%d)-----------------%d[%d]:%5.2f%%------------------", 
             i, size, item.Calls, accumulator, (item.Calls * 100) / float(accumulator));
         Log(item.StackTrace);
     }
 }
コード例 #5
0
std::vector<CIMSettings> InterwovenServers::GetDuplicateEntries(const std::map<CStdString, CIMSettings>& uniqueIntewovenServers, const std::multimap<CStdString, CIMSettings>& duplicateIntewovenServers)
{
	LOG_WS_FUNCTION_SCOPE();
	
	std::vector<CIMSettings> duplications;
	
	if(uniqueIntewovenServers.size() == duplicateIntewovenServers.size())
	{
		return duplications;
	}

	for(std::map<CStdString, CIMSettings>::const_iterator it = uniqueIntewovenServers.begin(); it != uniqueIntewovenServers.end(); ++it)
	{
		CStdString key = it->first;		
		
		if(duplicateIntewovenServers.count(key) == 1)
		{
			continue;
		}

		pair<multimap<CStdString, CIMSettings>::const_iterator, multimap<CStdString, CIMSettings>::const_iterator> equalRange = duplicateIntewovenServers.equal_range(key);
		for(multimap<CStdString, CIMSettings>::const_iterator it = equalRange.first; it != equalRange.second; ++it)
		{
			CIMSettings wsServer = it->second;
			wsServer.SetActionType(CIMSettings::REGISTRATION_ACTION_REMOVE);
			duplications.push_back(wsServer);		
		}
	}
	
	return duplications;
}
コード例 #6
0
inline void test_multimap_insert(std::multimap<int, int> c)
{
    using phx::arg_names::arg1;
    using phx::arg_names::arg2;
    using phx::arg_names::arg3;

    typedef std::multimap<int, int> Multimap;

    Multimap::value_type const value = *c.begin();
    Multimap::iterator c_begin = c.begin();
    // wrapper for
    // iterator insert(iterator where, const value_type& val);
    Multimap::iterator it =
        phx::insert(arg1, arg2, arg3)(c, c_begin, value);

    if (test(it != c.begin() || *it != *(++it))) {
        cerr << "Failed " << typeid(Multimap).name()
             << " test_multimap_insert 1\n";
        return;
    }

    // wrapper for
    // iterator insert(const value_type& val);
    Multimap::value_type const value2(1400, 2200);
    it = phx::insert(arg1, arg2)(c, value2);
    if (test(it == c.end())) {
        cerr << "Failed " << typeid(Multimap).name()
             << " test_multimap_insert 2\n";
        return;
    }

    // wrapper for
    // template<class InIt>
    // void insert(InIt first, InIt last);
    Multimap const const_c = build_multimap();
    Multimap::size_type size = c.size();
    phx::insert(arg1, const_c.begin(), const_c.end())(c);
    if (test(c.size() != size + const_c.size())) {
        cerr << "Failed " << typeid(Multimap).name()
             << " test_multimap_insert 3\n";
        return;
    }
}
コード例 #7
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();
}
コード例 #8
0
ファイル: map.hpp プロジェクト: RedSunCMX/izenelib
inline void operator<< (object::with_zone& o, const std::multimap<K,V>& v)
{
	o.type = type::MAP;
	if(v.empty()) {
		o.via.map.ptr  = NULL;
		o.via.map.size = 0;
	} else {
		object_kv* p = (object_kv*)o.zone->malloc(sizeof(object_kv)*v.size());
		object_kv* const pend = p + v.size();
		o.via.map.ptr  = p;
		o.via.map.size = v.size();
		typename std::multimap<K,V>::const_iterator it(v.begin());
		do {
			p->key = object(it->first, o.zone);
			p->val = object(it->second, o.zone);
			++p;
			++it;
		} while(p < pend);
	}
}
コード例 #9
0
ファイル: BroadPhase.cpp プロジェクト: linuxbandit/BroadPhase
bool findFab(std::multimap<int,int> pai, pair<int,int> couple)
{
    std::multimap<int,int>::iterator it = pai.end();

    if(pai.size() == 0) return false;

    for ( it = pai.equal_range(couple.first).first; it != pai.equal_range(couple.first).second; ++it)
      if( equals(couple, (*it)) )
          return true;

    return false;
}
コード例 #10
0
ファイル: settings.cpp プロジェクト: IcooN/OpenEmu
// TODO after a game is loaded, but should we?
void MDFN_CallSettingsNotification(void)
{
 for(unsigned int x = 0; x < CurrentSettings.size(); x++)
 {
  if(CurrentSettings[x].ChangeNotification)
  {
   // TODO, always call driver notification function, regardless of whether a game is loaded.
   if(MDFNGameInfo)
    CurrentSettings[x].ChangeNotification(CurrentSettings[x].name);
  }
 }
}
コード例 #11
0
ファイル: main.cpp プロジェクト: kirill-terekhov/SweepLine
void intersect(int a, int b, const Point & I, std::vector<Segment> & segments, std::multimap<Point, int> & sweep, std::multimap<std::pair<double,int>, int,event_less> & events, bool print)
{
	//remove event of ending of old segment
	{
		int rem_end_events[2];
		rem_end_events[0] = a;
		rem_end_events[1] = b;
		for (int k = 0; k < 2; ++k)
		{
			std::pair< std::multimap<std::pair<double,int>, int,event_less>::iterator, std::multimap<std::pair<double,int>,int,event_less>::iterator > del = events.equal_range(std::make_pair(segments[rem_end_events[k]].end.x,SEG_END)); //get all events at position of the end
			bool flag = false;
			for (std::multimap<std::pair<double,int>, int,event_less>::iterator it = del.first; it != del.second; ++it) //search over all events
			{
				if (it->first.second == SEG_END && it->second == rem_end_events[k]) //event is end of segment and segment matches current
				{
					events.erase(it); //remove that segment
					flag = true;
					break; //do not expect any more
				}
			}
			if (!flag) std::cout << "Cannot find proper ending event for segment" << std::endl;
		}
	}
	//add new segment with intersection point up to end
	segments.push_back(Segment(I, segments[a].end));
	//add event of starting of new segment
	events.insert(std::make_pair(std::make_pair(I.x,SEG_START), (int)segments.size() - 1));
	//add event of ending of new segment
	events.insert(std::make_pair(std::make_pair(segments.back().end.x,SEG_END),(int)segments.size() - 1));
	//change ending point for current segment
	segments[a].end = I;
	//add event of ending of old segment
	events.insert(std::make_pair(std::make_pair(I.x,SEG_END), a));
	//add new segment with intersection point up to end
	segments.push_back(Segment(I, segments[b].end));
	//add event of starting of new segment
	events.insert(std::make_pair(std::make_pair(I.x,SEG_START), (int)segments.size() - 1));
	//add event of ending of new segment
	events.insert(std::make_pair(std::make_pair(segments.back().end.x,SEG_END), (int)segments.size() - 1));
	//change ending point for current segment
	segments[b].end = I;
	//add event of ending of old segment
	events.insert(std::make_pair(std::make_pair(I.x,SEG_END), b));
	if (print)
	{
		std::cout << "Number of events: " << events.size() << std::endl;
		for (std::multimap<std::pair<double, int>, int,event_less>::iterator it = events.begin(); it != events.end(); ++it)
			std::cout << "x: " << it->first.first << " type " << (it->first.second == SEG_START ? "start" : "end") << " segment " << it->second << std::endl;
	}
}
コード例 #12
0
ファイル: TimedEvent.cpp プロジェクト: Tomcc/dojo
	void EventManager::runTimedEvents(TimePoint now) {
		//run all the events ready to run
		for (auto&& event : mEvents) {
			if (event->isReady(now)) {
				event->run();
			}
		}

		if (mSimpleTasks.size()) {
			auto top = mSimpleTasks.begin();
			if (now >= top->first) {
				top->second();
				mSimpleTasks.erase(top);
			}
		}
	}
コード例 #13
0
ファイル: SOFANcFile.cpp プロジェクト: sofacoustics/API_Cpp
void NetCDFFile::GetAllDimensionsNames(std::vector< std::string > &dimensionNames) const
{
    const std::multimap< std::string, netCDF::NcDim > dims = file.getDims();
    
    const std::size_t size = dims.size();
    
    dimensionNames.resize( size );
    
    std::size_t i = 0;
    for( std::multimap< std::string, netCDF::NcDim >::const_iterator it = dims.begin();
        it != dims.end();
        ++it )
    {
        dimensionNames[i] = (*it).first;
        i++;
    }
}
コード例 #14
0
ファイル: SOFANcFile.cpp プロジェクト: sofacoustics/API_Cpp
void NetCDFFile::GetAllVariablesNames(std::vector< std::string > &variableNames) const
{
    const std::multimap< std::string, netCDF::NcVar > vars = file.getVars();
    
    const std::size_t size = vars.size();
    
    variableNames.resize( size );
    
    std::size_t i = 0;
    for( std::multimap< std::string, netCDF::NcVar >::const_iterator it = vars.begin();
        it != vars.end();
        ++it )
    {
        variableNames[i]       = (*it).first;
        i++;
    }
}
コード例 #15
0
ファイル: SOFANcFile.cpp プロジェクト: sofacoustics/API_Cpp
void NetCDFFile::GetAllAttributesNames(std::vector< std::string > &attributeNames) const
{        
    const std::multimap< std::string, netCDF::NcGroupAtt > attributes = file.getAtts();
    
    const std::size_t size = attributes.size();
    
    attributeNames.resize( size );
    
    std::size_t i = 0;
    for( std::multimap< std::string, netCDF::NcGroupAtt >::const_iterator it = attributes.begin();
        it != attributes.end();
        ++it )
    {
        const std::string attributeName = (*it).first;
        
        attributeNames[ i ] = attributeName;
        i++;
    }
}
コード例 #16
0
ファイル: pretty_print.hpp プロジェクト: orthez/arc_utilities
 inline std::string PrettyPrint(const std::multimap<A, B, Compare, Allocator>& maptoprint, const bool add_delimiters=false, const std::string& separator=", ")
 {
     std::ostringstream strm;
     if (maptoprint.size() > 0)
     {
         if (add_delimiters)
         {
             strm << "{";
             typename std::multimap<A, B, Compare, Allocator>::const_iterator itr;
             for (itr = maptoprint.begin(); itr != maptoprint.end(); ++itr)
             {
                 std::pair<A, B> cur_pair(itr->first, itr->second);
                 if (itr != maptoprint.begin())
                 {
                     strm << separator << PrettyPrint(cur_pair, add_delimiters, separator);
                 }
                 else
                 {
                     strm << PrettyPrint(cur_pair, add_delimiters, separator);
                 }
             }
             strm << "}";
         }
         else
         {
             typename std::multimap<A, B, Compare, Allocator>::const_iterator itr;
             for (itr = maptoprint.begin(); itr != maptoprint.end(); ++itr)
             {
                 std::pair<A, B> cur_pair(itr->first, itr->second);
                 if (itr != maptoprint.begin())
                 {
                     strm << separator << PrettyPrint(cur_pair, add_delimiters, separator);
                 }
                 else
                 {
                     strm << PrettyPrint(cur_pair, add_delimiters, separator);
                 }
             }
         }
     }
     return strm.str();
 }
コード例 #17
0
std::multimap<float, std::vector<int> > HuffmanCoder::Pack(std::multimap<float, std::vector<int> >& map) {
    std::multimap<float, std::vector<int> > newMap;

    std::multimap<float, std::vector<int> >::iterator it = map.begin();
    for (unsigned int i = 0; i < map.size()/2; i++) {
        std::vector<int> newSymbolVector;
        float sumOfWeights = 0;

        for (int j = 0; j < 2; j++) {
            for (std::vector<int>::const_iterator itt = it->second.begin(); itt != it->second.end(); itt++) {
                newSymbolVector.push_back(*itt);
            }
            sumOfWeights += it->first;
            ++it;
        }

        newMap.insert(std::pair<float,std::vector<int> >(sumOfWeights, newSymbolVector));
    }
    return newMap;
}
コード例 #18
0
int main(int, char**)
{
    {
        typedef std::pair<const int, double> V;
        V ar[] =
        {
            V(1, 1),
            V(1, 1.5),
            V(1, 2),
            V(2, 1),
            V(2, 1.5),
            V(2, 2),
            V(3, 1),
            V(3, 1.5),
            V(3, 2),
            V(4, 1),
            V(4, 1.5),
            V(4, 2),
            V(5, 1),
            V(5, 1.5),
            V(5, 2),
            V(6, 1),
            V(6, 1.5),
            V(6, 2),
            V(7, 1),
            V(7, 1.5),
            V(7, 2),
            V(8, 1),
            V(8, 1.5),
            V(8, 2)
        };
        std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
        assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
        assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
        std::multimap<int, double>::iterator i;
        i = m.begin();
        std::multimap<int, double>::const_iterator k = i;
        assert(i == k);
        for (int j = 1; j <= 8; ++j)
            for (double d = 1; d <= 2; d += .5, ++i)
            {
                assert(i->first == j);
                assert(i->second == d);
                i->second = 2.5;
                assert(i->second == 2.5);
            }
    }
    {
        typedef std::pair<const int, double> V;
        V ar[] =
        {
            V(1, 1),
            V(1, 1.5),
            V(1, 2),
            V(2, 1),
            V(2, 1.5),
            V(2, 2),
            V(3, 1),
            V(3, 1.5),
            V(3, 2),
            V(4, 1),
            V(4, 1.5),
            V(4, 2),
            V(5, 1),
            V(5, 1.5),
            V(5, 2),
            V(6, 1),
            V(6, 1.5),
            V(6, 2),
            V(7, 1),
            V(7, 1.5),
            V(7, 2),
            V(8, 1),
            V(8, 1.5),
            V(8, 2)
        };
        const std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
        assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
        assert(static_cast<std::size_t>(std::distance(m.cbegin(), m.cend())) == m.size());
        assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
        assert(static_cast<std::size_t>(std::distance(m.crbegin(), m.crend())) == m.size());
        std::multimap<int, double>::const_iterator i;
        i = m.begin();
        for (int j = 1; j <= 8; ++j)
            for (double d = 1; d <= 2; d += .5, ++i)
            {
                assert(i->first == j);
                assert(i->second == d);
            }
    }
#if TEST_STD_VER >= 11
    {
        typedef std::pair<const int, double> V;
        V ar[] =
        {
            V(1, 1),
            V(1, 1.5),
            V(1, 2),
            V(2, 1),
            V(2, 1.5),
            V(2, 2),
            V(3, 1),
            V(3, 1.5),
            V(3, 2),
            V(4, 1),
            V(4, 1.5),
            V(4, 2),
            V(5, 1),
            V(5, 1.5),
            V(5, 2),
            V(6, 1),
            V(6, 1.5),
            V(6, 2),
            V(7, 1),
            V(7, 1.5),
            V(7, 2),
            V(8, 1),
            V(8, 1.5),
            V(8, 2)
        };
        std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
        assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
        assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
        std::multimap<int, double, std::less<int>, min_allocator<V>>::iterator i;
        i = m.begin();
        std::multimap<int, double, std::less<int>, min_allocator<V>>::const_iterator k = i;
        assert(i == k);
        for (int j = 1; j <= 8; ++j)
            for (double d = 1; d <= 2; d += .5, ++i)
            {
                assert(i->first == j);
                assert(i->second == d);
                i->second = 2.5;
                assert(i->second == 2.5);
            }
    }
    {
        typedef std::pair<const int, double> V;
        V ar[] =
        {
            V(1, 1),
            V(1, 1.5),
            V(1, 2),
            V(2, 1),
            V(2, 1.5),
            V(2, 2),
            V(3, 1),
            V(3, 1.5),
            V(3, 2),
            V(4, 1),
            V(4, 1.5),
            V(4, 2),
            V(5, 1),
            V(5, 1.5),
            V(5, 2),
            V(6, 1),
            V(6, 1.5),
            V(6, 2),
            V(7, 1),
            V(7, 1.5),
            V(7, 2),
            V(8, 1),
            V(8, 1.5),
            V(8, 2)
        };
        const std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
        assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
        assert(static_cast<std::size_t>(std::distance(m.cbegin(), m.cend())) == m.size());
        assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
        assert(static_cast<std::size_t>(std::distance(m.crbegin(), m.crend())) == m.size());
        std::multimap<int, double, std::less<int>, min_allocator<V>>::const_iterator i;
        i = m.begin();
        for (int j = 1; j <= 8; ++j)
            for (double d = 1; d <= 2; d += .5, ++i)
            {
                assert(i->first == j);
                assert(i->second == d);
            }
    }
#endif
#if TEST_STD_VER > 11
    { // N3644 testing
        typedef std::multimap<int, double> C;
        C::iterator ii1{}, ii2{};
        C::iterator ii4 = ii1;
        C::const_iterator cii{};
        assert ( ii1 == ii2 );
        assert ( ii1 == ii4 );

        assert (!(ii1 != ii2 ));

        assert ( (ii1 == cii ));
        assert ( (cii == ii1 ));
        assert (!(ii1 != cii ));
        assert (!(cii != ii1 ));
    }
#endif

  return 0;
}
コード例 #19
0
ファイル: main.cpp プロジェクト: Arnaud474/Warmux
int main(int argc, char* argv[])
{
  parseArgs(argc, argv);

  config.Load(config_file);

  DPRINT(INFO, "Warmux index server version %i", VERSION);
  DPRINT(INFO, "%s", wx_clock.DateStr());

  Env::SetConfigClass(config);
  Env::SetWorkingDir();

  bool local, r;
  r = config.Get("local", local);
  if (!r)
    PRINT_FATAL_ERROR;

  if (!local)
    DownloadServerList();

  Env::SetChroot();

  Env::MaskSigPipe();

  // Set the maximum number of connection
  Env::SetMaxConnection();
  Env::SetupAutoReloadConf();

  stats.Init();

  int port = 0;
  config.Get("port", port);
  Server listen_sock(port);

  // Set of socket where an activity have been detected
  fd_set acting_sock_set;

  if (!local)
    sync_slave.Start();

  while(1)
    {
      wx_clock.HandleJobs(local);
      sync_slave.CheckGames();

      struct timeval timeout;
      memset(&timeout, 0, sizeof(timeout));
      timeout.tv_sec = 1;
      timeout.tv_usec = 0;

      acting_sock_set = listen_sock.GetSockSet();
      // Lock the process until activity is detected
      if ( select(FD_SETSIZE, &acting_sock_set, NULL, NULL, &timeout) < 1 )
        {
          // Timeout to check for other games on other servers
          if(timeout.tv_sec != 0 && timeout.tv_usec != 0)
            PRINT_FATAL_ERROR;
        }

      // Find the socket where activity have been detected:
      // First check for already established connections
      for(std::multimap<std::string,Client*>::iterator client = clients.begin();
          client != clients.end();
          ++client)
        {
          client->second->CheckState();

          if( ! client->second->connected )
            {
              // Connection closed
              DPRINT(CONN, "Closind FD %u from client %p\n", client->second->GetFD(), client->second);
              listen_sock.CloseConnection( client->second->GetFD() );
              delete client->second;
              clients.erase(client);
              DPRINT(CONN, "%i connections up!", (int)clients.size());
              break;
            }
          if( FD_ISSET( client->second->GetFD(), &acting_sock_set) )
            {
              if( ! client->second->Receive() ) {
                DPRINT(CONN, "Nothing received from client %p, disconnecting!", client->second);
                client->second->connected = false;
              }
              // Exit as the clients list may have changed
              break;
            }
        }

      // Then check if there is any new incoming connection
      if( FD_ISSET(listen_sock.GetFD(), &acting_sock_set) )
        {
          Client* client = listen_sock.NewConnection();
          if(client != NULL)
            clients.insert(std::make_pair("unknown", client ));
          DPRINT(CONN, "%i connections up!", (int)clients.size());

          // Exit as the 'clients' list may have changed
        }
    }
}
コード例 #20
0
ファイル: Main.cpp プロジェクト: HeIIoween/FLHook
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();
	}
}
コード例 #21
0
ファイル: binarystream.hpp プロジェクト: AstroGPU/swarm
		inline BOSTREAM2(const std::multimap<K, V, C, A> &a) { return itwrite(out, a.size(), a.begin()); }
コード例 #22
0
void WhisperPeers::resizeMap(std::multimap<time_t, QString>& _map)
{
	while (_map.size() > 5000)
		_map.erase(_map.begin());
}
コード例 #23
0
    /**  advance in play loop by rtick_inc ticks, possibly generate some
     * csoundScoreEvent calls.
     */
    void step(MYFLT rtick_inc, MYFLT secs_per_tick , CSOUND * csound)
    {
        if (!playing) return;
        rtick += rtick_inc;
        int tick = (int)rtick % tickMax;
        if (tick == tick_prev) return;

        int events = 0;
        int loop0 = 0;
        int loop1 = 0;
        if (!ev.empty()) 
        {
            if (steps && (tick < tick_prev)) // should be true only after the loop wraps (not after insert)
            {
                while (ev_pos != ev.end())
                {
                    if (_debug && (VERBOSE > 3)) ev_pos->second->ev_print(_debug);
                    if (events < STEP_eventMax) ev_pos->second->event(csound, secs_per_tick);
                    ++ev_pos;
                    ++events;
                    ++loop0;
                }
                ev_pos = ev.begin();
            }
            while ((ev_pos != ev.end()) && (tick >= ev_pos->first))
            {
                if (_debug && (VERBOSE > 3)) ev_pos->second->ev_print(_debug);
                if (events < STEP_eventMax) ev_pos->second->event(csound, secs_per_tick);
                ++ev_pos;
                ++events;
                ++loop1;
            }
        }
        tick_prev = tick;
        if (_debug && (VERBOSE>1) && (events >= STEP_eventMax)) fprintf(_debug, "WARNING: %i/%i events at once (%i, %i)\n", events, (int)ev.size(),loop0,loop1);
        ++steps;
    }