2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
22 #include "guilib/LocalizeStrings.h"
23 #include "Temperature.h"
24 #include "utils/StringUtils.h"
26 CTemperature::CTemperature()
32 CTemperature::CTemperature(const CTemperature
& temperature
)
34 m_value
=temperature
.m_value
;
35 m_state
=temperature
.m_state
;
38 CTemperature::CTemperature(double value
)
44 bool CTemperature::operator >(const CTemperature
& right
) const
47 ASSERT(right
.IsValid());
49 if (!IsValid() || !right
.IsValid())
55 return (m_value
>right
.m_value
);
58 bool CTemperature::operator >=(const CTemperature
& right
) const
60 return operator >(right
) || operator ==(right
);
63 bool CTemperature::operator <(const CTemperature
& right
) const
66 ASSERT(right
.IsValid());
68 if (!IsValid() || !right
.IsValid())
74 return (m_value
<right
.m_value
);
77 bool CTemperature::operator <=(const CTemperature
& right
) const
79 return operator <(right
) || operator ==(right
);
82 bool CTemperature::operator ==(const CTemperature
& right
) const
85 ASSERT(right
.IsValid());
87 if (!IsValid() || !right
.IsValid())
93 return (m_value
==right
.m_value
);
96 bool CTemperature::operator !=(const CTemperature
& right
) const
98 return !operator ==(right
.m_value
);
101 const CTemperature
& CTemperature::operator =(const CTemperature
& right
)
103 m_state
=right
.m_state
;
104 m_value
=right
.m_value
;
108 const CTemperature
& CTemperature::operator +=(const CTemperature
& right
)
111 ASSERT(right
.IsValid());
113 m_value
+=right
.m_value
;
117 const CTemperature
& CTemperature::operator -=(const CTemperature
& right
)
120 ASSERT(right
.IsValid());
122 m_value
-=right
.m_value
;
126 const CTemperature
& CTemperature::operator *=(const CTemperature
& right
)
129 ASSERT(right
.IsValid());
131 m_value
*=right
.m_value
;
135 const CTemperature
& CTemperature::operator /=(const CTemperature
& right
)
138 ASSERT(right
.IsValid());
140 m_value
/=right
.m_value
;
144 CTemperature
CTemperature::operator +(const CTemperature
& right
) const
147 ASSERT(right
.IsValid());
149 CTemperature
temp(*this);
151 if (!IsValid() || !right
.IsValid())
152 temp
.SetState(invalid
);
154 temp
.m_value
+=right
.m_value
;
159 CTemperature
CTemperature::operator -(const CTemperature
& right
) const
162 ASSERT(right
.IsValid());
164 CTemperature
temp(*this);
165 if (!IsValid() || !right
.IsValid())
166 temp
.SetState(invalid
);
168 temp
.m_value
-=right
.m_value
;
173 CTemperature
CTemperature::operator *(const CTemperature
& right
) const
176 ASSERT(right
.IsValid());
178 CTemperature
temp(*this);
179 if (!IsValid() || !right
.IsValid())
180 temp
.SetState(invalid
);
182 temp
.m_value
*=right
.m_value
;
186 CTemperature
CTemperature::operator /(const CTemperature
& right
) const
189 ASSERT(right
.IsValid());
191 CTemperature
temp(*this);
192 if (!IsValid() || !right
.IsValid())
193 temp
.SetState(invalid
);
195 temp
.m_value
/=right
.m_value
;
199 CTemperature
& CTemperature::operator ++()
207 CTemperature
& CTemperature::operator --()
215 CTemperature
CTemperature::operator ++(int)
219 CTemperature
temp(*this);
224 CTemperature
CTemperature::operator --(int)
228 CTemperature
temp(*this);
233 bool CTemperature::operator >(double right
) const
240 return (m_value
>right
);
243 bool CTemperature::operator >=(double right
) const
245 return operator >(right
) || operator ==(right
);
248 bool CTemperature::operator <(double right
) const
255 return (m_value
<right
);
258 bool CTemperature::operator <=(double right
) const
260 return operator <(right
) || operator ==(right
);
263 bool CTemperature::operator ==(double right
) const
268 return (m_value
==right
);
271 bool CTemperature::operator !=(double right
) const
273 return !operator ==(right
);
276 const CTemperature
& CTemperature::operator +=(double right
)
284 const CTemperature
& CTemperature::operator -=(double right
)
292 const CTemperature
& CTemperature::operator *=(double right
)
300 const CTemperature
& CTemperature::operator /=(double right
)
308 CTemperature
CTemperature::operator +(double right
) const
312 CTemperature
temp(*this);
317 CTemperature
CTemperature::operator -(double right
) const
321 CTemperature
temp(*this);
326 CTemperature
CTemperature::operator *(double right
) const
330 CTemperature
temp(*this);
335 CTemperature
CTemperature::operator /(double right
) const
339 CTemperature
temp(*this);
344 CTemperature
CTemperature::CreateFromFahrenheit(double value
)
346 return CTemperature(value
);
349 CTemperature
CTemperature::CreateFromReaumur(double value
)
351 return CTemperature(value
*2.25f
+32.0f
);
354 CTemperature
CTemperature::CreateFromRankine(double value
)
356 return CTemperature(value
-459.67f
);
359 CTemperature
CTemperature::CreateFromRomer(double value
)
361 return CTemperature((value
-7.5f
)*24.0f
/7.0f
+32.0f
);
364 CTemperature
CTemperature::CreateFromDelisle(double value
)
366 CTemperature
temp(212.0f
- value
* 1.2f
);
370 CTemperature
CTemperature::CreateFromNewton(double value
)
372 return CTemperature(value
*60.0f
/11.0f
+32.0f
);
375 CTemperature
CTemperature::CreateFromCelsius(double value
)
377 return CTemperature(value
*1.8f
+32.0f
);
380 void CTemperature::Archive(CArchive
& ar
)
392 m_state
= CTemperature::STATE(state
);
396 void CTemperature::SetState(CTemperature::STATE state
)
401 bool CTemperature::IsValid() const
403 return (m_state
==valid
);
406 double CTemperature::ToFahrenheit() const
411 double CTemperature::ToKelvin() const
413 return (m_value
+459.67F
)/1.8f
;
416 double CTemperature::ToCelsius() const
418 return (m_value
-32.0f
)/1.8f
;
421 double CTemperature::ToReaumur() const
423 return (m_value
-32.0f
)/2.25f
;
426 double CTemperature::ToRankine() const
428 return m_value
+459.67f
;
431 double CTemperature::ToRomer() const
433 return (m_value
-32.0f
)*7.0f
/24.0f
+7.5f
;
436 double CTemperature::ToDelisle() const
438 return (212.f
-m_value
)*5.0f
/6.0f
;
441 double CTemperature::ToNewton() const
443 return (m_value
-32.0f
)*11.0f
/60.0f
;
446 double CTemperature::ToLocale() const
452 switch(g_langInfo
.GetTempUnit())
454 case CLangInfo::TEMP_UNIT_FAHRENHEIT
:
455 value
=ToFahrenheit();
457 case CLangInfo::TEMP_UNIT_KELVIN
:
460 case CLangInfo::TEMP_UNIT_CELSIUS
:
463 case CLangInfo::TEMP_UNIT_REAUMUR
:
466 case CLangInfo::TEMP_UNIT_RANKINE
:
469 case CLangInfo::TEMP_UNIT_ROMER
:
472 case CLangInfo::TEMP_UNIT_DELISLE
:
475 case CLangInfo::TEMP_UNIT_NEWTON
:
485 // Returns temperature as localized string
486 std::string
CTemperature::ToString() const
489 return g_localizeStrings
.Get(13205); // "Unknown"
491 return StringUtils::Format("%2.0f%s", ToLocale(), g_langInfo
.GetTempUnitString().c_str());