OSObject
Member Functions
Abstract: Is the target object a subclass of the reference object?
public:
Parameters
Name | Description |
typeinst | Reference instance of an object, desired type. |
inst | Instance of object to check for type compatibility. |
Result: false if typeinst or inst are 0 or inst is not a subclass of typeinst's class. true otherwise.
Abstract: Roughly analagous to (type *) inst, but check if valid first.
public:
OSDynamicCast is an attempt to implement a rudimentary equivalent to rtti's dynamic_cast operator. Embedded-C++ doesn't allow the use of rtti. OSDynamicCast is build on the OSMetaClass mechanism. Note it is safe to call this with a 0 paramter.
Parameters
Name | Description |
type | name of desired class name. Notice that it is assumed that you desire to cast to a pointer to an object of this type. Also type qualifiers, like const, are not recognised and will cause an, usually obscure, compile error. |
inst | Pointer to object that you wish to attempt to type cast. May be 0. |
Result: inst if object non-zero and it is of the desired type, otherwise 0.
Abstract: Disable implicit copy constructor by making private
private:
OSObject(OSObject &src);
Parameters
Name | Description |
src | Reference to source object that isn't allowed to be copied |
Abstract: Given the name of a class return it's typeID
public:
Parameters
Name | Description |
type | Name of the desired type, eg. OSObject. |
Result: 'this' if object is of desired type, otherwise 0.
Abstract: Given a pointer to an object return it's typeID
public:
Parameters
Name | Description |
typeinst | An instance of an OSObject subclass. |
Result: The typeID, ie. OSMetaClass *.
Abstract: The last reference is gone so clean up your resources.
protected:
virtual void free();
Release all resources held by the object, then call your parent's free().
Caution:
1> You can not assume that you have completed initialisation before your free is called, so be very careful in your implementation.
2> The implementation is OSObject::free() { delete this; } so do not call super::free() until just before you return.
3> Free is not allowed to fail all resource must be released on completion.
Abstract: How many times has this object been retained?
public:
virtual int getRetainCount() const;
Result: Current retain count
Abstract: Mac OS X kernel's primary mechanism for constructing objects.
protected:
virtual bool init();
Your responsibility as a subclass author is to override the init method of your parent. In general most of our implementations call ::init() before doing local initialisation, if the parent fails then return false immediately. If you have a failure during you local initialisation then return false.
Result: OSObject::init Always returns true, but subclasses will return false on init failure.
Abstract: Is this == anObj?
public:
virtual bool isEqualTo(const OSObject *anObj) const;
OSObject::isEqualTo implements this as a shallow pointer comparison. The OS container classes do a more meaningful comparison. Your mileage may vary.
Parameters
Name | Description |
anObj | Object to compare 'this' to. |
Result: true if the objects are equivalent, false otherwise.
Abstract: Check to see if this object is or inherits from the given type.
public:
OSObject *metaCast(const OSMetaClass *toMeta) const;
This function is the guts of the OSMetaClass system. IODynamicCast, qv, is implemented using this function.
Parameters
Name | Description |
toMeta | Pointer to a constant OSMetaClass for the desired target type. |
Result: 'this' if object is of desired type, otherwise 0.
Abstract: See OSObject::metaCast(const OSMetaClass *)
public:
OSObject *metaCast(const OSSymbol *toMeta) const;
Parameters
Name | Description |
toMeta | OSSymbol of the desired class' name. |
Result: 'this' if object is of desired type, otherwise 0.
Abstract: See OSObject::metaCast(const OSMetaClass *)
public:
OSObject *metaCast(const OSString *toMeta) const;
Parameters
Name | Description |
toMeta | OSString of the desired class' name. |
Result: 'this' if object is of desired type, otherwise 0.
Abstract: See OSObject::metaCast(const OSMetaClass *)
public:
OSObject *metaCast(const char *toMeta) const;
Parameters
Name | Description |
toMeta | const char * C String of the desired class' name. |
Result: 'this' if object is of desired type, otherwise 0.
Abstract: Disable implicit copy constructor by making private
private:
void operator =(OSObject &src);
Parameters
Name | Description |
src | Reference to source object that isn't allowed to be copied |
Abstract: Release the 'operator new'ed memory.
protected:
static void operator delete(void *mem, size_t size);
Never attempt to delete an object that inherits from OSObject directly use $link release().
Parameters
Name | Description |
mem | pointer to block of memory |
size | size of block of memory |
Abstract: Allocator for all objects that inherit from OSObject
public:
static void *operator new(size_t size);
Parameters
Name | Description |
size | number of bytes to allocate |
Result: returns pointer to block of memory if avaialable, 0 otherwise.
Abstract: Primary implementation of the release mechanism.
protected:
void release(int when) const;
If $link retainCount <= the when argument then call $link free(). This indirect implementation of $link release allows the developer to break reference circularity. An example of this sort of problem is a parent/child mutual reference, either the parent or child can implement: void release() { release(2); } thus breaking the cirularity.
Parameters
Name | Description |
when | When retainCount == when then call free(). |
Abstract: Release a reference to this object
public:
virtual void release() const;
Abstract: Retain a reference in this object.
public:
virtual void retain() const;
public:
virtual bool serialize(OSSerialize *s) const;
Member Data
private:
int retainCount;
Number of references held on this instance.
© 2000 Apple Computer, Inc. (Last Updated 2/23/2000)