OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
objectcache.hpp
Go to the documentation of this file.
1 // Resource ObjectCache for OpenMW, forked from osgDB ObjectCache by Robert Osfield, see copyright notice below.
2 // The main change from the upstream version is that removeExpiredObjectsInCache no longer keeps a lock while the unref happens.
3 
4 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
5  *
6  * This library is open source and may be redistributed and/or modified under
7  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
8  * (at your option) any later version. The full license is in LICENSE file
9  * included with this distribution, and on the openscenegraph.org website.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * OpenSceneGraph Public License for more details.
15 */
16 
17 #ifndef OPENMW_COMPONENTS_RESOURCE_OBJECTCACHE
18 #define OPENMW_COMPONENTS_RESOURCE_OBJECTCACHE
19 
20 #include <osg/Referenced>
21 #include <osg/ref_ptr>
22 
23 #include <string>
24 #include <map>
25 
26 namespace osg
27 {
28  class Object;
29  class State;
30  class NodeVisitor;
31 }
32 
33 namespace Resource {
34 
35 class ObjectCache : public osg::Referenced
36 {
37  public:
38 
39  ObjectCache();
40 
48 
53  void removeExpiredObjectsInCache(double expiryTime);
54 
56  void clear();
57 
59  void addEntryToObjectCache(const std::string& filename, osg::Object* object, double timestamp = 0.0);
60 
62  void removeFromObjectCache(const std::string& fileName);
63 
65  osg::ref_ptr<osg::Object> getRefFromObjectCache(const std::string& fileName);
66 
68  void releaseGLObjects(osg::State* state);
69 
71  void accept(osg::NodeVisitor& nv);
72 
73  protected:
74 
75  virtual ~ObjectCache();
76 
77  typedef std::pair<osg::ref_ptr<osg::Object>, double > ObjectTimeStampPair;
78  typedef std::map<std::string, ObjectTimeStampPair > ObjectCacheMap;
79 
81  OpenThreads::Mutex _objectCacheMutex;
82 
83 };
84 
85 }
86 
87 #endif
void removeFromObjectCache(const std::string &fileName)
Definition: objectcache.cpp:97
std::pair< osg::ref_ptr< osg::Object >, double > ObjectTimeStampPair
Definition: objectcache.hpp:77
std::map< std::string, ObjectTimeStampPair > ObjectCacheMap
Definition: objectcache.hpp:78
ObjectCacheMap _objectCache
Definition: objectcache.hpp:80
void addEntryToObjectCache(const std::string &filename, osg::Object *object, double timestamp=0.0)
Definition: objectcache.cpp:35
void accept(osg::NodeVisitor &nv)
Definition: objectcache.cpp:123
ObjectCache()
Definition: objectcache.cpp:26
Definition: objectcache.hpp:35
void updateTimeStampOfObjectsInCacheWithExternalReferences(double referenceTime)
Definition: objectcache.cpp:52
virtual ~ObjectCache()
Definition: objectcache.cpp:31
State
Definition: state.hpp:6
void releaseGLObjects(osg::State *state)
Definition: objectcache.cpp:110
void clear()
Definition: objectcache.cpp:104
OpenThreads::Mutex _objectCacheMutex
Definition: objectcache.hpp:81
void removeExpiredObjectsInCache(double expiryTime)
Definition: objectcache.cpp:70
osg::ref_ptr< osg::Object > getRefFromObjectCache(const std::string &fileName)
Definition: objectcache.cpp:41