This is MOClassVariable.rtf in view mode; [Download] [Up]
Version 1.0 Copyright ©1993, 1994 by Mike Ferris. All Rights Reserved. Mike Ferris - February 5th, 1994 MOClassVariable Inherits From: Object Declared In: MOKit/MOClassVariable.h Class Description MOClassVariable is used to implement class variables that keep separate values for each subclass. Usually to simulate class variables in Objective-C a static variable is declared at the top-level of the implementation block of the class and class methods are provided to get and set this static variable. The result is that all subclasses share the same value unless they explicitly re-implement the class variable again. MOClassVariables solve this problem. Instead of declaring a static variable of the type you want in your implementation, you will declare a static MOClassVariable pointer. The +initialize method should allocate and initialize this object. Then the get/set methods should call the MOClassVariable methods -getObjectForClass: and -setObject:forClass: to do their work. Finally, the +startUnloading method should free the object. See the MOController class for an example of the use of this object. The MOClassVariable can only store object values. The MOClassVariable can be configured at init time to free its values when it is freed. The default is not to free its values. Internally, it uses a hash table keyed on the class' name to store a separate value for each subclass. This class does not have -read: and -write: methods. The reason is I don't think they need them. MOClassVariab;e instances are meant to be used with static top-level variables of other classes, not as parts of instances of other classes. They should never need archiving. Of course I'm probably wrong... Instance Variables HashTable *ht; Bool doesFreeValues; ht The hash table used to store the values. doesFreeValues Whether the values should be automatically freed when the object is.. Method Types Initializing the class + initialize Initializing instances - init - initDoesFreeValues: - free Managing the values - setObject:forClass: - getObjectForClass: Class Methods initialize + initialize Sets the class version number. Instance Methods free ± free This method frees the hash table at least. It first frees all the object values if the instance is supposed to free its values. See also: ± init, ± initDoesFreeValues: getObjectForClass: ± getObjectForClass:(Class)class Looks up the value (if any) for the given class and returns it. Returns nil if no value has been set for the given class. See also: ± setObject:forClass: init: ± init Calls -initDoesFreeValues:NO. See also: ± initDoesFreeValues:, ± free initDoesFreeValues: ± initDoesFreeValues:(BOOL)flag This is the designated initializer for the class. It justs sets things up (the hash table in particular). See also: ± init, ± free setObject:forClass: ± setObject:obj forClass:(Class)class Sets the value for the given class to obj. If we are supposed to free values, the old value(if any) is freed and this method returns nil. If we don't free values, the old value is returned if there was one, else nil is returned. See also: ± getObjectForClass:
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.