Temperature.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_MATH_TEMPERATURE_HH_
18 #define IGNITION_MATH_TEMPERATURE_HH_
19 
20 #include <iostream>
21 #include <memory>
22 
23 #include <ignition/math/config.hh>
24 #include "ignition/math/Helpers.hh"
25 
26 namespace ignition
27 {
28  namespace math
29  {
30  inline namespace IGNITION_MATH_VERSION_NAMESPACE
31  {
32  // Forward declare private data class.
33  class TemperaturePrivate;
34 
67  class IGNITION_MATH_VISIBLE Temperature
68  {
70  public: Temperature();
71 
74  // cppcheck-suppress noExplicitConstructor
75  public: Temperature(const double _temp);
76 
79  public: Temperature(const Temperature &_temp);
80 
82  public: virtual ~Temperature();
83 
87  public: static double KelvinToCelsius(const double _temp);
88 
92  public: static double KelvinToFahrenheit(const double _temp);
93 
97  public: static double CelsiusToFahrenheit(const double _temp);
98 
102  public: static double CelsiusToKelvin(const double _temp);
103 
107  public: static double FahrenheitToCelsius(const double _temp);
108 
112  public: static double FahrenheitToKelvin(const double _temp);
113 
116  public: void SetKelvin(const double _temp);
117 
120  public: void SetCelsius(const double _temp);
121 
124  public: void SetFahrenheit(const double _temp);
125 
128  public: double Kelvin() const;
129 
132  public: double Celsius() const;
133 
136  public: double Fahrenheit() const;
137 
141  public: double operator()() const;
142 
146  public: Temperature &operator=(const double _temp);
147 
151  public: Temperature &operator=(const Temperature &_temp);
152 
156  public: Temperature operator+(const double _temp);
157 
161  public: Temperature operator+(const Temperature &_temp);
162 
167  public: friend Temperature operator+(double _t, const Temperature &_temp)
168  {
169  return _t + _temp.Kelvin();
170  }
171 
175  public: const Temperature &operator+=(const double _temp);
176 
180  public: const Temperature &operator+=(const Temperature &_temp);
181 
185  public: Temperature operator-(const double _temp);
186 
190  public: Temperature operator-(const Temperature &_temp);
191 
196  public: friend Temperature operator-(double _t, const Temperature &_temp)
197  {
198  return _t - _temp.Kelvin();
199  }
200 
204  public: const Temperature &operator-=(const double _temp);
205 
209  public: const Temperature &operator-=(const Temperature &_temp);
210 
214  public: Temperature operator*(const double _temp);
215 
219  public: Temperature operator*(const Temperature &_temp);
220 
225  public: friend Temperature operator*(double _t, const Temperature &_temp)
226  {
227  return _t * _temp.Kelvin();
228  }
229 
233  public: const Temperature &operator*=(const double _temp);
234 
238  public: const Temperature &operator*=(const Temperature &_temp);
239 
243  public: Temperature operator/(const double _temp);
244 
248  public: Temperature operator/(const Temperature &_temp);
249 
254  public: friend Temperature operator/(double _t, const Temperature &_temp)
255  {
256  return _t / _temp.Kelvin();
257  }
258 
262  public: const Temperature &operator/=(const double _temp);
263 
267  public: const Temperature &operator/=(const Temperature &_temp);
268 
272  public: bool operator==(const Temperature &_temp) const;
273 
278  public: bool operator==(const double _temp) const;
279 
283  public: bool operator!=(const Temperature &_temp) const;
284 
289  public: bool operator!=(const double _temp) const;
290 
294  public: bool operator<(const Temperature &_temp) const;
295 
300  public: bool operator<(const double _temp) const;
301 
305  public: bool operator<=(const Temperature &_temp) const;
306 
311  public: bool operator<=(const double _temp) const;
312 
316  public: bool operator>(const Temperature &_temp) const;
317 
322  public: bool operator>(const double _temp) const;
323 
327  public: bool operator>=(const Temperature &_temp) const;
328 
333  public: bool operator>=(const double _temp) const;
334 
339  public: friend std::ostream &operator<<(std::ostream &_out,
340  const ignition::math::Temperature &_temp)
341  {
342  _out << _temp.Kelvin();
343  return _out;
344  }
345 
351  public: friend std::istream &operator>>(std::istream &_in,
353  {
354  // Skip white spaces
355  _in.setf(std::ios_base::skipws);
356 
357  double kelvin;
358  _in >> kelvin;
359 
360  _temp.SetKelvin(kelvin);
361  return _in;
362  }
363 
364 #ifdef _WIN32
365 // Disable warning C4251 which is triggered by
366 // std::unique_ptr
367 #pragma warning(push)
368 #pragma warning(disable: 4251)
369 #endif
371  private: std::unique_ptr<TemperaturePrivate> dataPtr;
372 #ifdef _WIN32
373 #pragma warning(pop)
374 #endif
375  };
376  }
377  }
378 }
379 #endif
A class that stores temperature information, and allows conversion between different units.
Definition: Temperature.hh:68
friend Temperature operator/(double _t, const Temperature &_temp)
Division operator for double type.
Definition: Temperature.hh:254
void SetFahrenheit(const double _temp)
Set the temperature from a Fahrenheit value.
const Temperature & operator*=(const Temperature &_temp)
Multiplication assignment operator.
const Temperature & operator*=(const double _temp)
Multiplication assignment operator.
const Temperature & operator/=(const Temperature &_temp)
Division assignment operator.
double Kelvin() const
Get the temperature in Kelvin.
Temperature operator-(const double _temp)
Subtraction operator.
Temperature operator-(const Temperature &_temp)
Subtraction operator.
static double FahrenheitToKelvin(const double _temp)
Convert Fahrenheit to Kelvin.
Temperature & operator=(const Temperature &_temp)
Assignment operator.
const Temperature & operator+=(const double _temp)
Addition assignment operator.
bool operator==(const Temperature &_temp) const
Equal to operator.
Temperature(const Temperature &_temp)
Copy constructor.
bool operator!=(const Temperature &_temp) const
Inequality to operator.
bool operator==(const double _temp) const
Equal to operator, where the value of _temp is assumed to be in Kelvin.
bool operator>=(const double _temp) const
Greater than equal operator, where the value of _temp is assumed to be in Kelvin.
const Temperature & operator-=(const double _temp)
Subtraction assignment operator.
friend Temperature operator*(double _t, const Temperature &_temp)
Multiplication operator for double type.
Definition: Temperature.hh:225
Temperature operator*(const double _temp)
Multiplication operator.
friend Temperature operator+(double _t, const Temperature &_temp)
Addition operator for double type.
Definition: Temperature.hh:167
const Temperature & operator-=(const Temperature &_temp)
Subtraction assignment operator.
bool operator<=(const double _temp) const
Less than or equal operator, where the value of _temp is assumed to be in Kelvin.
bool operator>=(const Temperature &_temp) const
Greater than or equal to operator.
Temperature operator+(const double _temp)
Addition operator.
Temperature operator+(const Temperature &_temp)
Addition operator.
Temperature operator/(const Temperature &_temp)
Division operator.
const Temperature & operator/=(const double _temp)
Division assignment operator.
bool operator<=(const Temperature &_temp) const
Less than or equal to operator.
static double KelvinToFahrenheit(const double _temp)
Convert Kelvin to Fahrenheit.
Temperature operator/(const double _temp)
Division operator.
void SetCelsius(const double _temp)
Set the temperature from a Celsius value.
friend std::ostream & operator<<(std::ostream &_out, const ignition::math::Temperature &_temp)
Stream insertion operator.
Definition: Temperature.hh:339
bool operator<(const double _temp) const
Less than operator, where the value of _temp is assumed to be in Kelvin.
static double CelsiusToFahrenheit(const double _temp)
Convert Celsius to Fahrenheit.
void SetKelvin(const double _temp)
Set the temperature from a Kelvin value.
Temperature operator*(const Temperature &_temp)
Multiplication operator.
Temperature & operator=(const double _temp)
Assignment operator.
friend Temperature operator-(double _t, const Temperature &_temp)
Subtraction operator for double type.
Definition: Temperature.hh:196
friend std::istream & operator>>(std::istream &_in, ignition::math::Temperature &_temp)
Stream extraction operator.
Definition: Temperature.hh:351
bool operator>(const Temperature &_temp) const
Greater than operator.
Temperature(const double _temp)
Kelvin value constructor.
bool operator>(const double _temp) const
Greater than operator, where the value of _temp is assumed to be in Kelvin.
static double FahrenheitToCelsius(const double _temp)
Convert Fahrenheit to Celsius.
bool operator!=(const double _temp) const
Inequality to operator, where the value of _temp is assumed to be in Kelvin.
static double CelsiusToKelvin(const double _temp)
Convert Celsius to Kelvin.
const Temperature & operator+=(const Temperature &_temp)
Addition assignment operator.
bool operator<(const Temperature &_temp) const
Less than to operator.
double Celsius() const
Get the temperature in Celsius.
static double KelvinToCelsius(const double _temp)
Convert Kelvin to Celsius.
double Fahrenheit() const
Get the temperature in Fahrenheit.
Definition: Angle.hh:40