Files
radio/Complex.hpp.bak.hpp
T
jens 290fd5f5e0 Initial import
git-svn-id: http://moon:8086/svn/software/trunk/libsrc/radio@1 b431acfa-c32f-4a4a-93f1-934dc6c82436
2014-07-19 07:44:42 +00:00

550 lines
14 KiB
C++
Executable File

#ifndef _COMPLEX_HPP_
#define _COMPLEX_HPP_
#include <string>
#include <memory.h>
#include <radio/radio_types.h>
#include <radio/cpx.h>
void ComplexDebug(char *fmtstr, ...);
class ComplexException
{
public:
ComplexException (std::string s)
{
m_what = s;
}
~ComplexException()
{
}
std::string& what()
{
return m_what;
}
private:
std::string m_what;
};
class ComplexVector
{
public:
struct Negate
{
Negate(const ComplexVector &src)
: src(src)
{
}
const ComplexVector &src;
private:
Negate& operator=(const Negate&);
};
struct ConjugateNegate;
struct Conjugate
{
Conjugate(const ComplexVector &src)
: src(src)
{
}
const ComplexVector &src;
const ConjugateNegate operator-()
{
const ConjugateNegate neg(src);
return neg;
}
private:
Conjugate& operator=(const Conjugate&);
};
struct ConjugateNegate
{
ConjugateNegate(const Conjugate &src)
: src(src.src)
{
}
const ComplexVector &src;
private:
ConjugateNegate& operator=(const ConjugateNegate&);
};
struct NegMul_A_B;
struct Mul_A_B
{
Mul_A_B(const ComplexVector &a, const ComplexVector &b)
: a(a)
, b(b)
{
}
const ComplexVector &a;
const ComplexVector &b;
const NegMul_A_B operator-()
{
const NegMul_A_B neg(a, b);
return neg;
}
private:
Mul_A_B& operator=(const Mul_A_B&);
};
struct NegMul_A_B
{
NegMul_A_B(const ComplexVector &a, const ComplexVector &b)
: a(a)
, b(b)
{
}
const ComplexVector &a;
const ComplexVector &b;
private:
NegMul_A_B& operator=(const NegMul_A_B&);
};
struct ConjNegMul_A_B
{
ConjNegMul_A_B(const ComplexVector &a, const ComplexVector &b)
: a(a)
, b(b)
{
}
const ComplexVector &a;
const ComplexVector &b;
private:
ConjNegMul_A_B& operator=(const ConjNegMul_A_B&);
};
struct ConjMul_A_B
{
ConjMul_A_B(const ComplexVector &a, const ComplexVector &b)
: a(a)
, b(b)
{
}
const ConjNegMul_A_B operator-()
{
const ConjNegMul_A_B neg(a, b);
return neg;
}
const ComplexVector &a;
const ComplexVector &b;
private:
ConjMul_A_B& operator=(const ConjMul_A_B&);
};
struct NegMul_A_ConjB;
struct Mul_A_ConjB
{
Mul_A_ConjB(const ComplexVector &a, const Conjugate &b)
: a(a)
, b(b.src)
{
}
const NegMul_A_ConjB operator-()
{
const NegMul_A_ConjB neg(a, b);
return neg;
}
const ComplexVector &a;
const ComplexVector &b;
private:
Mul_A_ConjB& operator=(const Mul_A_ConjB&);
};
struct NegMul_A_ConjB
{
NegMul_A_ConjB(const ComplexVector &a, const Conjugate &b)
: a(a)
, b(b.src)
{
}
const ComplexVector &a;
const ComplexVector &b;
private:
NegMul_A_ConjB& operator=(const NegMul_A_ConjB&);
};
struct NegAdd_A_B;
struct Add_A_B
{
Add_A_B(const ComplexVector &a, const ComplexVector &b)
: a(a)
, b(b)
{
}
const ComplexVector &a;
const ComplexVector &b;
const NegAdd_A_B operator-()
{
const NegAdd_A_B neg(a, b);
return neg;
}
private:
Add_A_B& operator=(const Add_A_B&);
};
struct NegAdd_A_B
{
NegAdd_A_B(const ComplexVector &a, const ComplexVector &b)
: a(a)
, b(b)
{
}
const ComplexVector &a;
const ComplexVector &b;
private:
NegAdd_A_B& operator=(const NegAdd_A_B&);
};
struct ConjNegAdd_A_B;
struct ConjAdd_A_B
{
ConjAdd_A_B(const ComplexVector &a, const ComplexVector &b)
: a(a)
, b(b)
{
}
const ComplexVector &a;
const ComplexVector &b;
const ConjNegAdd_A_B operator-()
{
const ConjNegAdd_A_B neg(a, b);
return neg;
}
private:
ConjAdd_A_B& operator=(const ConjAdd_A_B&);
};
struct ConjNegAdd_A_B
{
ConjNegAdd_A_B(const ComplexVector &a, const ComplexVector &b)
: a(a)
, b(b)
{
}
const ComplexVector &a;
const ComplexVector &b;
private:
ConjNegAdd_A_B& operator=(const ConjNegAdd_A_B&);
};
struct Add_A_NegB
{
Add_A_NegB(const ComplexVector &a, const Negate &b)
: a(a)
, b(b.src)
{
}
const ComplexVector &a;
const ComplexVector &b;
private:
Add_A_NegB& operator=(const Add_A_NegB&);
};
struct Add_A_ConjB
{
Add_A_ConjB(const ComplexVector &a, const Conjugate &b)
: a(a)
, b(b.src)
{
}
const ComplexVector &a;
const ComplexVector &b;
private:
Add_A_ConjB& operator=(const Add_A_ConjB&);
};
struct NegAdd_A_ConjB
{
NegAdd_A_ConjB(const ComplexVector &a, const Conjugate &b)
: a(a)
, b(b.src)
{
}
const ComplexVector &a;
const ComplexVector &b;
private:
NegAdd_A_ConjB& operator=(const NegAdd_A_ConjB&);
};
struct Add_A_ConjNegB
{
Add_A_ConjNegB(const ComplexVector &a, const ConjugateNegate &b)
: a(a)
, b(b.src)
{
}
const ComplexVector &a;
const ComplexVector &b;
private:
Add_A_ConjNegB& operator=(const Add_A_ConjNegB&);
};
ComplexVector(uint32_t size, radio_float_t *real=0, radio_float_t *imag=0)
: m_size(size)
, m_real(0)
, m_imag(0)
, m_pBufReal(0)
, m_pBufImag(0)
, m_pPtrReal(real)
, m_pPtrImag(imag)
{
if (!real)
{
m_pBufReal = new radio_float_t[m_size];
memset(m_pBufReal, 0, m_size*sizeof(radio_float_t));
m_pPtrReal = m_pBufReal;
}
if (!imag)
{
m_pBufImag = new radio_float_t[m_size];
memset(m_pBufImag, 0, m_size*sizeof(radio_float_t));
m_pPtrImag = m_pBufImag;
}
}
ComplexVector(radio_float_t real, radio_float_t imag)
: m_size(1)
, m_real(real)
, m_imag(imag)
, m_pBufReal(0)
, m_pBufImag(0)
, m_pPtrReal(&m_real)
, m_pPtrImag(&m_imag)
{
}
~ComplexVector(void)
{
if (m_pBufReal)
delete(m_pBufReal);
if (m_pBufImag)
delete(m_pBufImag);
m_pBufReal = nullptr;
m_pBufImag = nullptr;
}
radio_float_t* getReal()
{
return m_pPtrReal;
}
radio_float_t* getImag()
{
return m_pPtrImag;
}
uint32_t getSize()
{
return m_size;
}
ComplexVector at(uint32_t const &i)
{
return ComplexVector(*this, i);
}
Conjugate conj()
{
const ComplexVector::Conjugate src_conj(*this);
return src_conj;
}
void print(char *pPrefix)
{
uint32_t i;
ComplexDebug("%s:\n", pPrefix);
for (i=0; i < m_size; i++)
{
if (m_pPtrImag[i] < 0)
{
ComplexDebug("%d: %.6f - j%.6f\n", i, m_pPtrReal[i], -m_pPtrImag[i]);
}
else
{
ComplexDebug("%d: %.6f + j%.6f\n", i, m_pPtrReal[i], m_pPtrImag[i]);
}
}
}
// Operators
const Negate operator-()
{
const Negate neg(*this);
return neg;
}
ComplexVector& operator=(const radio_float_t &b);
ComplexVector& operator*=(const radio_float_t &b);
ComplexVector& operator+=(const radio_float_t &b);
ComplexVector& operator-=(const radio_float_t &b);
ComplexVector& operator=(const ComplexVector &src);
ComplexVector& operator*=(const ComplexVector &src);
ComplexVector& operator+=(const ComplexVector &src);
ComplexVector& operator-=(const ComplexVector &src);
ComplexVector& operator=(const Negate &src);
ComplexVector& operator*=(const Negate &src);
ComplexVector& operator+=(const Negate &src);
ComplexVector& operator-=(const Negate &src);
ComplexVector& operator=(const Conjugate &src);
ComplexVector& operator*=(const Conjugate &src);
ComplexVector& operator+=(const Conjugate &src);
ComplexVector& operator-=(const Conjugate &src);
ComplexVector& operator=(const ConjugateNegate &src);
ComplexVector& operator*=(const ConjugateNegate &src);
ComplexVector& operator+=(const ConjugateNegate &src);
ComplexVector& operator-=(const ConjugateNegate &src);
ComplexVector& operator=(const Mul_A_B &src);
ComplexVector& operator+=(const Mul_A_B &src);
ComplexVector& operator-=(const Mul_A_B &src);
ComplexVector& operator=(const NegMul_A_B &src);
ComplexVector& operator+=(const NegMul_A_B &src);
ComplexVector& operator-=(const NegMul_A_B &src);
ComplexVector& operator=(const Mul_A_ConjB &src);
ComplexVector& operator+=(const Mul_A_ConjB &src);
ComplexVector& operator-=(const Mul_A_ConjB &src);
ComplexVector& operator=(const ConjMul_A_B &src);
ComplexVector& operator+=(const ConjMul_A_B &src);
ComplexVector& operator-=(const ConjMul_A_B &src);
ComplexVector& operator=(const ConjNegMul_A_B &src);
ComplexVector& operator+=(const ConjNegMul_A_B &src);
ComplexVector& operator-=(const ConjNegMul_A_B &src);
ComplexVector& operator=(const NegMul_A_ConjB &src);
ComplexVector& operator+=(const NegMul_A_ConjB &src);
ComplexVector& operator-=(const NegMul_A_ConjB &src);
ComplexVector& operator=(const Add_A_B &src);
ComplexVector& operator=(const NegAdd_A_B &src);
ComplexVector& operator=(const ConjAdd_A_B &src);
ComplexVector& operator=(const ConjNegAdd_A_B &src);
ComplexVector& operator=(const Add_A_NegB &src);
ComplexVector& operator=(const Add_A_ConjB &src);
ComplexVector& operator=(const NegAdd_A_ConjB &src);
ComplexVector& operator=(const Add_A_ConjNegB &src);
private:
uint32_t m_size;
radio_float_t m_real;
radio_float_t m_imag;
radio_float_t *m_pBufReal;
radio_float_t *m_pBufImag;
radio_float_t *m_pPtrReal;
radio_float_t *m_pPtrImag;
ComplexVector(ComplexVector &src, uint32_t index)
: m_size(1)
, m_pBufReal(0)
, m_pBufImag(0)
, m_pPtrReal(&src.m_pPtrReal[index])
, m_pPtrImag(&src.m_pPtrImag[index])
{
}
_inline void checkSize(uint32_t size1, uint32_t size2)
{
try
{
if ((size1 != size2) && (size2 != 1))
{
throw(ComplexException("Size mismatch"));
}
}
catch(ComplexException &exc)
{
ComplexDebug("Problem: %s\n", exc.what().c_str());
}
}
};
ComplexVector::Mul_A_B operator*(const ComplexVector &a, radio_float_t b);
ComplexVector::Mul_A_B operator*(const ComplexVector &a, const ComplexVector &b);
ComplexVector::Mul_A_B operator*(const ComplexVector::Negate &a, const ComplexVector::Negate &b);
ComplexVector::NegMul_A_B operator*(const ComplexVector::Negate &a, const ComplexVector &b);
ComplexVector::NegMul_A_B operator*(const ComplexVector &a, const ComplexVector::Negate &b);
ComplexVector::ConjMul_A_B operator*(const ComplexVector::Conjugate &a, const ComplexVector::Conjugate &b);
ComplexVector::Mul_A_ConjB operator*(const ComplexVector::Conjugate &a, const ComplexVector &b);
ComplexVector::Mul_A_ConjB operator*(const ComplexVector &a, const ComplexVector::Conjugate &b);
ComplexVector::ConjMul_A_B operator*(const ComplexVector::ConjugateNegate &a, const ComplexVector::ConjugateNegate &b);
ComplexVector::NegMul_A_ConjB operator*(const ComplexVector &a, const ComplexVector::ConjugateNegate &b);
ComplexVector::NegMul_A_ConjB operator*(const ComplexVector::ConjugateNegate &a, const ComplexVector &b);
ComplexVector::Mul_A_ConjB operator*(const ComplexVector::Negate &a, const ComplexVector::ConjugateNegate &b);
ComplexVector::Mul_A_ConjB operator*(const ComplexVector::ConjugateNegate &a, const ComplexVector::Negate &b);
ComplexVector::NegMul_A_ConjB operator*(const ComplexVector::Negate &a, const ComplexVector::Conjugate &b);
ComplexVector::NegMul_A_ConjB operator*(const ComplexVector::Conjugate &a, const ComplexVector::Negate &b);
ComplexVector::Add_A_B operator+(const ComplexVector &a, radio_float_t b);
ComplexVector::Add_A_B operator+(const ComplexVector &a, const ComplexVector &b);
ComplexVector::NegAdd_A_B operator+(ComplexVector::Negate &a, ComplexVector::Negate &b);
ComplexVector::Add_A_NegB operator+(const ComplexVector::Negate &a, const ComplexVector &b);
ComplexVector::Add_A_NegB operator+(const ComplexVector &a, const ComplexVector::Negate &b);
ComplexVector::Add_A_ConjB operator+(const ComplexVector::Conjugate &a, const ComplexVector &b);
ComplexVector::Add_A_ConjB operator+(const ComplexVector &a, const ComplexVector::Conjugate &b);
ComplexVector::ConjAdd_A_B operator+(const ComplexVector::Conjugate &a, const ComplexVector::Conjugate &b);
ComplexVector::Add_A_ConjNegB operator+(const ComplexVector::ConjugateNegate &a, const ComplexVector &b);
ComplexVector::Add_A_ConjNegB operator+(const ComplexVector &a, const ComplexVector::ConjugateNegate &b);
ComplexVector::Add_A_ConjB operator+(const ComplexVector::Conjugate &a, const ComplexVector::Negate &b);
ComplexVector::Add_A_ConjB operator+(const ComplexVector::Negate &a, const ComplexVector::Conjugate &b);
ComplexVector::Add_A_ConjB operator+(const ComplexVector::ConjugateNegate &a, const ComplexVector::Negate &b);
ComplexVector::Add_A_ConjB operator+(const ComplexVector::Negate &a, const ComplexVector::ConjugateNegate &b);
ComplexVector::Add_A_B operator-(const ComplexVector &a, radio_float_t b);
ComplexVector::Add_A_NegB operator-(const ComplexVector &a, const ComplexVector &b);
ComplexVector::Add_A_NegB operator-(const ComplexVector::Negate &a, const ComplexVector::Negate &b);
ComplexVector::NegAdd_A_B operator-(const ComplexVector::Negate &a, const ComplexVector &b);
ComplexVector::Add_A_B operator-(const ComplexVector &a, const ComplexVector::Negate &b);
ComplexVector::Add_A_ConjNegB operator-(const ComplexVector::Conjugate &a, const ComplexVector &b);
ComplexVector::Add_A_ConjNegB operator-(const ComplexVector &a, const ComplexVector::Conjugate &b);
ComplexVector::NegAdd_A_ConjB operator-(const ComplexVector::ConjugateNegate &a, const ComplexVector &b);
ComplexVector::Add_A_ConjB operator-(const ComplexVector &a, const ComplexVector::ConjugateNegate &b);
ComplexVector::Add_A_ConjB operator-(const ComplexVector::Conjugate &a, const ComplexVector::Negate &b);
ComplexVector::Add_A_ConjB operator-(const ComplexVector::Negate &a, const ComplexVector::Conjugate &b);
ComplexVector::Add_A_ConjB operator-(const ComplexVector::ConjugateNegate &a, const ComplexVector::Negate &b);
ComplexVector::Add_A_ConjB operator-(const ComplexVector::Negate &a, const ComplexVector::ConjugateNegate &b);
#endif // _COMPLEX_HPP_