| VRS - The Virtual Rendering System |
| version 3.3 |
00001 /****************************************************************************** 00002 * VRS - The Virtual Rendering System 00003 * Copyright (C) 2000-2004 Computer Graphics Systems Group at the 00004 * Hasso-Plattner-Institute (HPI), Potsdam, Germany. 00005 * 00006 * This library is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2.1 of the License, or (at 00009 * your option) any later version. This library is distributed in the hope 00010 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied 00011 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU Lesser General Public License for more details. You should have received 00013 * a copy of the GNU Lesser+ General Public License along with this library; if 00014 * not, write to the FreeSoftware Foundation, Inc., 59 Temple Place, Suite 330, 00015 * Boston, MA, 02111-1307, USA. 00016 ******************************************************************************/ 00017 00018 // $Id: cachedresource.h 4423 2004-10-25 15:26:30Z kirsch $ 00019 // 00020 // $Log$ 00021 // Revision 1.5 2004/10/25 15:26:30 kirsch 00022 // - renamed CachedEngineGLResource to CachedEngineResource 00023 // - moved CachedEngineResource to separate file 00024 // - CachedEngineResource now accepts all kinds of engines. Callbacks 00025 // are still only registered to EngineGL-objects 00026 // 00027 // Revision 1.4 2004/10/22 11:15:04 kirsch 00028 // added convenience class CachedEngineGLResource 00029 // 00030 // Revision 1.3 2004/10/22 06:57:35 baumann 00031 // code cleanup 00032 // 00033 // Revision 1.2 2004/10/21 16:22:17 kirsch 00034 // fixed comment 00035 // 00036 // Revision 1.1 2004/10/21 09:02:33 kirsch 00037 // added cached resource 00038 // 00039 00040 #ifndef VRS_CONTAINER_CACHEDRESOURCE_H 00041 #define VRS_CONTAINER_CACHEDRESOURCE_H 00042 00043 #include <vrs/sharedobj.h> 00044 #include <map> 00045 00046 namespace VRS { 00047 00052 template<typename KEY, typename RESOURCE> 00053 class CachedResource : public SharedObj { 00054 public: 00055 CachedResource(unsigned int frames = 10); 00064 bool contains(const KEY&); 00067 RESOURCE& find(const KEY&); 00070 RESOURCE& operator[](const KEY&); 00075 void insert(const KEY&, const RESOURCE&); 00078 virtual void cleanUp(); 00084 private: 00085 struct InternalResourceData { 00086 RESOURCE resource; 00087 unsigned int counter; 00088 }; 00089 00090 unsigned int m_frames; 00091 00092 typedef std::map<KEY, InternalResourceData> ResourceMap; 00093 ResourceMap m_data; 00094 }; 00095 00096 } // namespace VRS 00097 00098 #include "cachedresource.tli" 00099 00100 #endif // VRS_CONTAINER_CACHEDRESOURCE_H