GNUstep Core Data  0.1
NSAttributeDescription.m
00001 /* Implementation of the NSAttributeDescription class for the GNUstep
00002    Core Data framework.
00003    Copyright (C) 2005 Free Software Foundation, Inc.
00004 
00005    Written by:  Saso Kiselkov <diablos@manga.sk>
00006    Date: August 2005
00007 
00008    This file is part of the GNUstep Core Data framework.
00009 
00010    This library is free software; you can redistribute it and/or
00011    modify it under the terms of the GNU Lesser General Public
00012    License as published by the Free Software Foundation; either
00013    version 2.1 of the License, or (at your option) any later version.
00014 
00015    This library is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018    Lesser General Public License for more details.
00019 
00020    You should have received a copy of the GNU Lesser General Public
00021    License along with this library; if not, write to the Free
00022    Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
00023  */
00024 
00025 #import "CoreDataHeaders.h"
00026 
00027 @implementation NSAttributeDescription
00028 
00029 - (NSAttributeType) attributeType
00030 {
00031   return _attributeType;
00032 }
00033 
00034 - (void) setAttributeType: (NSAttributeType) type
00035 {
00036   [self _ensureEditableWithReason: @"Tried to set the type of an attribute "
00037                                    @"already in use."];
00038   _attributeType = type;
00039 }
00040 
00041 - (NSString *) attributeValueClassName
00042 {
00043         switch(_attributeType)
00044                 {
00045                 case NSUndefinedAttributeType: return @"NSNull";
00046                 case NSInteger16AttributeType: return @"NSNumber";
00047                 case NSInteger32AttributeType: return @"NSNumber";
00048                 case NSInteger64AttributeType: return @"NSNumber";
00049                 case NSDecimalAttributeType: return @"NSDecimalNumber";
00050                 case NSDoubleAttributeType: return @"NSNumber";
00051                 case NSFloatAttributeType: return @"NSNumber";
00052                 case NSStringAttributeType: return @"NSString";
00053                 case NSBooleanAttributeType: return @"NSNumber";
00054                 case NSDateAttributeType: return @"NSDate";
00055                 case NSBinaryDataAttributeType: return @"NSData";
00056                 }
00057         return nil;
00058 }
00059 
00060 - (id) defaultValue
00061 {
00062   return _defaultValue;
00063 }
00064 
00065 - (void) setDefaultValue: (id) aValue
00066 {
00067   [self _ensureEditableWithReason: @"Tried to set the default value for "
00068                                    @"an attribute already in use."];
00069 
00070   ASSIGN(_defaultValue, aValue);
00071 }
00072 
00073 // NSCoding
00074 
00075 - (id) initWithCoder: (NSCoder *) coder
00076 {
00077   if ((self = [super initWithCoder: coder]))
00078     {
00079       if ([coder allowsKeyedCoding])
00080         {
00081           _attributeType = [coder decodeIntForKey: @"AttributeType"];
00082  //         ASSIGN(_attributeValueClassName, [coder decodeObjectForKey:
00083   //          @"AttributeValueClassName"]);
00084           ASSIGN(_defaultValue, [coder decodeObjectForKey: @"DefaultValue"]);
00085         }
00086       else
00087         {
00088           [coder decodeValueOfObjCType: @encode(int) at: &_attributeType];
00089   //        ASSIGN(_attributeValueClassName, [coder decodeObject]);
00090           ASSIGN(_defaultValue, [coder decodeObject]);
00091         }
00092 
00093     }
00094         return self;
00095 }
00096 
00097 - (void) encodeWithCoder: (NSCoder *) coder
00098 {
00099   [super encodeWithCoder: coder];
00100 
00101   if ([coder allowsKeyedCoding])
00102     {
00103       [coder encodeInt: _attributeType forKey: @"AttributeType"];
00104   //    [coder encodeObject: _attributeValueClassName
00105   //               forKey: @"AttributeValueClassName"];
00106       [coder encodeObject: _defaultValue forKey: @"DefaultValue"];
00107     }
00108   else
00109     {
00110       [coder encodeValueOfObjCType: @encode(int) at: &_attributeType];
00111   //    [coder encodeObject: _attributeValueClassName];
00112       [coder encodeObject: _defaultValue];
00113     }
00114 }
00115 
00116 // NSCopying
00117 
00118 - (id) copyWithZone: (NSZone *) zone
00119 {
00120   NSAttributeDescription * attr = [super copyWithZone: zone];
00121 
00122   [attr setAttributeType: _attributeType];
00123 //  [attr setAttributeValueClassName: _attributeValueClassName];
00124   [attr setDefaultValue: _defaultValue];
00125 
00126   return attr;
00127 }
00128 
00129 @end