GNUstep Core Data 0.1
NSAttributeDescription.m
1/* Implementation of the NSAttributeDescription class for the GNUstep
2 Core Data framework.
3 Copyright (C) 2005 Free Software Foundation, Inc.
4
5 Written by: Saso Kiselkov <diablos@manga.sk>
6 Date: August 2005
7
8 This file is part of the GNUstep Core Data framework.
9
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
14
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free
22 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
23 */
24
25#import "CoreDataHeaders.h"
26
27@implementation NSAttributeDescription
28
29- (NSAttributeType) attributeType
30{
31 return _attributeType;
32}
33
34- (void) setAttributeType: (NSAttributeType) type
35{
36 [self _ensureEditableWithReason: @"Tried to set the type of an attribute "
37 @"already in use."];
38 _attributeType = type;
39}
40
41- (NSString *) attributeValueClassName
42{
43 switch(_attributeType)
44 {
45 case NSUndefinedAttributeType: return @"NSNull";
46 case NSInteger16AttributeType: return @"NSNumber";
47 case NSInteger32AttributeType: return @"NSNumber";
48 case NSInteger64AttributeType: return @"NSNumber";
49 case NSDecimalAttributeType: return @"NSDecimalNumber";
50 case NSDoubleAttributeType: return @"NSNumber";
51 case NSFloatAttributeType: return @"NSNumber";
52 case NSStringAttributeType: return @"NSString";
53 case NSBooleanAttributeType: return @"NSNumber";
54 case NSDateAttributeType: return @"NSDate";
55 case NSBinaryDataAttributeType: return @"NSData";
56 }
57 return nil;
58}
59
60- (id) defaultValue
61{
62 return _defaultValue;
63}
64
65- (void) setDefaultValue: (id) aValue
66{
67 [self _ensureEditableWithReason: @"Tried to set the default value for "
68 @"an attribute already in use."];
69
70 ASSIGN(_defaultValue, aValue);
71}
72
73// NSCoding
74
75- (id) initWithCoder: (NSCoder *) coder
76{
77 if ((self = [super initWithCoder: coder]))
78 {
79 if ([coder allowsKeyedCoding])
80 {
81 _attributeType = [coder decodeIntForKey: @"AttributeType"];
82 // ASSIGN(_attributeValueClassName, [coder decodeObjectForKey:
83 // @"AttributeValueClassName"]);
84 ASSIGN(_defaultValue, [coder decodeObjectForKey: @"DefaultValue"]);
85 }
86 else
87 {
88 [coder decodeValueOfObjCType: @encode(int) at: &_attributeType];
89 // ASSIGN(_attributeValueClassName, [coder decodeObject]);
90 ASSIGN(_defaultValue, [coder decodeObject]);
91 }
92
93 }
94 return self;
95}
96
97- (void) encodeWithCoder: (NSCoder *) coder
98{
99 [super encodeWithCoder: coder];
100
101 if ([coder allowsKeyedCoding])
102 {
103 [coder encodeInt: _attributeType forKey: @"AttributeType"];
104 // [coder encodeObject: _attributeValueClassName
105 // forKey: @"AttributeValueClassName"];
106 [coder encodeObject: _defaultValue forKey: @"DefaultValue"];
107 }
108 else
109 {
110 [coder encodeValueOfObjCType: @encode(int) at: &_attributeType];
111 // [coder encodeObject: _attributeValueClassName];
112 [coder encodeObject: _defaultValue];
113 }
114}
115
116// NSCopying
117
118- (id) copyWithZone: (NSZone *) zone
119{
120 NSAttributeDescription * attr = [super copyWithZone: zone];
121
122 [attr setAttributeType: _attributeType];
123// [attr setAttributeValueClassName: _attributeValueClassName];
124 [attr setDefaultValue: _defaultValue];
125
126 return attr;
127}
128
129@end