|
Mac Dev Center
Mac OS X Reference Library Drivers, Kernel, & Hardware: Kernel Device Drivers Kernel Framework Reference
|
OSDictionary |
| Inherits from: | |
| Declared In: |
OSDictionary provides an associative store using strings for keys.
OSDictionary is a container for Libkern C++ objects (those derived from OSMetaClassBase, in particular OSObject). Storage and access are associative, based on string-valued keys (C string, OSString, or OSSymbol). When adding an object to an OSDictionary, you provide a string identifier, which can then used to retrieve that object or remove it from the dictionary. Setting an object with a key that already has an associated object replaces the original object.
You must generally cast retrieved objects from
OSObject
to the desired class using
OSDynamicCast.
This macro returns the object cast to the desired class,
or NULL if the object isn't derived from that class.
When iterating an OSDictionary using
OSCollectionIterator,
the objects returned from
getNextObject
are dictionary keys (not the object values for those keys).
You can use the keys to retrieve their associated object values.
As with all Libkern collection classes, OSDictionary retains keys and objects added to it, and releases keys and objects removed from it (or replaced). An OSDictionary also grows as necessary to accommodate new key/value pairs, unlike Core Foundation collections (it does not, however, shrink).
Note: OSDictionary currently uses a linear search algorithm, and is not designed for high-performance access of many values. It is intended as a simple associative-storage mechanism only.
Use Restrictions
With very few exceptions in the I/O Kit, all Libkern-based C++ classes, functions, and macros are unsafe to use in a primary interrupt context. Consult the I/O Kit documentation related to primary interrupts for more information.
OSDictionary provides no concurrency protection; it's up to the usage context to provide any protection necessary. Some portions of the I/O Kit, such as IORegistryEntry, handle synchronization via defined member functions for setting properties.
Creates a deep copy of the dictionary and its child collections.
Ensures the dictionary has enough space to store the requested number of key/object pairs.
Removes and releases all keys and objects within the dictionary.
Deallocates or releases any resources used by the OSDictionary instance.
Returns the number of objects the dictionary can store without reallocating.
Returns the storage increment of the dictionary.
Returns the current number of key/object pairs contained within the dictionary.
Returns the object stored under a given key.
Returns the object stored under a given key.
Returns the object stored under a given key.
Initializes a new instance of OSDictionary.
Initializes a new OSDictionary with the contents of another dictionary.
Initializes a new OSDictionary with keys and objects provided.
Initializes a new OSDictionary with keys and objects provided.
Tests the equality of an OSDictionary to an arbitrary object.
Tests the equality of two OSDictionary objects.
Tests the equality of two OSDictionary objects over a subset of keys.
Merges the contents of a dictionary into the receiver.
Removes a key/object pair from the dictionary.
Removes a key/object pair from the dictionary.
Removes a key/object pair from the dictionary.
Archives the receiver into the provided OSSerialize object.
Sets the storage increment of the dictionary.
Stores an object in the dictionary under a key.
Stores an object in the dictionary under a key.
Stores an object in the dictionary under a key.
Recursively sets option bits in the dictionary and all child collections.
Creates and initializes an empty OSDictionary.
Creates and initializes an OSDictionary populated with the contents of another dictionary.
Creates and initializes an OSDictionary populated with keys and objects provided.
Creates and initializes an OSDictionary populated with keys and objects provided.
copyCollection |
Creates a deep copy of the dictionary and its child collections.
public
OSCollection * copyCollection( OSDictionary *cycleDict = 0);
cycleDictA dictionary of all of the collections
that have been copied so far,
which is used to track circular references.
To start the copy at the top level,
pass NULL.
The newly copied dictionary, with a retain count of 1,
or NULL if there is insufficient memory to do the copy.
The receiving dictionary, and any collections it contains, recursively, are copied. Objects that are not derived from OSCollection are retained rather than copied.
ensureCapacity |
Ensures the dictionary has enough space to store the requested number of key/object pairs.
public
virtual unsigned int ensureCapacity( unsigned int newCapacity);
newCapacityThe total number of key/object pairs the dictionary should be able to store.
The new capacity of the dictionary, which may be different from the number requested (if smaller, reallocation of storage failed).
This function immediately resizes the dictionary, if necessary,
to accommodate at least newCapacity key/object pairs.
If newCapacity is not greater than the current capacity,
or if an allocation error occurs, the original capacity is returned.
There is no way to reduce the capacity of an OSDictionary.
flushCollection |
Removes and releases all keys and objects within the dictionary.
public
virtual void flushCollection();
The dictionary's capacity (and therefore direct memory consumption) is not reduced by this function.
free |
Deallocates or releases any resources used by the OSDictionary instance.
public
virtual void free();
This function should not be called directly,
use
release
instead.
getCapacity |
Returns the number of objects the dictionary can store without reallocating.
public
virtual unsigned int getCapacity() const;
The number objects the dictionary can store without reallocating.
OSDictionary objects grow when full
to accommodate additional key/object pairs.
See
getCapacityIncrement
and
ensureCapacity.
getCapacityIncrement |
Returns the storage increment of the dictionary.
public
virtual unsigned int getCapacityIncrement() const;
The storage increment of the dictionary.
An OSDictionary allocates storage for key/object pairs in multiples of the capacity increment.
getCount |
Returns the current number of key/object pairs contained within the dictionary.
public
virtual unsigned int getCount() const;
The current number of key/object pairs contained within the dictionary.
getObject |
Returns the object stored under a given key.
public
virtual OSObject * getObject( const char * aKey) const;
aKeyA C string key identifying the object to be returned to caller.
The object stored under aKey,
or NULL if the key does not exist in the dictionary.
The returned object will be released if removed from the dictionary;
if you plan to store the reference, you should call
retain
on that object.
getObject(const OSString *) |
Returns the object stored under a given key.
public
virtual OSObject * getObject( const OSString * aKey) const;
aKeyAn OSString key identifying the object to be returned to caller.
The object stored under aKey,
or NULL if the key does not exist in the dictionary.
The returned object will be released if removed from the dictionary;
if you plan to store the reference, you should call
retain
on that object.
getObject(const OSSymbol *) |
Returns the object stored under a given key.
public
virtual OSObject * getObject( const OSSymbol * aKey) const;
aKeyAn OSSymbol key identifying the object to be returned to the caller.
The object stored under aKey,
or NULL if the key does not exist in the dictionary.
The returned object will be released if removed from the dictionary;
if you plan to store the reference, you should call
retain
on that object.
initWithCapacity |
Initializes a new instance of OSDictionary.
public
virtual bool initWithCapacity( unsigned int capacity);
capacityThe initial storage capacity of the new dictionary object.
true on success, false on failure.
Not for general use. Use the static instance creation method
withCapacity
instead.
capacity must be nonzero.
The new dictionary will grow as needed
to accommodate more key/object pairs
(unlike
CFMutableDictionary,
for which the initial capacity is a hard limit).
initWithDictionary |
Initializes a new OSDictionary with the contents of another dictionary.
public
virtual bool initWithDictionary( const OSDictionary * dict, unsigned int capacity = 0);
dictA dictionary whose contents will be placed in the new instance.
capacityThe initial storage capacity of the new dictionary object.
If 0, the capacity is set to the number of key/value pairs
in dict;
otherwise capacity must be greater than or equal to
the number of key/value pairs in dict.
true on success, false on failure.
Not for general use. Use the static instance creation method
withDictionary instead.
dict must be non-NULL.
If capacity is nonzero,
it must be greater than or equal to count.
The new dictionary will grow as needed
to accommodate more key/object pairs
(unlike
CFMutableDictionary,
for which the initial capacity is a hard limit).
The keys and objects in dict are retained for storage
in the new OSDictionary,
not copied.
initWithObjects(const OSObject *, const OSString *, unsigned int, unsigned int) |
Initializes a new OSDictionary with keys and objects provided.
public
virtual bool initWithObjects( const OSObject * objects[], const OSString * keys[], unsigned int count, unsigned int capacity = 0);
objectsA C array of OSMetaClassBase-derived objects.
keysA C array of OSString keys
for the corresponding objects in objects.
countThe number of keys and objects to be placed into the dictionary.
capacityThe initial storage capacity of the new dictionary object.
If 0, count is used; otherwise this value
must be greater than or equal to count.
true on success, false on failure.
Not for general use. Use the static instance creation method
withObjects
instead.
objects and keys must be non-NULL,
and count must be nonzero.
If capacity is nonzero, it must be greater than or equal to count.
The new dictionary will grow as needed
to accommodate more key/object pairs
(unlike
CFMutableDictionary,
for which the initial capacity is a hard limit).
initWithObjects(const OSObject *, const OSSymbol *, unsigned int, unsigned int) |
Initializes a new OSDictionary with keys and objects provided.
public
virtual bool initWithObjects( const OSObject * objects[], const OSSymbol * keys[], unsigned int count, unsigned int capacity = 0);
objectsA C array of OSMetaClassBase-derived objects.
keysA C array of OSSymbol keys
for the corresponding objects in objects.
countThe number of keys and objects to be placed into the dictionary.
capacityThe initial storage capacity of the new dictionary object.
If 0, count is used; otherwise this value
must be greater than or equal to count.
true on success, false on failure.
Not for general use. Use the static instance creation method
withObjects
instead.
objects and keys must be non-NULL,
and count must be nonzero.
If capacity is nonzero,
it must be greater than or equal to count.
The new dictionary will grow as neede
to accommodate more key/object pairs
(unlike
CFMutableDictionary,
for which the initial capacity is a hard limit).
isEqualTo |
Tests the equality of an OSDictionary to an arbitrary object.
public
virtual bool isEqualTo( const OSMetaClassBase * anObject) const;
anObjectAn object to be compared against the receiver.
true if the objects are equal.
An OSDictionary is considered equal to another object if that object is derived from OSDictionary and contains the same or equivalent objects.
isEqualTo(const OSDictionary *) |
Tests the equality of two OSDictionary objects.
public
virtual bool isEqualTo( const OSDictionary * aDictionary) const;
aDictionaryThe dictionary to be compared against the receiver.
true if the dictionaries are equal,
false if not.
Two OSDictionary objects are considered equal if they have same count,
the same keys, and if the objects stored in each under
a given key compare as equal using
isEqualTo.
isEqualTo(const OSDictionary *, const OSCollection *) |
Tests the equality of two OSDictionary objects over a subset of keys.
public
virtual bool isEqualTo( const OSDictionary * aDictionary, const OSCollection * keys) const;
true if the intersections
of the two dictionaries are equal.
Two OSDictionary objects are considered equal by this function
if both have objects stored for all keys provided,
and if the objects stored in each under
a given key compare as equal using
isEqualTo.
merge |
Merges the contents of a dictionary into the receiver.
public
virtual bool merge( const OSDictionary * aDictionary);
aDictionaryThe dictionary whose contents are to be merged with the receiver.
true if the merge succeeds, false otherwise.
If there are keys in aDictionary that match keys
in the receiving dictionary,
then the objects in the receiver are replaced
by those from aDictionary,
and the replaced objects are released.
removeObject |
Removes a key/object pair from the dictionary.
public
virtual void removeObject( const char * aKey);
aKeyA C string identifying the object to be removed from the dictionary.
The removed key (internally an OSSymbol) and object are automatically released.
removeObject(const OSString *) |
Removes a key/object pair from the dictionary.
public
virtual void removeObject( const OSString * aKey);
aKeyA OSString identifying the object to be removed from the dictionary.
The removed key (not necessarily aKey itself)
and object are automatically released.
removeObject(const OSSymbol *) |
Removes a key/object pair from the dictionary.
public
virtual void removeObject( const OSSymbol * aKey);
aKeyAn OSSymbol identifying the object to be removed from the dictionary.
The removed key (not necessarily aKey itself)
and object are automatically released.
serialize |
Archives the receiver into the provided OSSerialize object.
public
virtual bool serialize( OSSerialize *serializer) const;
serializerThe OSSerialize object.
true if serialization succeeds, false if not.
setCapacityIncrement |
Sets the storage increment of the dictionary.
public
virtual unsigned int setCapacityIncrement( unsigned increment);
The new storage increment of the dictionary, which may be different from the number requested.
An OSDictionary allocates storage for key/object pairs in multiples of the capacity increment. Calling this function does not immediately reallocate storage.
setObject |
Stores an object in the dictionary under a key.
public
virtual bool setObject( const char * aKey, const OSMetaClassBase * anObject);
aKeyA C string identifying the object placed within the dictionary.
anObjectThe object to be stored in the dictionary. It is automatically retained.
true if the addition was successful,
false otherwise.
An OSSymbol for aKey is created internally.
An object already stored under aKey is released.
setObject(const OSString *, const OSMetaClassBase *) |
Stores an object in the dictionary under a key.
public
virtual bool setObject( const OSString * aKey, const OSMetaClassBase * anObject);
aKeyAn OSString identifying the object placed within the dictionary.
anObjectThe object to be stored in the dictionary. It is automatically retained.
true if the addition was successful,
false otherwise.
An OSSymbol for aKey is created internally.
An object already stored under aKey is released.
setObject(const OSSymbol *, const OSMetaClassBase *) |
Stores an object in the dictionary under a key.
public
virtual bool setObject( const OSSymbol * aKey, const OSMetaClassBase * anObject);
aKeyAn OSSymbol identifying the object placed within the dictionary. It is automatically retained.
anObjectThe object to be stored in the dictionary. It is automatically retained.
true if the addition was successful,
false otherwise.
An object already stored under aKey is released.
setOptions |
Recursively sets option bits in the dictionary and all child collections.
public
virtual unsigned setOptions( unsigned options, unsigned mask, void *context = 0);
optionsA bitfield whose values turn the options on (1) or off (0).
maskA mask indicating which bits
in options to change.
Pass 0 to get the whole current options bitfield
without changing any settings.
contextUnused.
The options bitfield as it was before the set operation.
Kernel extensions should not call this function.
Child collections' options are changed only if the receiving dictionary's options actually change.
withCapacity |
Creates and initializes an empty OSDictionary.
public
static OSDictionary * withCapacity( unsigned int capacity);
capacityThe initial storage capacity of the new dictionary object.
An empty instance of OSDictionary
with a retain count of 1;
NULL on failure.
capacity must be nonzero.
The new dictionary will grow as needed to accommodate more key/object pairs
(unlike CFMutableDictionary,
for which the initial capacity is a hard limit).
withDictionary |
Creates and initializes an OSDictionary populated with the contents of another dictionary.
public
static OSDictionary * withDictionary( const OSDictionary * dict, unsigned int capacity = 0);
dictA dictionary whose contents will be stored in the new instance.
capacityThe initial storage capacity of the new dictionary object.
If 0, the capacity is set to the number of key/value pairs
in dict;
otherwise capacity must be greater than or equal to
the number of key/value pairs in dict.
An instance of OSDictionary
containing the key/value pairs of dict,
with a retain count of 1;
NULL on failure.
dict must be non-NULL.
If capacity is nonzero, it must be greater than or equal to count.
The new dictionary will grow as needed
to accommodate more key/object pairs
(unlike
CFMutableDictionary,
for which the initial capacity is a hard limit).
The keys and objects in dict are retained for storage
in the new OSDictionary,
not copied.
withObjects(const OSObject *, const OSString *, unsigned int, unsigned int) |
Creates and initializes an OSDictionary populated with keys and objects provided.
public
static OSDictionary * withObjects( const OSObject * objects[], const OSString * keys[], unsigned int count, unsigned int capacity = 0);
objectsA C array of OSMetaClassBase-derived objects.
keysA C array of OSString keys for the corresponding objects
in objects.
countThe number of keys and objects to be placed into the dictionary.
capacityThe initial storage capacity of the new dictionary object.
If 0, count is used; otherwise this value
must be greater than or equal to count.
An instance of OSDictionary
containing the key/object pairs provided,
with a retain count of 1;
NULL on failure.
objects and keys must be non-NULL,
and count must be nonzero.
If capacity is nonzero, it must be greater than or equal to count.
The new dictionary will grow as needed
to accommodate more key/object pairs
(unlike
CFMutableDictionary,
for which the initial capacity is a hard limit).
withObjects(const OSObject *, const OSSymbol *, unsigned int, unsigned int) |
Creates and initializes an OSDictionary populated with keys and objects provided.
public
static OSDictionary * withObjects( const OSObject * objects[], const OSSymbol * keys[], unsigned int count, unsigned int capacity = 0);
objectsA C array of OSMetaClassBase-derived objects.
keysA C array of OSSymbol keys
for the corresponding objects in objects.
countThe number of keys and objects to be placed into the dictionary.
capacityThe initial storage capacity of the new dictionary object.
If 0, count is used; otherwise this value
must be greater than or equal to count.
An instance of OSDictionary
containing the key/object pairs provided,
with a retain count of 1;
NULL on failure.
objects and keys must be non-NULL,
and count must be nonzero.
If capacity is nonzero,
it must be greater than or equal to count.
The new dictionary will grow as needed
to accommodate more key/object pairs
(unlike
CFMutableDictionary,
for which the initial capacity is a hard limit).
Last Updated: 2009-10-14