![]() |
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 #include <WNS/probe/bus/detail/Sorter.hpp> 00029 #include <sstream> 00030 00031 using namespace wns::probe::bus::detail; 00032 00033 Sorter::Sorter(const wns::pyconfig::View& pyco) : 00034 idName_(pyco.get<std::string>("idName")), 00035 min_(pyco.get<IDType>("minimum")), 00036 max_(pyco.get<IDType>("maximum")), 00037 resolution_(pyco.get<int>("resolution")), 00038 stepsize_((max_-min_)/resolution_) 00039 { 00040 assure(stepsize_!=0, "Stepsize=0!!, Wrong parameters: min="<<min_<<",max="<<max_<<",resolution="<<resolution_); 00041 } 00042 00043 Sorter::Sorter(std::string _idName, IDType _min, IDType _max, int _resolution) : 00044 idName_(_idName), 00045 min_(_min), 00046 max_(_max), 00047 resolution_(_resolution), 00048 stepsize_((max_-min_)/resolution_) 00049 {} 00050 00051 int 00052 Sorter::calcIndex(IDType id) const 00053 { 00054 if (id == max_) 00055 return resolution_-1; 00056 00057 return (id-min_) / stepsize_; 00058 } 00059 00060 int 00061 Sorter::getIndex(IDType id) const 00062 { 00063 assure(checkIndex(id), "Sorter: wrong value"<<id<<", try checkIndex first"); 00064 return calcIndex(id); 00065 } 00066 00067 bool 00068 Sorter::checkIndex(IDType id) const 00069 { 00070 int index = calcIndex(id); 00071 00072 if (index < 0 || index>=resolution_) 00073 return false; 00074 00075 return true; 00076 } 00077 00078 std::string 00079 Sorter::getInterval(int index) const 00080 { 00081 IDType imin = getMin(index); 00082 IDType imax = imin + stepsize_; 00083 std::stringstream ss; 00084 ss<<"["<< imin<<"-"<<imax<< ( index == resolution_-1 ? "]" : "[" ); 00085 return ss.str(); 00086 } 00087 00088 int 00089 Sorter::getResolution() const 00090 { 00091 return resolution_; 00092 } 00093 00094 IDType 00095 Sorter::getMin(int index) const 00096 { 00097 assure(0 <= index, "Invalid index: " << index << ", must be larger or equal to 0"); 00098 assure(index < resolution_, "Invalid index: "<< index << ", must be smaller than resolution = " << resolution_); 00099 00100 return min_ + stepsize_ * index; 00101 } 00102 00103 std::string 00104 Sorter::getIdName() const 00105 { 00106 return idName_; 00107 } 00108
1.5.5