Jamoma API  0.6.0.a19
TemperatureDataspace.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationDataspaceLib
4  *
5  * @brief The #TemperatureDataspace converts between different measurement untis describing temperature.
6  *
7  * @details The neutral unit of the temperature dataspace is _Kelvin (K)_.
8  *
9  * @authors Nils Peters, Trond Lossius, Tim Peters, ...
10  *
11  * @copyright Copyright © 2007 by Tim Place @n
12  * This code is licensed under the terms of the "New BSD License" @n
13  * http://creativecommons.org/licenses/BSD/
14  */
15 
16 
17 #include "TemperatureDataspace.h"
18 
19 
20 #define thisTTClass CelsiusUnit
21 #define thisTTClassName "unit.celsius"
22 #define thisTTClassTags "dataspace.unit, temperature"
23 
25 TTDataspaceUnit(arguments)
26 {;}
27 
28 CelsiusUnit::~CelsiusUnit(){;}
29 
30 void CelsiusUnit::convertToNeutral(const TTValue& input, TTValue& output)
31 {
32 // output.resize(1);
33 // *output = atom_getfloat(inputAtoms) + 273.15;
34  output = TTFloat64(input) + 273.15;
35 }
36 
37 
38 void CelsiusUnit::convertFromNeutral(const TTValue& input, TTValue& output)
39 {
40 // output.resize(1);
41 // atom_setfloat(*outputAtoms, *input - 273.15);
42  output = TTFloat64(input) - 273.15;
43 }
44 
45 
46 #undef thisTTClass
47 #undef thisTTClassName
48 #undef thisTTClassTags
49 
50 /***********************************************************************************************/
51 
52 #define thisTTClass FahrenheitUnit
53 #define thisTTClassName "unit.fahrenheit"
54 #define thisTTClassTags "dataspace.unit, temperature"
55 
57 TTDataspaceUnit(arguments)
58 {;}
59 
60 FahrenheitUnit::~FahrenheitUnit(){;}
61 
63 {
64 // output.resize(1);
65 // *output = (atom_getfloat(inputAtoms) + 459.67) / 1.8;
66  output = (TTFloat64(input) + 459.67) / 1.8;
67 }
68 
69 
71 {
72 // output.resize(1);
73 // atom_setfloat(*outputAtoms, (*input * 1.8) - 459.67);
74  output = TTFloat64(input) * 1.8 - 459.67;
75 }
76 
77 
78 #undef thisTTClass
79 #undef thisTTClassName
80 #undef thisTTClassTags
81 
82 /***********************************************************************************************/
83 
84 #define thisTTClass KelvinUnit
85 #define thisTTClassName "unit.kelvin"
86 #define thisTTClassTags "dataspace.unit, temperature"
87 
89 TTDataspaceUnit(arguments)
90 {;}
91 
92 KelvinUnit::~KelvinUnit(){;}
93 
94 void KelvinUnit::convertToNeutral(const TTValue& input, TTValue& output)
95 {
96  output = input;
97 }
98 
99 
100 void KelvinUnit::convertFromNeutral(const TTValue& input, TTValue& output)
101 {
102  output = input;
103 }
104 
105 
106 #undef thisTTClass
107 #undef thisTTClassName
108 #undef thisTTClassTags
109 
110 /***********************************************************************************************/
111 
112 #define thisTTClass TemperatureDataspace
113 #define thisTTClassName "dataspace.temperature"
114 #define thisTTClassTags "foundationDataspaceLib, dataspace, temperature"
115 
117 {
118  // Create one of each kind of unit, and cache them in a hash
119  registerUnit(TT("unit.celsius"), TT("C"));
120  registerUnit(TT("unit.celsius"), TT("Celsius"));
121  registerUnit(TT("unit.fahrenheit"), TT("F"));
122  registerUnit(TT("unit.fahrenheit"), TT("Fahrenheit"));
123  registerUnit(TT("unit.kelvin"), TT("K"));
124  registerUnit(TT("unit.kelvin"), TT("Kelvin"));
125 
126  // Set our neutral unit (the unit through which all conversions are made)
127  neutralUnit = TT("Kelvin");
128 
129  // Now that the cache is created, we can create a set of default units
130  setInputUnit(neutralUnit);
131  setOutputUnit(neutralUnit);
132 }
133 
134 
135 TemperatureDataspace::~TemperatureDataspace()
136 {
137  ;
138 }
139 
140 #undef thisTTClass
141 #undef thisTTClassName
142 #undef thisTTClassTags
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to Celsius.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from Celsius to neutral unit.
double TTFloat64
64 bit floating point number
Definition: TTBase.h:188
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from Kelvin to neutral unit.
Specification for the base class of each DataspaceUnit.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to Fahrenheit.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to Kelvin.
TT_OBJECT_CONSTRUCTOR
Constructor macro.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from Fahrenheit to neutral unit.
The TemperatureDataspace converts between different measurement untis describing temperature.