2020-03-03 06:24:41 +00:00
|
|
|
#include <PropertyList.h>
|
2004-11-13 01:55:00 +00:00
|
|
|
|
|
|
|
@implementation PLItem
|
|
|
|
|
2011-02-13 12:25:36 +00:00
|
|
|
+ (PLItem *) newDictionary
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
return [PLDictionary new];
|
|
|
|
}
|
|
|
|
|
2011-02-13 12:25:36 +00:00
|
|
|
+ (PLItem *) newArray
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
return [PLArray new];
|
|
|
|
}
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
+ (PLItem *) newData:(void*) data size:(int) len
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
return [PLData new:data size:len];
|
|
|
|
}
|
|
|
|
|
2011-02-13 12:25:36 +00:00
|
|
|
+ (PLItem *) newString:(string) str
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
return [PLString new:str];
|
|
|
|
}
|
|
|
|
|
2006-12-02 06:51:41 +00:00
|
|
|
+ itemClass:(plitem_t) item
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
2011-01-14 03:07:40 +00:00
|
|
|
local string classname = nil;
|
2010-12-16 11:01:49 +00:00
|
|
|
local id class;
|
2004-11-13 01:55:00 +00:00
|
|
|
|
2012-12-18 06:54:30 +00:00
|
|
|
if (!item)
|
2011-01-14 03:07:40 +00:00
|
|
|
return nil;
|
2004-11-13 01:55:00 +00:00
|
|
|
switch (PL_Type (item)) {
|
|
|
|
case QFDictionary:
|
|
|
|
classname = "PLDictionary";
|
|
|
|
break;
|
|
|
|
case QFArray:
|
|
|
|
classname = "PLArray";
|
|
|
|
break;
|
|
|
|
case QFBinary:
|
|
|
|
classname = "PLData";
|
|
|
|
break;
|
|
|
|
case QFString:
|
|
|
|
classname = "PLString";
|
|
|
|
break;
|
|
|
|
default:
|
2011-01-14 03:07:40 +00:00
|
|
|
return nil;
|
2004-11-13 01:55:00 +00:00
|
|
|
}
|
|
|
|
class = obj_lookup_class (classname);
|
|
|
|
return [[class alloc] initWithItem: item];
|
|
|
|
}
|
|
|
|
|
2011-02-13 12:25:36 +00:00
|
|
|
+ (PLItem *) fromString:(string) str
|
2010-12-16 11:01:49 +00:00
|
|
|
{
|
|
|
|
return [[PLItem itemClass: PL_GetPropertyList (str)] autorelease];
|
|
|
|
}
|
|
|
|
|
2011-02-13 12:25:36 +00:00
|
|
|
+ (PLItem *) fromFile:(QFile) file
|
2010-12-16 11:01:49 +00:00
|
|
|
{
|
|
|
|
return [[PLItem itemClass: PL_GetFromFile (file)] autorelease];
|
|
|
|
}
|
|
|
|
|
2006-12-02 06:51:41 +00:00
|
|
|
- initWithItem:(plitem_t) item
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
if (!(self = [super init]))
|
|
|
|
return self;
|
|
|
|
self.item = item;
|
|
|
|
own = 0;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-initWithOwnItem:(plitem_t) item
|
|
|
|
{
|
|
|
|
if (!(self = [super init]))
|
|
|
|
return self;
|
|
|
|
self.item = item;
|
|
|
|
own = 1;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2011-02-13 12:29:24 +00:00
|
|
|
- (void) dealloc
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
if (own)
|
|
|
|
PL_Free (item);
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (string) write
|
|
|
|
{
|
|
|
|
return PL_WritePropertyList (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (pltype_t) type
|
|
|
|
{
|
|
|
|
return PL_Type (item);
|
|
|
|
}
|
|
|
|
|
2020-12-23 12:52:42 +00:00
|
|
|
- (int) line
|
|
|
|
{
|
|
|
|
return PL_Line (item);
|
|
|
|
}
|
|
|
|
|
2020-07-05 05:38:44 +00:00
|
|
|
- (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);
|
|
|
|
}
|
|
|
|
|
2004-11-13 01:55:00 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
@implementation PLDictionary
|
|
|
|
|
2011-02-13 12:25:36 +00:00
|
|
|
+ (PLDictionary *) new
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
return [[PLDictionary alloc] initWithOwnItem: PL_NewDictionary ()];
|
|
|
|
}
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
- (int) count
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
return PL_D_NumKeys (item);
|
|
|
|
}
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
- (int) numKeys
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
return PL_D_NumKeys (item);
|
|
|
|
}
|
|
|
|
|
2011-02-13 12:25:36 +00:00
|
|
|
- (PLItem *) getObjectForKey:(string) key
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
2010-11-22 05:05:48 +00:00
|
|
|
return [[PLItem itemClass: PL_ObjectForKey (item, key)] autorelease];
|
2004-11-13 01:55:00 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 12:25:36 +00:00
|
|
|
- (PLItem *) allKeys
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
2010-11-22 05:05:48 +00:00
|
|
|
return [[PLItem itemClass: PL_D_AllKeys (item)] autorelease];
|
2004-11-13 01:55:00 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 12:25:36 +00:00
|
|
|
- addKey:(string) key value:(PLItem *) value
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
2006-12-09 06:00:36 +00:00
|
|
|
if (!value.own) {
|
2004-11-13 01:55:00 +00:00
|
|
|
obj_error (self, 0, "add of unowned key/value to PLDictionary");
|
|
|
|
return self;
|
|
|
|
}
|
2006-12-09 06:00:36 +00:00
|
|
|
PL_D_AddObject (item, key, value.item);
|
|
|
|
value.own = 0;
|
2004-11-13 01:55:00 +00:00
|
|
|
[value release];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PLArray
|
|
|
|
|
2011-02-13 12:25:36 +00:00
|
|
|
+ (PLArray *) new
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
return [[PLArray alloc] initWithOwnItem: PL_NewArray ()];
|
|
|
|
}
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
- (int) count
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
return PL_A_NumObjects (item);
|
|
|
|
}
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
- (int) numObjects
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
return PL_A_NumObjects (item);
|
|
|
|
}
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
- (PLItem *) getObjectAtIndex:(int) index
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
2010-11-22 05:05:48 +00:00
|
|
|
return [[PLItem itemClass: PL_ObjectAtIndex (item, index)] autorelease];
|
2004-11-13 01:55:00 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 12:25:36 +00:00
|
|
|
- addObject:(PLItem *) object
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
- insertObject:(PLItem *) object atIndex:(int) index
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PLData
|
|
|
|
|
2011-03-25 07:46:32 +00:00
|
|
|
+ (PLData *) new:(void*) data size:(int) len
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
return [[PLData alloc] initWithOwnItem: PL_NewData (data, len)];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PLString
|
|
|
|
|
2011-02-13 12:25:36 +00:00
|
|
|
+ (PLString *) new: (string) str
|
2004-11-13 01:55:00 +00:00
|
|
|
{
|
|
|
|
return [[PLString alloc] initWithOwnItem: PL_NewString (str)];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (string) string
|
|
|
|
{
|
|
|
|
return PL_String (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|