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