ADC Home > Reference Library > Reference > Darwin > Kernel Framework Reference

 


OSMetaClassBase

Inherits from:
class
Declared In:

Overview

OSMetaClassBase is the abse class for libkern data types.



Functions

getRetainCount

Gets the number of times this object has been retained.

isEqualTo

Returns whether 'this' == anObj.

metaCast(const char *)

See OSMetaClassBase::metaCast(const OSMetaClass *).

metaCast(const OSMetaClass *)

Checks to see if this object is or inherits from the given type.

metaCast(const OSString *)

See OSMetaClassBase::metaCast(const OSMetaClass *).

metaCast(const OSSymbol *)

See OSMetaClassBase::metaCast(const OSMetaClass *).

operator =

Disables implicit copy constructor by making private.

OSMetaClassBase

Disables implicit copy constructor by making private.

release()

Releases a reference to this object.

release(int)

Primary implementation of the release mechanism.

retain

Retains a reference to this object.

serialize

Archives the receiver.

taggedRelease(const void *)

Releases a tagged reference to this object

taggedRelease(const void *, const int)

Releases a tagged reference to this object and free if retainCount == 'when' on entry.

taggedRetain

Retains a tagged reference to this object.


getRetainCount


Gets the number of times this object has been retained.

public

virtual int getRetainCount() const = 0;
Return Value

Returns the current retain count.


isEqualTo


Returns whether 'this' == anObj.

public

virtual bool isEqualTo( const OSMetaClassBase *anObj) const;
Parameters
anObj

Object to compare 'this' to.

Return Value

Returns true if the objects are equivalent, false otherwise.

Discussion

OSMetaClassBase::isEqualTo implements this as a shallow pointer comparison. The OS container classes do a more meaningful comparison. Your mileage may vary.


metaCast(const char *)


See OSMetaClassBase::metaCast(const OSMetaClass *).

public

OSMetaClassBase *metaCast( const char *toMeta) const;
Parameters
toMeta

const char * C String of the desired class' name.

Return Value

Returns 'this' if the object is of the desired type, otherwise 0.


metaCast(const OSMetaClass *)


Checks to see if this object is or inherits from the given type.

public

OSMetaClassBase *metaCast( const OSMetaClass *toMeta) const;
Parameters
toMeta

Pointer to a constant OSMetaClass for the desired target type.

Return Value

Returns 'this' if the object is of the desired type, otherwise 0.

Discussion

This function is the guts of the OSMetaClass system. IODynamicCast, qv, is implemented using this function.


metaCast(const OSString *)


See OSMetaClassBase::metaCast(const OSMetaClass *).

public

OSMetaClassBase *metaCast( const OSString *toMeta) const;
Parameters
toMeta

OSString of the desired class' name.

Return Value

Returns 'this' if the object is of the desired type, otherwise 0.


metaCast(const OSSymbol *)


See OSMetaClassBase::metaCast(const OSMetaClass *).

public

OSMetaClassBase *metaCast( const OSSymbol *toMeta) const;
Parameters
toMeta

OSSymbol of the desired class' name.

Return Value

Returns 'this' if the object is of the desired type, otherwise 0.


operator =


Disables implicit copy constructor by making private.

private

void operator =( OSMetaClassBase &src);
Parameters
src

Reference to source object that isn't allowed to be copied.


OSMetaClassBase


Disables implicit copy constructor by making private.

private

OSMetaClassBase( OSMetaClassBase &src);
Parameters
src

Reference to source object that isn't allowed to be copied.


release()


Releases a reference to this object.

public

virtual void release() const = 0;


release(int)


Primary implementation of the release mechanism.

public

virtual void release( int when) const = 0;
Parameters
when

When retainCount == 'when' then call free().

Discussion

If retainCount


retain


Retains a reference to this object.

public

virtual void retain() const = 0;


serialize


Archives the receiver.

public

virtual bool serialize( OSSerialize *s) const = 0;
Parameters
s

The OSSerialize object.

Return Value

Returns true if serialization was successful, false if not.


taggedRelease(const void *)


Releases a tagged reference to this object

public

virtual void taggedRelease( const void *tag = 0) const = 0;


taggedRelease(const void *, const int)


Releases a tagged reference to this object and free if retainCount == 'when' on entry.

protected

virtual void taggedRelease( const void *tag, const int when) const = 0;


taggedRetain


Retains a tagged reference to this object.

public

virtual void taggedRetain( const void *tag = 0) const = 0;

#defines


OSCheckTypeInst


Is the target object a subclass of the reference object?

#define OSCheckTypeInst(typeinst, inst) \ 
    OSMetaClassBase::checkTypeInst(inst, typeinst) 
Parameters
typeinst

Reference instance of an object, desired type.

inst

Instance of object to check for type compatibility.

Return Value

false if typeinst or inst are 0 or inst is not a subclass of typeinst's class. true otherwise.


OSDynamicCast


Roughly analogous to (type *) inst, but check if valid first.

#define OSDynamicCast(type, inst) \ 
    ((type *) OSMetaClassBase::safeMetaCast((inst), (type::metaClass))) 
Parameters
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 recognized and will cause an, usually obscure, compile error.

inst

Pointer to object that you wish to attempt to type cast. May be 0.

Return Value

inst if object non-zero and it is of the desired type, otherwise 0.

Discussion

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 parameter.


OSMemberFunctionCast


Converts a pointer to a member function to a C-style pointer to function (note that no warnings are generated).

#define OSMemberFunctionCast(cptrtype, self, func) \ 
    (cptrtype) OSMetaClassBase:: \ 
    _ptmf2ptf(self, (void (OSMetaClassBase::*)(void)) func) 
Parameters
cptrtype

The type of pointer function desired.

self

The 'this' pointer of the object whose function you wish to cache.

func

The pointer to the member function itself, something like &Base::func.

Return Value

Returns a pointer to function of the given type. This function will panic if an attempt is made to call it with a multiply inherited class.


OSTypeAlloc


Allocate an instance of the desired object.

#define OSTypeAlloc(type)  
Parameters
type

Name of the desired type to be created.

Return Value

'this' if object cas been successfully created.

Discussion

The OSTypeAlloc macro can be used to break the binary compatibility difficulties presented by new. The problem is that C++ compiles the knowledge of the size of the class into the cade calling new. If you use the alloc code however the class size is determined by the callee not the caller.


OSTypeID


Given the name of a class return it's typeID

#define OSTypeID(type)  
Parameters
type

Name of the desired type, eg. OSObject.

Return Value

A unique Type ID for the class.


OSTypeIDInst


Given a pointer to an object return it's typeID

#define OSTypeIDInst(typeinst)  
Parameters
typeinst

An instance of an OSObject subclass.

Return Value

The typeID, ie. OSMetaClass *.


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.

 

Last Updated: 2008-12-19