Jamoma API  0.6.0.a19
TTClass.h
Go to the documentation of this file.
1 /** @file
2  *
3  * @ingroup foundationLibrary
4  *
5  * @brief The TTClass object represents a class in the Jamoma environment.
6  *
7  * @details This is to say that it represents everything about a class except for the class itself,
8  * which is a subclass of TTObjectBase.
9  *
10  * @todo: We could override the () operator to make TTClass a functor for creating instances.
11  *
12  * @author Timothy Place, Trond Lossius
13  *
14  * @copyright Copyright © 2008, Timothy Place @n
15  * This code is licensed under the terms of the "New BSD License" @n
16  * http://creativecommons.org/licenses/BSD/
17  */
18 
19 
20 #ifndef __TT_CLASS_H__
21 #define __TT_CLASS_H__
22 
23 #include "TTObject.h"
24 #include "TTHash.h"
25 #include "TTEnvironment.h"
26 
27 
28 /** The TTClass object represents a class in the Jamoma environment.
29  * This is to say that it represents everything about a class except for the class itself,
30  * which is a subclass of TTObjectBase.
31  */
32 class TTFOUNDATION_EXPORT TTClass {
33 private:
34  friend class TTEnvironment;
35  friend class TTObjectBase;
36 
37  TTSymbol name; ///< The name of the class.
38  TTValue tags; ///< An array of TTSymbols containing tags associated with this class.
39  TTObjectBaseInstantiationMethod instantiationMethod; ///< Pointer to the function that will create a new instance.
40  TTString path; ///< The path to executable from which this class loaded.
41  TTBoolean external; ///< Is this class external to the main library?
42  TTUInt16 count; ///< Reference count for how many instantiateds of this object exist.
43 
44 public:
45 
46  /** Constructor method.
47  @param className The name of the class.
48  @param tags The tags that this class is associated with.
49  @param anInstantiationMethod The instantiation method for this class.
50  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
51  */
52  TTClass(const TTSymbol className, const TTValue& tags, const TTObjectBaseInstantiationMethod anInstantiationMethod);
53 
54 
55  /** Destructor. */
56  virtual ~TTClass();
57 
58 
59  /** Create a new instance of a registered #TTObjectBase class.
60  @param anObject Upon successful return, the value will be set to a #TTObjectBase which is the new instance.
61  If the pointer is passed in as non-NULL then createUnit() will try to free to the
62  existing object to which it points prior to instantiating the new unit.
63  @param anArgument For most audio processing objects, this should be passed the maximum number of channels.
64  For this reason, we overload this method with a TTUint16 argument as a convenience.
65  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
66  */
67  TTErr createInstance(TTObjectBase** anObject, const TTValue& anArgument);
68 
69 
70  /** Free an instance of a #TTObjectBase class.
71  There are a couple of reasons we want to have this wrapper around the delete operator.
72  - For instrumenting the code to investigate bugs, performance, etc.@n
73  - So that we can handle any threading, spin-locks, mutexes, or other issues before actually freeing the object.
74 
75  @param unit A pointer to the unit to free.
76  @return #TTErr error code if the method fails to execute, else #kTTErrNone.
77  */
78  TTErr releaseInstance(TTObjectBase* anObject);
79 
80 
81 };
82 
83 /** Pointer to a #TTClass.
84  @ingroup typedefs
85  */
87 
88 
89 #endif // __TT_CLASS_H__
90 
TTClass * TTClassPtr
Pointer to a TTClass.
Definition: TTClass.h:86
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
Definition: TTBase.h:167
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
Create Jamoma object instances.
Base class for all first-class Jamoma objects.
Definition: TTObjectBase.h:109
TTObjectBase *(* TTObjectBaseInstantiationMethod)(TTSymbol className, const TTValue arguments)
A function pointer for an instance creation function required to be provided by all classes...
Definition: TTEnvironment.h:29
The TTClass object represents a class in the Jamoma environment.
Definition: TTClass.h:32
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
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
The TTString class is used to represent a string.
Definition: TTString.h:34
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34
The global object maintains all global attributes/settings for the Jamoma environment.
Definition: TTEnvironment.h:47