コード例 #1
0
        inline const message::factory *get_factory(message_type type) const
        {
            lock guard(m);

            auto it = factories.find(type);
            return (it == factories.end()) ? nullptr : it->value;
        }
コード例 #2
0
ファイル: dispatch.cpp プロジェクト: luispedro/hearts
Dispatch::Handler Dispatch::code2handler( Message::type_t type )
{
	typedef std::map<Message::type_t, Handler> map_type;
	static map_type handlers;
	if ( handlers.empty() ) {
		using namespace MessageTypes;
		handlers[ NameQuery ] = &Dispatch::namequery_handler;
		handlers[ NameReply ] = &Dispatch::namereply_handler;
		handlers[ Opponentname ] = &Dispatch::opponentname_handler;
		handlers[ Receive ] = &Dispatch::receive_handler;
		handlers[ Invalidmove ] = &Dispatch::invalidmove_handler;
		handlers[ Inform ] = &Dispatch::inform_handler;
		handlers[ Status ] = &Dispatch::status_handler;
		handlers[ Points ] = &Dispatch::points_handler;
		handlers[ PlayQuery ] = &Dispatch::playquery_handler;
		handlers[ PlayReply ] = &Dispatch::playreply_handler;
		handlers[ Give3Query ] = &Dispatch::give3query_handler;
		handlers[ Terminate ] = &Dispatch::terminate_handler;
		//	handlers[Reset] = &Dispatch::reset_handler;
		handlers[ Give3Reply ] = &Dispatch::give3reply_handler;
		handlers[ PlayReply ] = &Dispatch::playreply_handler;

	}
	map_type::iterator resp = handlers.find( type );
	if ( resp == handlers.end() ) {
		LOG_PLACE() << "No handler for " << type << ".\n";
		return &Dispatch::error_handler;
	}
	return resp->second;
}
コード例 #3
0
ファイル: test_map_with_vector.cpp プロジェクト: pspe/various
void probe (map_type& testMap, std::string name, auto keys, auto values, size_t toFind)
{
    // map_type
    const int width (15);
    const int precision (6);
    std::cout << std::setw (width) << keys.size () << " : " << std::setw (width) << name << " : " << std::flush;
    high_resolution_clock::time_point startTime = high_resolution_clock::now ();
    auto itValues = begin (values);
    for_each (begin (keys), end (keys), [&testMap, &itValues](size_t key)
              {
                  testMap.insert (std::make_pair (key, (*itValues++)));
              });

    high_resolution_clock::time_point findTime = high_resolution_clock::now ();
    size_t currFind = 0;
    for (auto k : keys)
    {
        if (currFind >= toFind)
            break;

        bool exists = testMap.find (k) != testMap.end ();
        if (exists)
            ++currFind;
    }
    high_resolution_clock::time_point endTime   = high_resolution_clock::now ();
    duration<double> time_span_insert = duration_cast<duration<double>> (findTime-startTime);
    duration<double> time_span_find = duration_cast<duration<double>> (endTime-findTime);
    std::cout << "time insert = " << std::fixed << std::setprecision (precision) << time_span_insert.count () << "  time find = " << std::setprecision (precision) << time_span_find.count () << std::setw (width) << "   found = " << std::setw (width) << currFind << std::endl;
}
コード例 #4
0
ファイル: WordAnal.cpp プロジェクト: tim124058/pthread
void *runner(void *f)
{
    string tmp = "", content = *(string *)f;            //將傳過來的指標轉成string

    for (int i = 0; i < content.length()+1; ++i) {
        if(content[i]=='\'' && tmp!="" &&((content[i+1]>='a' && content[i+1]<='z') || (content[i+1]>='A' && content[i+1]<='Z')) )   // 單引號的前後為英文單字的
        {
            tmp += content[i];
            continue;
        }

        if(content[i]>='a' && content[i] <='z') 
            tmp += content[i];
        else if(content[i] >='A' && content[i] <= 'Z')
            tmp += tolower(content[i]);
        else if(tmp != "")
        {
            pthread_mutex_lock(&mutex);         //鎖

            /* critical section */
            iter = m.find(tmp);                 //搜尋
            if(iter != m.end())
                iter->second++;                 //資料重複,所以將次數+1
            else
                m.insert(map_type::value_type(tmp,1));          //插入資料

            pthread_mutex_unlock(&mutex);       //解鎖
            tmp = "";
        }
    }

    pthread_exit(0);                            //結束thread
}
コード例 #5
0
inline std::error_category const & to_std_category( boost::system::error_category const & cat )
{
    if( cat == boost::system::system_category() )
    {
        static const std_category system_instance( &cat, 0x1F4D7 );
        return system_instance;
    }
    else if( cat == boost::system::generic_category() )
    {
        static const std_category generic_instance( &cat, 0x1F4D3 );
        return generic_instance;
    }
    else
    {
        typedef std::map< boost::system::error_category const *, std::unique_ptr<std_category>, cat_ptr_less > map_type;

        static map_type map_;
        static std::mutex map_mx_;

        std::lock_guard<std::mutex> guard( map_mx_ );

        map_type::iterator i = map_.find( &cat );

        if( i == map_.end() )
        {
            std::unique_ptr<std_category> p( new std_category( &cat, 0 ) );

            std::pair<map_type::iterator, bool> r = map_.insert( map_type::value_type( &cat, std::move( p ) ) );

            i = r.first;
        }

        return *i->second;
    }
}
コード例 #6
0
ファイル: inheritance.hpp プロジェクト: neomantra/luabind
inline class_id class_id_map::get(type_id const& type) const
{
    map_type::const_iterator i = m_classes.find(type);
    if (i == m_classes.end() || i->second >= local_id_base)
        return unknown_class;
    return i->second;
}
コード例 #7
0
ファイル: hktest_mex.cpp プロジェクト: kkloste/hkgrow
 /** Get an element and provide a default value when it doesn't exist
  * This command does not insert the element into the vector
  */
 double get(mwIndex index, double default_value=0.0) {
     map_type::iterator it = map.find(index);
     if (it == map.end()) {
         return default_value;
     } else {
         return it->second;
     }
 }
コード例 #8
0
ファイル: PyLibrary.cpp プロジェクト: BackupTheBerlios/slon
 static void del(map_type& cont, const key_type& key)
 {
     if ( cont.find(key) != cont.end() ) {
         cont.erase(key);
     }
     else {
         KeyError();
     }
 }
コード例 #9
0
inline void operation_sequence::remove_operation(int id)
{
    using namespace std;
    map_type::iterator it = operations_.find(id);
    if (it == operations_.end())
        throw runtime_error( string("No such operation: ") + 
                             lexical_cast<string>(id) );
    operations_.erase(it);
}
コード例 #10
0
                std::unique_ptr<osmium::io::detail::OutputFormat> create_output(const osmium::io::File& file, data_queue_type& output_queue) {
                    file.check();

                    auto it = m_callbacks.find(file.format());
                    if (it != m_callbacks.end()) {
                        return std::unique_ptr<osmium::io::detail::OutputFormat>((it->second)(file, output_queue));
                    }

                    throw std::runtime_error(std::string("Support for output format '") + as_string(file.format()) + "' not compiled into this binary.");
                }
コード例 #11
0
ファイル: input_format.hpp プロジェクト: Gozhack/osrm-backend
                std::unique_ptr<osmium::io::detail::InputFormat> create_input(const osmium::io::File& file, osmium::osm_entity_bits::type read_which_entities, osmium::thread::Queue<std::string>& input_queue) {
                    file.check();

                    auto it = m_callbacks.find(file.format());
                    if (it != m_callbacks.end()) {
                        return std::unique_ptr<osmium::io::detail::InputFormat>((it->second)(file, read_which_entities, input_queue));
                    }

                    throw std::runtime_error(std::string("Support for input format '") + as_string(file.format()) + "' not compiled into this binary.");
                }
コード例 #12
0
ファイル: procs.hpp プロジェクト: quartorz/quote
		void remove(hash_type hash, wchar_t c)
		{
			auto it = map.find(c);
			if(it == map.end())
				return;

			auto &container = it->second;
			auto iter = std::find_if(container.begin(), container.end(), [&hash](container_type::value_type &v){return std::get<0>(v) == hash;});
			if(iter != container.end())
				container.erase(iter);
		}
コード例 #13
0
static void find_unreachable_objects_impl(map_type const & m, map2_type & m2)
{
    // scan objects for shared_ptr members, compute internal counts

    {
        std::cout << "... " << m.size() << " objects in m.\n";

        for(map_type::const_iterator i = m.begin(); i != m.end(); ++i)
        {
            abt_boost::detail::sp_counted_base const * p = static_cast<abt_boost::detail::sp_counted_base const *>(i->first);

            BOOST_ASSERT(p->use_count() != 0); // there should be no inactive counts in the map

            m2[ i->first ];

            scan_and_count(i->second.first, i->second.second, m, m2);
        }

        std::cout << "... " << m2.size() << " objects in m2.\n";
    }

    // mark reachable objects

    {
        open_type open;

        for(map2_type::iterator i = m2.begin(); i != m2.end(); ++i)
        {
            abt_boost::detail::sp_counted_base const * p = static_cast<abt_boost::detail::sp_counted_base const *>(i->first);
            if(p->use_count() != i->second) open.push_back(p);
        }

        std::cout << "... " << open.size() << " objects in open.\n";

        for(open_type::iterator j = open.begin(); j != open.end(); ++j)
        {
            m2.erase(*j);
        }

        while(!open.empty())
        {
            void const * p = open.front();
            open.pop_front();

            map_type::const_iterator i = m.find(p);
            BOOST_ASSERT(i != m.end());

            scan_and_mark(i->second.first, i->second.second, m2, open);
        }
    }

    // m2 now contains the unreachable objects
}
コード例 #14
0
 inline OccupationInfo& find_or_insert(Point const& point, Point& mapped_point)
 {
     typename map_type::iterator it = map.find(point);
     if (it == boost::end(map))
     {
         std::pair<typename map_type::iterator, bool> pair 
                     = map.insert(std::make_pair(point, OccupationInfo()));
         it = pair.first;
     }
     mapped_point = it->first;
     return it->second;
 }
コード例 #15
0
ファイル: input_format.hpp プロジェクト: alex85k/osm2pgsql
 create_parser_type get_creator_function(const osmium::io::File& file) {
     auto it = m_callbacks.find(file.format());
     if (it == m_callbacks.end()) {
         throw unsupported_file_format_error(
                 std::string("Can not open file '") +
                 file.filename() +
                 "' with type '" +
                 as_string(file.format()) +
                 "'. No support for reading this format in this program.");
     }
     return it->second;
 }
コード例 #16
0
ファイル: procs.hpp プロジェクト: quartorz/quote
		void remove_handler_helper(hash_type hash, unsigned id, Integers... ids)
		{
			auto it = map.find(id);
			if(it == map.end())
				return;

			auto &container = it->second;
			auto iter = std::find_if(container.begin(), container.end(), [&hash](container_type::value_type &v){return std::get<0>(v) == hash;});
			if(iter != container.end())
				container.erase(iter);

			remove_handler_helper(hash, ids...);
		}
コード例 #17
0
ファイル: output_format.hpp プロジェクト: AFDudley/osm2pgsql
                std::unique_ptr<osmium::io::detail::OutputFormat> create_output(const osmium::io::File& file, future_string_queue_type& output_queue) {
                    auto it = m_callbacks.find(file.format());
                    if (it != m_callbacks.end()) {
                        return std::unique_ptr<osmium::io::detail::OutputFormat>((it->second)(file, output_queue));
                    }

                    throw unsupported_file_format_error(
                                std::string("Can not open file '") +
                                file.filename() +
                                "' with type '" +
                                as_string(file.format()) +
                                "'. No support for writing this format in this program.");
                }
コード例 #18
0
ファイル: chm2.cpp プロジェクト: ahiguti/pxc
int test1(const map_type& m, int cnt, int v) {
  int k = 0;
  for (int i = 0; i < cnt; ++i) {
    // int k = i % 100;
    // const int *p = m.find(k, k);
    const int *p = m.find(k);
    if (p != 0) {
      v += *p;
    }
    if (++k >= 100) k = 0;
  }
  return v;
}
コード例 #19
0
inline void dictionary::replace(std::string& key)
{
    using namespace std;
    string copy(key);
    tolower(copy);
    map_type::iterator it = map_.find(key);
    if (it == map_.end())
        return;
    string& value = it->second;
    if (!value.empty() && !key.empty() && std::isupper((unsigned char) key[0]))
        value[0] = std::toupper((unsigned char) value[0]);
    key = value;
    return;
}
コード例 #20
0
ファイル: procs.hpp プロジェクト: quartorz/quote
		bool WindowProc(Derived &, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT &lresult)
		{
			if(msg == WM_TIMER){
				auto it = map.find(static_cast<id_type>(wParam));
				if(it != map.end()){
					auto &container = it->second;
					for(auto &tuple: container){
						std::get<1>(tuple)(static_cast<id_type>(wParam));
					}
				}
				static_cast<Derived*>(this)->on_timer(static_cast<id_type>(wParam));
			}

			return true;
		}
コード例 #21
0
ファイル: wt.hpp プロジェクト: tb37/sdsl-lite
 static size_type alphabet_size_and_map(const reference_type rac, size_type n, map_type& map, inv_map_type& inv_map, value_type& first_symbol) {
     if (n > 0)
         first_symbol = rac[0];
     map.clear();
     inv_map.clear();
     size_type alphabet_size = 0;
     for (size_type i=0; i<n; ++i) {
         if (map.find(rac[i]) == map.end()) {
             map[rac[i]]    = 1;
         }
     }
     for (typename map_type::iterator it = map.begin(); it != map.end(); ++it) { // this preserves the order
         it->second = alphabet_size;
         inv_map[alphabet_size] = it->first;
         ++alphabet_size;
     }
     return alphabet_size;
 }
コード例 #22
0
ファイル: main.cpp プロジェクト: CCJY/coliru
bool check_win( const BOARD& board, pos_type last_move,
                const map_type& look_up, std::size_t N )
{
    const auto& v = board[last_move.first][last_move.second] ;
    const std::vector<pos_type>& seq = look_up.find(last_move)->second ;

    // size of row, col diuag == N, so check blocks of N-1 (other positions) at a time
    const std::size_t NLOOKUPS = N-1 ;
    for( auto iter = seq.begin() ; iter < seq.end() ; iter += NLOOKUPS )
    {
        std::size_t cnt = 0 ;
        for( auto subiter = iter ; subiter < iter + NLOOKUPS ; ++subiter )
            if( board[subiter->first][subiter->second] == v ) ++cnt ;
            else break ;
        if( cnt == NLOOKUPS ) return true ; // found row, col or diag with all N == v
    }

    return false ;
}
コード例 #23
0
ファイル: union_find.hpp プロジェクト: RobertLeahy/MST
			/**
			 *	Finds the parent of a vertex.
			 *
			 *	Collapses as it searches.
			 *
			 *	\param [in] a
			 *		The vertex whose parent shall
			 *		be found.
			 *
			 *	\return
			 *		The parent of \em a.  May be \em a
			 *		itself in which case \em a is the root
			 *		of its component.
			 */
			T Find (const T & a) {
			
				//	Find this vertex
				auto iter=map.find(a);
				//	If this vertex isn't in the map, or
				//	if this vertex has itself as its
				//	parent, it's the root of its component,
				//	so just return it
				if (
					(iter==map.end()) ||
					(iter->second==a)
				) return a;
				
				//	Find the deepest parent
				auto parent=Find(iter->second);
				
				//	Collapse
				iter->second=parent;
				
				return parent;
			
			}
コード例 #24
0
inline operation operation_sequence::new_operation(int id, int error_code)
{
    using namespace std;
    if ( error_code < 0 || 
         (error_code > BOOST_IOSTREAMS_TEST_MAX_OPERATION_ERROR &&
             error_code != INT_MAX) )
    {
        throw runtime_error( string("The error code ") + 
                             lexical_cast<string>(error_code) +
                             " is out of range" );
    }
    if (last_executed_ != INT_MIN)
        throw runtime_error( "Operations in progress; call reset() "
                             "before creating more operations" );
    map_type::const_iterator it = operations_.find(id);
    if (it != operations_.end())
        throw runtime_error( string("The operation ") + 
                             lexical_cast<string>(id) +
                             " already exists" );
    operation op(*this, id, error_code);
    operations_.insert(make_pair(id, ptr_type(op.pimpl_)));
    return op;
}
コード例 #25
0
 inline bool contains(Point const& point) const
 {
     typename map_type::const_iterator it = map.find(point);
     return it != boost::end(map);
 }
コード例 #26
0
ファイル: wt.hpp プロジェクト: tb37/sdsl-lite
 static bool symbol_available(const map_type& map, const value_type c, SDSL_UNUSED const value_type first_symbol,
                              SDSL_UNUSED const size_type) {
     return map.find(c)!=map.end();
 }
コード例 #27
0
ファイル: PartAssign.hpp プロジェクト: OKullmann/oklibrary
 bool in_domain(const var_type v) const {
     return pa.find(v) != pa.end();
 }
コード例 #28
0
ファイル: PartAssign.hpp プロジェクト: OKullmann/oklibrary
 bool val(const var_type v) const {
     const iterator p = pa.find(v);
     if (p == pa.end()) throw Error::not_in_domain();
     return p -> second;
 }