Jamoma API  0.6.0.a19
TTDataspaceConverter.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationDataspaceLib
4  *
5  * @brief Specification for #TTDataspaceConverter, the base class of dataspace converters.
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 "TTDataspaceConverter.h"
16 
17 #define thisTTClass TTDataspaceConverter
18 #define thisTTClassName "dataspace"
19 #define thisTTClassTags "dataspace.converter"
20 
21 
23  mDataspaceTTObject(NULL),
24  mDataspaceObject(NULL)
25 {
29 
30  addMessageWithArguments(dictionary);
31  addMessageWithArguments(convert);
32 
33  addMessageWithArguments(getAvailableUnits);
34  addMessageWithArguments(getAvailableDataspaces);
35 
36  setAttributeValue(TT("dataspace"), TT("none"));
37 }
38 
39 
40 TTDataspaceConverter::~TTDataspaceConverter()
41 {
42  TTObjectBaseRelease((TTObjectBasePtr*)&mDataspaceTTObject);
43 }
44 
45 
46 TTErr TTDataspaceConverter::setDataspace(const TTValue& newValue)
47 {
48  TTSymbol name;
49  TTErr err;
50  TTString objectName = "dataspace.";
51 
52  name = newValue[0];
53 
54  // TODO: validate the name provided before proceeding
55  objectName += name.c_str();
56  err = TTObjectBaseInstantiate(TT(objectName.c_str()), &mDataspaceTTObject, 0);
57  if (err) {
58  // Rather than crashing:
59  //throw TTException("Error trying to load dataspace with that name");
60  // we set it to "none" and post an error message to the log
61  TTLogError("Error trying to load %s, set to none\n", objectName.c_str());
62  objectName = "dataspace.none";
63  TTObjectBaseInstantiate(TT(objectName.c_str()), &mDataspaceTTObject, 0);
64  }
65  mDataspaceObject = dynamic_cast<TTDataspacePtr>(mDataspaceTTObject);
66  mDataspace = name;
67 
68  return err;
69 }
70 
71 
72 TTErr TTDataspaceConverter::convert(const TTValue& anInputValue, TTValue& anOutputValue)
73 {
74  return mDataspaceObject->convert(anInputValue, anOutputValue);
75 }
76 
77 
78 TTErr TTDataspaceConverter::dictionary(const TTValue& anInputValue, TTValue& anOutputValue)
79 {
80  TTDictionaryPtr d = NULL;
81  TTValue in;
82  TTValue out;
83  TTErr err;
84 
85  d = (TTDictionaryPtr)&(anInputValue[0]);
86  d->getValue(in);
87  err = convert(in, out);
88  d->setValue(out);
89  anOutputValue.set(0, TTPtr(d));
90  return err;
91 }
92 
93 
94 TTErr TTDataspaceConverter::getInputUnit(TTValue& inUnitName)
95 {
96  inUnitName = mDataspaceObject->getInputUnit();
97  return kTTErrNone;
98 }
99 
100 
101 TTErr TTDataspaceConverter::setInputUnit(const TTValue& inUnitName)
102 {
103  TTSymbol s = inUnitName;
104  return mDataspaceObject->setInputUnit(s);
105 }
106 
107 
108 TTErr TTDataspaceConverter::getOutputUnit(TTValue& outUnitName)
109 {
110  outUnitName = mDataspaceObject->getOutputUnit();
111  return kTTErrNone;
112 }
113 
114 
115 TTErr TTDataspaceConverter::setOutputUnit(const TTValue& outUnitName)
116 {
117  TTSymbol s = outUnitName;
118  return mDataspaceObject->setOutputUnit(s);
119 }
120 
121 
122 TTErr TTDataspaceConverter::getAvailableUnits(const TTValue& anUnusedInputValue, TTValue& unitNames)
123 {
124  return mDataspaceObject->getAvailableUnits(unitNames);
125 }
126 
127 
128 TTErr TTDataspaceConverter::getAvailableDataspaces(const TTValue& anUnusedInputValue, TTValue& dataspaceNames)
129 {
130  TTErr err;
131 
132  err = TTObject::GetRegisteredClassNamesForTags(dataspaceNames, TT("dataspace"));
133  if (!err) {
134  // strip the leading "dataspace." prefix off all the names
135  for (TTUInt32 i=0; i < dataspaceNames.size(); i++) {
136  TTSymbol s;
137  //TTString str;
138  const char* cStr;
139 
140  s = dataspaceNames[i];
141  /*
142  str = s->getString(); // this causes crashes on Windows, need to use C string instead
143  str.erase(0, 10);
144  */
145  cStr = s.c_str() + 10;
146  s = TT(cStr);
147  dataspaceNames.set(i, s);
148  }
149  }
150  return err;
151 }
152 
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 getAvailableUnits(TTValue &unitNames)
Return a list of all available units for this dataspace.
const char * c_str() const
Return a pointer to the internal C-string.
Definition: TTString.h:83
size_type size() const noexcept
Return the number of elements.
static TTErr GetRegisteredClassNamesForTags(TTValue &classNames, const TTValue &searchTags)
Query TTEnvironment for names of all registered TTObjectBase classes that share specific tags...
Definition: TTObject.cpp:78
Specification for TTDataspaceConverter, the base class of dataspace converters.
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
TTErr getValue(T &aReturnedValue) const
Get the dictionary's primary value.
Definition: TTDictionary.h:202
Symbol type.
Definition: TTBase.h:282
A type that represents the key as a C-String and the value as a pointer to the matching TTSymbol obje...
Definition: TTDictionary.h:47
#define TT
This macro is defined as a shortcut for doing a lookup in the symbol table.
Definition: TTSymbol.h:155
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
void TTFOUNDATION_EXPORT TTLogError(TTImmutableCString message,...)
Platform and host independent method for posting errors.
Definition: TTBase.cpp:572
TTErr TTObjectBaseInstantiate(const TTSymbol className, TTObjectBasePtr *returnedObjectPtr, const TTValue arguments)
DEPRECATED.
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
const char * c_str() const
Return a pointer to the internal string as a C-string.
Definition: TTSymbol.h:77
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
TTErr setValue(const TTValue aNewValue)
TODO: Add documentation.
Definition: TTDictionary.h:191
void set(const TTUInt16 index, const T &anElementValue)
DEPRECATED.
Definition: TTValue.h:569
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
std::uint32_t TTUInt32
32 bit unsigned integer
Definition: TTBase.h:178
Base class for each dataspace.
Definition: TTDataspace.h:30
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
No Error.
Definition: TTBase.h:343
The TTString class is used to represent a string.
Definition: TTString.h:34
TTDictionary * TTDictionaryPtr
[doxygenAppendixC_typedefExample]
Definition: TTDictionary.h:279
TT_OBJECT_CONSTRUCTOR
Constructor macro.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
#define addAttributeWithGetterAndSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom getter and sett...
Definition: TTAttribute.h:57