Ignition Math

API Reference

6.8.0
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 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);
158 
162  public: Temperature operator+(const Temperature &_temp);
163 
168  public: friend Temperature operator+(double _t, const Temperature &_temp)
169  {
170  return _t + _temp.Kelvin();
171  }
172 
176  public: const Temperature &operator+=(const double _temp);
177 
181  public: const Temperature &operator+=(const Temperature &_temp);
182 
186  public: Temperature operator-(const double _temp);
187 
191  public: Temperature operator-(const Temperature &_temp);
192 
197  public: friend Temperature operator-(double _t, const Temperature &_temp)
198  {
199  return _t - _temp.Kelvin();
200  }
201 
205  public: const Temperature &operator-=(const double _temp);
206 
210  public: const Temperature &operator-=(const Temperature &_temp);
211 
215  public: Temperature operator*(const double _temp);
216 
220  public: Temperature operator*(const Temperature &_temp);
221 
226  public: friend Temperature operator*(double _t, const Temperature &_temp)
227  {
228  return _t * _temp.Kelvin();
229  }
230 
234  public: const Temperature &operator*=(const double _temp);
235 
239  public: const Temperature &operator*=(const Temperature &_temp);
240 
244  public: Temperature operator/(const double _temp);
245 
249  public: Temperature operator/(const Temperature &_temp);
250 
255  public: friend Temperature operator/(double _t, const Temperature &_temp)
256  {
257  return _t / _temp.Kelvin();
258  }
259 
263  public: const Temperature &operator/=(const double _temp);
264 
268  public: const Temperature &operator/=(const Temperature &_temp);
269 
273  public: bool operator==(const Temperature &_temp) const;
274 
279  public: bool operator==(const double _temp) const;
280 
284  public: bool operator!=(const Temperature &_temp) const;
285 
290  public: bool operator!=(const double _temp) const;
291 
295  public: bool operator<(const Temperature &_temp) const;
296 
301  public: bool operator<(const double _temp) const;
302 
306  public: bool operator<=(const Temperature &_temp) const;
307 
312  public: bool operator<=(const double _temp) const;
313 
317  public: bool operator>(const Temperature &_temp) const;
318 
323  public: bool operator>(const double _temp) const;
324 
328  public: bool operator>=(const Temperature &_temp) const;
329 
334  public: bool operator>=(const double _temp) const;
335 
340  public: friend std::ostream &operator<<(std::ostream &_out,
341  const ignition::math::Temperature &_temp)
342  {
343  _out << _temp.Kelvin();
344  return _out;
345  }
346 
352  public: friend std::istream &operator>>(std::istream &_in,
354  {
355  // Skip white spaces
356  _in.setf(std::ios_base::skipws);
357 
358  double kelvin;
359  _in >> kelvin;
360 
361  if (!_in.fail())
362  {
363  _temp.SetKelvin(kelvin);
364  }
365  return _in;
366  }
367 
368 #ifdef _WIN32
369 // Disable warning C4251 which is triggered by
370 // std::unique_ptr
371 #pragma warning(push)
372 #pragma warning(disable: 4251)
373 #endif
374  private: std::unique_ptr<TemperaturePrivate> dataPtr;
376 #ifdef _WIN32
377 #pragma warning(pop)
378 #endif
379  };
380  }
381  }
382 }
383 #endif
T setf(T... args)
double Kelvin() const
Get the temperature in Kelvin.
T fail(T... args)
A class that stores temperature information, and allows conversion between different units...
Definition: Temperature.hh:68
STL class.
friend Temperature operator*(double _t, const Temperature &_temp)
Multiplication operator for double type.
Definition: Temperature.hh:226
void SetKelvin(const double _temp)
Set the temperature from a Kelvin value.
friend std::istream & operator>>(std::istream &_in, Temperature &_temp)
Stream extraction operator.
Definition: Temperature.hh:352
friend std::ostream & operator<<(std::ostream &_out, const Temperature &_temp)
Stream insertion operator.
Definition: Temperature.hh:340
friend Temperature operator/(double _t, const Temperature &_temp)
Division operator for double type.
Definition: Temperature.hh:255
friend Temperature operator+(double _t, const Temperature &_temp)
Addition operator for double type.
Definition: Temperature.hh:168
friend Temperature operator-(double _t, const Temperature &_temp)
Subtraction operator for double type.
Definition: Temperature.hh:197
Definition: Angle.hh:42
STL class.