SEScalarQuantity.h
1 /**************************************************************************************
2 Copyright 2015 Applied Research Associates, Inc.
3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 this file except in compliance with the License. You may obtain a copy of the License
5 at:
6 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software distributed under
8 the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9 CONDITIONS OF ANY KIND, either express or implied. See the License for the
10 specific language governing permissions and limitations under the License.
11 **************************************************************************************/
12 
13 #pragma once
14 #include <biogears/cdm/properties/SEScalar.h>
15 #include <biogears/cdm/properties/SEUnitScalar.h>
16 #include <biogears/cdm/utils/unitconversion/CompoundUnit.h>
17 
18 CDM_BIND_DECL(ScalarData)
19 
20 namespace biogears {
21 
22 
23 template <typename Unit>
25 public:
28  explicit SEScalarQuantity(double, const Unit&);
29  ~SEScalarQuantity() override;
30 
31  void Clear() override;
32  void Invalidate() override;
33  bool IsValid() const override;
34 
35  virtual void Load(const CDM::ScalarData& in) override;
36  virtual CDM::ScalarData* Unload() const override;
37 
38  virtual bool Set(const SEScalarQuantity<Unit>& s);
39  void Copy(const SEScalarQuantity<Unit>& s);
40 
41  void SetValue(double d, const Unit& unit);
42  virtual double GetValue(const Unit& unit) const;
43  virtual double GetValue() const final;
44 
45  double GetValue(const char* unit) const override;
46  double GetValue(const std::string& unit) const override;
47 
48  const Unit* GetUnit() const override;
49 
50  SEScalarQuantity& IncrementValue(double d, const char* unit) override;
51  SEScalarQuantity& IncrementValue(double d, const std::string& unit) override;
52  SEScalarQuantity& IncrementValue(double d, const Unit& unit);
53  SEScalarQuantity& Increment(const SEScalarQuantity& s);
54  SEScalarQuantity& DecrementValue(double d, const char* unit) override;
55  SEScalarQuantity& DecrementValue(double d, const std::string& unit) override;
56  SEScalarQuantity& DecrementValue(double d, const Unit& unit);
57  SEScalarQuantity& Decrement(const SEScalarQuantity& s);
58  SEScalarQuantity& MultiplyValue(double d);
59  SEScalarQuantity& Multiply(const SEScalar& s);
60  SEScalarQuantity& DivideValue(double d);
61  SEScalarQuantity& Divide(const SEScalar& s);
62 
63  bool operator<(const SEScalarQuantity& rhs) const;
64  bool operator<=(const SEScalarQuantity& rhs) const;
65  bool operator>(const SEScalarQuantity& rhs) const;
66  bool operator>=(const SEScalarQuantity& rhs) const;
67 
68  bool operator==(const SEScalarQuantity& rhs) const;
69  bool operator!=(const SEScalarQuantity& rhs) const;
70 
72  SEScalarQuantity& operator+=(const SEScalarQuantity& rhs);
74  SEScalarQuantity& operator-=(const SEScalarQuantity& rhs);
75  SEScalarQuantity operator/(const SEScalar& rhs) const;
77  SEScalarQuantity operator*(const SEScalar& rhs) const;
79 
80  virtual bool Equals(const SEScalarQuantity<Unit>& to) const;
81 
82  virtual void ToString(std::ostream& str) const override;
83 
84  const Unit* GetCompoundUnit(const char* unit) const override;
85  const Unit* GetCompoundUnit(const std::string& unit) const override;
86 protected:
87  virtual void Unload(CDM::ScalarData& s) const override;
88 
89 
90 protected:
91  const Unit* m_unit;
92 };
93 
94 //-------------------------------------------------------------------------------
95 template <class Unit>
97 {
98  bool b = to.IsReadOnly();
99  to.SetReadOnly(false);
100  to.Set(from);
101  to.SetReadOnly(b);
102 }
103 //-------------------------------------------------------------------------------
104 template <class Unit>
105 inline void ValueOverride(SEScalarQuantity<Unit>& s, double value, const Unit& unit)
106 {
107  bool b = s.IsReadOnly();
108  s.SetReadOnly(false);
109  s.SetValue(value, unit);
110  s.SetReadOnly(b);
111 }
112 //-------------------------------------------------------------------------------
113 template <class Unit>
114 inline void IncrementOverride(SEScalarQuantity<Unit>& s, double value, const Unit& unit)
115 {
116  bool b = s.IsReadOnly();
117  s.SetReadOnly(false);
118  s.IncrementValue(value, unit);
119  s.SetReadOnly(b);
120 }
121 //-------------------------------------------------------------------------------
122 }
123 #include <biogears/cdm/properties/SEScalarQuantity.inl>
bool operator>=(double lhs, const SEScalar &rhs)
Definition: SEScalar.h:127
bool operator<=(double lhs, const SEScalar &rhs)
Definition: SEScalar.h:125
bool IsReadOnly() const
Definition: SEScalar.cpp:177
Definition: SEScalar.h:33
void Copy(const std::vector< T * > &from, std::vector< T * > &to)
Definition: Macros.h:69
const Unit * m_unit
Definition: SEScalarQuantity.h:91
void Override(const SEScalar &from, SEScalar &to)
Definition: SEScalar.h:145
Definition: SEScalarQuantity.h:24
SEScalar operator+(double lhs, const SEScalar &rhs)
Definition: SEScalar.h:120
CPScalar & operator*=(CPScalar &lhs, const T &rhs)
Definition: PScalar.h:376
bool operator!=(double lhs, const SEScalar &rhs)
Definition: SEScalar.h:129
SEScalarQuantity & IncrementValue(double d, const char *unit) override
SEScalar operator/(double lhs, const SEScalar &rhs)
Definition: SEScalar.h:122
void ValueOverride(SEScalar &s, double value)
Definition: SEScalar.h:154
SEScalar operator*(double lhs, const SEScalar &rhs)
Definition: SEScalar.h:123
Class corresponding to the ScalarData schema type.
Definition: Properties.hxx:3007
bool operator==(double lhs, const SEScalar &rhs)
Definition: SEScalar.h:128
void SetValue(double d, const Unit &unit)
bool operator>(double lhs, const SEScalar &rhs)
Definition: SEScalar.h:126
bool operator<(double lhs, const SEScalar &rhs)
Definition: SEScalar.h:124
CPScalar & operator/=(CPScalar &lhs, const T &rhs)
Definition: PScalar.h:396
SEScalar operator-(double lhs, const SEScalar &rhs)
Definition: SEScalar.h:121
void SetReadOnly(bool b)
Definition: SEScalar.cpp:172
virtual bool Set(const SEScalarQuantity< Unit > &s)
Definition: SEUnitScalar.h:18
Definition: SEElectricalCircuit.h:18
void IncrementOverride(SEScalar &s, double value)
Definition: SEScalar.h:162