Пример #1
0
int map_unset(map_t map, void *key, void **olddata)
{
	bucket_t *b, *prev;
	int hash;

	if (!map || !key)
		return RETERROR(EINVAL, -1);

	hash = map->hashf(map->size, key);
	b = map->buckets[hash];
	prev = 0;
	while (b)
	{
		if (!map->compf(key, b->key))
		{
			if (prev)
				prev->next = b->next;
			else
				map->buckets[hash] = b->next;
			mem_init(olddata, b->data);
			map_bucket_free(map, b);
			return -- map->count;;
		}
		prev = b;
		b = b->next;
	}
	return RETERROR(ERANGE, -1);
}
Пример #2
0
            void go( bool construct )
            {
                typedef std::pair<std::string,int> key_t;
                typedef std::map<key_t, int> map_t;

                static map_t map;
                key_t id = key_t( file, line );
                map_t::iterator it = map.find( id );

                if( construct )
                {
                    compiled = ( it != map.end() );
                    if( !compiled )
                    {
                        static int list = 0;
                        list++;
                        map.insert( std::pair<key_t,int>( id, list) );
                        glNewList( list, GL_COMPILE );
                    }
                }
                else
                {
                    int list = it->second;
                    if( !compiled )
                    {
                        glEndList();
                        //std::cout << "compiled list #" << list << std::endl;
                    }
                    //std::cout << "calling list #" << list << std::endl;
                    glCallList( list );
                }
            }
Пример #3
0
 /** Mark an element as recently used. */
 void touch (const key_type& k)
 {
     auto found (map_.find(k));
     assert(found != map_.end());
     if (found != map_.end())
         list_.splice(list_.begin(), list_, found->second);
 }
Пример #4
0
    boost::optional<mapped_type&> try_get (const key_type& k) const
    {
        auto found (map_.find(k));
        if (found == map_.end())
            return boost::optional<mapped_type&>();

        return found->second->second;
    }
Пример #5
0
	void init()
	{
		map_t::iterator it = gMap.find(mKey);
		if (it == gMap.end()) {
			throw std::runtime_error("uninitialized mongo_stream sink");
		}
		mObject = it->second;
	}
Пример #6
0
		~constants()
		{
#ifndef NDEBUG
			for( map_t::const_iterator it = map.begin(); it != map.end(); ++it )
				if( !used[ it->first ].as<bool>() )
					fprintf( stdout, ( moon9::iostring() << "<moon9/play/constants.hpp> says: warning, unused constant '" << it->first << "'" << std::endl ).c_str() );
#endif
		}
Пример #7
0
    /** Get an element from the cache without changing its age. */
    mapped_type& get (const key_type& k) const
    {
        auto found (map_.find(k));
        if (found == map_.end())
            throw std::runtime_error("lru_cache::get: key not found");

        return found->second->second;
    }
Пример #8
0
		std::string debug( const moon9::iostring &head = moon9::iostring(), const moon9::iostring &format12 = "\t\1=\2\n", const moon9::iostring &footer = moon9::iostring() ) //const
		{
			moon9::iostring body;

			for( map_t::const_iterator it = map.begin(); it != map.end(); ++it )
				body << moon9::iostring( format12, it->first, it->second );

			return head + body + footer;
		}
Пример #9
0
    boost::optional<mapped_type&> try_get (const key_type& k)
    {
        auto found (map_.find(k));
        if (found == map_.end())
            return boost::optional<mapped_type&>();

        list_.splice(list_.begin(), list_, found->second);
        return found->second->second;
    }
Пример #10
0
    /** Remove an element from the cache. */
    void remove (const key_type& k)
    {
        auto found (map_.find(k));
        if (found == map_.end())
            return;

        list_.erase(found->second);
        map_.erase(found);
        --size_;
    }
Пример #11
0
void		ModuleNcurses::display(map_t const & map)
{
  uint		x;

  if (werase(this->win) == ERR)
    throw Exception(strerror(errno));
  for (uint y = 0; y != map.size() ; ++y)
    {
      for (x = 0; x != map.size() ; ++x)
	display_slot(x, y, map[y][x]);
    }
  if (wrefresh(this->win) == ERR)
    throw Exception(strerror(errno));
}
Пример #12
0
static void check_and_add_output_file(Module* NewMod, const std::string& str)
{
    typedef std::map<std::string, Module*> map_t;
    static map_t files;

    map_t::iterator i = files.find(str);
    if (i != files.end()) {
        Module* ThisMod = i->second;
        error(Loc(), "Output file '%s' for module '%s' collides with previous module '%s'. See the -oq option",
            str.c_str(), NewMod->toPrettyChars(), ThisMod->toPrettyChars());
        fatal();
    }
    files.insert(std::make_pair(str, NewMod));
}
Пример #13
0
		static std::uint32_t to(state_t &state, const map_t &map_val)
		{
			::lua_createtable(state, (int)map_val.size(), (int)map_val.size());

			std::for_each(map_val.cbegin(), map_val.cend(), 
				[&state](const typename map_t::value_type &val)
			{
				convertion_t<typename map_t::key_type>::to(state, val.first);
				convertion_t<typename map_t::mapped_type>::to(state, val.second);

				::lua_settable(state, -3);
			});

			return map_val.size() == 0 ? 0 : 1;
		}
Пример #14
0
    /** Fetch an element from the cache.
     *  If the key does not exist yet, a new empty element will be
     *  created. */
    mapped_type& operator[] (const key_type& k)
    {
        auto found (map_.find(k));
        if (found == map_.end())
        {
            list_.push_front(pair_t(k, mapped_type()));
            map_[k] = list_.begin();
            ++size_;

            return list_.begin()->second;
        }
        list_.splice(list_.begin(), list_, found->second);

        return found->second->second;
    }
Пример #15
0
const char* name_t::map_string(const char* str, std::size_t hash) {
    typedef std::unordered_map<std::size_t, const char*> map_t;
    typedef std::lock_guard<std::mutex> lock_t;

    static std::mutex sync_s;

    lock_t lock(sync_s);

    static adobe::unique_string_pool_t pool_s;
    static map_t map_s;
    map_t::const_iterator found(map_s.find(hash));

    return found == map_s.end() ? map_s.emplace(hash, pool_s.add(str)).first->second
                                : found->second;
}
Пример #16
0
 // has
 bool has(const KEY_T& key) const {
   if (find(key) != map->end()) {
     return true;
   } else {
     return false;
   }
 }
Пример #17
0
int map_set(map_t map, void *key, void *data, void **olddata)
{
	bucket_t *b;

	if (!map || !key)
		return RETERROR(EINVAL, -1);

	b = map_bucket_find(map, key);
	if (b)
	{
		mem_init(olddata, b->data);
		b->data = data;
	}
	else
	{
		int hash;

		if (!map_resize(map, map->count + 1, 0))
			return -1;

		if (!(b = map_bucket_alloc(map, key, data)))
			return -1;

		hash = map->hashf(map->size, key);
		b->next = map->buckets[hash];
		map->buckets[hash] = b;
		++ map->count;
	}

	return map->count;
}
Пример #18
0
void		ModuleOpenGL::display(map_t const & map)
{
    uint		x;
    uint		y = 0;

    glClear(GL_COLOR_BUFFER_BIT);
    glViewport(0, 0, this->width, this->height);
    xglBegin(GL_QUADS);
    glColor3ub(51, 51, 51);
    glVertex2d(-1,-1);
    glVertex2d(-1,1);
    glColor3ub(30, 30, 30);
    glVertex2d(1,1);
    glVertex2d(1,-1);
    xglEnd();
    for (std::vector<std::vector<slot_t> >::const_iterator it_y = map.begin(); it_y != map.end(); ++it_y)
    {
        x = 0;
        for (std::vector<slot_t>::const_iterator it_x = (*it_y).begin(); it_x != (*it_y).end(); ++it_x)
        {
            display_slot(x, y, (*it_x));
            ++x;
        }
        ++y;
    }
    xglFlush();
    SDL_GL_SwapBuffers();
}
Пример #19
0
    // change
    std::pair<class map_t::const_iterator, bool>
    change(const KEY_T& key, const PAY_T& pay) {
      if (file_mode == READ_ONLY) {
        throw std::runtime_error("Error: change called in RO mode");
      }

      // erase the old element
      size_t num_erased = erase(key);
      if (num_erased != 1) {
        // erase failed
        return std::pair<class map_t::const_iterator, bool>(map->end(), false);
      } else {
        // put in new
        return map->emplace(key, pay);
      }
    }
Пример #20
0
 template <typename... IndexType> void insert(IndexType const&... ind) {
  map_index_n.insert({{ind...}, size()});
  // reorder the indices which are always given in the order of the indices tuple
  map_t m;
  int i = 0;
  for (auto const& p : map_index_n) m.insert({p.first, i++});
  std::swap(m, map_index_n);
 }
Пример #21
0
    // insert
    std::pair<class map_t::const_iterator, bool>
    emplace(const KEY_T& key, const PAY_T& pay) {
      if (file_mode == READ_ONLY) {
        throw std::runtime_error("Error: emplace called in RO mode");
      }

      return map->emplace(key, pay);
    }
Пример #22
0
    // erase
    size_t erase(const KEY_T& key) {
      if (file_mode == READ_ONLY) {
        throw std::runtime_error("Error: erase called in RO mode");
      }

      size_t num_erased = map->erase(key);
      return num_erased;
    }
Пример #23
0
 /** Prune the cache back to a given size.
  *  If the cache is larger than the maximum, the oldest entries
  *  will be deleted.
  * @post size() <= max_size
  * @param max_size  The maximum cache size */
 void prune (size_t max_size)
 {
     while (size_ > max_size)
     {
         map_.erase(list_.back().first);
         list_.pop_back();
         --size_;
     }
 }
Пример #24
0
        //Returns a reference to the resource associated with the file name 'key' if it exists in memory.
        //Otherwise it loads the texture into memory, and returns a reference to the the resource.
        T &Load(key_type const &key) noexcept(false)
        {
            map_i i = m_map.find(key);
            if(i != m_map.end())
            {
                return *i->second.get(); //return resource if exists
            }

            //else, load resource
            ptr_t p {onLoadResource(key)};
            if(p.get() == NULL)
            {
                throw Exception(std::string("Error loading Image at ") + key);
            }

            m_map.insert(std::make_pair(key, std::move(p)));
            return *m_map[key].get();
        }
Пример #25
0
		void set_fields(doid_t do_id, const map_t &fields)
		{
			m_log->trace() << "Setting fields on obj-" << do_id << endl;

			YAML::Node document;
			if(!load(do_id, document))
			{
				return;
			}

			// Get the fields from the file that are not being updated
			const Class* dcc = g_dcf->get_class_by_name(document["class"].as<string>());
			ObjectData dbo(dcc->get_id());
			YAML::Node existing = document["fields"];
			for(auto it = existing.begin(); it != existing.end(); ++it)
			{
				const Field* field = dcc->get_field_by_name(it->first.as<string>());
				if(!field)
				{
					m_log->warning() << "Field '" << it->first.as<string>()
					                 << "', loaded from '" << filename(do_id)
					                 << "', does not exist." << endl;
					continue;
				}

				auto found = fields.find(field);
				if(found == fields.end())
				{
					vector<uint8_t> value = read_yaml_field(field, it->second, do_id);
					if(value.size() > 0)
					{
						dbo.fields[field] = value;
					}
				}
			}

			// Add in the fields that are being updated:
			for(auto it = fields.begin(); it != fields.end(); ++it)
			{
				dbo.fields[it->first] = it->second;
			}

			write_yaml_object(do_id, dcc, dbo);
		}
Пример #26
0
 void prune (size_t max_size, func on_remove)
 {
     while (size_ > max_size)
     {
         pair_t& tbr (list_.back());
         on_remove(tbr.first, tbr.second);
         map_.erase(tbr.first);
         list_.pop_back();
         --size_;
     }
 }
Пример #27
0
 void write()
 {
     static comma::csv::output_stream< interval_t< From, To > > ostream( std::cout, ocsv );
     static comma::csv::ascii< from_t< std::string > > from_ascii( ascii_csv );
     static comma::csv::ascii< to_t< std::string > > to_ascii( ascii_csv );
     for( typename map_t::iterator it = map.begin(); it != map.end(); ++it )
     {
         bound_t< bound_type > from = it->first.lower();
         bound_t< bound_type > to = it->first.upper();
         interval_t< From, To > interval;
         bool from_has_value = true;
         bool to_has_value = true;
         if( from.value ) { interval.from.value = *from.value; }
         else if( use_limits ) { interval.from.value = limits< From >::lowest(); }
         else if( empty ) { interval.from.value = static_cast< From >( *empty ); }
         else { from_has_value = false; }
         if( to.value ) { interval.to.value = *to.value; }
         else if( use_limits ) { interval.to.value = limits< To >::max(); }
         else if( empty ) { interval.to.value = static_cast< To >( *empty ); }
         else { to_has_value = false; }
         const set_t& s = it->second;
         if( csv.binary() )
         {
             if( intervals_only ) { ostream.write( interval ); ostream.flush(); continue; }
             for( typename set_t::const_iterator v = s.begin(); v != s.end(); ++v ) { ostream.write( interval, *v ); }
             ostream.flush();
         }
         else
         {
             for( typename set_t::const_iterator v = s.begin(); v != s.end(); ++v )
             {
                 std::string payload( intervals_only ? "" : *v );
                 ostream.ascii().ascii().put( interval, payload );
                 if( !from_has_value ) { from_ascii.put( from_t< std::string >(), payload ); }
                 if( !to_has_value ) { to_ascii.put( to_t< std::string >(), payload); }
                 std::cout << payload << std::endl;
                 if( intervals_only ) { break; }
             }
         }
     }
 }
Пример #28
0
void		ModuleSDL::display(map_t const & map)
{
  uint		x, y;
  int		r;

  y = 0;
  r = SDL_FillRect(this->s_ecran, NULL, SDL_MapRGB(this->s_ecran->format, 0, 0, 0));
  if (r == -1)
    throw Exception(SDL_GetError());
  for (std::vector<std::vector<slot_t> >::const_iterator it_y = map.begin(); it_y != map.end(); ++it_y)
    {
      x = 0;
      for (std::vector<slot_t>::const_iterator it_x = (*it_y).begin(); it_x != (*it_y).end(); ++it_x)
	{
	  display_slot(x, y, (*it_x));
	  ++x;
	}
      ++y;
    }
  r = SDL_Flip(this->s_ecran);
  if (r == -1)
    throw Exception(SDL_GetError());
}
Пример #29
0
    void prune_if (size_t max_size, pred op)
    {
        if (list_.empty())
            return;

        auto i (std::prev(list_.end()));
        while (size_ > max_size)
        {
            if (op(*i))
            {
                map_.erase(i->first);
                i = list_.erase(i);
                --size_;
            }
            if (i == list_.begin())
                return;

            --i;
        }
    }
Пример #30
0
inline void insertEmptyNodePtr(map_t& map, hash_t key) {
	map.put(key, unique_ptr<Node>(new Node{}));
}