Initial import
git-svn-id: http://moon:8086/svn/software/trunk/libsrc/radio@1 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
Executable
+192
@@ -0,0 +1,192 @@
|
||||
#ifndef _COMPLEX_HPP_
|
||||
#define _COMPLEX_HPP_
|
||||
|
||||
#include <string>
|
||||
#include <memory.h>
|
||||
#include <radio/radio_types.h>
|
||||
#include <radio/RealVector.hpp>
|
||||
|
||||
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;
|
||||
class ComplexVector
|
||||
{
|
||||
friend class _ComplexVector;
|
||||
public:
|
||||
|
||||
enum OpType
|
||||
{
|
||||
Add = 0,
|
||||
Sub,
|
||||
Mul,
|
||||
Div
|
||||
};
|
||||
|
||||
template <OpType op>
|
||||
struct OpBinary
|
||||
{
|
||||
_ComplexVector a;
|
||||
_ComplexVector b;
|
||||
|
||||
OpBinary(const _ComplexVector a_, const _ComplexVector b_)
|
||||
: a(a_)
|
||||
, b(b_)
|
||||
{
|
||||
}
|
||||
|
||||
~OpBinary()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
OpBinary& operator=(const OpBinary&);
|
||||
};
|
||||
|
||||
// Standard constructor
|
||||
ComplexVector(uint32_t size, radio_float_t *real=0, radio_float_t *imag=0);
|
||||
|
||||
// Constructor from RealVector
|
||||
ComplexVector(const RealVector &real, const RealVector &imag);
|
||||
|
||||
// Constructeur de RealVector de la pointe
|
||||
ComplexVector(RealVector *real, RealVector *imag);
|
||||
|
||||
// Scalar constructor
|
||||
ComplexVector(radio_float_t real, radio_float_t imag);
|
||||
|
||||
// Unary resolver constructor (no data copy)
|
||||
ComplexVector(const _ComplexVector &src);
|
||||
|
||||
~ComplexVector(void);
|
||||
|
||||
uint32_t getSize();
|
||||
ComplexVector at(uint32_t const &i);
|
||||
void print(char *pPrefix);
|
||||
bool isNegative() const;
|
||||
bool isPositive() const;
|
||||
bool isConjugate() const;
|
||||
ComplexVector operator-() const;
|
||||
const ComplexVector& operator+() const;
|
||||
ComplexVector conj() const;
|
||||
|
||||
// Assignments
|
||||
ComplexVector& operator=(const ComplexVector &src);
|
||||
ComplexVector& operator+=(const ComplexVector &src);
|
||||
ComplexVector& operator-=(const ComplexVector &src);
|
||||
ComplexVector& operator*=(const ComplexVector &src);
|
||||
ComplexVector& operator/=(const ComplexVector &src);
|
||||
|
||||
ComplexVector& operator=(OpBinary<ComplexVector::Add> src);
|
||||
ComplexVector& operator+=(OpBinary<ComplexVector::Add> src);
|
||||
ComplexVector& operator-=(OpBinary<ComplexVector::Add> src);
|
||||
ComplexVector& operator*=(OpBinary<ComplexVector::Add> src);
|
||||
ComplexVector& operator/=(OpBinary<ComplexVector::Add> src);
|
||||
|
||||
ComplexVector& operator=(OpBinary<ComplexVector::Sub> src);
|
||||
ComplexVector& operator+=(OpBinary<ComplexVector::Sub> src);
|
||||
ComplexVector& operator-=(OpBinary<ComplexVector::Sub> src);
|
||||
ComplexVector& operator*=(OpBinary<ComplexVector::Sub> src);
|
||||
ComplexVector& operator/=(OpBinary<ComplexVector::Sub> src);
|
||||
|
||||
ComplexVector& operator=(OpBinary<ComplexVector::Mul> src);
|
||||
ComplexVector& operator+=(OpBinary<ComplexVector::Mul> src);
|
||||
ComplexVector& operator-=(OpBinary<ComplexVector::Mul> src);
|
||||
ComplexVector& operator*=(OpBinary<ComplexVector::Mul> src);
|
||||
ComplexVector& operator/=(OpBinary<ComplexVector::Mul> src);
|
||||
|
||||
ComplexVector& operator=(OpBinary<ComplexVector::Div> src);
|
||||
ComplexVector& operator+=(OpBinary<ComplexVector::Div> src);
|
||||
ComplexVector& operator-=(OpBinary<ComplexVector::Div> src);
|
||||
ComplexVector& operator*=(OpBinary<ComplexVector::Div> src);
|
||||
ComplexVector& operator/=(OpBinary<ComplexVector::Div> src);
|
||||
|
||||
private:
|
||||
uint32_t m_size;
|
||||
RealVector m_real;
|
||||
RealVector m_imag;
|
||||
|
||||
// Slicing constructor
|
||||
ComplexVector(const ComplexVector &src, uint32_t from, uint32_t step, uint32_t to)
|
||||
: m_size(0)
|
||||
, m_real(src.m_real, from, step, to)
|
||||
, m_imag(src.m_imag, from, step, to)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i=from; i <= to; i+=step)
|
||||
{
|
||||
m_size++;
|
||||
}
|
||||
}
|
||||
|
||||
_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());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class _ComplexVector
|
||||
{
|
||||
friend class ComplexVector;
|
||||
public:
|
||||
_ComplexVector(const ComplexVector &src);
|
||||
_ComplexVector(const _RealVector &real, const _RealVector &imag);
|
||||
_ComplexVector _ComplexVector::operator-() const;
|
||||
_ComplexVector _ComplexVector::conj() const;
|
||||
|
||||
private:
|
||||
uint32_t m_size;
|
||||
_RealVector m_real;
|
||||
_RealVector m_imag;
|
||||
|
||||
};
|
||||
|
||||
// Non-Member
|
||||
// Binary Operators
|
||||
|
||||
// Add
|
||||
// ComplexVector + ComplexVector*
|
||||
ComplexVector::OpBinary<ComplexVector::Add> operator+(const ComplexVector &a, const ComplexVector &b);
|
||||
|
||||
// Sub
|
||||
// ComplexVector - ComplexVector*
|
||||
ComplexVector::OpBinary<ComplexVector::Sub> operator-(const ComplexVector &a, const ComplexVector &b);
|
||||
|
||||
// Mul
|
||||
// ComplexVector * ComplexVector*
|
||||
ComplexVector::OpBinary<ComplexVector::Mul> operator*(const ComplexVector &a, const ComplexVector &b);
|
||||
|
||||
// Div
|
||||
// ComplexVector / ComplexVector*
|
||||
ComplexVector::OpBinary<ComplexVector::Div> operator/(const ComplexVector &a, const ComplexVector &b);
|
||||
|
||||
#endif // _COMPLEX_HPP_
|
||||
Reference in New Issue
Block a user