API  1.0.0
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 
30 @implementation CPValue : CPObject
31 {
32  JSObject _JSObject;
33 }
34 
40 + (id)valueWithJSObject:(JSObject)aJSObject
41 {
42  return [[self alloc] initWithJSObject:aJSObject];
43 }
44 
50 - (id)initWithJSObject:(JSObject)aJSObject
51 {
52  self = [super init];
53 
54  if (self)
55  _JSObject = aJSObject;
56 
57  return self;
58 }
59 
63 - (JSObject)JSObject
64 {
65  return _JSObject;
66 }
67 
68 @end
69 
70 var CPValueValueKey = @"CPValueValueKey";
71 
72 @implementation CPValue (CPCoding)
73 
79 - (id)initWithCoder:(CPCoder)aCoder
80 {
81  self = [super init];
82 
83  if (self)
84  _JSObject = JSON.parse([aCoder decodeObjectForKey:CPValueValueKey]);
85 
86  return self;
87 }
88 
93 - (void)encodeWithCoder:(CPCoder)aCoder
94 {
95  [aCoder encodeObject:JSON.stringify(_JSObject) forKey:CPValueValueKey];
96 }
97 
98 @end
99 
100 function CPJSObjectCreateJSON(aJSObject)
101 {
102  CPLog.warn("CPJSObjectCreateJSON deprecated, use JSON.stringify() or CPString's objectFromJSON");
103  return JSON.stringify(aJSObject);
104 }
105 
106 function CPJSObjectCreateWithJSON(aString)
107 {
108  CPLog.warn("CPJSObjectCreateWithJSON deprecated, use JSON.parse() or CPString's JSONFromObject");
109  return JSON.parse(aString);
110 }
id initWithJSObject:(JSObject aJSObject)
Definition: CPValue.j:50
JSObject JSObject()
Definition: CPValue.j:63
var CPValueValueKey
Definition: CPValue.j:70
A generic "value". Can be subclassed to hold specific data types.
Definition: CPValue.h:2
function CPJSObjectCreateJSON(aJSObject)
Definition: CPValue.j:100
Defines methods for use when archiving & restoring (enc/decoding).
Definition: CPCoder.h:2
id init()
Definition: CPObject.j:145
id alloc()
Definition: CPObject.j:130
function CPJSObjectCreateWithJSON(aString)
Definition: CPValue.j:106