CC3Identifiable Class Reference
Inherits from | NSObject |
Conforms to | CC3Cacheable NSCopying |
Declared in | CC3Identifiable.h |
Overview
This is a base subclass for any class that uses tags or names to identify individual instances. Instances can be initialized with either or both a tag and a name. Instances initialized without an explcit tag will have a unique tag automatically generated and assigned.
You can assign your own data to instances of CC3Identifiable or its subclasses through the userData property.
When overriding initialization, subclasses typically need only override the most generic initializer, initWithTag:withName:.
Extensions to CC3Identifiable to support PVR POD data.
Tasks
Other Methods
-
tag
property -
name
property -
– deriveNameFrom:
-
– deriveNameFrom:usingSuffix:
-
nameSuffix
property -
userData
property -
– initUserData
-
– copyUserDataFrom:
-
– releaseUserData
-
__deprecated
property -
– init
-
– initWithTag:
-
– initWithName:
-
– initWithTag:withName:
-
– copy
-
– copyWithName:
-
– copyAsClass:
-
– copyWithName:asClass:
-
– copyWithZone:withName:
-
– copyWithZone:withName:asClass:
-
– populateFrom:
-
shouldIncludeInDeepCopy
property -
– nextTag
-
+ resetTagAllocation
-
+ instanceCount
-
– fullDescription
PVRPOD Methods
-
podIndex
property -
– initAtIndex:fromPODResource:
Properties
__deprecated
@deprecated Use userData instead. The userData and sharedUserData properties are now the same.
@property (nonatomic, retain) NSObject *__deprecated
Declared In
CC3Identifiable.h
name
An arbitrary name for this object. It is not necessary to give all identifiable objects a name, but can be useful for retrieving objects at runtime, and for identifying objects during development.
@property (nonatomic, retain) NSString *name
Discussion
In general, names need not be unique, are not automatically assigned, and leaving the name as nil is acceptable.
Some subclasses are designed so that their instances can be cached. For instances of those subclasses, the name is required, and must be unique.
Declared In
CC3Identifiable.h
nameSuffix
Returns a string to concatenate to the name of another CC3Identifiable to automatically create a useful name for this instance.
@property (nonatomic, retain, readonly) NSString *nameSuffix
Discussion
This property is used by the deriveNameFrom: method.
This implementation simply raises an assertion exception. Each concrete subclass should override this property to return a useful identifiable name suffix. A subclass can return nil from this property to indicate that automatic naming should not be performed.
Declared In
CC3Identifiable.h
podIndex
The index of this object in the POD resource data. This generally means the podIndex'th type of object of the class.
@property (nonatomic, assign) GLint podIndex
Declared In
CC3IdentifiablePODExtensions.h
shouldIncludeInDeepCopy
Returns whether this instance should be included in a deep copy.
@property (nonatomic, readonly) BOOL shouldIncludeInDeepCopy
Discussion
This method simply returns YES by default, and in most cases this is sufficient. However, for some structural subclasses (notably subclasses of CC3Node) it may be desirable to not copy some components.
This property is not universally automatically applied or honoured. It is up to the invoker and invokee to agree on when to make use of this property.
Declared In
CC3Identifiable.h
tag
An arbitrary identification. Useful for keeping track of instances. Unique tags are not explicitly required, but are highly recommended. In most cases, it is best to just let the tag be assigned automatically by using an initializer that does not explicitly set the tag.
@property (nonatomic, assign) GLuint tag
Declared In
CC3Identifiable.h
userData
Application-specific data associated with this object.
@property (nonatomic, retain) NSObject *userData
Discussion
You can use this property to add any additional information you want to an instance of CC3Identifiable or its concrete subclasses (CC3Node, CC3Mesh, CC3Material, CC3Texture, etc.).
If you have non-object data to attach, such as a structure, or a pointer to data in a memory space (perhaps loaded from a file), you can wrap it in an instance of NSData and attach it here.
To assist in managing this data, the methods initUserData is invoked automatically during the initialization and deallocation of each instance of this class. You can override this method by subclassing, or by adding extention categories to the concrete subclasses of CC3Identifiable, (CC3Node, CC3Mesh, CC3Material, CC3Texture, etc.), to create or retrieve the data, and attach it to the new instance.
When copying instances of CC3Identifiable and its subclasses, the copyUserDataFrom: method is invoked in the new copy so that it can copy the data from the original instance to the new instance copy.
In this abstract class, the copyUserDataFrom: method simply sets the userData property of the copy to the object returned from the same property in the original instance, without creating a copy of the userData object. If you need the userData object to be copied as well, you can override the copyUserDataFrom: method by subclassing, or by adding extention categories to the concrete subclasses of CC3Identifiable, (CC3Node, CC3Mesh, CC3Material, CC3Texture, etc.), to copy the userData object and assign it to the new instance.
Declared In
CC3Identifiable.h
Class Methods
instanceCount
Indicates the total number of active instances, over all subclasses, that have been allocated and initialized, but not deallocated. This can be useful when creating hordes of 3D objects, to verify that your application is properly deallocating them again when you are done with them.
+ (GLint)instanceCount
Declared In
CC3Identifiable.h
Instance Methods
copy
Returns a newly allocated (retained) copy of this instance. The new copy will have the same name as this instance, but will have a unique tag.
- (id)copy
Discussion
The returned instance is retained. It is the responsiblity of the caller to manage the lifecycle of the returned instance and perform the corresponding invocation of the release method at the appropriate time.
This copy operation is a deep copy. Copies of most of the content of the original will be created as well. For structural subclasses, such as CC3Node, copies will be made of each structual element (eg- child nodes). Some exceptions are made. For instance, copies are generally not made for fixed, voluminous content such as mesh data. In addition, subclasses may excuse themselves from being copied through the shouldIncludeInDeepCopy property.
This copy operation is a deep copy. Copies of most of the content of the original will be created as well. For structural subclasses, such as CC3Node, copies will be made of each structual element (eg- child nodes). Some exceptions are made. For instance, copies are generally not made for fixed, voluminous content such as mesh data. In addition, subclasses may excuse themselves from being copied through the shouldIncludeInDeepCopy property.
The copy… methods may often be used to duplicate an instance many times, to create large number of similar instances to populate a game. To help you verify that you are correctly releasing and deallocating all these copies, you can use the instanceCount class method to get a current count of the total number of instances of all subclasses of CC3Identifiable,
Subclasses that extend copying should not override this method, but should override the populateFrom: method instead.
Declared In
CC3Identifiable.h
copyAsClass:
Returns a newly allocated (retained) copy of this instance. The new copy will be an instance of the specified class, will have the same name as this instance, and will have a unique tag.
- (id)copyAsClass:(Class)aClass
Discussion
Care should be taken when choosing the class to be instantiated. If the class is different than that of this instance, the populateFrom: method of that class must be compatible with the contents of this instance.
The returned instance is retained. It is the responsiblity of the caller to manage the lifecycle of the returned instance and perform the corresponding invocation of the release method at the appropriate time.
This copy operation is a deep copy. Copies of most of the content of the original will be created as well. For structural subclasses, such as CC3Node, copies will be made of each structual element (eg- child nodes). Some exceptions are made. For instance, copies are generally not made for fixed, voluminous content such as mesh data. In addition, subclasses may excuse themselves from being copied through the shouldIncludeInDeepCopy property.
The copy… methods may often be used to duplicate an instance many times, to create large number of similar instances to populate a game. To help you verify that you are correctly releasing and deallocating all these copies, you can use the instanceCount class method to get a current count of the total number of instances of all subclasses of CC3Identifiable,
Subclasses that extend copying should not override this method, but should override the populateFrom: method instead.
Declared In
CC3Identifiable.h
copyUserDataFrom:
Invoked automatically after this instance has been created as a copy of the specified instance, to copy the userData property from the original instance to this instance.
- (void)copyUserDataFrom:(CC3Identifiable *)another
Discussion
In this abstract class, this method simply sets the userData property of this instance to the object returned from the same property in the specified original instance, without creating a copy of the userData object. If you need the userData object to be copied as well, you can override this method by subclassing, or by adding extention categories to the concrete subclasses of CC3Identifiable, (CC3Node, CC3Mesh, CC3Material, CC3Texture, etc.), to copy the userData object and assign it to the new instance.
Declared In
CC3Identifiable.h
copyWithName:
Returns a newly allocated (retained) copy of this instance. The new copy will have its name set to the specified name, and will have a unique tag.
- (id)copyWithName:(NSString *)aName
Discussion
The returned instance is retained. It is the responsiblity of the caller to manage the lifecycle of the returned instance and perform the corresponding invocation of the release method at the appropriate time.
This copy operation is a deep copy. Copies of most of the content of the original will be created as well. For structural subclasses, such as CC3Node, copies will be made of each structual element (eg- child nodes). Some exceptions are made. For instance, copies are generally not made for fixed, voluminous content such as mesh data. In addition, subclasses may excuse themselves from being copied through the shouldIncludeInDeepCopy property.
The copy… methods may often be used to duplicate an instance many times, to create large number of similar instances to populate a game. To help you verify that you are correctly releasing and deallocating all these copies, you can use the instanceCount class method to get a current count of the total number of instances of all subclasses of CC3Identifiable,
Subclasses that extend copying should not override this method, but should override the populateFrom: method instead.
Declared In
CC3Identifiable.h
copyWithName:asClass:
Returns a newly allocated (retained) copy of this instance. The new copy will be an instance of the specified class, will have its name set to the specified name, and will have a unique tag.
- (id)copyWithName:(NSString *)aName asClass:(Class)aClass
Discussion
Care should be taken when choosing the class to be instantiated. If the class is different than that of this instance, the populateFrom: method of that class must be compatible with the contents of this instance.
The returned instance is retained. It is the responsiblity of the caller to manage the lifecycle of the returned instance and perform the corresponding invocation of the release method at the appropriate time.
This copy operation is a deep copy. Copies of most of the content of the original will be created as well. For structural subclasses, such as CC3Node, copies will be made of each structual element (eg- child nodes). Some exceptions are made. For instance, copies are generally not made for fixed, voluminous content such as mesh data. In addition, subclasses may excuse themselves from being copied through the shouldIncludeInDeepCopy property.
The copy… methods may often be used to duplicate an instance many times, to create large number of similar instances to populate a game. To help you verify that you are correctly releasing and deallocating all these copies, you can use the instanceCount class method to get a current count of the total number of instances of all subclasses of CC3Identifiable,
Subclasses that extend copying should not override this method, but should override the populateFrom: method instead.
Declared In
CC3Identifiable.h
copyWithZone:withName:
Returns a newly allocated (retained) copy of this instance. The new copy will have its name set to the specified name, and will have a unique tag.
- (id)copyWithZone:(NSZone *)zone withName:(NSString *)aName
Discussion
The returned instance is retained. It is the responsiblity of the caller to manage the lifecycle of the returned instance and perform the corresponding invocation of the release method at the appropriate time.
This copy operation is a deep copy. Copies of most of the content of the original will be created as well. For structural subclasses, such as CC3Node, copies will be made of each structual element (eg- child nodes). Some exceptions are made. For instance, copies are generally not made for fixed, voluminous content such as mesh data. In addition, subclasses may excuse themselves from being copied through the shouldIncludeInDeepCopy property.
The copy… methods may often be used to duplicate an instance many times, to create large number of similar instances to populate a game. To help you verify that you are correctly releasing and deallocating all these copies, you can use the instanceCount class method to get a current count of the total number of instances of all subclasses of CC3Identifiable,
Subclasses that extend copying should not override this method, but should override the populateFrom: method instead.
Declared In
CC3Identifiable.h
copyWithZone:withName:asClass:
Returns a newly allocated (retained) copy of this instance. The new copy will be an instance of the specified class, will have its name set to the specified name, and will have a unique tag.
- (id)copyWithZone:(NSZone *)zone withName:(NSString *)aName asClass:(Class)aClass
Discussion
Care should be taken when choosing the class to be instantiated. If the class is different than that of this instance, the populateFrom: method of that class must be compatible with the contents of this instance.
The returned instance is retained. It is the responsiblity of the caller to manage the lifecycle of the returned instance and perform the corresponding invocation of the release method at the appropriate time.
This copy operation is a deep copy. Copies of most of the content of the original will be created as well. For structural subclasses, such as CC3Node, copies will be made of each structual element (eg- child nodes). Some exceptions are made. For instance, copies are generally not made for fixed, voluminous content such as mesh data. In addition, subclasses may excuse themselves from being copied through the shouldIncludeInDeepCopy property.
The copy… methods may often be used to duplicate an instance many times, to create large number of similar instances to populate a game. To help you verify that you are correctly releasing and deallocating all these copies, you can use the instanceCount class method to get a current count of the total number of instances of all subclasses of CC3Identifiable,
Subclasses that extend copying should not override this method, but should override the populateFrom: method instead.
Declared In
CC3Identifiable.h
deriveNameFrom:
If this instance does not already have a name, it is derived from the name of the specified other CC3Identifiable, if it has one. If this instance has a name already, or if the other CC3Identifiable does not have a name, the name of this instance is not changed.
- (BOOL)deriveNameFrom:(CC3Identifiable *)another
Discussion
Typically, this is invoked when one CC3Identifiable is added as a component to another.
This implementation concatenates the value of the nameSuffix property of this instance onto the name of the specified CC3Identifiable, and sets that into the name property of this instance. If a subclass returns nil from the nameSuffix property, no name is generated.
Returns whether the name of this instance was changed.
Declared In
CC3Identifiable.h
deriveNameFrom:usingSuffix:
If this instance does not already have a name, it is derived from the name of the specified other CC3Identifiable, if it has one. If this instance has a name already, or if the other CC3Identifiable does not have a name, the name of this instance is not changed.
- (BOOL)deriveNameFrom:(CC3Identifiable *)another usingSuffix:(NSString *)suffix
Discussion
Typically, this is invoked when one CC3Identifiable is added as a component to another.
This implementation concatenates the value of the specified suffix onto the name of the specified CC3Identifiable, and sets that into the name property of this instance.
Returns whether the name of this instance was changed.
Declared In
CC3Identifiable.h
fullDescription
Returns a string containing a more complete description of this object.
- (NSString *)fullDescription
Discussion
This implementation simply invokes the description method. Subclasses with more substantial content can override to provide much more information.
Declared In
CC3Identifiable.h
init
Initializes this unnamed instance with an automatically generated unique tag value. The tag value will be generated automatically via the method nextTag.
- (id)init
Declared In
CC3Identifiable.h
initAtIndex:fromPODResource:
Initializes this instance from the data of this type at the specified index within the specified POD resource.
- (id)initAtIndex:(GLint)aPODIndex fromPODResource:(CC3PODResource *)aPODRez
Declared In
CC3IdentifiablePODExtensions.h
initUserData
Invoked automatically from the init* family of methods to initialize the userData property of this instance.
- (void)initUserData
Discussion
This implementation simply sets the userData property to nil. You can override this method in a subclass or by creating extension categories for the concrete subclasses, (CC3Node, CC3Mesh, CC3Material, CC3Texture, etc.), if the userData can be initialized and retained in a self-contained manner.
Alternately, you can leave this method unimplemented, and set the userData property from outside this instance.
Declared In
CC3Identifiable.h
initWithName:
Initializes this instance with the specified name and an automatically generated unique tag value. The tag value will be generated automatically via the method nextTag.
- (id)initWithName:(NSString *)aName
Declared In
CC3Identifiable.h
initWithTag:
Initializes this unnamed instance with the specified tag.
- (id)initWithTag:(GLuint)aTag
Declared In
CC3Identifiable.h
initWithTag:withName:
Initializes this instance with the specified tag and name. When overriding initialization, subclasses typically need only override this initializer.
- (id)initWithTag:(GLuint)aTag withName:(NSString *)aName
Declared In
CC3Identifiable.h
nextTag
Returns a unique tag value to identify instances. This value is unique across all instances of all subclasses. The initial value returned will be one, and subsequent calls will increment the value retuned on each call. The starting value can be reset back to one via the resetTagAllocation method.
- (GLuint)nextTag
Declared In
CC3Identifiable.h
populateFrom:
Template method that populates this instance from the specified other instance.
- (void)populateFrom:(CC3Identifiable *)another
Discussion
This method is invoked automatically during object copying via the copy or copyWithZone: method. In most situations, the application should use the copy method, and should never need to invoke this method directly.
Subclasses that add additional instance state (instance variables) should extend copying by overriding this method to copy that additional state. Superclass that override this method should be sure to invoke the superclass implementation to ensure that superclass state is copied as well.
Declared In
CC3Identifiable.h