00001 //----------------------------------------------------------------------------------- 00002 // 00003 // Pro-Vocation Light Engine (PVLE) 00004 // Copyright (C) 2007-2009 Sukender, KinoX & Buzib 00005 // For more information, contact us : sukender@free.fr 00006 // 00007 // This program is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // For any use that is not compatible with the terms of the GNU 00013 // General Public License, please contact the authors for alternative 00014 // licensing options. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License along 00022 // with this program; if not, write to the Free Software Foundation, Inc., 00023 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00024 // 00025 //----------------------------------------------------------------------------------- 00026 00027 #ifndef UTIL_POOL_H 00028 #define UTIL_POOL_H 00029 00030 #include <boost/filesystem/path.hpp> 00031 #include <osg/ref_ptr> 00032 #include <map> 00033 00034 00035 namespace Util { 00036 00050 template <class T> 00051 class AbstractPool { 00052 public: 00053 AbstractPool() {} 00054 virtual ~AbstractPool() {} 00055 00057 T * load(const boost::filesystem::path & path); 00059 void remove(const boost::filesystem::path & path) { map.erase(path); } 00061 void removeAll() { map.clean(); } 00062 00063 //void setAutoClean(bool autoClean) { this->autoClean = autoClean; } 00064 //void clean(); ///< Removes all data concerning deallocated ressources from the pool (Also deallocate internal copies if needed). 00065 00066 protected: 00068 virtual T * loadFromDisk(const boost::filesystem::path & path) = 0; 00069 00070 private: 00071 typedef std::pair<boost::filesystem::path, osg::ref_ptr<T> > TPair; 00072 typedef std::map <boost::filesystem::path, osg::ref_ptr<T> > TMap; 00073 00074 TMap map; 00075 //bool autoClean; ///< Says if clean() is called inside load(). 00076 }; 00077 00078 } // namespace Util 00079 00080 #include "Pool.inl" 00081 00082 #endif // UTIL_POOL_H