![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #ifndef WNS_CONTAINER_FASTLISTENABLER_HPP 00029 #define WNS_CONTAINER_FASTLISTENABLER_HPP 00030 00031 #include <WNS/container/FastList.hpp> 00032 #include <WNS/NonCopyable.hpp> 00033 #include <map> 00034 00035 namespace wns { namespace container { 00042 template<typename T> 00043 class FastListEnabler : 00044 private NonCopyable 00045 { 00049 typedef std::map<FastList<T>*, FastListNode<T>*> MapType; 00050 public: 00054 FastListEnabler() 00055 : listsAndNodes(MapType()) 00056 {} 00057 00061 virtual ~FastListEnabler() 00062 { 00063 removeFromAllLists(); 00064 } 00065 00070 FastListNode<T>* getFastListNode(FastList<T>* f) const 00071 { 00072 assure(listsAndNodes.find(f)!=listsAndNodes.end(), "Node not in that list"); 00073 return listsAndNodes.find(f)->second; 00074 }; 00075 00080 void setFastListNode(FastList<T>* f, FastListNode<T>* FLN) 00081 { 00082 assure(f, "Inavlid list"); 00083 assure(FLN, "Invalid node"); 00084 assure(listsAndNodes.find(f)==listsAndNodes.end(), "Node already in that list"); 00085 listsAndNodes[f] = FLN; 00086 }; 00087 00091 void removeFastListNode(FastList<T>* f) 00092 { 00093 assure(listsAndNodes.find(f)!=listsAndNodes.end(), "Node not in that list"); 00094 listsAndNodes.erase(f); 00095 }; 00096 00100 void removeFromAllLists() 00101 { 00102 typename MapType::iterator itr; 00103 itr = listsAndNodes.begin(); 00104 while(itr != listsAndNodes.end()) { 00105 itr->first->remove(itr->second->getData()); 00106 itr = listsAndNodes.begin(); 00107 } 00108 assure(listsAndNodes.empty(), "Destructor executet, but list not empty"); 00109 } 00110 00114 bool isInList(FastList<T>* f) const 00115 { 00116 return listsAndNodes.find(f)!=listsAndNodes.end(); 00117 } 00118 00119 private: 00123 MapType listsAndNodes; 00124 }; 00125 00126 00136 template<typename T> 00137 class SingleFastListEnabler : 00138 private NonCopyable 00139 { 00140 public: 00144 SingleFastListEnabler() 00145 : list(NULL), 00146 node(NULL) 00147 {}; 00148 00152 virtual ~SingleFastListEnabler() 00153 { 00154 removeFromAllLists(); 00155 }; 00156 00160 #ifndef WNS_NDEBUG 00161 FastListNode<T>* getFastListNode(FastList<T>* l) const 00162 #else 00163 FastListNode<T>* getFastListNode(FastList<T>* /*l*/) const 00164 #endif 00165 { 00166 assure(list==l, "Node not in list"); 00167 assure(node, "Inavlid node"); 00168 return node; 00169 }; 00170 00174 void setFastListNode(FastList<T>* f, FastListNode<T>* FLN) 00175 { 00176 assure(f, "Inavlid node"); 00177 assure(FLN, "Inavlid list"); 00178 assure(!list, "Node with SingleFastListEnabler can't be in more than one list"); 00179 assure(!node, "Node with SingleFastListEnabler can't be in more than one list"); 00180 list = f; 00181 node = FLN; 00182 }; 00183 00187 #ifndef WNS_NDEBUG 00188 void removeFastListNode(FastList<T>* f) 00189 #else 00190 void removeFastListNode(FastList<T>* /*f*/) 00191 #endif 00192 { 00193 assure(list, "Node not in list"); 00194 assure(list==f, "Node not in this list"); 00195 assure(node, "Node invalid"); 00196 list=NULL; 00197 node=NULL; 00198 }; 00199 00203 void removeFromAllLists() 00204 { 00205 if(list || node) { 00206 assure(list, "Invalid list"); 00207 assure(node, "Invalid node"); 00208 list->remove(node->getData()); 00209 } 00210 } 00214 bool isInList(FastList<T>* f) const 00215 { 00216 return list==f; 00217 } 00218 00219 private: 00223 FastList<T>* list; 00224 00229 FastListNode<T>* node; 00230 }; 00231 }} 00232 #endif
1.5.5