Gazebo Math

API Reference

6.15.1
gz/math/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 GZ_MATH_TEMPERATURE_HH_
18 #define GZ_MATH_TEMPERATURE_HH_
19 
20 #include <iostream>
21 #include <memory>
22 
23 #include <gz/math/config.hh>
24 #include "gz/math/Helpers.hh"
25 
26 namespace ignition
27 {
28  namespace math
29  {
30  // Inline bracket to help doxygen filtering.
31  inline namespace IGNITION_MATH_VERSION_NAMESPACE {
32  //
33  // Forward declare private data class.
34  class TemperaturePrivate;
35 
68  class IGNITION_MATH_VISIBLE Temperature
69  {
71  public: Temperature();
72 
75  // cppcheck-suppress noExplicitConstructor
76  public: Temperature(const double _temp);
77 
80  public: Temperature(const Temperature &_temp);
81 
83  public: virtual ~Temperature();
84 
88  public: static double KelvinToCelsius(const double _temp);
89 
93  public: static double KelvinToFahrenheit(const double _temp);
94 
98  public: static double CelsiusToFahrenheit(const double _temp);
99 
103  public: static double CelsiusToKelvin(const double _temp);
104 
108  public: static double FahrenheitToCelsius(const double _temp);
109 
113  public: static double FahrenheitToKelvin(const double _temp);
114 
117  public: void SetKelvin(const double _temp);
118 
121  public: void SetCelsius(const double _temp);
122 
125  public: void SetFahrenheit(const double _temp);
126 
129  public: double Kelvin() const;
130 
133  public: double Celsius() const;
134 
137  public: double Fahrenheit() const;
138 
142  public: double operator()() const;
143 
147  public: Temperature &operator=(const double _temp);
148 
152  public: Temperature &operator=(const Temperature &_temp);
153 
157  public: Temperature operator+(const double _temp) const;
158 
162  public: Temperature operator+(const Temperature &_temp) const;
163 
167  public: Temperature operator+(const double _temp);
168 
172  public: Temperature operator+(const Temperature &_temp);
173 
178  public: friend Temperature operator+(double _t, const Temperature &_temp)
179  {
180  return _t + _temp.Kelvin();
181  }
182 
186  public: const Temperature &operator+=(const double _temp);
187 
191  public: const Temperature &operator+=(const Temperature &_temp);
192 
196  public: Temperature operator-(const double _temp);
197 
201  public: Temperature operator-(const Temperature &_temp);
202 
206  public: Temperature operator-(const double _temp) const;
207 
211  public: Temperature operator-(const Temperature &_temp) const;
212 
217  public: friend Temperature operator-(double _t, const Temperature &_temp)
218  {
219  return _t - _temp.Kelvin();
220  }
221 
225  public: const Temperature &operator-=(const double _temp);
226 
230  public: const Temperature &operator-=(const Temperature &_temp);
231 
235  public: Temperature operator*(const double _temp);
236 
240  public: Temperature operator*(const Temperature &_temp);
241 
245  public: Temperature operator*(const double _temp) const;
246 
250  public: Temperature operator*(const Temperature &_temp) const;
251 
256  public: friend Temperature operator*(double _t, const Temperature &_temp)
257  {
258  return _t * _temp.Kelvin();
259  }
260 
264  public: const Temperature &operator*=(const double _temp);
265 
269  public: const Temperature &operator*=(const Temperature &_temp);
270 
274  public: Temperature operator/(const double _temp);
275 
279  public: Temperature operator/(const Temperature &_temp);
280 
284  public: Temperature operator/(const double _temp) const;
285 
289  public: Temperature operator/(const Temperature &_temp) const;
290 
295  public: friend Temperature operator/(double _t, const Temperature &_temp)
296  {
297  return _t / _temp.Kelvin();
298  }
299 
303  public: const Temperature &operator/=(const double _temp);
304 
308  public: const Temperature &operator/=(const Temperature &_temp);
309 
313  public: bool operator==(const Temperature &_temp) const;
314 
319  public: bool operator==(const double _temp) const;
320 
324  public: bool operator!=(const Temperature &_temp) const;
325 
330  public: bool operator!=(const double _temp) const;
331 
335  public: bool operator<(const Temperature &_temp) const;
336 
341  public: bool operator<(const double _temp) const;
342 
346  public: bool operator<=(const Temperature &_temp) const;
347 
352  public: bool operator<=(const double _temp) const;
353 
357  public: bool operator>(const Temperature &_temp) const;
358 
363  public: bool operator>(const double _temp) const;
364 
368  public: bool operator>=(const Temperature &_temp) const;
369 
374  public: bool operator>=(const double _temp) const;
375 
380  public: friend std::ostream &operator<<(std::ostream &_out,
381  const gz::math::Temperature &_temp)
382  {
383  _out << _temp.Kelvin();
384  return _out;
385  }
386 
392  public: friend std::istream &operator>>(std::istream &_in,
393  gz::math::Temperature &_temp)
394  {
395  // Skip white spaces
396  _in.setf(std::ios_base::skipws);
397 
398  double kelvin;
399  _in >> kelvin;
400 
401  if (!_in.fail())
402  {
403  _temp.SetKelvin(kelvin);
404  }
405  return _in;
406  }
407 
408 #ifdef _WIN32
409 // Disable warning C4251 which is triggered by
410 // std::unique_ptr
411 #pragma warning(push)
412 #pragma warning(disable: 4251)
413 #endif
414  private: std::unique_ptr<TemperaturePrivate> dataPtr;
416 #ifdef _WIN32
417 #pragma warning(pop)
418 #endif
419  };
420  }
421  }
422 }
423 #endif
static double KelvinToFahrenheit(const double _temp)
Convert Kelvin to Fahrenheit.
Temperature operator*(const double _temp)
Multiplication operator.
const Temperature & operator/=(const double _temp)
Division assignment operator.
double operator()() const
Accessor operator.
void SetFahrenheit(const double _temp)
Set the temperature from a Fahrenheit value.
Definition: gz/math/AdditivelySeparableScalarField3.hh:27
friend Temperature operator+(double _t, const Temperature &_temp)
Addition operator for double type.
Definition: gz/math/Temperature.hh:178
static double FahrenheitToKelvin(const double _temp)
Convert Fahrenheit to Kelvin.
double Celsius() const
Get the temperature in Celsius.
bool operator>=(const Temperature &_temp) const
Greater than or equal to operator.
friend std::istream & operator>>(std::istream &_in, Temperature &_temp)
Stream extraction operator.
Definition: gz/math/Temperature.hh:392
bool operator<=(const Temperature &_temp) const
Less than or equal to operator.
Temperature()
Default constructor.
friend Temperature operator/(double _t, const Temperature &_temp)
Division operator for double type.
Definition: gz/math/Temperature.hh:295
bool operator!=(const Temperature &_temp) const
Inequality to operator.
const Temperature & operator+=(const double _temp)
Addition assignment operator.
static double KelvinToCelsius(const double _temp)
Convert Kelvin to Celsius.
Temperature operator/(const double _temp)
Division operator.
bool operator>(const Temperature &_temp) const
Greater than operator.
friend std::ostream & operator<<(std::ostream &_out, const Temperature &_temp)
Stream insertion operator.
Definition: gz/math/Temperature.hh:380
Temperature operator-(const double _temp)
Subtraction operator.
static double CelsiusToKelvin(const double _temp)
Convert Celsius to Kelvin.
STL class.
bool operator<(const Temperature &_temp) const
Less than to operator.
T setf(T... args)
double Fahrenheit() const
Get the temperature in Fahrenheit.
double Kelvin() const
Get the temperature in Kelvin.
void SetCelsius(const double _temp)
Set the temperature from a Celsius value.
const Temperature & operator-=(const double _temp)
Subtraction assignment operator.
T fail(T... args)
virtual ~Temperature()
Destructor.
A class that stores temperature information, and allows conversion between different units.
Definition: gz/math/Temperature.hh:68
static double FahrenheitToCelsius(const double _temp)
Convert Fahrenheit to Celsius.
friend Temperature operator-(double _t, const Temperature &_temp)
Subtraction operator for double type.
Definition: gz/math/Temperature.hh:217
friend Temperature operator*(double _t, const Temperature &_temp)
Multiplication operator for double type.
Definition: gz/math/Temperature.hh:256
Temperature operator+(const double _temp) const
Addition operator.
bool operator==(const Temperature &_temp) const
Equal to operator.
const Temperature & operator*=(const double _temp)
Multiplication assignment operator.
STL class.
static double CelsiusToFahrenheit(const double _temp)
Convert Celsius to Fahrenheit.
Temperature & operator=(const double _temp)
Assignment operator.
void SetKelvin(const double _temp)
Set the temperature from a Kelvin value.