GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 0 / 1 / 1
Functions: -% 0 / 1 / 1
Branches: -% 0 / 1 / 1

src/utilities/units/OSQuantityVector.hpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #ifndef UTILITIES_UNITS_OSQUANTITYVECTOR_HPP
7 #define UTILITIES_UNITS_OSQUANTITYVECTOR_HPP
8
9 #include "../UtilitiesAPI.hpp"
10
11 #include "Unit.hpp"
12
13 #include <vector>
14
15 namespace openstudio {
16
17 class Quantity;
18
19 /** Represents a vector of \link Quantity quantities \endlink all with the same units.
20 * Provides performance improvements over directly operating on std::vector<Quantity>.
21 * The constructors and assignment operator ensure that this class behaves as "plain
22 * old data" (POD) by cloning any units information (to avoid multiple objects
23 * pointing to the exact same unit data). */
24 class UTILITIES_API OSQuantityVector
25 {
26 public:
27 /** @name Constructors and Destructors */
28 //@{
29
30 explicit OSQuantityVector(const Unit& units = Unit());
31
32 OSQuantityVector(const Unit& units, unsigned n, double value = 0.0);
33
34 OSQuantityVector(const Unit& units, const std::vector<double>& values);
35
36 explicit OSQuantityVector(const std::vector<Quantity>& values);
37
38 OSQuantityVector(const OSQuantityVector& other);
39
40 OSQuantityVector& operator=(const OSQuantityVector& other);
41
42 //@}
43 /** @name Getters and Queries */
44 //@{
45
46 /** Returns a clone of this object's units. */
47 Unit units() const;
48
49 UnitSystem system() const;
50
51 Scale scale() const;
52
53 /** Creates a vector of separate quantities. Note that it is better to do mathematical
54 * operations and convert units using OSOptionalQuantity. Only use this method once the
55 * values and units of this OSOptionalQuantity are fixed. */
56 std::vector<Quantity> quantities() const;
57
58 /** Returns the underlying values of this OSQuantityVector. */
59 std::vector<double> values() const;
60
61 Quantity getQuantity(unsigned i) const;
62
63 /** Return value is equivalent to values().empty(). */
64 bool empty() const;
65
66 /** Return value is equivalent to values().size(). */
67 unsigned size() const;
68
69 //@}
70 /** @name Setters */
71 //@{
72
73 /// Sets the scale to the one registered in ScaleFactory for 10^scaleExponent.
74 bool setScale(int scaleExponent);
75
76 /// Sets the scale to the one registered in ScaleFactory under scaleAbbreviation.
77 bool setScale(const std::string& scaleAbbreviation);
78
79 /** Pushes q onto this vector if possible, otherwise throws. */
80 void push_back(Quantity q);
81
82 /** Removes the last value in this OSQuantityVector. */
83 void pop_back();
84
85 /** Changes the size of this OSQuantityVector to n, using value to fill in any newly
86 * created elements as necessary. \post{size() == n} */
87 void resize(unsigned n, double value = 0.0);
88
89 /** Empties all values out of this OSQuantityVector. \post{size() == 0u} \post{empty()} */
90 void clear();
91
92 //@}
93 /** @name Temperature Methods
94 *
95 * Quantities that have units of temperature need several extra functions to distinguish
96 * between absolute and relative measures. */
97 //@{
98
99 /** Returns true if units().optionalCast<TemperatureUnit>(). */
100 bool isTemperature() const;
101
102 /** Throws if !units().optionalCast<TemperatureUnit>(). */
103 bool isAbsolute() const;
104
105 /** Throws if !units().optionalCast<TemperatureUnit>(). */
106 bool isRelative() const;
107
108 /** Set temperature as absolute. Throws if !units().optionalCast<TemperatureUnit>().
109 * \post{isAbsolute()} */
110 void setAsAbsolute();
111
112 /** Set temperature as relative. Throws if !units().optionalCast<TemperatureUnit>().
113 * \post{isRelative()} */
114 void setAsRelative();
115
116 //@}
117 /** @name IP Methods */
118 //@{
119
120 /** Conversions for pounds mass to pounds force. These functions will throw if
121 * !units().optionalCast<IPUnit>(). \post{units().baseUnitExponent("lbm") == 0} */
122 void lbmToLbf();
123
124 /** Conversions for pounds mass to pounds force. These functions will throw if
125 * !units().optionalCast<IPUnit>(). \post{units().baseUnitExponent("lbf") == 0} */
126 void lbfToLbm();
127
128 //@}
129 /** @name Mathematical Operators */
130 //@{
131
132 /** Adds rVector to this vector, if possible. Throws if vectors are of different size or units
133 * are different. */
134 OSQuantityVector& operator+=(OSQuantityVector rVector);
135
136 /** Adds rQuantity to this vector element-wise, if possible. Throws if units are different. */
137 OSQuantityVector& operator+=(Quantity rQuantity);
138
139 /** Subtracts rVector from this vector, if possible. Throws if vectors are of different size or
140 * units are different. */
141 OSQuantityVector& operator-=(OSQuantityVector rVector);
142
143 /** Subtracts rQuantity from this vector element-wise, if possible. Throws if units are
144 * different. */
145 OSQuantityVector& operator-=(Quantity rQuantity);
146
147 /** Multiplies all values of this vector by rQuantity. */
148 OSQuantityVector& operator*=(const Quantity& rQuantity);
149
150 /** Divides all values of this vector by rQuantity. */
151 OSQuantityVector& operator/=(const Quantity& rQuantity);
152
153 /** Multiplies all values of this vector by d. */
154 OSQuantityVector& operator*=(double d);
155
156 /** Divides all values of this vector by d. */
157 OSQuantityVector& operator/=(double d);
158
159 //@}
160 private:
161 Unit m_units;
162 std::vector<double> m_values;
163
164 − REGISTER_LOGGER("openstudio.units.OSQuantityVector")
165 };
166
167 /** \relates OSQuantityVector */
168 UTILITIES_API OSQuantityVector operator-(const OSQuantityVector& rVector);
169
170 /** \relates OSQuantityVector */
171 UTILITIES_API OSQuantityVector operator+(const OSQuantityVector& lVector, const OSQuantityVector& rVector);
172
173 /** \relates OSQuantityVector */
174 UTILITIES_API OSQuantityVector operator+(const OSQuantityVector& lVector, const Quantity& rQuantity);
175
176 /** \relates OSQuantityVector */
177 UTILITIES_API OSQuantityVector operator+(const Quantity& lQuantity, const OSQuantityVector& rVector);
178
179 /** \relates OSQuantityVector */
180 UTILITIES_API OSQuantityVector operator-(const OSQuantityVector& lVector, const OSQuantityVector& rVector);
181
182 /** \relates OSQuantityVector */
183 UTILITIES_API OSQuantityVector operator-(const OSQuantityVector& lVector, const Quantity& rQuantity);
184
185 /** \relates OSQuantityVector */
186 UTILITIES_API OSQuantityVector operator-(const Quantity& lQuantity, const OSQuantityVector& rVector);
187
188 /** \relates OSQuantityVector */
189 UTILITIES_API OSQuantityVector operator*(const OSQuantityVector& lVector, const Quantity& rQuantity);
190
191 /** \relates OSQuantityVector */
192 UTILITIES_API OSQuantityVector operator*(const OSQuantityVector& lVector, double d);
193
194 /** \relates OSQuantityVector */
195 UTILITIES_API OSQuantityVector operator*(const Quantity& lQuantity, const OSQuantityVector& rVector);
196
197 /** \relates OSQuantityVector */
198 UTILITIES_API OSQuantityVector operator*(double d, const OSQuantityVector& rVector);
199
200 /** \relates OSQuantityVector */
201 UTILITIES_API OSQuantityVector operator/(const OSQuantityVector& lVector, const Quantity& rQuantity);
202
203 /** \relates OSQuantityVector */
204 UTILITIES_API OSQuantityVector operator/(const OSQuantityVector& lVector, double d);
205
206 /** \relates OSQuantityVector */
207 UTILITIES_API Quantity dot(OSQuantityVector lVector, const OSQuantityVector& rVector);
208
209 /** \relates OSQuantityVector */
210 UTILITIES_API bool operator==(const OSQuantityVector& lVector, const OSQuantityVector& rVector);
211
212 /** \relates OSQuantityVector */
213 UTILITIES_API bool operator!=(const OSQuantityVector& lVector, const OSQuantityVector& rVector);
214
215 } // namespace openstudio
216
217 #endif // UTILITIES_UNITS_OSQUANTITYVECTOR_HPP
218