Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 218 lines (177 sloc) 5.173 kb
3cc7082 Initial git checkin
Michael Dales authored
1 //
2 // XXConnectionBag.m
3 // osx2x
4 //
5 // Copyright (c) Michael Dales 2002, 2003
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
11 //
12 // Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // Neither the name of Michael Dales nor the names of its contributors may be
20 // used to endorse or promote products derived from this software without
21 // specific prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 // PURPOSE ARE DISCLAIMED. IN NO EVENT S HALL THE COPYRIGHT OWNER OR
27 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 // PROFITS; OR BUSINESS I NTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 //
35
36 #import "XXConnectionBag.h"
37
38
39 @implementation XXConnectionBag
40
41 - init
42 {
43 if ((self = [super init]) != nil)
44 {
45 int i;
46
47 for (i = 0; i < 5; i++)
48 bag[i] = nil;
49
50 size = 0;
51 }
52
53 return self;
54 }
55
56 - (void)addConnection: (XXConnection*)connection
57 {
58 XXWindowPos pos;
59
60 // first see if we have a connection in that position, if not, don't allow it
61 pos = [connection getPosition];
62
63 if (bag[pos] != nil)
64 {
65 NSException* myException = [NSException exceptionWithName: @"InsertionFailed"
66 reason: @"Duplicate Entry"
67 userInfo: nil];
68 [myException raise];
69 }
70
71 bag[pos] = connection;
72 size += 1;
73 }
74
75 - (void)removeConnection: (XXConnection*)connection
76 {
77 int i;
78 NSException* myException;
79
80 for (i = 0; i < 5; i++)
81 {
82 if (bag[i] == connection)
83 {
84 NSLog(@"Removing connection\n");
85
86 size -= 1;
87 bag[i] = nil;
88
89 return;
90 }
91 }
92
93 myException = [NSException exceptionWithName: @"RemoveFailed"
94 reason: @"Invalid Entry"
95 userInfo: nil];
96 [myException raise];
97 }
98
99 - (void)removeFromPosition: (XXWindowPos)position
100 {
101 NSException* myException;
102
103
104 if (bag[position] != nil)
105 {
106 size -= 1;
107 bag[position] = nil;
108
109 return;
110 }
111
112 myException = [NSException exceptionWithName: @"RemoveFailed"
113 reason: @"Invalid Entry"
114 userInfo: nil];
115 [myException raise];
116 }
117
118
119 - (XXConnection*)getFromPosition: (XXWindowPos)position;
120 {
121 if (position < 5)
122 return bag[position];
123 else
124 return nil;
125 }
126
127
128 - (XXConnection*)getFromTableRow: (int)row
129 {
130 int i, j;
131 XXConnection* connection = nil;
132
133 // get the "rowIndex"th entry
134 for (i = 0, j = -1; i < 5; i++)
135 {
136 if (bag[i] != nil)
137 {
138 j++;
139 if (j == row)
140 {
141 connection = bag[i];
142 break;
143 }
144 }
145 }
146
147 return connection;
148 }
149
150 - (int)count
151 {
152 return size;
153 }
154
155
156 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
157 {
158 return size;
159 }
160
161
162 - (id)tableView: (NSTableView *)aTableView
163 objectValueForTableColumn:(NSTableColumn *)aTableColumn
164 row:(int)rowIndex
165 {
166 NSUserDefaults *defaults;
167 int column, i, j;
168 id temp;
169 XXConnection* connection;
170
171 temp = [aTableColumn identifier];
172 column = [temp intValue];
173 defaults = [NSUserDefaults standardUserDefaults];
174
175 // get the "rowIndex"th entry
176 for (i = 0, j = -1; i < 5; i++)
177 {
178 if (bag[i] != nil)
179 {
180 j++;
181 if (j == rowIndex)
182 {
183 connection = bag[i];
184 break;
185 }
186 }
187 }
188
189 if (connection != nil)
190 {
191 switch (column)
192 {
193 case 1:
194 return [connection getHostName];
195 break;
196 case 2:
197 return [connection getPositionName];
198 break;
199 case 3:
200 return [connection getConnectionName];
201 break;
202 }
203 }
204
205 return nil;
206 }
207
208
209 - (void)tableView:(NSTableView *)aTableView
210 setObjectValue:(id)anObject
211 forTableColumn:(NSTableColumn *)aTableColumn
212 row:(int)rowIndex
213 {
214 }
215
216
217 @end
Something went wrong with that request. Please try again.