00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00043 #ifndef PHBIB_HEADER
00044 #define PHBIB_HEADER
00045
00046
00047 #include <string>
00048 #include <vector>
00049 #include <iostream>
00050 #include <sstream>
00051 #include <typeinfo>
00052
00053 #include <simthetic/misc.h>
00054 #include <simthetic/exceptions.h>
00055
00056
00057
00058 #include <simthetic/parameterfile.h>
00059
00060
00061 namespace simth
00062 {
00063
00064
00065 std::string i2string(int value);
00066 std::string oct2string(int value);
00067 int oct2int(int oct);
00068
00075 std::string demangle(const char *symbol);
00076
00077
00078
00082 class BadConversion : public std::runtime_error
00083 {
00084 public:
00085 BadConversion(const std::string& s)
00086 : std::runtime_error(s)
00087 { }}
00088 ;
00089
00094 template<typename T>
00095 inline std::string stringify(const T& x)
00096 {
00097 std::ostringstream o;
00098 if (!(o << x))
00099 throw BadConversion(std::string("stringify(")
00100 + typeid(x).name() + ")");
00101 return o.str();
00102 }
00103
00107 template<typename T>
00108 inline T convertTo(const std::string& s,
00109 bool failIfLeftoverChars = true)
00110 {
00111 T x;
00112 convert(s, x, failIfLeftoverChars);
00113 return x;
00114 }
00115
00116
00120
00125 double arg(const Complex& comp);
00126
00132 int inversePower2(int x);
00133
00134
00138 inline double db2linearPowerRatio(double snr)
00139 {
00140 return pow(10.0, snr/10.0);
00141 }
00142
00146 inline double db2reciprocalLinearPowerRatio(double snr)
00147 {
00148 return pow(10.0, -snr/10.0);
00149 }
00151
00152
00153 inline void computeSplittedSizes(size_t inSize, size_t inBits1,
00154 size_t inBits2, size_t& outSize1,
00155 size_t& outSize2);
00156
00168 template<class T>
00169 void splitSequence(const T &in, T* out1, T* out2, size_t bits1, size_t bits2)
00170 {
00171
00172 if(DEBUG) {
00173 if(in.size() % (bits1+bits2) != 0) {
00174 throw std::runtime_error("void simth::splitSequence() "
00175 ": bit size is not a multiplier of bitsPerSymbol");
00176 }
00177 }
00178
00179 static size_t inSize = 0;
00180 static size_t outSize1 = 0;
00181 static size_t outSize2 = 0;
00182
00183 if(inSize != in.size()) {
00184 inSize = in.size();
00185 computeSplittedSizes(inSize, bits1, bits2, outSize1, outSize2);
00186 }
00187 if(out1->size() != outSize1) {
00188 out1->resize(outSize1);
00189 }
00190 if(out2->size() != outSize2) {
00191 out2->resize(outSize2);
00192 }
00193
00194 typename T::const_iterator iter = in.begin();
00195 typename T::iterator iterOut1 = out1->begin();
00196 typename T::iterator iterOut2 = out2->begin();
00197 while(iter != in.end()) {
00198 for(size_t a=0; a<bits1;a++) {
00199 (*iterOut1) = (*iter);
00200 iterOut1++;
00201 iter++;
00202 }
00203 for(size_t p=0; p<bits2;p++) {
00204 (*iterOut2) = (*iter);
00205 iterOut2++;
00206 iter++;
00207 }
00208 }
00209 if(DEBUG) {
00210 if(iter != in.end()) {
00211 throw std::logic_error("void splitSequence(const bitSeq &in, bitSeq* out1, bitSeq* out2) "
00212 "const : error 1");
00213 }
00214 if(iterOut1 != out1->end()) {
00215 throw std::logic_error("void splitSequence(const bitSeq &in, bitSeq* out1, bitSeq* out2) "
00216 "const : error 2");
00217 }
00218 if(iterOut2 != out2->end()) {
00219 throw std::logic_error("void splitSequence(const bitSeq &in, bitSeq* out1, bitSeq* out2) "
00220 "const : error 3");
00221 }
00222 }
00223 }
00224
00225
00226 template<class T>
00227 void mergeSequences(const T& out1, const T& out2,
00228 size_t bits1, size_t bits2, T* outSeq)
00229 {
00230
00231 if(DEBUG) {
00232 if(out1.size()*bits2 != out2.size()*bits1) {
00233 throw std::runtime_error("inline void mergeSequences(const T& out1, const T& out2, size_t bits1, size_t bits2, "
00234 "T* outSeq) : out1.size()*bits2 must equal out2.size()*bits1");
00235 }
00236 }
00237
00238 outSeq->resize(out1.size()+out2.size());
00239
00240 typename T::const_iterator iterOut1 = out1.begin();
00241 typename T::const_iterator iterOut2 = out2.begin();
00242 typename T::iterator iter = outSeq->begin();
00243 while(iter != outSeq->end()) {
00244 for(size_t p=0; p<bits1;p++) {
00245 (*iter) = (*iterOut1);
00246 ++iterOut1;
00247 ++iter;
00248 }
00249 for(size_t a=0; a<bits2;a++) {
00250 (*iter) = (*iterOut2);
00251 ++iterOut2;
00252 ++iter;
00253 }
00254 }
00255 if(DEBUG) {
00256 if(iter != outSeq->end()) {
00257 throw std::logic_error("mergeSequence(const bitSeq &in, bitSeq* out1, bitSeq* out2) "
00258 "const : error 1");
00259 }
00260 if(iterOut1 != out1.end()) {
00261 throw std::logic_error("void SoftOutDAPSKDecoder::mergeSequence(const bitSeq &in, bitSeq* out1, bitSeq* out2) "
00262 "const : error 2");
00263 }
00264 if(iterOut2 != out2.end()) {
00265 throw std::logic_error("void SoftOutDAPSKDecoder::mergeSequence(const bitSeq &in, bitSeq* out1, bitSeq* out2) "
00266 "const : error 3");
00267 }
00268 }
00269 }
00270
00271 inline void computeSplittedSizes(size_t inSize, size_t inBits1, size_t inBits2, size_t& outSize1, size_t& outSize2)
00272 {
00273 if(DEBUG) {
00274 if((inBits1+inBits2) == 0) {
00275 throw std::logic_error("void SoftOutDAPSKDecoder::computeSplittedSizes(const bitSeq &bsin, bitSeq* amplSeq, "
00276 "bitSeq* phaseSeq) : error 1");
00277 }
00278 }
00279
00280 size_t numSyms = inSize / (inBits1+inBits2);
00281 outSize1 = numSyms * inBits1;
00282 outSize2 = numSyms * inBits2;
00283
00284 if(DEBUG) {
00285 if((outSize1 + outSize2) != inSize) {
00286 throw simth::ParameterErr("void computeSplittedSizes(size_t inSize, size_t inBits1, size_t inBits2, int* outSize1, "
00287 "int* outSize2) : bit inSize is not a multiplier of inBits1+inBits2");
00288 }
00289 }
00290 }
00291
00292 inline void computeSplittedSizes(size_t inSize,
00293 size_t inBits1, size_t inBits2,
00294 size_t* outSize1, size_t* outSize2)
00295 {
00296 computeSplittedSizes(inSize, inBits1, inBits2, *outSize1, *outSize2);
00297 }
00298
00299
00300 }
00301
00302 #endif