forked from cappuccino/cappuccino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCPCoder.j
158 lines (140 loc) · 3.83 KB
/
CPCoder.j
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* CPCoder.j
* Foundation
*
* Created by Francisco Tolmasky.
* Copyright 2008, 280 North, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import "CPException.j"
@import "CPObject.j"
/*!
@class CPCoder
@ingroup foundation
@brief Defines methods for use when archiving & restoring (enc/decoding).
Top-level class defining methods for use when archiving (encoding) objects to a byte array
or file, and when restoring (decoding) objects.
*/
@implementation CPCoder : CPObject
{
}
/*!
Returns a flag indicating whether the receiver supports keyed coding. The default implementation returns
\c NO. Subclasses supporting keyed coding must override this to return \c YES.
*/
- (BOOL)allowsKeyedCoding
{
return NO;
}
/*!
Encodes a structure or object of a specified type. Usually this
is used for primitives though it can be used for objects as well.
Subclasses must override this method.
@param aType the structure or object type
@param anObject the object to be encoded
*/
- (void)encodeValueOfObjCType:(CPString)aType at:(id)anObject
{
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
Encodes a data object. Subclasses must override this method.
@param aData the object to be encoded.
*/
- (void)encodeDataObject:(CPData)aData
{
_CPRaiseInvalidAbstractInvocation(self, _cmd);
}
/*!
Encodes an object. Subclasses must override this method.
@param anObject the object to be encoded
*/
- (void)encodeObject:(id)anObject
{
// [self encodeValueOfObjCType:@encode(id) at:object];
}
/*!
Encodes a point
@param aPoint the point to be encoded.
*/
- (void)encodePoint:(CPPoint)aPoint
{
[self encodeNumber:aPoint.x];
[self encodeNumber:aPoint.y];
}
/*!
Encodes a CGRect
@param aRect the rectangle to be encoded.
*/
- (void)encodeRect:(CGRect)aRect
{
[self encodePoint:aRect.origin];
[self encodeSize:aRect.size];
}
/*!
Encodes a CGSize
@param aSize the size to be encoded
*/
- (void)encodeSize:(CPSize)aSize
{
[self encodeNumber:aSize.width];
[self encodeNumber:aSize.height];
}
/*!
Encodes a property list. Not yet implemented.
@param aPropertyList the property list to be encoded
*/
- (void)encodePropertyList:(id)aPropertyList
{
// [self encodeValueOfObjCType:@encode(id) at:&propertyList];
}
/*!
Encodes the root object of a group of Obj-J objects.
@param rootObject the root object to be encoded.
*/
- (void)encodeRootObject:(id)anObject
{
[self encodeObject:anObject];
}
/*!
Encodes an object.
@param anObject the object to be encoded.
*/
- (void)encodeBycopyObject:(id)anObject
{
[self encodeObject:anObject];
}
/*!
Encodes an object.
@param anObject the object to be encoded.
*/
- (void)encodeConditionalObject:(id)anObject
{
[self encodeObject:anObject];
}
@end
@implementation CPObject (CPCoding)
/*!
Called after an object is unarchived in case a different object should be used in place of it.
The default method returns \c self. Interested subclasses should override this.
@param aDecoder
@return the original object or it's substitute.
*/
- (id)awakeAfterUsingCoder:(CPCoder)aDecoder
{
return self;
}
@end