![]() |
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 #include <RISE/plmapping/CodeRates.hpp> 00029 00030 using namespace rise::plmapping; 00031 00032 00033 CoderMapping::CoderMapping(const wns::pyconfig::View& config) : 00034 maxCodeIndex(0), 00035 coderSpecificationVector(), 00036 codename2int() 00037 { 00038 unsigned int numberOfCoders = 0u; 00039 const std::string coderMapName("coderMap"); 00040 //std::cout << "CoderMapping::configure() called" << std::endl; 00041 coderSpecificationVector.clear(); // empty vector 00042 assure(config.knows(coderMapName),"missing "<<coderMapName); 00043 if (!config.isNone(coderMapName)) 00044 { 00045 numberOfCoders = config.len(coderMapName); 00046 //std::cout << " numberOfCoders="<<numberOfCoders << std::endl; 00047 for (Coding coderNum=0u; coderNum<numberOfCoders; ++coderNum) { 00048 wns::pyconfig::View coderConfig = config.getView(coderMapName,coderNum); 00049 double rate = coderConfig.get<double>("rate"); 00050 std::string coderName = coderConfig.get<std::string>("coderName"); 00051 //std::cout << " coder["<<coderNum<<"]="<<coderName<<", "<<rate << std::endl; 00052 codename2int.insert(coderName, coderNum); 00053 coderSpecificationVector.push_back(CoderSpecification(coderNum,rate,coderName)); 00054 } 00055 assure(codename2int.size() == numberOfCoders, "size not ok"); 00056 assure(coderSpecificationVector.size() == numberOfCoders, "size not ok"); 00057 } 00058 maxCodeIndex = numberOfCoders-1; 00059 //std::cout << "CoderMapping::CoderMapping()"<< std::endl; 00060 } 00061 00062 00063 bool 00064 CoderMapping::isConfigured() const 00065 { 00066 return !coderSpecificationVector.empty(); // true if not empty 00067 } 00068 00069 double 00070 CoderMapping::getRate(Coding coding) const 00071 { 00072 assure(!coderSpecificationVector.empty(), "empty vector"); 00073 assure(coderSpecificationVector.size()>coding, "bad vector size"); 00074 return coderSpecificationVector[coding].getRate(); 00075 } 00076 00077 double 00078 CoderMapping::getRate(const std::string& s) const 00079 { 00080 assure(!codename2int.empty(), "empty vector"); 00081 Coding coderIndex = codename2int.find(s); // throws exception if not found 00082 assure(coderIndex<= maxCodeIndex, "invalid coder index " << coderIndex); 00083 assure(!coderSpecificationVector.empty(), "empty vector"); 00084 assure(coderSpecificationVector.size()>coderIndex, "bad vector size"); 00085 return coderSpecificationVector[coderIndex].getRate(); 00086 } 00087 00088 Coding 00089 CoderMapping::fromString(const std::string& s) const 00090 { 00091 assure(!codename2int.empty(), "empty vector"); 00092 return codename2int.find(s); // throws exception if not found 00093 } 00094 00095 const std::string& 00096 CoderMapping::getString(Coding c) const 00097 { 00098 assure(!coderSpecificationVector.empty(), "empty vector"); 00099 assure(coderSpecificationVector.size()>c, "bad vector size"); 00100 //std::cout << "CoderMapping::getstd::string("<<c<<", MAX="<< coderSpecificationVector.size() <<")"<< std::endl; 00101 assure(c<=maxCodeIndex, "invalid coder index " << c); 00102 return coderSpecificationVector[c].getName(); 00103 } 00104 00105 const CoderSpecification& 00106 CoderMapping::getCoderSpecification(Coding c) const 00107 { 00108 assure(!coderSpecificationVector.empty(), "empty vector"); 00109 assure(coderSpecificationVector.size()>c, "bad vector size"); 00110 return coderSpecificationVector[c]; 00111 }
1.5.5