Jamoma API  0.6.0.a19
TTDataspace.h
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 #ifndef __TTDATASPACE_H__
16 #define __TTDATASPACE_H__
17 
18 
19 // Dataspaces and Units employ C++ double-inheritance and are thus unsuitable for direct use
20 // through the usual TTObject API
21 #define TT_NO_DEPRECATION_WARNINGS
22 
23 
24 #include "TTDataspaceLib.h"
25 #include "TTDataspaceUnit.h"
26 
27 
28 /** Base class for each dataspace.
29  */
30 class TTDataspace {
31 
32  /** Pointer to the input unit as a #TTObjectBasePtr.
33  @details We maintain individual pointers to the two base-classes for dataspace units so we can quickly access both without expensive casting during operation(multiple-inheritance).
34  */
35  TTObjectBasePtr inUnitTT;
36 
37  /** Pointer to the input unit as a #TTDataspaceUnitPtr.
38  @details We maintain individual pointers to the two base-classes for dataspace units so we can quickly access both without expensive casting during operation(multiple-inheritance).
39  */
40  TTDataspaceUnitPtr inUnit;
41 
42  /** Pointer to the output unit as a #TTObjectBasePtr.
43  @details We maintain individual pointers to the two base-classes for dataspace units so we can quickly access both without expensive casting during operation(multiple-inheritance).
44  */
45  TTObjectBasePtr outUnitTT;
46 
47  /** Pointer to the output unit as a #TTDataspaceUnitPtr.
48  @details We maintain individual pointers to the two base-classes for dataspace units so we can quickly access both without expensive casting during operation(multiple-inheritance).
49  */
50  TTDataspaceUnitPtr outUnit;
51 
52  /** Map unit-names to the class-names that implement the units.
53  */
54  TTHashPtr unitHash;
55 
56 public:
57 
58  TTSymbol neutralUnit; ///< The neutral unit of the dataspace as a symbol.
59 
60  /** Constructor.
61  */
62  TTDataspace();
63 
64  /** Destructor.
65  */
66  virtual ~TTDataspace();
67 
68 
69  /**
70  @brief Converts a value from one unit to another.
71  @details Internally in the dataspace the conversion is done in two steps: First the input value is converted to the neutral unit, and that value is then converted to the output value. If a dataspace has N alternative units, this prevents us from having to provide NxN methods for conversions. Instead we make do with 2xN methods, making the DataspaceLib more manageable and scaleable.
72  @param input The input value, described using the input unit.
73  @param output The output value, converted to the output unit.
74  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
75  */
76  TTErr convert(const TTValue& input, TTValue& output);
77 
78 
79  /** Set the input unit type for this dataspace object by it's name as a symbol.
80  @param inUnitName The input unit type for this dataspace object as a symbol.
81  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
82  */
83  TTErr setInputUnit(TTSymbol inUnitName);
84 
85 
86  /** Get the input unit type for this dataspace object as a symbol.
87  @return Input unit type for this dataspace object as a symbol.
88  */
90 
91 
92  /** Set the output unit type for this dataspace object by it's name as a symbol.
93  @param outUnitName The input unit type for this dataspace object as a symbol.
94  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
95  */
96  TTErr setOutputUnit(TTSymbol outUnitName);
97 
98  /** Get the output unit type for this dataspace object as a symbol.
99  @return Output unit type for this dataspace object as a symbol.
100  */
102 
103 
104  /** Return a list of all available units for this dataspace.
105  @param unitNames Returns a list of all available units for this dataspace.
106  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
107  */
108  TTErr getAvailableUnits(TTValue& unitNames);
109 
110 protected:
111  /** Called by subclasses to register units with the dataspace.
112  @param className
113  @param unitName
114  */
115  void registerUnit(const TTSymbol& className, const TTSymbol& unitName);
116 
117 };
118 
119 typedef TTDataspace* TTDataspacePtr;
120 
121 
122 #endif // __TTDATASPACE_H__
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 getAvailableUnits(TTValue &unitNames)
Return a list of all available units for this dataspace.
Specification for TTDataspaceUnit, the base class of each dataspace unit.
TTDataspace()
Constructor.
Definition: TTDataspace.cpp:18
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 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
TTSymbol & getOutputUnit()
Get the output unit type for this dataspace object as a symbol.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
TTSymbol neutralUnit
The neutral unit of the dataspace as a symbol.
Definition: TTDataspace.h:58
Base class for each dataspace.
Definition: TTDataspace.h:30
void registerUnit(const TTSymbol &className, const TTSymbol &unitName)
Called by subclasses to register units with the dataspace.
This library provides convertions between different measurement units for values relating to time...
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34