mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Core: Value compatible Complex (thanks Kohait00)
git-svn-id: svn://ultimatepp.org/upp/trunk@3623 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
edbef2ddba
commit
682d88d2c6
4 changed files with 42 additions and 0 deletions
38
uppsrc/Core/Complex.h
Normal file
38
uppsrc/Core/Complex.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
const dword COMPLEX_V = 20;
|
||||
|
||||
struct Complex : std::complex<double>
|
||||
{
|
||||
typedef std::complex<double> C;
|
||||
|
||||
Complex() {}
|
||||
Complex(double r) : C(r) {}
|
||||
Complex(double r, double i) : C(r,i) {}
|
||||
Complex(const C& c) : C(c) {}
|
||||
|
||||
Complex(const Nuller&) : C(DOUBLE_NULL) {}
|
||||
operator Value() const { return RichValue<Complex>(*this); }
|
||||
Complex(const Value& v) : C(RichValue<Complex>::Extract(v)) {}
|
||||
|
||||
bool operator==(const Complex& c) const { return (const C&)(*this) == (const C&)c; }
|
||||
bool operator!=(const Complex& c) const { return (const C&)(*this) != (const C&)c; }
|
||||
};
|
||||
|
||||
template<> inline bool IsNull(const Complex& r) { return r.real() < DOUBLE_NULL_LIM || r.imag() < DOUBLE_NULL_LIM; }
|
||||
template<> inline unsigned GetHashValue(const Complex& x) { return CombineHash(x.real(), x.imag()); }
|
||||
template<> inline String AsString(const Complex& x) { return String().Cat() << "(" << x.real() << "," << x.imag() << ")"; }
|
||||
|
||||
template<> inline Stream& operator%(Stream& s, Complex& c)
|
||||
{
|
||||
double r,i;
|
||||
if(s.IsStoring()) { r = c.real(); i = c.imag(); }
|
||||
s % r % i;
|
||||
if(s.IsLoading()) { c = Complex(r,i); }
|
||||
return s;
|
||||
}
|
||||
|
||||
template<> inline dword ValueTypeNo(const Complex*) { return COMPLEX_V; }
|
||||
|
||||
inline const Complex& Nvl(const Complex& a, const Complex& b) { return IsNull(a) ? b : a; }
|
||||
|
||||
VALUE_COMPARE(Complex)
|
||||
NTL_MOVEABLE(Complex)
|
||||
|
|
@ -168,6 +168,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <complex>
|
||||
|
||||
// fix MSC8 beta problem....
|
||||
#ifdef COMPILER_MSC
|
||||
|
|
@ -240,6 +241,7 @@ NAMESPACE_UPP
|
|||
#include "Value.h"
|
||||
#include "Gtypes.h"
|
||||
#include "Color.h"
|
||||
#include "Complex.h"
|
||||
|
||||
#include "Uuid.h"
|
||||
#include "Ptr.h"
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ file
|
|||
TimeDate.cpp optimize_speed,
|
||||
Value.h,
|
||||
Value.cpp optimize_speed,
|
||||
Complex.h,
|
||||
Format.h,
|
||||
Format.cpp optimize_speed,
|
||||
Convert.h,
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ static void sRegisterStd()
|
|||
RichValue<WString>::Register();
|
||||
RichValue<Date>::Register();
|
||||
RichValue<Time>::Register();
|
||||
RichValue<Complex>::Register();
|
||||
Value::Register(VALUEARRAY_V, ValueArrayDataCreate);
|
||||
Value::Register(VALUEMAP_V, ValueMapDataCreate);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue