Jamoma API  0.6.0.a19
DistanceDataspace.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationDataspaceLib
4  *
5  * @brief The #DistanceDataspace converts between different measurement untis describing distance.
6  *
7  * @details The neutral unit of the distance dataspace is _meter_.
8  *
9  * @authors Tim Place, Trond Lossius, Nils 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 "DistanceDataspace.h"
18 
19 
20 #define thisTTClass CentimeterUnit
21 #define thisTTClassName "unit.centimeter"
22 #define thisTTClassTags "dataspace.unit, distance"
23 
25 TTDataspaceUnit(arguments)
26 {;}
27 
28 CentimeterUnit::~CentimeterUnit(){;}
29 
31 {
32 // output.resize(1);
33 // *output = atom_getfloat(inputAtoms) * 0.01;
34  output = TTFloat64(input) * 0.01;
35 }
36 
37 
39 {
40 // output.resize(1);
41 // atom_setfloat(*outputAtoms, *input * 100.0);
42  output = TTFloat64(input) * 100.0;
43 }
44 
45 
46 #undef thisTTClass
47 #undef thisTTClassName
48 #undef thisTTClassTags
49 
50 /***********************************************************************************************/
51 
52 #define thisTTClass FootUnit
53 #define thisTTClassName "unit.foot"
54 #define thisTTClassTags "dataspace.unit, distance"
55 
57 TTDataspaceUnit(arguments)
58 {;}
59 
60 FootUnit::~FootUnit(){;}
61 
62 void FootUnit::convertToNeutral(const TTValue& input, TTValue& output)
63 {
64 // output.resize(1);
65 // *output = atom_getfloat(inputAtoms) / 3.281;
66  output = TTFloat64(input) / 3.281;
67 }
68 
69 
70 void FootUnit::convertFromNeutral(const TTValue& input, TTValue& output)
71 {
72 // output.resize(1);
73 // atom_setfloat(*outputAtoms, (*input * 3.281));
74  output = TTFloat64(input) * 3.281;
75 }
76 
77 
78 #undef thisTTClass
79 #undef thisTTClassName
80 #undef thisTTClassTags
81 
82 /***********************************************************************************************/
83 
84 #define thisTTClass InchUnit
85 #define thisTTClassName "unit.inch"
86 #define thisTTClassTags "dataspace.unit, distance"
87 
89 TTDataspaceUnit(arguments)
90 {;}
91 
92 InchUnit::~InchUnit(){;}
93 
94 void InchUnit::convertToNeutral(const TTValue& input, TTValue& output)
95 {
96 // output.resize(1);
97 // *output = atom_getfloat(inputAtoms) / 39.37;
98  output = TTFloat64(input) / 39.37;
99 }
100 
101 
102 void InchUnit::convertFromNeutral(const TTValue& input, TTValue& output)
103 {
104 // output.resize(1);
105 // atom_setfloat(*outputAtoms, (*input * 39.37));
106  output = TTFloat64(input) * 39.37;
107 }
108 
109 
110 #undef thisTTClass
111 #undef thisTTClassName
112 #undef thisTTClassTags
113 
114 /***********************************************************************************************/
115 
116 #define thisTTClass MeterUnit
117 #define thisTTClassName "unit.meter"
118 #define thisTTClassTags "dataspace.unit, distance"
119 
121 TTDataspaceUnit(arguments)
122 {;}
123 
124 MeterUnit::~MeterUnit(){;}
125 
126 void MeterUnit::convertToNeutral(const TTValue& input, TTValue& output)
127 {
128  output = input;
129 }
130 
131 
132 void MeterUnit::convertFromNeutral(const TTValue& input, TTValue& output)
133 {
134  output = input;
135 }
136 
137 
138 #undef thisTTClass
139 #undef thisTTClassName
140 #undef thisTTClassTags
141 
142 /***********************************************************************************************/
143 
144 #define thisTTClass DistanceDataspace
145 #define thisTTClassName "dataspace.distance"
146 #define thisTTClassTags "foundationDataspaceLib, dataspace, distance"
147 
149 {
150  // Create one of each kind of unit, and cache them in a hash
151  registerUnit(TT("unit.centimeter"), TT("cm"));
152  registerUnit(TT("unit.centimeter"), TT("centimeters"));
153  registerUnit(TT("unit.foot"), TT("'"));
154  registerUnit(TT("unit.foot"), TT("feet"));
155  registerUnit(TT("unit.inch"), TT("\""));
156  registerUnit(TT("unit.inch"), TT("inches"));
157  registerUnit(TT("unit.meter"), TT("m"));
158  registerUnit(TT("unit.meter"), TT("meters"));
159 
160  // Set our neutral unit (the unit through which all conversions are made)
161  neutralUnit = TT("meters");
162 
163  // Now that the cache is created, we can create a set of default units
164  setInputUnit(neutralUnit);
165  setOutputUnit(neutralUnit);
166 }
167 
168 
169 DistanceDataspace::~DistanceDataspace()
170 {
171  ;
172 }
173 
174 #undef thisTTClass
175 #undef thisTTClassName
176 #undef thisTTClassTags
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from centimeter 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 convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to meters.
The DistanceDataspace converts between different measurement untis describing distance.
Specification for the base class of each DataspaceUnit.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to centimeter.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from inches to neutral unit.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from feet to neutral unit.
TT_OBJECT_CONSTRUCTOR
Constructor macro.
void convertToNeutral(const TTValue &input, TTValue &output)
Convert from meters to neutral unit.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to inches.
void convertFromNeutral(const TTValue &input, TTValue &output)
Convert from neutral unit to feet.