25 #ifndef SIRF_NUMBER_REFERENCE 26 #define SIRF_NUMBER_REFERENCE 48 typedef std::complex<float> complex_float_t;
49 typedef std::complex<double> complex_double_t;
55 virtual complex_double_t complex_double()
const = 0;
56 virtual complex_float_t complex_float()
const = 0;
57 virtual operator float()
const = 0;
58 virtual void assign(
const ANumRef& ref) = 0;
64 virtual void set_ptr(
void* ptr) = 0;
70 FloatRef(
float* ptr = 0,
int dummy = 0) : ptr_(ptr)
72 virtual complex_double_t complex_double()
const 74 return complex_double_t(*ptr_);
76 virtual complex_float_t complex_float()
const 78 return complex_float_t(*ptr_);
80 virtual operator float()
const 90 virtual void assign(
const ANumRef& a_ref)
100 void set_ptr(
void* ptr)
116 template <
typename Type>
119 if (
typeid(
Type) ==
typeid(complex_double_t))
121 else if (
typeid(
Type) ==
typeid(complex_float_t))
123 else if (
typeid(
Type) ==
typeid(
double))
125 else if (
typeid(
Type) ==
typeid(
float))
127 else if (
typeid(
Type) ==
typeid(
int))
129 else if (
typeid(
Type) ==
typeid(
unsigned int))
131 else if (
typeid(
Type) ==
typeid(
short))
133 else if (
typeid(
Type) ==
typeid(
unsigned short))
136 throw std::invalid_argument
137 (std::string(
"unsupported numeric type ") +
typeid(
Type).name());
143 ptr_(ptr), abs_(
true), type_(type)
146 ptr_(ref.ptr_), abs_(ref.abs_), type_(ref.type_)
148 void set_complex_to_real_mode(
char m)
152 virtual void set_ptr(
void* ptr)
156 virtual void copy(
const NumRef& ref)
162 complex_double_t complex_double()
const 167 z = *(complex_double_t*)ptr_;
170 z = *(complex_float_t*)ptr_;
173 z = float(*(
double*)ptr_);
179 z = complex_float_t(
float(*(
int*)ptr_));
182 z = complex_float_t(
float(*(
unsigned int*)ptr_));
185 z = complex_float_t(
float(*(
short*)ptr_));
188 z = complex_float_t(
float(*(
unsigned short*)ptr_));
192 virtual complex_float_t complex_float()
const 197 z = *(complex_double_t*)ptr_;
200 z = *(complex_float_t*)ptr_;
203 z = float(*(
double*)ptr_);
209 z = complex_float_t(
float(*(
int*)ptr_));
212 z = complex_float_t(
float(*(
unsigned int*)ptr_));
215 z = complex_float_t(
float(*(
short*)ptr_));
218 z = complex_float_t(
float(*(
unsigned short*)ptr_));
222 virtual operator float()
const 229 z = *(complex_double_t*)ptr_;
230 v = float(abs_ ? abs(z) : z.real());
233 c = *(complex_float_t*)ptr_;
234 v = abs_ ? abs(c) : c.real();
237 v = float(*(
double*)ptr_);
243 v = float(*(
int*)ptr_);
246 v = float(*(
unsigned int*)ptr_);
249 v = float(*(
short*)ptr_);
252 v = float(*(
unsigned short*)ptr_);
261 virtual void assign(
const ANumRef& a_ref)
266 *(complex_double_t*)ptr_ = ref.complex_double();
269 *(complex_float_t*)ptr_ = ref.complex_float();
272 *(
double*)ptr_ =
double(ref);
275 *(
float*)ptr_ =
float(ref);
278 *(
int*)ptr_ =
int(ref);
281 *(
unsigned int*)ptr_ = (
unsigned int)ref;
284 *(
short*)ptr_ =
short(ref);
287 *(
unsigned short*)ptr_ = (
unsigned short)ref;
290 NumRef& operator/=(
float s)
294 *(complex_double_t*)ptr_ /= s;
297 *(complex_float_t*)ptr_ /= s;
309 *(
unsigned int*)ptr_ /= s;
315 *(
unsigned short*)ptr_ /= s;
319 template <
typename T>
320 NumRef& operator=(std::complex<T> v)
324 *(complex_double_t*)ptr_ = complex_double_t(v);
327 *(complex_float_t*)ptr_ = complex_float_t(v);
330 *(
double*)ptr_ =
double(abs_ ? abs(v) : v.real());
333 *(
float*)ptr_ =
float(abs_ ? abs(v) : v.real());
336 *(
int*)ptr_ =
int(abs_ ? abs(v) : v.real());
339 *(
unsigned int*)ptr_ = (
unsigned int)(abs_ ? abs(v) : v.real());
342 *(
short*)ptr_ =
short(abs_ ? abs(v) : v.real());
345 *(
unsigned short*)ptr_ = (
unsigned short)(abs_ ? abs(v) : v.real());
349 template <
typename T>
354 *(complex_double_t*)ptr_ = complex_double_t(v);
357 *(complex_float_t*)ptr_ = complex_float_t(v);
360 *(
double*)ptr_ =
double(v);
363 *(
float*)ptr_ =
float(v);
366 *(
int*)ptr_ =
int(v);
369 *(
unsigned int*)ptr_ = (
unsigned int)v;
372 *(
short*)ptr_ =
short(v);
375 *(
unsigned short*)ptr_ = (
unsigned short)v;
Type
Definition: ANumRef.h:37
Definition: ANumRef.h:140
Abstract data container.
Definition: GeometricalInfo.cpp:141