API 0.9.5
Foundation/CPValue.j
Go to the documentation of this file.
00001 /*
00002  * CPValue.j
00003  * Foundation
00004  *
00005  * Created by Francisco Tolmasky.
00006  * Copyright 2008, 280 North, Inc.
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 
00031 @implementation CPValue : CPObject
00032 {
00033     JSObject    _JSObject;
00034 }
00035 
00041 + (id)valueWithJSObject:(JSObject)aJSObject
00042 {
00043     return [[self alloc] initWithJSObject:aJSObject];
00044 }
00045 
00051 - (id)initWithJSObject:(JSObject)aJSObject
00052 {
00053     self = [super init];
00054 
00055     if (self)
00056         _JSObject = aJSObject;
00057 
00058     return self;
00059 }
00060 
00064 - (JSObject)JSObject
00065 {
00066     return _JSObject;
00067 }
00068 
00069 @end
00070 
00071 var CPValueValueKey = @"CPValueValueKey";
00072 
00073 @implementation CPValue (CPCoding)
00074 
00080 - (id)initWithCoder:(CPCoder)aCoder
00081 {
00082     self = [super init];
00083 
00084     if (self)
00085         _JSObject = JSON.parse([aCoder decodeObjectForKey:CPValueValueKey]);
00086 
00087     return self;
00088 }
00089 
00094 - (void)encodeWithCoder:(CPCoder)aCoder
00095 {
00096     [aCoder encodeObject:JSON.stringify(_JSObject) forKey:CPValueValueKey];
00097 }
00098 
00099 @end
00100 
00101 function CPJSObjectCreateJSON(aJSObject)
00102 {
00103     CPLog.warn("CPJSObjectCreateJSON deprecated, use JSON.stringify() or CPString's objectFromJSON");
00104     return JSON.stringify(aJSObject);
00105 }
00106 
00107 function CPJSObjectCreateWithJSON(aString)
00108 {
00109     CPLog.warn("CPJSObjectCreateWithJSON deprecated, use JSON.parse() or CPString's JSONFromObject");
00110     return JSON.parse(aString);
00111 }
 All Classes Files Functions Variables Defines