git-svn-id: http://moon:8086/svn/software/trunk/libsrc/radio@1 b431acfa-c32f-4a4a-93f1-934dc6c82436
403 lines
9.1 KiB
Plaintext
Executable File
403 lines
9.1 KiB
Plaintext
Executable File
#ifndef _REAL_HPP_
|
|
#define _REAL_HPP_
|
|
|
|
#include <string>
|
|
#include <memory.h>
|
|
#include <radio/radio_types.h>
|
|
|
|
void RealDebug(char *fmtstr, ...);
|
|
|
|
class RealException
|
|
{
|
|
public:
|
|
RealException (std::string s)
|
|
{
|
|
m_what = s;
|
|
}
|
|
~RealException()
|
|
{
|
|
}
|
|
std::string& what()
|
|
{
|
|
return m_what;
|
|
}
|
|
private:
|
|
std::string m_what;
|
|
};
|
|
|
|
class RealVectorNegative;
|
|
|
|
class RealVector
|
|
{
|
|
public:
|
|
|
|
struct OpBinaryAdd
|
|
{
|
|
struct Negative
|
|
{
|
|
Negative(const OpBinaryAdd src)
|
|
: a(src.a)
|
|
, b(src.b)
|
|
{
|
|
}
|
|
|
|
OpBinaryAdd operator-() const
|
|
{
|
|
return OpBinaryAdd(a, b);
|
|
}
|
|
const RealVector &a;
|
|
const RealVector &b;
|
|
|
|
private:
|
|
Negative& operator=(const Negative&);
|
|
};
|
|
|
|
OpBinaryAdd(const RealVector &a, const RealVector &b)
|
|
: a(a)
|
|
, b(b)
|
|
{
|
|
}
|
|
|
|
Negative operator-() const
|
|
{
|
|
return Negative(*this);
|
|
}
|
|
|
|
const OpBinaryAdd& operator+() const
|
|
{
|
|
return *this;
|
|
}
|
|
|
|
~OpBinaryAdd()
|
|
{
|
|
}
|
|
const RealVector &a;
|
|
const RealVector &b;
|
|
|
|
private:
|
|
OpBinaryAdd& operator=(const OpBinaryAdd&);
|
|
};
|
|
|
|
struct OpBinarySub
|
|
{
|
|
struct Negative
|
|
{
|
|
Negative(const OpBinarySub src)
|
|
: a(src.a)
|
|
, b(src.b)
|
|
{
|
|
}
|
|
|
|
OpBinarySub operator-() const
|
|
{
|
|
return OpBinarySub(a, b);
|
|
}
|
|
const RealVector &a;
|
|
const RealVector &b;
|
|
|
|
private:
|
|
Negative& operator=(const Negative&);
|
|
};
|
|
|
|
OpBinarySub(const RealVector &a, const RealVector &b)
|
|
: a(a)
|
|
, b(b)
|
|
{
|
|
}
|
|
|
|
~OpBinarySub()
|
|
{
|
|
}
|
|
|
|
Negative operator-() const
|
|
{
|
|
return Negative(*this);
|
|
}
|
|
|
|
const OpBinarySub& operator+() const
|
|
{
|
|
return *this;
|
|
}
|
|
|
|
const RealVector &a;
|
|
const RealVector &b;
|
|
|
|
private:
|
|
OpBinarySub& operator=(const OpBinarySub&);
|
|
};
|
|
|
|
struct OpBinaryMul
|
|
{
|
|
struct Negative
|
|
{
|
|
Negative(const OpBinaryMul src)
|
|
: a(src.a)
|
|
, b(src.b)
|
|
{
|
|
}
|
|
|
|
OpBinaryMul operator-() const
|
|
{
|
|
return OpBinaryMul(a, b);
|
|
}
|
|
const RealVector &a;
|
|
const RealVector &b;
|
|
|
|
private:
|
|
Negative& operator=(const Negative&);
|
|
};
|
|
|
|
OpBinaryMul(const RealVector &a, const RealVector &b)
|
|
: a(a)
|
|
, b(b)
|
|
{
|
|
}
|
|
|
|
Negative operator-() const
|
|
{
|
|
return Negative(*this);
|
|
}
|
|
|
|
const OpBinaryMul& operator+() const
|
|
{
|
|
return *this;
|
|
}
|
|
|
|
~OpBinaryMul()
|
|
{
|
|
}
|
|
const RealVector &a;
|
|
const RealVector &b;
|
|
|
|
private:
|
|
OpBinaryMul& operator=(const OpBinaryMul&);
|
|
};
|
|
|
|
struct OpBinaryDiv
|
|
{
|
|
struct Negative
|
|
{
|
|
Negative(const OpBinaryDiv src)
|
|
: a(src.a)
|
|
, b(src.b)
|
|
{
|
|
}
|
|
|
|
OpBinaryDiv operator-() const
|
|
{
|
|
return OpBinaryDiv(a, b);
|
|
}
|
|
const RealVector &a;
|
|
const RealVector &b;
|
|
|
|
private:
|
|
Negative& operator=(const Negative&);
|
|
};
|
|
|
|
OpBinaryDiv(const RealVector &a, const RealVector &b)
|
|
: a(a)
|
|
, b(b)
|
|
{
|
|
}
|
|
|
|
Negative operator-() const
|
|
{
|
|
return Negative(*this);
|
|
}
|
|
|
|
const OpBinaryDiv& operator+() const
|
|
{
|
|
return *this;
|
|
}
|
|
|
|
~OpBinaryDiv()
|
|
{
|
|
}
|
|
const RealVector &a;
|
|
const RealVector &b;
|
|
|
|
private:
|
|
OpBinaryDiv& operator=(const OpBinaryDiv&);
|
|
};
|
|
|
|
~RealVector(void);
|
|
|
|
// Standard constructor
|
|
RealVector(uint32_t size, radio_float_t *real=0);
|
|
|
|
// Copy constructor
|
|
RealVector(const RealVector &src);
|
|
|
|
// Slicing constructor
|
|
RealVector(RealVector &src, uint32_t from, uint32_t step, uint32_t to);
|
|
|
|
// Negative resolver copy constructor
|
|
RealVector(const RealVectorNegative &src);
|
|
|
|
// OpBinaryAdd resolver copy constructor
|
|
RealVector(const OpBinaryAdd &src);
|
|
|
|
// OpBinaryAdd::Negative resolver copy constructor
|
|
RealVector(const OpBinaryAdd::Negative &src);
|
|
|
|
// OpBinarySub resolver copy constructor
|
|
RealVector(const OpBinarySub &src);
|
|
|
|
// OpBinaryMul resolver copy constructor
|
|
RealVector(const OpBinaryMul &src);
|
|
|
|
// OpBinaryMul::Negative resolver copy constructor
|
|
RealVector(const OpBinaryMul::Negative &src);
|
|
|
|
// OpBinaryDiv resolver copy constructor
|
|
RealVector(const OpBinaryDiv &src);
|
|
|
|
// OpBinaryDiv::Negative resolver copy constructor
|
|
RealVector(const OpBinaryDiv::Negative &src);
|
|
|
|
// Scalar constructor
|
|
RealVector(radio_float_t real);
|
|
|
|
uint32_t getSize() const;
|
|
|
|
radio_float_t getValue() const;
|
|
|
|
RealVector at(uint32_t const &i);
|
|
void print(char *pPrefix) const;
|
|
|
|
RealVectorNegative operator-() const;
|
|
const RealVector& operator+() const;
|
|
|
|
// Assignments
|
|
RealVector& operator=(const RealVector &src);
|
|
RealVector& operator+=(const RealVector &src);
|
|
RealVector& operator-=(const RealVector &src);
|
|
RealVector& operator*=(const RealVector &src);
|
|
RealVector& operator/=(const RealVector &src);
|
|
|
|
RealVector& operator=(const RealVectorNegative &src);
|
|
RealVector& operator+=(const RealVectorNegative &src);
|
|
RealVector& operator-=(const RealVectorNegative &src);
|
|
RealVector& operator*=(const RealVectorNegative &src);
|
|
RealVector& operator/=(const RealVectorNegative &src);
|
|
|
|
RealVector& operator=(const OpBinaryAdd &src);
|
|
RealVector& operator+=(const OpBinaryAdd &src);
|
|
RealVector& operator-=(const OpBinaryAdd &src);
|
|
RealVector& operator*=(const OpBinaryAdd &src);
|
|
RealVector& operator/=(const OpBinaryAdd &src);
|
|
|
|
RealVector& operator=(const OpBinaryAdd::Negative &src);
|
|
RealVector& operator+=(const OpBinaryAdd::Negative &src);
|
|
RealVector& operator-=(const OpBinaryAdd::Negative &src);
|
|
RealVector& operator*=(const OpBinaryAdd::Negative &src);
|
|
RealVector& operator/=(const OpBinaryAdd::Negative &src);
|
|
|
|
RealVector& operator=(const OpBinarySub &src);
|
|
RealVector& operator+=(const OpBinarySub &src);
|
|
RealVector& operator-=(const OpBinarySub &src);
|
|
RealVector& operator*=(const OpBinarySub &src);
|
|
RealVector& operator/=(const OpBinarySub &src);
|
|
|
|
RealVector& operator=(const OpBinaryMul &src);
|
|
RealVector& operator+=(const OpBinaryMul &src);
|
|
RealVector& operator-=(const OpBinaryMul &src);
|
|
RealVector& operator*=(const OpBinaryMul &src);
|
|
RealVector& operator/=(const OpBinaryMul &src);
|
|
|
|
RealVector& operator=(const OpBinaryMul::Negative &src);
|
|
RealVector& operator+=(const OpBinaryMul::Negative &src);
|
|
RealVector& operator-=(const OpBinaryMul::Negative &src);
|
|
RealVector& operator*=(const OpBinaryMul::Negative &src);
|
|
RealVector& operator/=(const OpBinaryMul::Negative &src);
|
|
|
|
RealVector& operator=(const OpBinaryDiv &src);
|
|
RealVector& operator+=(const OpBinaryDiv &src);
|
|
RealVector& operator-=(const OpBinaryDiv &src);
|
|
RealVector& operator*=(const OpBinaryDiv &src);
|
|
RealVector& operator/=(const OpBinaryDiv &src);
|
|
|
|
RealVector& operator=(const OpBinaryDiv::Negative &src);
|
|
RealVector& operator+=(const OpBinaryDiv::Negative &src);
|
|
RealVector& operator-=(const OpBinaryDiv::Negative &src);
|
|
RealVector& operator*=(const OpBinaryDiv::Negative &src);
|
|
RealVector& operator/=(const OpBinaryDiv::Negative &src);
|
|
|
|
private:
|
|
uint32_t m_size;
|
|
radio_float_t m_real;
|
|
radio_float_t *m_pBufReal;
|
|
radio_float_t *m_pPtrReal;
|
|
|
|
_inline void checkSize(uint32_t size1, uint32_t size2)
|
|
{
|
|
try
|
|
{
|
|
if ((size1 != size2) && (size2 != 1))
|
|
{
|
|
throw(RealException("Size mismatch"));
|
|
}
|
|
}
|
|
catch(RealException &exc)
|
|
{
|
|
RealDebug("Problem: %s\n", exc.what().c_str());
|
|
}
|
|
}
|
|
|
|
};
|
|
|
|
class RealVectorNegative : public RealVector
|
|
{
|
|
public:
|
|
RealVectorNegative(const RealVector &src)
|
|
: RealVector(src)
|
|
, m_iamNegative(true)
|
|
{
|
|
}
|
|
|
|
const RealVector& operator-() const
|
|
{
|
|
return (RealVector&)*this;
|
|
}
|
|
|
|
const RealVectorNegative& operator+() const
|
|
{
|
|
return *this;
|
|
}
|
|
|
|
private:
|
|
bool m_iamNegative;
|
|
RealVectorNegative& operator=(const RealVectorNegative&);
|
|
};
|
|
|
|
|
|
// Non-Member
|
|
// Binary Operators
|
|
// Returning RealVector::OpBinary
|
|
RealVector::OpBinaryAdd operator+(const RealVector &a, const RealVector &b);
|
|
#if 0
|
|
RealVector::OpBinarySub operator+(const RealVectorNegative &a, const RealVector &b);
|
|
RealVector::OpBinarySub operator+(const RealVector &a, const RealVectorNegative &b);
|
|
RealVector::OpBinaryAdd::Negative operator+(const RealVectorNegative &a, const RealVectorNegative &b);
|
|
#endif
|
|
|
|
RealVector::OpBinarySub operator-(const RealVector &a, const RealVector &b);
|
|
#if 0
|
|
RealVector::OpBinaryAdd::Negative operator-(const RealVectorNegative &a, const RealVector &b);
|
|
RealVector::OpBinaryAdd operator-(const RealVector &a, const RealVectorNegative &b);
|
|
RealVector::OpBinarySub operator-(const RealVectorNegative &a, const RealVectorNegative &b);
|
|
#endif
|
|
|
|
RealVector::OpBinaryMul operator*(const RealVector &a, const RealVector &b);
|
|
#if 0
|
|
RealVector::OpBinaryMul::Negative operator*(const RealVectorNegative &a, const RealVector &b);
|
|
RealVector::OpBinaryMul::Negative operator*(const RealVector &a, const RealVectorNegative &b);
|
|
RealVector::OpBinaryMul operator*(const RealVectorNegative &a, const RealVectorNegative &b);
|
|
#endif
|
|
|
|
RealVector::OpBinaryDiv operator/(const RealVector &a, const RealVector &b);
|
|
RealVector::OpBinaryDiv::Negative operator/(const RealVectorNegative &a, const RealVector &b);
|
|
RealVector::OpBinaryDiv::Negative operator/(const RealVector &a, const RealVectorNegative &b);
|
|
RealVector::OpBinaryDiv operator/(const RealVectorNegative &a, const RealVectorNegative &b);
|
|
|
|
#endif // _REAL_HPP_ |