API  0.9.7
 All Classes Files Functions Variables Macros Groups Pages
CPValue.j
Go to the documentation of this file.
1 /*
2  * CPValue.j
3  * Foundation
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2008, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
31 @implementation CPValue : CPObject
32 {
33  JSObject _JSObject;
34 }
35 
41 + (id)valueWithJSObject:(JSObject)aJSObject
42 {
43  return [[self alloc] initWithJSObject:aJSObject];
44 }
45 
51 - (id)initWithJSObject:(JSObject)aJSObject
52 {
53  self = [super init];
54 
55  if (self)
56  _JSObject = aJSObject;
57 
58  return self;
59 }
60 
64 - (JSObject)JSObject
65 {
66  return _JSObject;
67 }
68 
69 @end
70 
71 var CPValueValueKey = @"CPValueValueKey";
72 
73 @implementation CPValue (CPCoding)
74 
80 - (id)initWithCoder:(CPCoder)aCoder
81 {
82  self = [super init];
83 
84  if (self)
85  _JSObject = JSON.parse([aCoder decodeObjectForKey:CPValueValueKey]);
86 
87  return self;
88 }
89 
94 - (void)encodeWithCoder:(CPCoder)aCoder
95 {
96  [aCoder encodeObject:JSON.stringify(_JSObject) forKey:CPValueValueKey];
97 }
98 
99 @end
100 
101 function CPJSObjectCreateJSON(aJSObject)
102 {
103  CPLog.warn("CPJSObjectCreateJSON deprecated, use JSON.stringify() or CPString's objectFromJSON");
104  return JSON.stringify(aJSObject);
105 }
106 
107 function CPJSObjectCreateWithJSON(aString)
108 {
109  CPLog.warn("CPJSObjectCreateWithJSON deprecated, use JSON.parse() or CPString's JSONFromObject");
110  return JSON.parse(aString);
111 }