mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
[libr] Make PLItem more useful
I can't say that I like what's there even now, but at least PLItem can be used without a lot of casting. Really, Ruamoko needs dictionary and string classes so reading a property list can build more natural object trees rather than this mess from when I knew too little.
This commit is contained in:
parent
f544a6f0b0
commit
7a478b4ce7
2 changed files with 101 additions and 18 deletions
|
@ -4,7 +4,29 @@
|
|||
#include <plist.h>
|
||||
#include <Object.h>
|
||||
|
||||
@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 <PLDictionary, PLArray, PLString>
|
||||
{
|
||||
plitem_t item;
|
||||
int own;
|
||||
|
@ -22,34 +44,20 @@
|
|||
- (pltype_t) type;
|
||||
@end
|
||||
|
||||
@interface PLDictionary: PLItem
|
||||
@interface PLDictionary: PLItem <PLDictionary>
|
||||
+ (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>
|
||||
+ (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>
|
||||
+ (PLString *) new:(string) str;
|
||||
|
||||
- (string) string;
|
||||
@end
|
||||
|
||||
#endif//__ruamoko_PropertyList_h
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue