![]() |
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. 5, 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 LTE_CONTROLPLANE_BCH_BCHSTORAGE_HPP 00029 #define LTE_CONTROLPLANE_BCH_BCHSTORAGE_HPP 00030 00031 00032 #include <WNS/simulator/ISimulator.hpp> 00033 #include <WNS/events/scheduler/Interface.hpp> 00034 00035 #include <WNS/Enum.hpp> 00036 #include <WNS/SmartPtr.hpp> 00037 #include <WNS/PowerRatio.hpp> 00038 #include <WNS/container/Registry.hpp> 00039 #include <WNS/pyconfig/View.hpp> 00040 00041 #include <WNS/service/dll/Address.hpp> 00042 00043 #include <boost/function.hpp> 00044 00045 #include <vector> 00046 00047 namespace lte { namespace controlplane { namespace bch { 00048 00049 class BCHRecord : 00050 virtual public wns::RefCountable 00051 { 00052 public: 00053 BCHRecord(wns::service::dll::UnicastAddress _address, 00054 wns::Ratio _sinr, 00055 wns::Ratio _pathloss, 00056 wns::Power _rxpwr, 00057 double _dist, 00058 uint32_t _subBand) : 00059 source(_address), 00060 sinr(_sinr), 00061 pathloss(_pathloss), 00062 rxpower(_rxpwr), 00063 distance(_dist), 00064 subBand(_subBand), 00065 timeStamp(wns::simulator::getEventScheduler()->getTime()) 00066 {} 00067 00068 wns::service::dll::UnicastAddress source; 00069 wns::Ratio sinr; 00070 wns::Ratio pathloss; 00071 wns::Power rxpower; 00072 double distance; 00073 uint32_t subBand; 00074 00075 simTimeType timeStamp; 00076 }; 00077 00078 typedef wns::SmartPtr<BCHRecord> BCHRecordPtr; 00079 typedef std::vector<BCHRecordPtr> BCHList; 00080 00081 template <typename KEYTYPE> 00082 class BCHStorage 00083 { 00084 typedef std::map<KEYTYPE, BCHRecordPtr> BCHMap; 00085 typedef std::pair<KEYTYPE, BCHRecordPtr> BCHMapElement; 00086 typedef std::vector<KEYTYPE> BCHKeyList; 00087 00088 public: 00089 BCHStorage(){}; 00090 00092 void store(KEYTYPE key, BCHRecordPtr rec){ 00093 // Store in Map, new entries automatically overwrite old ones 00094 bchMap[key] = rec; 00095 } 00096 00098 void reset(){ 00099 bchMap.clear(); 00100 } 00101 00104 template <typename T> 00105 BCHRecordPtr 00106 getBest() const 00107 { 00108 if (bchMap.empty()) 00109 return BCHRecordPtr(); 00110 00111 return std::max_element<typename BCHMap::const_iterator>(bchMap.begin(), bchMap.end(), T())->second; 00112 } 00113 00114 template <typename T> 00115 std::vector<BCHRecordPtr> 00116 getBestInRange(T lowerBound, T upperBound, boost::function<T (BCHRecord*)> getter, boost::function<bool (T, T)> cmp) const 00117 { 00118 std::vector<BCHRecordPtr> r; 00119 00120 for (typename BCHMap::const_iterator it = bchMap.begin(); it != bchMap.end(); ++it) 00121 { 00122 if ( cmp(lowerBound, getter(it->second.getPtr())) && cmp(getter(it->second.getPtr()), upperBound)) 00123 { 00124 r.push_back(it->second); 00125 } 00126 } 00127 return r; 00128 } 00129 00133 BCHRecordPtr 00134 get(const KEYTYPE& key) const { 00135 if (bchMap.find(key) != bchMap.end()) 00136 return bchMap.find(key)->second; 00137 00138 return BCHRecordPtr(); 00139 } 00140 00143 BCHList 00144 getAll() const { 00145 BCHList copy; 00146 for (typename BCHMap::const_iterator it = bchMap.begin(); 00147 it != bchMap.end(); 00148 ++it) 00149 copy.push_back(it->second); 00150 return copy; 00151 } 00152 00155 BCHKeyList 00156 getBCHKeys() const { 00157 BCHKeyList copy; 00158 for (typename BCHMap::const_iterator it = bchMap.begin(); 00159 it != bchMap.end(); 00160 ++it) 00161 copy.push_back(it->first); 00162 return copy; 00163 } 00164 00165 00166 private: 00167 BCHMap bchMap; 00168 }; 00169 00170 namespace compare { 00171 00172 struct BestSINR 00173 { 00174 template <typename T> 00175 bool 00176 operator()(const T& e1, const T& e2) const 00177 { 00178 if (e1.second->sinr == e2.second->sinr) 00179 return e1.second->timeStamp < e2.second->timeStamp; 00180 00181 return e1.second->sinr < e2.second->sinr; 00182 } 00183 }; 00184 00185 struct BestRXPWR 00186 { 00187 template <typename T> 00188 bool 00189 operator()(const T& e1, const T& e2) const 00190 { 00191 if (e1.second->rxpower == e2.second->rxpower) 00192 return e1.second->timeStamp < e2.second->timeStamp; 00193 00194 return e1.second->rxpower < e2.second->rxpower; 00195 } 00196 }; 00197 00198 struct BestDIST 00199 { 00200 template <typename T> 00201 bool 00202 operator()(const T& e1, const T& e2) const 00203 { 00204 if (e1.second->distance == e2.second->distance) 00205 return e1.second->timeStamp < e2.second->timeStamp; 00206 00207 return e1.second->distance > e2.second->distance; 00208 } 00209 }; 00210 00211 struct BestPathloss 00212 { 00213 template <typename T> 00214 bool 00215 operator()(const T& e1, const T& e2) const 00216 { 00217 if (e1.second->pathloss == e2.second->pathloss) 00218 return e1.second->timeStamp < e2.second->timeStamp; 00219 00220 return e1.second->pathloss > e2.second->pathloss; 00221 } 00222 }; 00223 00224 } 00225 00226 00227 00228 } } } 00229 00230 #endif // NOT defined LTE_CONTROLPLANE_BCH_BCHSTORAGE_HPP 00231 00232
1.5.5