55 #ifndef _COLLECTION_H_
56 #define _COLLECTION_H_
60 #ifdef SNMP_PP_NAMESPACE
64 #define MAXT 25 // elements per block
83 : count(0), data(0,0) {};
89 : count(1), data(0, 0)
91 data.item[0] = (T*) (t.clone());
98 : count(0), data(0, 0)
100 if (c.
count == 0)
return;
107 while (count < c.
count)
111 nextBlock =
new cBlock(current, 0);
112 current->
next = nextBlock;
118 current->
item[cn] = (T*) (tmp->clone());
146 int cn = (int) count %
MAXT;
147 while (current->
next)
148 current = current->
next;
149 if ((count > 0) && ((count %
MAXT) == 0))
152 if (!add)
return *
this;
154 add->
item[0] = (T*) (i.clone());
158 current->
item[cn] = (T*) (i.clone());
170 if (
this == &c)
return *
this;
174 if (c.
count == 0)
return *
this;
181 while (count < c.
count)
185 nextBlock =
new cBlock(current, 0);
186 current->
next = nextBlock;
192 current->
item[cn] = (T*) (tmp->clone());
207 if ((p < count) && (p >= 0))
209 cBlock const *current = &data;
210 int bn = (int) (p /
MAXT);
211 int cn = (int) p %
MAXT;
212 for (
int z=0; z<bn; z++)
213 current = current->
next;
214 return *(current->
item[cn]);
231 if ((p < 0) || (p > count))
return -1;
234 int bn = (int) p /
MAXT;
235 int cn = (int) p %
MAXT;
236 for (
int z=0; z<bn; z++)
237 current = current->
next;
238 delete current->
item[cn];
239 current->
item[cn] = (T*) (i.clone());
250 if ((p < 0) || (p > count))
return -1;
252 cBlock const *current = &data;
253 int bn = (int) p /
MAXT;
254 int cn = (int) p %
MAXT;
255 for (
int z=0; z<bn; z++)
256 current = current->
next;
257 t = *(current->
item[cn]);
268 if ((p < 0) || (p > count))
return -1;
270 cBlock const *current = &data;
271 int bn = (int) p /
MAXT;
272 int cn = (int) p %
MAXT;
273 for (
int z=0; z<bn; z++)
274 current = current->
next;
275 t = current->
item[cn];
285 for (
int z=0; z<count; z++)
287 this->get_element(temp, z);
297 int find(
const T& i,
int &pos)
const
300 for (
int z=0; z<count; z++)
302 this->get_element(temp, z);
314 int remove(
const T& i)
322 for (
int z=0; z<count; z++)
327 get_element(item, z);
328 newCollection += item;
333 operator =(newCollection);
345 if (count == 0)
return;
355 current = current->
next;
357 delete current->
item[cn];
363 while (current->
next)
364 current = current->
next;
365 while (current->
prev)
367 current = current->
prev;
368 delete current->
next;
381 #ifdef SNMP_PP_NAMESPACE
385 #endif // _COLLECTION_H_
int size() const
Get the size of the collection.
int set_element(const T &i, const int p)
Set an element in the collection.
SnmpCollection(const T &t)
Create a collection using a single template object.
int find(const T &i, int &pos) const
Looks for an element in the collection.
~SnmpCollection()
Destroy the collection.
int get_element(T *&t, const int p) const
Get a pointer to an element in the collection.
SnmpCollection(const SnmpCollection< T > &c)
Create a collection with another collection (copy constructor).
int get_element(T &t, const int p) const
Get an element in the collection.
void apply(void f(T &))
Apply an function to the entire collection, iterator.
T operator[](const int p) const
Access an element in the collection.
void clear()
Delete all elements within the collection.
SnmpCollection()
Create an empty collection.