Initial revision
[TestXSLT.git] / ParameterSet.m
1 //
2 //  ParameterSet.m
3 //  TestXSLT
4 //
5 //  Created by Marc Liyanage on Sat Mar 09 2002.
6 //  Copyright (c) 2001 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "ParameterSet.h"
10
11
12 @implementation ParameterSet
13
14 - (id)init {
15
16         if (self = [super init]) {
17                 parameters = [[NSMutableArray alloc] init];
18                 cArray = NULL;
19         }
20
21         //      NSLog(@"ParameterSet init, %@", parameters);
22
23         return self;
24
25 }
26
27 - (void)dealloc {
28
29         [parameters release];
30         if (cArray != NULL) {
31                 free(cArray);
32         }
33
34         [super dealloc];
35 //      NSLog(@"ParameterSet dealloc");
36 }
37
38
39 - (void)encodeWithCoder:(NSCoder *)coder {
40         [coder encodeObject:parameters];
41 }
42
43
44 - (id)initWithCoder:(NSCoder *)coder {
45
46         if (self = [super init]) {
47                 [self setParameterSet:[coder decodeObject]];
48         }
49         return self;
50
51 }
52
53 - (void)setParameterSet:(NSMutableArray *)array {
54
55         [array retain];
56         [parameters release];
57         parameters = array;
58
59 }
60
61
62 - (void)addParameter:(NSString *)name withValue:(NSString *)value {
63         
64         NSMutableDictionary *entry = [NSMutableDictionary dictionaryWithCapacity:2];
65         [entry setObject:name forKey:@"parameterName"];
66         [entry setObject:value forKey:@"parameterValue"];
67
68 //      NSLog("entry: %@", entry);      
69         
70         [parameters addObject:entry];
71
72 }
73
74
75
76 - (void)setField:(NSString *)fieldName atIndex:(int)index toString:(NSString *)s {
77         [[parameters objectAtIndex:index] setObject:s forKey:fieldName];
78 }
79
80 - (NSString *)getField:(NSString *)fieldName atIndex:(int)index {
81         return [[parameters objectAtIndex:index] objectForKey:fieldName];
82 }
83
84
85
86 - (void)removeParameterAtIndex:(int)index {
87         [parameters removeObjectAtIndex:index];
88 }
89
90 - (void)removeParameterByName:(NSString *)name {
91
92         int i;
93         NSString *currentName;
94         
95         for (i = 0; i < [self count]; i++) {
96                 currentName = [self getField:@"parameterName" atIndex:i];
97                 if ([currentName isEqualToString:name]) {
98                         [self removeParameterAtIndex:i];
99                         [self removeParameterByName:name];
100                 }
101         }
102
103 }
104
105
106 - (int)count {
107         return [parameters count];
108 }
109
110 - (const char **)cArray {
111
112         int i;
113         const char **temp;
114         
115         if (cArray != NULL) {
116                 free(cArray);
117         }
118
119         temp = cArray = malloc((([self count] * 2) + 1) * sizeof(char *));
120
121
122         for (i = 0; i < [self count]; i++) {
123
124                 *(temp++) = (char *)[[self getField:@"parameterName" atIndex:i] cString];
125                 *(temp++) = (char *)[[self getField:@"parameterValue" atIndex:i] cString];
126         
127         }
128         
129         *(temp) = NULL;
130         
131         return cArray;
132 }
133
134
135
136 @end