Jamoma API  0.6.0.a19
TTObject.cpp
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationLibrary
4  *
5  * @brief Create Jamoma object instances.
6  *
7  * @author Timothy Place
8  *
9  * @copyright Copyright © 2014, Timothy 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 #include "TTObject.h"
15 #include "TTObjectBase.h"
16 #include "TTEnvironment.h"
17 #include "TTObjectTemplates.h"
18 
19 
20 TTObject::TTObject(const TTSymbol aClassName, const TTValue arguments) :
21 mObjectInstance(NULL)
22 {
23  TTErr err = ttEnvironment->createInstance(aClassName, &mObjectInstance, arguments);
24 
25  if (err) {
26  TTLogError("TTObject -- error %i instantiating %s\n", err, aClassName.c_str());
27  throw TTException("object instantiation failed");
28  }
29 }
30 
31 
32 TTObject::TTObject(const TTSymbol aClassName) :
33 mObjectInstance(NULL)
34 {
35  TTErr err = ttEnvironment->createInstance(aClassName, &mObjectInstance, TTValue());
36 
37  if (err) {
38  TTLogError("TTObject -- error %i instantiating %s\n", err, aClassName.c_str());
39  throw TTException("object instantiation failed");
40  }
41 }
42 
43 
45 mObjectInstance(NULL)
46 {
47 
48 }
49 
50 
52 mObjectInstance(NULL)
53 {
54  mObjectInstance = ttEnvironment->referenceInstance(anObjectBase);
55 }
56 
57 
58 TTObject::TTObject(const TTObject& anObjectToCopy)
59 {
60  mObjectInstance = ttEnvironment->referenceInstance(anObjectToCopy.mObjectInstance);
61 }
62 
63 
65 {
66  if (mObjectInstance)
67  ttEnvironment->releaseInstance(&mObjectInstance);
68 }
69 
70 
72 {
73  TTValue unused;
74  return ttEnvironment->getAllClassNames(unused, classNames);
75 }
76 
77 
79 {
80  return ttEnvironment->getClassNamesWithTags(classNames, searchTags);
81 }
82 
83 
85 {
86  // TODO: Needs to be implemented!
87  return kTTErrMethodNotFound;
88 }
89 
90 
92 {
93  if (mObjectInstance)
94  ttEnvironment->releaseInstance(&mObjectInstance);
95 
96  if (object.mObjectInstance)
97  mObjectInstance = ttEnvironment->referenceInstance(object.mObjectInstance);
98  else
99  mObjectInstance = NULL;
100 
101  return *this;
102 }
103 
104 
106 {
107  return mObjectInstance;
108 }
109 
110 
111 void TTObject::attributes(TTValue& returnedAttributeNames) const
112 {
113  mObjectInstance->getAttributeNames(returnedAttributeNames);
114 }
115 
116 
118 {
119  return mObjectInstance->getAttributeType(aName);
120 }
121 
122 
123 void TTObject::messages(TTValue& returnedMessageNames) const
124 {
125  mObjectInstance->getMessageNames(returnedMessageNames);
126 }
127 
128 
130 {
131  return mObjectInstance->getName();
132 }
133 
134 
136 {
137  return mObjectInstance->sendMessage(aName);
138 }
139 
140 TTValue TTObject::send(const TTSymbol aName, const TTValue& anInputValue)
141 {
142  TTValue anOutputValue;
143 
144  mObjectInstance->sendMessage(aName, anInputValue, anOutputValue);
145  return anOutputValue;
146 }
147 
148 #ifdef SUPPORT_OLD_SEND_SYNTAX
149 TTErr TTObject::send(const TTSymbol aName, const TTValue& anInputValue, TTValue& anOutputValue)
150 {
151  return mObjectInstance->sendMessage(aName, anInputValue, anOutputValue);
152 }
153 #endif
154 
156 {
157  return mObjectInstance->registerObserverForNotifications(anObservingObject);
158 }
159 
160 
162 {
163  return mObjectInstance->unregisterObserverForNotifications(anObservingObject);
164 }
165 
166 
167 bool operator == (const TTObject& anObject, const TTObject& anotherObject)
168 {
169  return (anObject.instance() == anotherObject.instance());
170 }
171 
172 
173 bool operator != (const TTObject& anObject, const TTObject& anotherObject)
174 {
175  return (anObject.instance() != anotherObject.instance());
176 }
177 
178 
180 {
181  if (mObjectInstance && mObjectInstance->valid)
182  return YES;
183  else
184  return NO;
185 }
186 
187 void TTObject::track(TTBoolean newTrackingValue)
188 {
189  if (mObjectInstance && mObjectInstance->valid)
190  mObjectInstance->track = newTrackingValue;
191 }
TTErr sendMessage(const TTSymbol name)
TODO: Document this function.
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
TTErr registerObserverForNotifications(const TTObject &observingObject)
Register an observer.
bool operator!=(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for inequality.
Definition: TTObject.cpp:173
The Jamoma Object Base Class.
TTErr send(const TTSymbol aName)
Send a message to this object with no arguments.
Definition: TTObject.cpp:135
Create Jamoma object instances.
void messages(TTValue &returnedMessageNames) const
Return a list of names of the available messages.
Definition: TTObject.cpp:123
static TTErr GetRegisteredClassNames(TTValue &classNames)
Query TTEnvironment for names of all registered TTObjectBase classes.
Definition: TTObject.cpp:71
TTErr unregisterObserverForNotifications(const TTObject &observingObject)
Unregister an observer for notifications.
TTErr getClassNamesWithTags(TTValue &classNames, const TTValue &searchTags)
Retreive the names of all registered TTObjectBase classes in the environment that are associated with...
TTFOUNDATION_EXPORT TTEnvironment * ttEnvironment
The environment object has one instance, which is global in scope.
Implementation of template code exported by TTObject.
void track(TTBoolean newTrackingValue)
Enable/Disable reference count tracking of the instance.
Definition: TTObject.cpp:187
TTErr getAllClassNames(const TTValue &anInputValue, TTValue &anOutputValue)
Remove a class from the environment's registry.
TTSymbol getName() const
Return the name of this class.
TTObject()
Constructor to create an empyt container which will be assigned/copied-to at a later point...
Definition: TTObject.cpp:44
Create and use Jamoma object instances.
Definition: TTObject.h:29
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
TTErr unregisterObserverForNotifications(const TTObject &anObservingObject)
Unregister an observer for notifications.
Definition: TTObject.cpp:161
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
TTBoolean valid
If the object isn't completely built, or is in the process of freeing, this will be false...
Definition: TTObjectBase.h:124
TTErr createInstance(const TTSymbol className, TTObjectBasePtr *anObject, const TTValue &anArgument)
Create a new instance of a registered TTObjectBase class.
bool operator==(const TTObject &anObject, const TTObject &anotherObject)
Compare two objects for equality.
Definition: TTObject.cpp:167
TTErr registerObserverForNotifications(const TTObject &anObservingObject)
Register an observer.
Definition: TTObject.cpp:155
TTErr releaseInstance(TTObjectBasePtr *anObject)
Release an instance of a TTObjectBase class.
A TTBlue exception is thown with this object.
Definition: TTBase.h:368
TTSymbol name() const
Return the name of this class.
Definition: TTObject.cpp:129
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
void getMessageNames(TTValue &messageNameList)
Return a list of names of the available messages.
void TTFOUNDATION_EXPORT TTLogError(TTImmutableCString message,...)
Platform and host independent method for posting errors.
Definition: TTBase.cpp:572
TTSymbol getAttributeType(const TTSymbol name)
Return the type of an attribute as a symbol.
TTObjectBasePtr referenceInstance(TTObjectBasePtr anObject)
Create a reference to an object.
TTSymbol attributeType(const TTSymbol aName)
Return the type of an attribute as a symbol.
Definition: TTObject.cpp:117
TTBoolean track
enable the print of a log message to ease the track of reference counting mechanism on an instance ...
Definition: TTObjectBase.h:125
const char * c_str() const
Return a pointer to the internal string as a C-string.
Definition: TTSymbol.h:77
TTObject & operator=(TTObject object)
Assign a TTObject instance to another TTObject.
Definition: TTObject.cpp:91
virtual ~TTObject()
Destructor.
Definition: TTObject.cpp:64
TTEnvironment is a global object providing information on the environemt.
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
void attributes(TTValue &returnedAttributeNames) const
Return a list of names of the available attributes.
Definition: TTObject.cpp:111
static TTErr GetRegisteredTags(TTValue &tags)
Query TTEnvironment for all registered tags used by TTObjectBase classes.
Definition: TTObject.cpp:84
TTObjectBase * instance() const
Return a direct pointer to the internal instance.
Definition: TTObject.cpp:105
Method not found. Typically returned by the TTObject::sendMessage() function.
Definition: TTBase.h:351
TTBoolean valid() const
Determine if the object contained by this TTObject is truly ready for use.
Definition: TTObject.cpp:179
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
void getAttributeNames(TTValue &attributeNameList)
Return a list of names of the available attributes.