Jamoma API  0.6.0.a19
TTDataspace.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationDataspaceLib
4  *
5  * @brief Specification for #TTDataspace, the base class of each dataspace.
6  *
7  * @authors Tim Place, Trond Lossius, ...
8  *
9  * @copyright Copyright © 2007 by Tim Place @n
10  * This code is licensed under the terms of the "New BSD License" @n
11  * http://creativecommons.org/licenses/BSD/
12  */
13 
14 
15 #include "TTDataspace.h"
16 
17 
19  inUnitTT(NULL),
20  inUnit(NULL),
21  outUnitTT(NULL),
22  outUnit(NULL)
23 {
24  unitHash = new TTHash;
25 }
26 
27 
29 {
30  delete unitHash;
33 }
34 
35 
36 TTErr TTDataspace::convert(const TTValue& input, TTValue& output)
37 {
38  if (inUnit->name == outUnit->name)
39  output = input;
40  else {
41  TTValue value;
42 
43  inUnit->convertToNeutral(input, value);
44  outUnit->convertFromNeutral(value, output);
45  }
46  return kTTErrNone;
47 }
48 
49 
51 {
52  TTSymbol newUnitClassName;
53  TTErr err;
54  TTValue v;
55 
56  if (inUnit && inUnitName == inUnit->name) // already have this one loaded
57  return kTTErrNone;
58  else {
59  err = unitHash->lookup(inUnitName, v);
60 
61  if (!err) {
62 
63  newUnitClassName = v;
64 
65  if (newUnitClassName) {
66  err = TTObjectBaseInstantiate(newUnitClassName, &inUnitTT, inUnitName); // this will free a pre-existing unit
67  inUnit = dynamic_cast<TTDataspaceUnitPtr>(inUnitTT);
68  }
69  }
70  return err;
71  }
72 }
73 
74 
76 {
77  return inUnit->name;
78 }
79 
80 
82 {
83  TTSymbol newUnitClassName;
84  TTErr err;
85  TTValue v;
86 
87  if (outUnit && outUnitName == outUnit->name) // already have this one loaded
88  return kTTErrNone;
89  else {
90  err = unitHash->lookup(outUnitName, v);
91 
92  if (!err) {
93 
94  newUnitClassName = v;
95 
96  if (newUnitClassName) {
97  err = TTObjectBaseInstantiate(newUnitClassName, &outUnitTT, outUnitName); // this will free a pre-existing unit
98  outUnit = dynamic_cast<TTDataspaceUnitPtr>(outUnitTT);
99  }
100  }
101  return err;
102  }
103 }
104 
105 
107 {
108  return outUnit->name;
109 }
110 
111 
112 void TTDataspace::registerUnit(const TTSymbol& className, const TTSymbol& unitName)
113 {
114  TTValuePtr v = new TTValue(className);
115 
116  unitHash->append(unitName, *v);
117 }
118 
119 
121 {
122  return unitHash->getKeys(unitNames);
123 }
124 
virtual ~TTDataspace()
Destructor.
Definition: TTDataspace.cpp:28
TTErr setInputUnit(TTSymbol inUnitName)
Set the input unit type for this dataspace object by it's name as a symbol.
Definition: TTDataspace.cpp:50
TTSymbol & getInputUnit()
Get the input unit type for this dataspace object as a symbol.
Definition: TTDataspace.cpp:75
TTErr TTObjectBaseRelease(TTObjectBasePtr *anObject)
DEPRECATED.
TTErr lookup(const TTSymbol key, TTValue &value)
Find the value for the given key.
Definition: TTHash.cpp:76
TTErr getAvailableUnits(TTValue &unitNames)
Return a list of all available units for this dataspace.
TTDataspace()
Constructor.
Definition: TTDataspace.cpp:18
TTErr getKeys(TTValue &hashKeys)
Get an array of all of the keys for the hash table.
Definition: TTHash.cpp:126
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
Maintain a collection of TTValue objects indexed by TTSymbol pointers.
Definition: TTHash.h:36
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
Specification for the base class of each DataspaceUnit.
TTErr append(const TTSymbol key, const TTValue &value)
Insert an item into the hash table.
Definition: TTHash.cpp:70
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
TTSymbol name
Name of this unit.
TTErr setOutputUnit(TTSymbol outUnitName)
Set the output unit type for this dataspace object by it's name as a symbol.
Definition: TTDataspace.cpp:81
TTErr convert(const TTValue &input, TTValue &output)
Converts a value from one unit to another.
Definition: TTDataspace.cpp:36
virtual void convertFromNeutral(const TTValue &input, TTValue &output)=0
Converts from a neutral unit back to an actual unit.
TTSymbol & getOutputUnit()
Get the output unit type for this dataspace object as a symbol.
Specification for TTDataspace, the base class of each dataspace.
virtual void convertToNeutral(const TTValue &input, TTValue &output)=0
Converts from an actual unit to a 'neutral' unit that can be interpreted by other units within this d...
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
void registerUnit(const TTSymbol &className, const TTSymbol &unitName)
Called by subclasses to register units with the dataspace.
No Error.
Definition: TTBase.h:343
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34