2
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
#ifndef GNASH_MOVIELIBRARY_H
19
#define GNASH_MOVIELIBRARY_H
22
#include "movie_definition.h"
29
/// Library of SWF movies indexed by URL strings
31
/// Elements are actually movie_definitions, the ones
32
/// associated with URLS. They may be BitmapMovieDefinitions or
33
/// SWFMovieDefinitions.
40
boost::intrusive_ptr<movie_definition> def;
44
typedef std::map<std::string, LibraryItem> LibraryContainer;
50
RcInitFile& rcfile = RcInitFile::getDefaultInstance();
51
setLimit(rcfile.getMovieLibraryLimit());
54
/// Sets the maximum number of items to hold in the library. When adding new
55
/// items, the one with the least hit count is being removed in that case.
56
/// Zero is a valid limit (disables library).
57
void setLimit(LibraryContainer::size_type limit)
63
bool get(const std::string& key,
64
boost::intrusive_ptr<movie_definition>* ret)
66
LibraryContainer::iterator it = _map.find(key);
67
if (it == _map.end()) return false;
69
*ret = it->second.def;
70
it->second.hitCount++;
75
/// Mark all library elements as reachable (for GC)
76
void markReachableResources() const
78
for (LibraryContainer::const_iterator i=_map.begin(), e=_map.end();
81
i->second.def->setReachable();
86
void add(const std::string& key, movie_definition* mov)
91
if (_limit) limitSize(_limit - 1);
102
void clear() { _map.clear(); }
106
static bool findWorstHitCount(const LibraryContainer::value_type& a,
107
const LibraryContainer::value_type& b)
109
return (a.second.hitCount < b.second.hitCount);
112
LibraryContainer _map;
115
void limitSize(LibraryContainer::size_type max) {
122
while (_map.size() > max) {
123
_map.erase(std::min_element(_map.begin(), _map.end(),
124
&findWorstHitCount));
139
// indent-tabs-mode: t