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/Helpers.hh"
24 
25 namespace ignition
26 {
27  namespace math
28  {
29  // Forward declare private data class.
30  class TemperaturePrivate;
31 
65  {
67  public: Temperature();
68 
71  // cppcheck-suppress noExplicitConstructor
72  public: Temperature(const double _temp);
73 
76  public: Temperature(const Temperature &_temp);
77 
79  public: virtual ~Temperature();
80 
84  public: static double KelvinToCelsius(const double _temp);
85 
89  public: static double KelvinToFahrenheit(const double _temp);
90 
94  public: static double CelsiusToFahrenheit(const double _temp);
95 
99  public: static double CelsiusToKelvin(const double _temp);
100 
104  public: static double FahrenheitToCelsius(const double _temp);
105 
109  public: static double FahrenheitToKelvin(const double _temp);
110 
113  public: void SetKelvin(const double _temp);
114 
117  public: void SetCelsius(const double _temp);
118 
121  public: void SetFahrenheit(const double _temp);
122 
125  public: double Kelvin() const;
126 
129  public: double Celsius() const;
130 
133  public: double Fahrenheit() const;
134 
138  public: double operator()() const;
139 
143  public: Temperature &operator=(const double _temp);
144 
148  public: Temperature &operator=(const Temperature &_temp);
149 
153  public: Temperature operator+(const double _temp);
154 
158  public: Temperature operator+(const Temperature &_temp);
159 
164  public: friend Temperature operator+(double _t, const Temperature &_temp)
165  {
166  return _t + _temp.Kelvin();
167  }
168 
172  public: const Temperature &operator+=(const double _temp);
173 
177  public: const Temperature &operator+=(const Temperature &_temp);
178 
182  public: Temperature operator-(const double _temp);
183 
187  public: Temperature operator-(const Temperature &_temp);
188 
193  public: friend Temperature operator-(double _t, const Temperature &_temp)
194  {
195  return _t - _temp.Kelvin();
196  }
197 
201  public: const Temperature &operator-=(const double _temp);
202 
206  public: const Temperature &operator-=(const Temperature &_temp);
207 
211  public: Temperature operator*(const double _temp);
212 
216  public: Temperature operator*(const Temperature &_temp);
217 
222  public: friend Temperature operator*(double _t, const Temperature &_temp)
223  {
224  return _t * _temp.Kelvin();
225  }
226 
230  public: const Temperature &operator*=(const double _temp);
231 
235  public: const Temperature &operator*=(const Temperature &_temp);
236 
240  public: Temperature operator/(const double _temp);
241 
245  public: Temperature operator/(const Temperature &_temp);
246 
251  public: friend Temperature operator/(double _t, const Temperature &_temp)
252  {
253  return _t / _temp.Kelvin();
254  }
255 
259  public: const Temperature &operator/=(const double _temp);
260 
264  public: const Temperature &operator/=(const Temperature &_temp);
265 
269  public: bool operator==(const Temperature &_temp) const;
270 
275  public: bool operator==(const double _temp) const;
276 
280  public: bool operator!=(const Temperature &_temp) const;
281 
286  public: bool operator!=(const double _temp) const;
287 
291  public: bool operator<(const Temperature &_temp) const;
292 
297  public: bool operator<(const double _temp) const;
298 
302  public: bool operator<=(const Temperature &_temp) const;
303 
308  public: bool operator<=(const double _temp) const;
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 
336  public: friend std::ostream &operator<<(std::ostream &_out,
337  const ignition::math::Temperature &_temp)
338  {
339  _out << _temp.Kelvin();
340  return _out;
341  }
342 
348  public: friend std::istream &operator>>(std::istream &_in,
350  {
351  // Skip white spaces
352  _in.setf(std::ios_base::skipws);
353 
354  double kelvin;
355  _in >> kelvin;
356 
357  _temp.SetKelvin(kelvin);
358  return _in;
359  }
360 
361 #ifdef _WIN32
362 // Disable warning C4251 which is triggered by
363 // std::unique_ptr
364 #pragma warning(push)
365 #pragma warning(disable: 4251)
366 #endif
367  private: std::unique_ptr<TemperaturePrivate> dataPtr;
369 #ifdef _WIN32
370 #pragma warning(pop)
371 #endif
372  };
373  }
374 }
375 #endif
void SetKelvin(const double _temp)
Set the temperature from a Kelvin value.
A class that stores temperature information, and allows conversion between different units...
Definition: Temperature.hh:64
friend Temperature operator*(double _t, const Temperature &_temp)
Multiplication operator for double type.
Definition: Temperature.hh:222
friend std::istream & operator>>(std::istream &_in, ignition::math::Temperature &_temp)
Stream extraction operator.
Definition: Temperature.hh:348
#define IGNITION_VISIBLE
Use to represent "symbol visible" if supported.
Definition: System.hh:59
friend Temperature operator/(double _t, const Temperature &_temp)
Division operator for double type.
Definition: Temperature.hh:251
friend Temperature operator+(double _t, const Temperature &_temp)
Addition operator for double type.
Definition: Temperature.hh:164
friend std::ostream & operator<<(std::ostream &_out, const ignition::math::Temperature &_temp)
Stream insertion operator.
Definition: Temperature.hh:336
friend Temperature operator-(double _t, const Temperature &_temp)
Subtraction operator for double type.
Definition: Temperature.hh:193
Definition: Angle.hh:38
double Kelvin() const
Get the temperature in Kelvin.