19 #ifndef GNASH_MOVIELIBRARY_H
20 #define GNASH_MOVIELIBRARY_H
25 #include <boost/intrusive_ptr.hpp>
29 #include <boost/thread/thread.hpp>
44 boost::intrusive_ptr<movie_definition>
def;
61 void setLimit(LibraryContainer::size_type limit)
67 bool get(
const std::string& key,
68 boost::intrusive_ptr<movie_definition>* ret)
70 boost::mutex::scoped_lock lock(_mapMutex);
71 LibraryContainer::iterator it = _map.find(key);
72 if (it == _map.end())
return false;
74 *ret = it->second.def;
75 it->second.hitCount++;
84 if (_limit) limitSize(_limit - 1);
91 boost::mutex::scoped_lock lock(_mapMutex);
98 boost::mutex::scoped_lock lock(_mapMutex);
104 static bool findWorstHitCount(
const LibraryContainer::value_type&
a,
105 const LibraryContainer::value_type&
b)
107 return (a.second.hitCount < b.second.hitCount);
110 LibraryContainer _map;
113 void limitSize(LibraryContainer::size_type max) {
120 while (_map.size() > max) {
121 boost::mutex::scoped_lock lock(_mapMutex);
122 _map.erase(std::min_element(_map.begin(), _map.end(),
123 &findWorstHitCount));
128 mutable boost::mutex _mapMutex;
Definition: GnashKey.h:147
Client program's interface to the definition of a movie or sprite.
Definition: movie_definition.h:95
void setLimit(LibraryContainer::size_type limit)
Definition: MovieLibrary.h:61
Library of SWF movies indexed by URL strings.
Definition: MovieLibrary.h:38
unsigned hitCount
Definition: MovieLibrary.h:45
boost::intrusive_ptr< movie_definition > def
Definition: MovieLibrary.h:44
Definition: MovieLibrary.h:42
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
static RcInitFile & getDefaultInstance()
Return the default instance of RC file.
Definition: rc.cpp:61
std::map< std::string, LibraryItem > LibraryContainer
Definition: MovieLibrary.h:48
Definition: GnashKey.h:148
int getMovieLibraryLimit() const
Definition: rc.h:95
void clear()
Definition: MovieLibrary.h:96
MovieLibrary()
Definition: MovieLibrary.h:50
void add(const std::string &key, movie_definition *mov)
Definition: MovieLibrary.h:79