2 Copyright (C) 2005 Helge Hess
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "NGVCardAddress.h"
25 @implementation NGVCardAddress
28 [self->pobox release];
29 [self->extadd release];
30 [self->street release];
31 [self->locality release];
32 [self->region release];
33 [self->pcode release];
34 [self->country release];
43 - (NSString *)extadd {
46 - (NSString *)street {
49 - (NSString *)locality {
50 return self->locality;
52 - (NSString *)region {
58 - (NSString *)country {
62 /* fake being an array */
64 - (id)objectAtIndex:(unsigned)_idx {
68 case 0: return (s = [self pobox]) ? s : (NSString *)[NSNull null];
69 case 1: return (s = [self extadd]) ? s : (NSString *)[NSNull null];
70 case 2: return (s = [self street]) ? s : (NSString *)[NSNull null];
71 case 3: return (s = [self locality]) ? s : (NSString *)[NSNull null];
72 case 4: return (s = [self region]) ? s : (NSString *)[NSNull null];
73 case 5: return (s = [self pcode]) ? s : (NSString *)[NSNull null];
74 case 6: return (s = [self country]) ? s : (NSString *)[NSNull null];
77 // TODO: throw exception
86 - (NSString *)stringValue {
87 return [self vCardString];
90 - (NSString *)xmlString {
94 ms = [[NSMutableString alloc] initWithCapacity:256];
95 [self appendXMLTag:@"pobox" value:[self pobox] to:ms];
96 [self appendXMLTag:@"extadd" value:[self extadd] to:ms];
97 [self appendXMLTag:@"street" value:[self street] to:ms];
98 [self appendXMLTag:@"locality" value:[self locality] to:ms];
99 [self appendXMLTag:@"region" value:[self region] to:ms];
100 [self appendXMLTag:@"pcode" value:[self pcode] to:ms];
101 [self appendXMLTag:@"country" value:[self country] to:ms];
102 s = [[ms copy] autorelease];
107 - (NSString *)vCardString {
111 ms = [[NSMutableString alloc] initWithCapacity:256];
112 [self appendVCardValue:[self pobox] to:ms]; [ms appendString:@";"];
113 [self appendVCardValue:[self extadd] to:ms]; [ms appendString:@";"];
114 [self appendVCardValue:[self street] to:ms]; [ms appendString:@";"];
115 [self appendVCardValue:[self locality] to:ms]; [ms appendString:@";"];
116 [self appendVCardValue:[self region] to:ms]; [ms appendString:@";"];
117 [self appendVCardValue:[self pcode] to:ms]; [ms appendString:@";"];
118 [self appendVCardValue:[self country] to:ms];
119 s = [[ms copy] autorelease];
124 - (NSDictionary *)asDictionary {
125 static NSString *keys[] = {
126 @"pobox", @"extadd", @"street", @"locality", @"region", @"pcode",
132 for (i = 0; i < [self count]; i++)
133 values[i] = [self objectAtIndex:i];
135 return [NSDictionary dictionaryWithObjects:values forKeys:keys
139 - (NSArray *)asArray {
140 id values[[self count] + 1];
143 for (i = 0; i < [self count]; i++)
144 values[i] = [self objectAtIndex:i];
146 return [NSArray arrayWithObjects:values count:[self count]];
151 - (void)encodeWithCoder:(NSCoder *)_coder {
152 [super encodeWithCoder:_coder];
154 [_coder encodeObject:self->pobox];
155 [_coder encodeObject:self->extadd];
156 [_coder encodeObject:self->street];
157 [_coder encodeObject:self->locality];
158 [_coder encodeObject:self->region];
159 [_coder encodeObject:self->pcode];
160 [_coder encodeObject:self->country];
162 - (id)initWithCoder:(NSCoder *)_coder {
163 if ((self = [super initWithCoder:_coder]) != nil) {
164 self->pobox = [[_coder decodeObject] copy];
165 self->extadd = [[_coder decodeObject] copy];
166 self->street = [[_coder decodeObject] copy];
167 self->locality = [[_coder decodeObject] copy];
168 self->region = [[_coder decodeObject] copy];
169 self->pcode = [[_coder decodeObject] copy];
170 self->country = [[_coder decodeObject] copy];
175 @end /* NGVCardAddress */