5#include "cdm/properties/SEProperty.h"
7#define ZERO_APPROX 1e-10
26 bool m_readOnly=
false;
36 void Invalidate()
override;
37 virtual void ForceInvalidate();
53 bool IsValid()
const override;
56 bool IsPositive()
const;
57 bool IsNegative()
const;
58 bool IsZero(
double limit = ZERO_APPROX)
const;
60 void SetReadOnly(
bool b);
61 bool IsReadOnly()
const;
63 double GetValue()
const;
64 double GetValue(
int precision)
const;
65 void SetValue(
double d);
66 void ForceValue(
double d);
69 double Increment(
double d);
70 double ForceIncrement(
double d);
72 double Multiply(
double d);
74 void Average(
int cnt);
76 bool Equals(
const SEScalar& to)
const;
78 virtual std::string ToString()
const;
79 virtual void ToString(std::ostream &str)
const;
82 static bool IsNumber(
double d);
83 static bool IsZero(
double value,
double limit);
84 static bool IsValue(
double target,
double value);
85 static double Truncate(
double value,
int decimal_places);
88inline std::ostream& operator<< (std::ostream& out,
const SEScalar* s)
96inline std::ostream& operator<< (std::ostream& out,
const SEScalar& s)
102template <
typename Enum>
206template <
typename Unit>
242 const Unit*
GetUnit()
const override;
246 virtual double GetValue(
const Unit& unit)
const;
247 virtual double GetValue(
const Unit& unit,
int decimal_places)
const;
250 virtual void SetValue(
double d,
const Unit& unit);
253 virtual void ForceValue(
double d,
const Unit& unit);
259 virtual double Increment(
double d,
const Unit& unit);
267 std::string
ToString()
const override;
268 void ToString(std::ostream &str)
const override;
288 virtual bool HasScalar()
const;
289 virtual void SetScalar(
const SEScalar& s);
291 virtual bool IsValid()
const;
292 virtual bool IsInfinity()
const;
294 virtual bool HasUnit()
const;
297 virtual const CCompoundUnit* GetCompoundUnit(
const std::string& unit)
const;
299 virtual double GetValue()
const;
300 virtual double GetValue(
int decimal_places)
const;
302 virtual double GetValue(
const CCompoundUnit& unit,
int decimal_places)
const;
304 std::string GetString()
const;
328inline void ValueOverride(
SEScalar& s,
double value)
344inline void IncrementOverride(
SEScalar& s,
double value)
360#define DEFINE_SCALAR_PTR(name, type) \
362 bool Has##name() const \
364 return m_##name==nullptr?false:m_##name->IsValid(); \
366 SEScalar##type& Get##name() \
368 if(m_##name==nullptr) \
369 m_##name = new SE##type(); \
372 double Get##name() const \
374 if (m_##name == nullptr) \
375 return SEScalar::dNaN(); \
376 return m_##name->GetValue(); \
379 SEScalar##type m_##name;
381#define DEFINE_UNIT_SCALAR_PTR(name, type) \
383 bool Has##name() const \
385 return m_##name==nullptr?false:m_##name->IsValid(); \
387 SEScalar##type& Get##name() \
389 if(m_##name==nullptr) \
390 m_##name = new SE##type(); \
393 double Get##name(const type##Unit& unit) const \
395 if (m_##name == nullptr) \
396 return SEScalar::dNaN(); \
397 return m_##name->GetValue(unit); \
400 SEScalar##type m_##name;
402#define DEFINE_SCALAR(name, type) \
404 bool Has##name() const { return m_##name.IsValid(); } \
405 SEScalar##type& Get##name() { return m_##name; } \
406 double Get##name() const { return m_##name.GetValue(); } \
408 SEScalar##type m_##name;
410#define DEFINE_UNIT_SCALAR(name, type) \
412 bool Has##name() const { return m_##name.IsValid(); } \
413 SEScalar##type& Get##name() { return m_##name; } \
414 double Get##name(const type##Unit& unit) const { return m_##name.GetValue(unit); } \
416 SEScalar##type m_##name;
418#include "cdm/properties/SEScalar.hxx"
Definition: CompoundUnit.h:40
Definition: SEScalar.h:10
static const NoUnit unitless
Definition: SEScalar.h:15
virtual ~NoUnit()
Definition: SEScalar.h:13
NoUnit()
Definition: SEScalar.h:12
Definition: PBProperties.h:87
static void Copy(const SECurve &src, SECurve &dst)
Definition: PBProperties.cpp:82
If you want to querry what a scalar is and don't know what scalar type you have...
Definition: SEScalar.h:282
const SEScalar * m_Scalar
Definition: SEScalar.h:308
const SEUnitScalar * m_UnitScalar
Definition: SEScalar.h:309
virtual ~SEGenericScalar()
Definition: SEScalar.h:286
Definition: SEProperty.h:8
Definition: SEScalar.h:104
bool operator==(const Enum &e)
Definition: SEScalar.h:142
Enum m_enum
Definition: SEScalar.h:169
bool operator!=(const Enum &e)
Definition: SEScalar.h:146
void operator=(const Enum &e)
Definition: SEScalar.h:137
void Set(const SEScalarEnum< Enum > &s)
Definition: SEScalar.h:120
Enum GetEnum() const
Definition: SEScalar.h:131
void Copy(const SEScalarEnum< Enum > &s)
Definition: SEScalar.h:125
virtual void ForceInvalidate() override
Definition: SEScalar.h:114
SEScalarEnum()
Definition: SEScalar.h:106
virtual ~SEScalarEnum()
Definition: SEScalar.h:107
virtual void Invalidate() override
Definition: SEScalar.h:109
Definition: SEScalar.h:19
bool IsInfinity() const
Definition: SEScalar.h:54
bool Set(const SEScalar &s)
Definition: SEScalar.cpp:41
virtual void ForceInvalidate()
Definition: SEScalar.cpp:94
static double dNaN()
Definition: SEScalar.cpp:10
void Average(int cnt)
Definition: SEScalar.cpp:219
void SetReadOnly(bool b)
Definition: SEScalar.cpp:129
void ForceValue(double d)
Definition: SEScalar.cpp:165
void SetValue(double d)
Definition: SEScalar.cpp:152
void Invalidate() override
Definition: SEScalar.cpp:85
virtual std::string ToString() const
Definition: SEScalar.cpp:239
double Multiply(double d)
Definition: SEScalar.cpp:208
bool IsReadOnly() const
Definition: SEScalar.cpp:133
bool IsPositive() const
Definition: SEScalar.cpp:115
double m_value
Definition: SEScalar.h:22
bool IsZero(double limit=ZERO_APPROX) const
Definition: SEScalar.cpp:108
bool IsNegative() const
Definition: SEScalar.cpp:122
double ForceIncrement(double d)
Definition: SEScalar.cpp:197
double Increment(const SEScalar &s)
Definition: SEScalar.cpp:177
Definition: SEScalar.h:208
bool Force(const SEScalar &s) override
Definition: SEScalar.hxx:80
double GetValue() const =delete
void ForceValue(double d, const CCompoundUnit &unit) override
Definition: SEScalar.hxx:189
void Invalidate() override
Definition: SEScalar.hxx:14
bool IsValid() const override
Definition: SEScalar.hxx:28
void SetValue(double d)=delete
void ForceInvalidate() override
Definition: SEScalar.hxx:21
const Unit * GetUnit() const override
Definition: SEScalar.hxx:145
double GetValue(int precision) const =delete
double Increment(double d)=delete
void ForceValue(double d)=delete
const Unit * m_unit
Definition: SEScalar.h:271
bool HasUnit() const override
Definition: SEScalar.hxx:140
const CCompoundUnit * GetCompoundUnit(const std::string &unit) const override
Definition: SEScalar.hxx:267
bool Set(const SEScalar &s) override
Definition: SEScalar.hxx:38
SEScalarQuantity()
Definition: SEScalar.h:211
std::string ToString() const override
Definition: SEScalar.hxx:273
void Copy(const SEScalar &s) override
Definition: SEScalar.hxx:65
double Increment(const SEScalar &s)=delete
void SetValue(double d, const CCompoundUnit &unit) override
Definition: SEScalar.hxx:181
double Increment(double d, const CCompoundUnit &unit) override
Definition: SEScalar.hxx:220
virtual ~SEScalarQuantity()
Definition: SEScalar.hxx:8
bool Equals(const SEScalar &to) const =delete
double ForceIncrement(double d)=delete
double ForceIncrement(double d, const CCompoundUnit &unit) override
Definition: SEScalar.hxx:241
An interface to be used for gaining access to a scalar with any unit type
Definition: SEScalar.h:178
SEUnitScalar()
Definition: SEScalar.h:183
bool IsValid() const override=0
void ForceInvalidate() override=0
friend SEGenericScalar
Definition: SEScalar.h:180
virtual ~SEUnitScalar()
Definition: SEScalar.h:184
virtual bool Set(const SEScalar &s)=0
virtual void SetValue(double d, const CCompoundUnit &unit)=0
virtual double GetValue(const CCompoundUnit &unit, int decimal_places) const =0
virtual bool HasUnit() const =0
virtual double GetValue(const CCompoundUnit &unit) const =0
virtual void Copy(const SEScalar &s)=0
virtual bool Force(const SEScalar &s)=0
virtual double ForceIncrement(double d, const CCompoundUnit &unit)=0
virtual const CCompoundUnit * GetUnit() const =0
virtual void ForceValue(double d, const CCompoundUnit &unit)=0
void Invalidate() override=0
virtual double Increment(double d, const CCompoundUnit &unit)=0
virtual const CCompoundUnit * GetCompoundUnit(const std::string &unit) const =0