diff --git a/ruamoko/include/PropertyList.h b/ruamoko/include/PropertyList.h index 3deb99a2b..c0c4bed35 100644 --- a/ruamoko/include/PropertyList.h +++ b/ruamoko/include/PropertyList.h @@ -4,7 +4,29 @@ #include #include -@interface PLItem: Object +@class PLItem; + +@protocol PLDictionary +- (int) count; +- (int) numKeys; +- (PLItem *) getObjectForKey:(string) key; +- (PLItem *) allKeys; +- addKey:(string) key value:(PLItem *) value; +@end + +@protocol PLArray +- (int) count; +- (int) numObjects; +- (PLItem *) getObjectAtIndex:(int) index; +- addObject:(PLItem *) object; +- insertObject:(PLItem *) object atIndex:(int) index; +@end + +@protocol PLString +- (string) string; +@end + +@interface PLItem: Object { plitem_t item; int own; @@ -22,34 +44,20 @@ - (pltype_t) type; @end -@interface PLDictionary: PLItem +@interface PLDictionary: PLItem + (PLDictionary *) new; - -- (int) count; -- (int) numKeys; -- (PLItem *) getObjectForKey:(string) key; -- (PLItem *) allKeys; -- addKey:(string) key value:(PLItem *) value; @end -@interface PLArray: PLItem +@interface PLArray: PLItem + (PLArray *) new; - -- (int) count; -- (int) numObjects; -- (PLItem *) getObjectAtIndex:(int) index; -- addObject:(PLItem *) object; -- insertObject:(PLItem *) object atIndex:(int) index; @end @interface PLData: PLItem + (PLData *) new:(void*) data size:(int) len; @end -@interface PLString: PLItem +@interface PLString: PLItem + (PLString *) new:(string) str; - -- (string) string; @end #endif//__ruamoko_PropertyList_h diff --git a/ruamoko/lib/PropertyList.r b/ruamoko/lib/PropertyList.r index b65edc85d..b8469e473 100644 --- a/ruamoko/lib/PropertyList.r +++ b/ruamoko/lib/PropertyList.r @@ -94,6 +94,81 @@ return PL_Type (item); } +- (int) count +{ + if ([self class] == [PLDictionary class]) { + return PL_D_NumKeys (item); + } else { + return PL_A_NumObjects (item); + } +} + +- (int) numKeys +{ + return PL_D_NumKeys (item); +} + +- (PLItem *) getObjectForKey:(string) key +{ + return [[PLItem itemClass: PL_ObjectForKey (item, key)] autorelease]; +} + +- (PLItem *) allKeys +{ + return [[PLItem itemClass: PL_D_AllKeys (item)] autorelease]; +} + +- addKey:(string) key value:(PLItem *) value +{ + if (!value.own) { + obj_error (self, 0, "add of unowned key/value to PLDictionary"); + return self; + } + PL_D_AddObject (item, key, value.item); + value.own = 0; + [value release]; + return self; +} + +- (int) numObjects +{ + return PL_A_NumObjects (item); +} + +- (PLItem *) getObjectAtIndex:(int) index +{ + return [[PLItem itemClass: PL_ObjectAtIndex (item, index)] autorelease]; +} + +- addObject:(PLItem *) object +{ + if (!object.own) { + obj_error (self, 0, "add of unowned object to PLArray"); + return self; + } + PL_A_AddObject (item, object.item); + object.own = 0; + [object release]; + return self; +} + +- insertObject:(PLItem *) object atIndex:(int) index +{ + if (!object.own) { + obj_error (self, 0, "add of unowned object to PLArray"); + return self; + } + PL_A_InsertObjectAtIndex (item, object.item, index); + object.own = 0; + [object release]; + return self; +} + +- (string) string +{ + return PL_String (item); +} + @end