00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import "CPObject.j"
00024 @import "CPCoder.j"
00025
00026
00032 @implementation CPValue : CPObject
00033 {
00034 JSObject _JSObject;
00035 }
00036
00042 + (id)valueWithJSObject:(JSObject)aJSObject
00043 {
00044 return [[self alloc] initWithJSObject:aJSObject];
00045 }
00046
00052 - (id)initWithJSObject:(JSObject)aJSObject
00053 {
00054 self = [super init];
00055
00056 if (self)
00057 _JSObject = aJSObject;
00058
00059 return self;
00060 }
00061
00065 - (JSObject)JSObject
00066 {
00067 return _JSObject;
00068 }
00069
00070 @end
00071
00072 var CPValueValueKey = @"CPValueValueKey";
00073
00074 @implementation CPValue (CPCoding)
00075
00081 - (id)initWithCoder:(CPCoder)aCoder
00082 {
00083 self = [super init];
00084
00085 if (self)
00086 _JSObject = JSON.parse([aCoder decodeObjectForKey:CPValueValueKey]);
00087
00088 return self;
00089 }
00090
00095 - (void)encodeWithCoder:(CPCoder)aCoder
00096 {
00097 [aCoder encodeObject:JSON.stringify(_JSObject) forKey:CPValueValueKey];
00098 }
00099
00100 @end
00101
00102 function CPJSObjectCreateJSON(aJSObject)
00103 {
00104 CPLog.warn("CPJSObjectCreateJSON deprecated, use JSON.stringify() or CPString's objectFromJSON");
00105 return JSON.stringify(aJSObject);
00106 }
00107
00108 function CPJSObjectCreateWithJSON(aString)
00109 {
00110 CPLog.warn("CPJSObjectCreateWithJSON deprecated, use JSON.parse() or CPString's JSONFromObject");
00111 return JSON.parse(aString);
00112 }