/usr/include/ignition/math2/ignition/math/Temperature.hh is in libignition-math2-dev 2.9.0+dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | /*
* Copyright (C) 2016 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef IGNITION_MATH_TEMPERATURE_HH_
#define IGNITION_MATH_TEMPERATURE_HH_
#include <iostream>
#include <memory>
#include "ignition/math/Helpers.hh"
namespace ignition
{
namespace math
{
// Forward declare private data class.
class TemperaturePrivate;
/// \brief A class that stores temperature information, and allows
/// conversion between different units.
///
/// This class is mostly for convenience. It can be used to easily
/// convert between temperature units and encapsulate temperature values.
///
/// The default unit is Kelvin. Most functions that accept a double
/// value will assume the double is Kelvin. The exceptions are a few of
/// the conversion functions, such as CelsiusToFahrenheit. Similarly,
/// most doubles that are returned will be in Kelvin.
///
/// ## Example usage ##
///
/// ### Convert from Kelvin to Celsius ###
///
/// double celsius = ignition::math::Temperature::KelvinToCelsius(2.5);
///
/// ### Create and use a Temperature object ###
///
/// ignition::math::Temperature temp(123.5);
/// std::cout << "Temperature in Kelvin = " << temp << std::endl;
/// std::cout << "Temperature in Celsius = "
/// << temp.Celsius() << std::endl;
///
/// temp += 100.0;
/// std::cout << "Temperature + 100.0 = " << temp << "K" << std::endl;
///
/// ignition::math::Temperature newTemp(temp);
/// newTemp += temp + 23.5;
/// std::cout << "Copied the temp object and added 23.5K. newTemp = "
/// << newTemp.Fahrenheit() << "F" << std::endl;
///
class IGNITION_VISIBLE Temperature
{
/// \brief Default constructor
public: Temperature();
/// \brief Kelvin value constructor. This is a conversion constructor
/// \param[in] _temp Temperature in Kelvin
// cppcheck-suppress noExplicitConstructor
public: Temperature(const double _temp);
/// \brief Copy constructor
/// \param[in] _temp Temperature object to copy.
public: Temperature(const Temperature &_temp);
/// \brief Destructor
public: virtual ~Temperature();
/// \brief Convert Kelvin to Celsius
/// \param[in] _temp Temperature in Kelvin
/// \return Temperature in Celsius
public: static double KelvinToCelsius(const double _temp);
/// \brief Convert Kelvin to Fahrenheit
/// \param[in] _temp Temperature in Kelvin
/// \return Temperature in Fahrenheit
public: static double KelvinToFahrenheit(const double _temp);
/// \brief Convert Celsius to Fahrenheit
/// \param[in] _temp Temperature in Celsius
/// \return Temperature in Fahrenheit
public: static double CelsiusToFahrenheit(const double _temp);
/// \brief Convert Celsius to Kelvin
/// \param[in] _temp Temperature in Celsius
/// \return Temperature in Kelvin
public: static double CelsiusToKelvin(const double _temp);
/// \brief Convert Fahrenheit to Celsius
/// \param[in] _temp Temperature in Fahrenheit
/// \return Temperature in Celsius
public: static double FahrenheitToCelsius(const double _temp);
/// \brief Convert Fahrenheit to Kelvin
/// \param[in] _temp Temperature in Fahrenheit
/// \return Temperature in Kelvin
public: static double FahrenheitToKelvin(const double _temp);
/// \brief Set the temperature from a Kelvin value
/// \param[in] _temp Temperature in Kelvin
public: void SetKelvin(const double _temp);
/// \brief Set the temperature from a Celsius value
/// \param[in] _temp Temperature in Celsius
public: void SetCelsius(const double _temp);
/// \brief Set the temperature from a Fahrenheit value
/// \param[in] _temp Temperature in Fahrenheit
public: void SetFahrenheit(const double _temp);
/// \brief Get the temperature in Kelvin
/// \return Temperature in Kelvin
public: double Kelvin() const;
/// \brief Get the temperature in Celsius
/// \return Temperature in Celsius
public: double Celsius() const;
/// \brief Get the temperature in Fahrenheit
/// \return Temperature in Fahrenheit
public: double Fahrenheit() const;
/// \brief Accessor operator
/// \return Temperature in Kelvin
/// \sa Kelvin()
public: double operator()() const;
/// \brief Assignment operator
/// \param[in] _temp Temperature in Kelvin
/// \return Reference to this instance
public: Temperature &operator=(const double _temp);
/// \brief Assignment operator
/// \param[in] _temp Temperature object
/// \return Reference to this instance
public: Temperature &operator=(const Temperature &_temp);
/// \brief Addition operator
/// \param[in] _temp Temperature in Kelvin
/// \return Resulting temperature
public: Temperature operator+(const double _temp);
/// \brief Addition operator
/// \param[in] _temp Temperature object
/// \return Resulting temperature
public: Temperature operator+(const Temperature &_temp);
/// \brief Addition operator for double type.
/// \param[in] _t Temperature in kelvin
/// \param[in] _temp Temperature object
/// \return Resulting temperature
public: friend Temperature operator+(double _t, const Temperature &_temp)
{
return _t + _temp.Kelvin();
}
/// \brief Addition assignment operator
/// \param[in] _temp Temperature in Kelvin
/// \return Reference to this instance
public: const Temperature &operator+=(const double _temp);
/// \brief Addition assignment operator
/// \param[in] _temp Temperature object
/// \return Reference to this instance
public: const Temperature &operator+=(const Temperature &_temp);
/// \brief Subtraction operator
/// \param[in] _temp Temperature in Kelvin
/// \return Resulting temperature
public: Temperature operator-(const double _temp);
/// \brief Subtraction operator
/// \param[in] _temp Temperature object
/// \return Resulting temperature
public: Temperature operator-(const Temperature &_temp);
/// \brief Subtraction operator for double type.
/// \param[in] _t Temperature in kelvin
/// \param[in] _temp Temperature object
/// \return Resulting temperature
public: friend Temperature operator-(double _t, const Temperature &_temp)
{
return _t - _temp.Kelvin();
}
/// \brief Subtraction assignment operator
/// \param[in] _temp Temperature in Kelvin
/// \return Reference to this instance
public: const Temperature &operator-=(const double _temp);
/// \brief Subtraction assignment operator
/// \param[in] _temp Temperature object
/// \return Reference to this instance
public: const Temperature &operator-=(const Temperature &_temp);
/// \brief Multiplication operator
/// \param[in] _temp Temperature in Kelvin
/// \return Resulting temperature
public: Temperature operator*(const double _temp);
/// \brief Multiplication operator
/// \param[in] _temp Temperature object
/// \return Resulting temperature
public: Temperature operator*(const Temperature &_temp);
/// \brief Multiplication operator for double type.
/// \param[in] _t Temperature in kelvin
/// \param[in] _temp Temperature object
/// \return Resulting temperature
public: friend Temperature operator*(double _t, const Temperature &_temp)
{
return _t * _temp.Kelvin();
}
/// \brief Multiplication assignment operator
/// \param[in] _temp Temperature in Kelvin
/// \return Reference to this instance
public: const Temperature &operator*=(const double _temp);
/// \brief Multiplication assignment operator
/// \param[in] _temp Temperature object
/// \return Reference to this instance
public: const Temperature &operator*=(const Temperature &_temp);
/// \brief Division operator
/// \param[in] _temp Temperature in Kelvin
/// \return Resulting temperature
public: Temperature operator/(const double _temp);
/// \brief Division operator
/// \param[in] _temp Temperature object
/// \return Resulting temperature
public: Temperature operator/(const Temperature &_temp);
/// \brief Division operator for double type.
/// \param[in] _t Temperature in kelvin
/// \param[in] _temp Temperature object
/// \return Resulting temperature
public: friend Temperature operator/(double _t, const Temperature &_temp)
{
return _t / _temp.Kelvin();
}
/// \brief Division assignment operator
/// \param[in] _temp Temperature in Kelvin
/// \return Reference to this instance
public: const Temperature &operator/=(const double _temp);
/// \brief Division assignment operator
/// \param[in] _temp Temperature object
/// \return Reference to this instance
public: const Temperature &operator/=(const Temperature &_temp);
/// \brief Equal to operator
/// \param[in] _temp The temperature to compare
/// \return true if the temperatures are the same, false otherwise
public: bool operator==(const Temperature &_temp) const;
/// \brief Equal to operator, where the value of _temp is assumed to
/// be in Kelvin
/// \param[in] _temp The temperature (in Kelvin) to compare
/// \return true if the temperatures are the same, false otherwise
public: bool operator==(const double _temp) const;
/// \brief Inequality to operator
/// \param[in] _temp The temperature to compare
/// \return false if the temperatures are the same, true otherwise
public: bool operator!=(const Temperature &_temp) const;
/// \brief Inequality to operator, where the value of _temp is assumed to
/// be in Kelvin
/// \param[in] _temp The temperature (in Kelvin) to compare
/// \return false if the temperatures are the same, true otherwise
public: bool operator!=(const double _temp) const;
/// \brief Less than to operator
/// \param[in] _temp The temperature to compare
/// \return True if this is less than _temp.
public: bool operator<(const Temperature &_temp) const;
/// \brief Less than operator, where the value of _temp is assumed to
/// be in Kelvin
/// \param[in] _temp The temperature (in Kelvin) to compare
/// \return True if this is less than _temp.
public: bool operator<(const double _temp) const;
/// \brief Less than or equal to operator
/// \param[in] _temp The temperature to compare
/// \return True if this is less than or equal _temp.
public: bool operator<=(const Temperature &_temp) const;
/// \brief Less than or equal operator,
/// where the value of _temp is assumed to be in Kelvin
/// \param[in] _temp The temperature (in Kelvin) to compare
/// \return True if this is less than or equal to _temp.
public: bool operator<=(const double _temp) const;
/// \brief Greater than operator
/// \param[in] _temp The temperature to compare
/// \return True if this is greater than _temp.
public: bool operator>(const Temperature &_temp) const;
/// \brief Greater than operator, where the value of _temp is assumed to
/// be in Kelvin
/// \param[in] _temp The temperature (in Kelvin) to compare
/// \return True if this is greater than _temp.
public: bool operator>(const double _temp) const;
/// \brief Greater than or equal to operator
/// \param[in] _temp The temperature to compare
/// \return True if this is greater than or equal to _temp.
public: bool operator>=(const Temperature &_temp) const;
/// \brief Greater than equal operator,
/// where the value of _temp is assumed to be in Kelvin
/// \param[in] _temp The temperature (in Kelvin) to compare
/// \return True if this is greater than or equal to _temp.
public: bool operator>=(const double _temp) const;
/// \brief Stream insertion operator
/// \param[in] _out the output stream
/// \param[in] _temp Temperature to write to the stream
/// \return the output stream
public: friend std::ostream &operator<<(std::ostream &_out,
const ignition::math::Temperature &_temp)
{
_out << _temp.Kelvin();
return _out;
}
/// \brief Stream extraction operator
/// \param[in] _in the input stream
/// \param[in] _temp Temperature to read from to the stream. Assumes
/// temperature value is in Kelvin.
/// \return the input stream
public: friend std::istream &operator>>(std::istream &_in,
ignition::math::Temperature &_temp)
{
// Skip white spaces
_in.setf(std::ios_base::skipws);
double kelvin;
_in >> kelvin;
_temp.SetKelvin(kelvin);
return _in;
}
#ifdef _WIN32
// Disable warning C4251 which is triggered by
// std::unique_ptr
#pragma warning(push)
#pragma warning(disable: 4251)
#endif
/// \brief Private data pointer.
private: std::unique_ptr<TemperaturePrivate> dataPtr;
#ifdef _WIN32
#pragma warning(pop)
#endif
};
}
}
#endif
|