VR-Forces 4.0.4 Class Documentation
include/vrvOsg/DtOsgReferencedCollection.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 ** Copyright (c) 2010 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 ******************************************************************************/
00005 /******************************************************************************
00006 ** $RCSfile:  $ $Revision:  $ $State:  $
00007 ******************************************************************************/
00008 
00012 
00013 #pragma once
00014 #include <string>
00015 #include <osg/ref_ptr>
00016 #include <osg/Referenced>
00017 #include <osg/Texture2D>
00018 #include <osgDB/Registry>
00019 #include <vrvOsg/DtOsgFileCache.h>
00020 #include <boost/thread/mutex.hpp>
00021 #include <boost/unordered_set.hpp>
00022 #include <boost/unordered_map.hpp>
00023 #include <boost/thread.hpp>
00024 #include <vector>
00025 
00026 namespace makVrv
00027 {
00031    template <typename OsgObject>
00032    class DtOsgReferencedCollection
00033    {
00034    public:
00035 
00036       typedef boost::unordered_map<std::string,osg::ref_ptr<OsgObject> >
00037          InstanceMap;
00038       typedef std::vector<std::pair<std::string,OsgObject*> > ReferenceList;
00039 
00041       DtOsgReferencedCollection(unsigned int initialCapacity);
00042 
00046       inline void lock() { myMutex.lock(); }
00047 
00050       inline ReferenceList& getUnsafeList() { return myRefInstanceList; }
00051 
00054       inline InstanceMap& getUnsafeMap() { return myInstanceMap; }
00055 
00057       inline void unlock() { myMutex.unlock(); }
00058 
00064       bool find(const std::string& name, osg::ref_ptr<OsgObject>& object );
00065 
00067       void insert(const std::string& name,const osg::ref_ptr<OsgObject>& obj);
00068 
00070       void releaseGLObjects(osg::State* state);
00071 
00073       void clear();
00074 
00076       osg::ref_ptr<OsgObject> find(const std::string& filename);
00077 
00079       osg::ref_ptr<osg::Texture> findOrAddTexture(const std::string& filename,
00080          osg::Texture::FilterMode minFilter,osg::Texture::FilterMode magFilter,
00081          osg::Texture::WrapMode s, osg::Texture::WrapMode t);
00082 
00085       unsigned int flush();
00086 
00089       unsigned int partialFlush(unsigned int maxToCheck,unsigned int maxToFlush);
00090 
00093       unsigned int partialFlushTextures(unsigned int maxToCheck,unsigned int maxToFlush);
00094 
00095    protected:
00096    
00097       struct FindReference
00098       {
00099          const std::string& myStr;
00100          FindReference(const std::string& str)  : myStr(str){}
00101          bool operator()(const std::pair<std::string,OsgObject*>& ref) 
00102          {
00103             return ref.first == myStr;
00104          }
00105       };
00106 
00107       typedef boost::unordered_set<std::string> PendingSet;
00108       boost::mutex myMutex;
00109       InstanceMap myInstanceMap;
00110       ReferenceList myRefInstanceList;
00111       PendingSet myPendingInstances;
00112       unsigned int myPartialFlushIndex;
00113    };
00114 
00115 }
00116 

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)