API  1.0.0
CPData.j
Go to the documentation of this file.
1 /*
2  * CPData.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 
28 @implementation CPData : CPObject
29 {
30  id __doxygen__;
31 }
32 
33 + (id)alloc
34 {
35  var result = new CFMutableData();
36  result.isa = [self class];
37  return result;
38 }
39 
40 + (CPData)data
41 {
42  return [[self alloc] init];
43 }
44 
45 + (CPData)dataWithRawString:(CPString)aString
46 {
47  return [[self alloc] initWithRawString:aString];
48 }
49 
50 + (CPData)dataWithPlistObject:(id)aPlistObject
51 {
52  return [[self alloc] initWithPlistObject:aPlistObject];
53 }
54 
55 + (CPData)dataWithPlistObject:(id)aPlistObject format:(CPPropertyListFormat)aFormat
56 {
57  return [[self alloc] initWithPlistObject:aPlistObject format:aFormat];
58 }
59 
60 + (CPData)dataWithJSONObject:(Object)anObject
61 {
62  return [[self alloc] initWithJSONObject:anObject];
63 }
64 
65 + (CPData)dataWithBytes:(CPArray)bytesArray
66 {
67  var data = [[self alloc] init];
68  data.setBytes(bytesArray);
69 
70  return data;
71 }
72 
73 + (CPData)dataWithBase64:(CPString)aString
74 {
75  var data = [[self alloc] init];
76  data.setBase64String(aString);
77 
78  return data;
79 }
80 
81 - (id)initWithRawString:(CPString)aString
82 {
83  self = [super init];
84 
85  if (self)
86  [self setRawString:aString];
87 
88  return self;
89 }
90 
91 - (id)initWithPlistObject:(id)aPlistObject
92 {
93  self = [super init];
94 
95  if (self)
96  [self setPlistObject:aPlistObject];
97 
98  return self;
99 }
100 
101 - (id)initWithPlistObject:(id)aPlistObject format:aFormat
102 {
103  self = [super init];
104 
105  if (self)
106  [self setPlistObject:aPlistObject format:aFormat];
107 
108  return self;
109 }
110 
111 - (id)initWithJSONObject:(Object)anObject
112 {
113  self = [super init];
114 
115  if (self)
116  [self setJSONObject:anObject];
117 
118  return self;
119 }
120 
121 - (CPString)rawString
122 {
123  return self.rawString();
124 }
125 
126 - (id)plistObject
127 {
128  return self.propertyList();
129 }
130 
131 - (Object)JSONObject
132 {
133  return self.JSONObject();
134 }
135 
136 - (CPArray)bytes
137 {
138  return self.bytes();
139 }
140 
141 - (CPString)base64
142 {
143  return self.base64();
144 }
145 
146 - (int)length
147 {
148  return [[self rawString] length];
149 }
150 
152 {
153  return self.toString();
154 }
155 
156 @end
157 
158 @implementation CPData (CPMutableData)
159 
160 - (void)setRawString:(CPString)aString
161 {
162  self.setRawString(aString);
163 }
164 
165 - (void)setPlistObject:(id)aPlistObject
166 {
167  self.setPropertyList(aPlistObject);
168 }
169 
170 - (void)setPlistObject:(id)aPlistObject format:(CPPropertyListFormat)aFormat
171 {
172  self.setPropertyList(aPlistObject, aFormat);
173 }
174 
175 - (void)setJSONObject:(Object)anObject
176 {
177  self.setJSONObject(anObject);
178 }
179 
180 @end
181 
182 @implementation CPData (Deprecated)
183 
184 + (id)dataWithString:(CPString)aString
185 {
186  _CPReportLenientDeprecation(self, _cmd, @selector(dataWithRawString:));
187 
188  return [self dataWithRawString:aString];
189 }
190 
191 - (id)initWithString:(CPString)aString
192 {
193  _CPReportLenientDeprecation(self, _cmd, @selector(initWithRawString:));
194 
195  return [self initWithRawString:aString];
196 }
197 
198 - (void)setString:(CPString)aString
199 {
200  _CPReportLenientDeprecation(self, _cmd, @selector(setRawString:));
201 
202  [self setRawString:aString];
203 }
204 
205 - (CPString)string
206 {
207  _CPReportLenientDeprecation(self, _cmd, @selector(rawString));
208 
209  return [self rawString];
210 }
211 
212 @end
213 
214 CFData.prototype.isa = CPData;
215 CFMutableData.prototype.isa = CPData;
id initWithRawString:(CPString aString)
Definition: CPData.j:81
id initWithPlistObject:(id aPlistObject)
Definition: CPData.j:91
id alloc()
Definition: CPData.j:33
CPString rawString()
Definition: CPData.j:121
A Cappuccino wrapper for any data type.
Definition: CPData.h:2
An immutable string (collection of characters).
Definition: CPString.h:2
CPData dataWithRawString:(CPString aString)
Definition: CPData.j:45
int length()
Definition: CPString.j:186
void setJSONObject:(Object anObject)
Definition: CPData.j:175
id init()
Definition: CPObject.j:145
void setPlistObject:format:(id aPlistObject, [format] CPPropertyListFormat aFormat)
Definition: CPData.j:170
Class class()
Definition: CPObject.j:179
id initWithPlistObject:format:(id aPlistObject, [format] id aFormat)
Definition: CPData.j:101
void setRawString:(CPString aString)
Definition: CPData.j:160
void setPlistObject:(id aPlistObject)
Definition: CPData.j:165
id initWithJSONObject:(Object anObject)
Definition: CPData.j:111
FrameUpdater prototype description