Esempio n. 1
0
File: lists.hpp Progetto: r-lyeh/eve
            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 );
                }
            }
Esempio n. 2
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);
 }
Esempio n. 3
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;
    }
Esempio n. 4
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;
    }
Esempio n. 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;
	}
Esempio n. 6
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;
    }
Esempio n. 7
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_;
    }
Esempio n. 8
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));
}
Esempio n. 9
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;
}
Esempio n. 10
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;
    }
Esempio n. 11
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();
        }
Esempio n. 12
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);
		}
Esempio n. 13
0
 ///parameters class-like element access
 _object const & operator[](std::string const & key) const {
  auto it = object_map.find(key);
  if ( it== object_map.end()) TRIQS_RUNTIME_ERROR<<"Key : "<< key<< " not found";
  return it->second;
 }
Esempio n. 14
0
 bool has_key(std::string const & key) const { return object_map.find(key) != object_map.end();}
Esempio n. 15
0
 //Deletes the entry of a key in the resource map.
 //This will call deleter_type to deallocate the resource from memory as well.
 void Free(key_type const &key) noexcept
 {
     map_i i = m_map.find(key);
     m_map.erase(i);
 }
Esempio n. 16
0
 // find
 typename map_t::const_iterator find(const KEY_T& key) const {
     class map_t::const_iterator itr = map->find(key);
     return itr;
 }