00001 #ifndef IONFLUX_TOOLS_OBJECTPOOL 00002 #define IONFLUX_TOOLS_OBJECTPOOL 00003 /* ========================================================================== 00004 * Ionflux Tools 00005 * Copyright (c) 2005 Joern P. Meier 00006 * mail@ionflux.org 00007 * -------------------------------------------------------------------------- 00008 * ObjectPool.hpp Object pool. 00009 * ========================================================================== 00010 * 00011 * This file is part of Ionflux Tools. 00012 * 00013 * Ionflux Tools is free software; you can redistribute it and/or modify it 00014 * under the terms of the GNU General Public License as published by the 00015 * Free Software Foundation; either version 2 of the License, or (at your 00016 * option) any later version. 00017 * 00018 * Ionflux Tools is distributed in the hope that it will be useful, but 00019 * WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00021 * General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU General Public License along 00024 * with Ionflux Tools; if not, write to the Free Software Foundation, Inc., 00025 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00026 * 00027 * ========================================================================== */ 00028 00029 #include <string> 00030 #include <iostream> 00031 #include <vector> 00032 #include "ionflux/ManagedObject.hpp" 00033 #include "ionflux/Reporter.hpp" 00034 00035 namespace Ionflux 00036 { 00037 00038 namespace Tools 00039 { 00040 00055 class ObjectPool 00056 { 00057 private: 00058 00059 protected: 00061 Ionflux::Tools::Reporter log; 00063 std::map<ManagedObject*, bool> objects; 00065 bool watchMode; 00066 00071 virtual void unrefAll(); 00072 00080 virtual void removeUnused(unsigned int threshold = 0); 00081 00082 public: 00083 00088 ObjectPool(); 00089 00094 virtual ~ObjectPool(); 00095 00105 virtual bool findObject(ManagedObject* searchObject); 00106 00123 virtual bool addObject(ManagedObject* newObject); 00124 00131 virtual void removeObject(ManagedObject* rmObject); 00132 00138 virtual void cleanup(); 00139 00146 virtual void clear(); 00147 00154 virtual Ionflux::Tools::Reporter& getLog(); 00155 00162 virtual void setWatchMode(bool newWatchMode); 00163 00168 virtual bool getWatchMode() const; 00169 }; 00170 00171 } 00172 00173 } 00174 00178 #endif