1 #ifndef JAWS_ASSOC_ARRAY_CPP
2 #define JAWS_ASSOC_ARRAY_CPP
4 #include "ace/config-all.h"
5 #include "JAWS/Assoc_Array.h"
7 template <class KEY
, class DATA
>
8 JAWS_Assoc_Array
<KEY
,DATA
>::JAWS_Assoc_Array (int maxsize
)
13 typedef void * ptr_type
;
15 this->k_array_
= reinterpret_cast<KEY
**> (new ptr_type
[this->maxsize_
]);
16 if (this->k_array_
== 0)
22 this->d_array_
= reinterpret_cast<DATA
**> (new ptr_type
[this->maxsize_
]);
23 if (this->d_array_
== 0)
25 delete[] this->k_array_
;
30 for (int i
= 0; i
< this->maxsize_
; i
++)
32 this->k_array_
[i
] = 0;
33 this->d_array_
[i
] = 0;
37 template <class KEY
, class DATA
>
38 JAWS_Assoc_Array
<KEY
,DATA
>::~JAWS_Assoc_Array ()
42 delete[] reinterpret_cast<void **> (this->k_array_
);
43 delete[] reinterpret_cast<void **> (this->d_array_
);
49 template <class KEY
, class DATA
> int
50 JAWS_Assoc_Array
<KEY
,DATA
>::index (const KEY
&k
)
52 return this->find_i (k
);
55 template <class KEY
, class DATA
> DATA
*
56 JAWS_Assoc_Array
<KEY
,DATA
>::find (const KEY
&k
)
58 int i
= this->find_i (k
);
60 return (i
< this->maxsize_
) ? this->d_array_
[i
] : 0;
63 template <class KEY
, class DATA
> DATA
*
64 JAWS_Assoc_Array
<KEY
,DATA
>::find_by_index (int i
)
66 return ((0 <= i
) && (i
< this->maxsize_
)) ? this->d_array_
[i
] : 0;
69 template <class KEY
, class DATA
> DATA
*
70 JAWS_Assoc_Array
<KEY
,DATA
>::insert (const KEY
&k
, const DATA
&d
)
72 int i
= this->find_i (k
);
74 if (i
== this->maxsize_
)
77 KEY
*&kk
= this->k_array_
[i
];
78 DATA
*&dd
= this->d_array_
[i
];
86 KEY
*kkk
= new KEY (k
);
98 template <class KEY
, class DATA
> int
99 JAWS_Assoc_Array
<KEY
,DATA
>::remove (const KEY
&k
)
101 int i
= this->find_i (k
);
103 if (i
== this->maxsize_
)
106 KEY
*&kk
= this->k_array_
[i
];
107 DATA
*&dd
= this->d_array_
[i
];
122 template <class KEY
, class DATA
> void
123 JAWS_Assoc_Array
<KEY
,DATA
>::clear ()
125 for (int i
= 0; i
< this->maxsize_
; i
++)
127 if (this->k_array_
[i
] != 0)
129 delete this->k_array_
[i
];
130 delete this->d_array_
[i
];
132 this->k_array_
[i
] = 0;
133 this->d_array_
[i
] = 0;
138 template <class KEY
, class DATA
> int
139 JAWS_Assoc_Array
<KEY
,DATA
>::find_i (const KEY
&k
)
141 int j
= this->maxsize_
;
143 for (int i
= 0; i
< this->maxsize_
; i
++)
145 KEY
*kk
= this->k_array_
[i
];
151 else if (j
== this->maxsize_
)
157 template <class KEY
, class DATA
>
158 JAWS_Assoc_Array_Iterator
<KEY
,DATA
>::
159 JAWS_Assoc_Array_Iterator (const JAWS_Assoc_Array
<KEY
, DATA
> &aa
)
166 template <class KEY
, class DATA
>
167 JAWS_Assoc_Array_Iterator
<KEY
,DATA
>::~JAWS_Assoc_Array_Iterator ()
171 template <class KEY
, class DATA
> KEY
*
172 JAWS_Assoc_Array_Iterator
<KEY
,DATA
>::key ()
174 return this->aa_
.k_array_
[this->i_
];
177 template <class KEY
, class DATA
> DATA
*
178 JAWS_Assoc_Array_Iterator
<KEY
,DATA
>::data ()
180 return this->aa_
.d_array_
[this->i_
];
183 template <class KEY
, class DATA
> int
184 JAWS_Assoc_Array_Iterator
<KEY
,DATA
>::first ()
187 for (this->j_
= 0; this->j_
< this->aa_
.maxsize_
; this->j_
++)
189 if (this->aa_
.k_array_
[this->j_
] != 0)
192 return this->next ();
195 template <class KEY
, class DATA
> int
196 JAWS_Assoc_Array_Iterator
<KEY
,DATA
>::last ()
198 this->j_
= this->aa_
.maxsize_
;
199 for (this->i_
= this->aa_
.maxsize_
; this->i_
> 0; this->i_
--)
201 if (this->aa_
.k_array_
[this->i_
-1] != 0)
205 return (this->i_
-- > 0);
208 template <class KEY
, class DATA
> int
209 JAWS_Assoc_Array_Iterator
<KEY
,DATA
>::next ()
211 if (this->j_
< this->aa_
.maxsize_
)
214 for (this->j_
++; this->j_
< this->aa_
.maxsize_
; this->j_
++)
216 if (this->aa_
.k_array_
[this->j_
] != 0)
221 return (this->i_
< this->aa_
.maxsize_
);
224 template <class KEY
, class DATA
> int
225 JAWS_Assoc_Array_Iterator
<KEY
,DATA
>::previous ()
229 for (this->j_
= this->i_
; this->i_
> 0; this->i_
--)
231 if (this->aa_
.k_array_
[this->i_
-1] != 0)
244 template <class KEY
, class DATA
> int
245 JAWS_Assoc_Array_Iterator
<KEY
,DATA
>::is_done ()
247 return (this->j_
== this->aa_
.maxsize_
);
250 template <class KEY
, class DATA
>
251 JAWS_Assoc_Array_Iterator
<KEY
,DATA
>::
252 JAWS_Assoc_Array_Iterator (const JAWS_Assoc_Array_Iterator
<KEY
, DATA
> &aai
)
259 template <class KEY
, class DATA
> void
260 JAWS_Assoc_Array_Iterator
<KEY
,DATA
>::
261 operator= (const JAWS_Assoc_Array_Iterator
<KEY
, DATA
> &)
265 #endif /* !defined (JAWS_ASSOC_ARRAY_CPP) */