The IDLValueType class represents
valuetype type and is responsible for marshaling and de-marshaling valuetypes. A
valuetype can be mapped to an arbitrary Objective C class using the
#pragma class directive in an IDL file or programmatically, using
-setObjectClassName: method. The Objective C class should define the appropriate instance variables or access methods. Different valuetypes can be mapped to the same Objective C class. The framework does not force the Objective C classes to have the same inheritance relationships as the corresponding valuetypes. It is up to developer how to design the Objective C classes.
Unlike IDL struct type, valuetype allows to send and receive an object of a valuetype derived from the argument's type, which may be valuetype or an abstract interface.
The receiving context knows how to decode a received object because the valuetype's typeID is passed along with the object state. This being passed valuetype is used to decode and instantiate the object. If an Objective C class is specified for the being passed valuetype using
#pragma class, the object is instantiated with
if instances respond to selector
-initWithIDLType:, and with
If no class is specified
IDLObject class is used. The object's state is set using KVC method
The sending context has no direct information, which valuetype to use to encode the being passed Objective C object. There is no reverse Objective C class to valuetype mapping. The
valuetype must be either the one specified in the IDL definition or any derived valuetype.
If the object implements method
-valuetype and this method returns a valid IDL type then this IDL type is used to encode the object. Otherwise, to find out the IDLValueType instance to encode the object the IDLValueType class first checks its cache for the object's class. If IDLValueType instance for the class is in the cache and if that instance satisfies the IDL definition (i.e. is the one specified or is derived from it) then this instance is used.
Otherwise IDLValueType sends a notification
IDLValuetypeNeededForObject on behalf of the Objective C object providing NSMutableDictionary as the userInfo with the key(s) valuetype and/or interface and the values that are instances of
IDLInterface classes correspondingly. If a subscriber for this notification knows the proper valuetype for the object it adds or replaces the entry with the key valuetype in the userInfo dictionary.
If the argument type is a valuetype then the corresponding IDLValueType instance is provided in the userInfo dictionary. Otherwise, if the argument is an abstract interface the corresponding instance of IDLInterface class is provided with the key interface.
The IDLValueType instances subscribe for the notification
IDLValuetypeNeededForObject. An IDLValueType instance provides the valuetype for an object in the following way:
#pragma classor programmatically, and the object is kind of that object class, i.e. instance of the class itself or its subclass, then IDLValueType checks the userInfo dictionary. Otherwise it ignores the notification.
The framework uses Key Value Coding to encode the object's state, by calling the method
setValue:forKey: for every valuetype's member.
Returns the IDLValueType instance for
Returns an IDLValueType instance to encode the object.
Returns an IDLValueType instance to encode the object. The instance supports the abstract interface interface.
The method first looks in the cache. If not in the cache or does not support interface, the method posts notification
IDLValuetypeNeededForObject on behalf of the object. The userInfo contains key
@"interface" with the interface as the value.
Registers value for the Objective C class objectClass in the IDLValueType class' cache.
Removes all classes from IDLValueType cache.
Returns an IDLValueType instance to encode the object. The returned instance is the receiver or is derived from the receiver.
If not found in the cache, the receiver posts notification
IDLValuetypeNeededForObject on behalf of the object. The userInfo contains the key "valuetype" with the receiver as the value.
Returns YES if the receiver is an abstract valuetype.
Returns the concrete valuetype the receiver is derived from, if any, or nil.
Returns YES if the receiver is derived from the valuetype value, directly or indirectly. The value may be concrete or abstract.
Returns YES if the receiver is derived from the (abstract) interface interface, directly or indirectly.
If type is a valuetype or an interface then calls one of the previous two methods. Otherwise returns NO.
This notification is posted when a valuetype is needed to marshal an object. The notification object is the object that needs to be marshaled. The userInfo is the NSMutableDictionary with the key valuetype in the case IDL specifies a valuetype, or with the key interface in the case IDL specifies an abstract interface.
Note that if IDL specifies an abstract interface and the object can be marshaled as an object reference with a derived concrete interface then the object will be marshaled as IOR.