55 #ifndef _SNMP_COLLECT_H_ 56 #define _SNMP_COLLECT_H_ 61 #ifdef SNMP_PP_NAMESPACE 65 #define MAXT 25 // elements per block 84 : count(0), data(0,0) {}
90 : count(1), data(0, 0)
92 data.item[0] = (T*) (t.clone());
99 : count(0), data(0, 0)
101 if (c.
count == 0)
return;
108 while (count < c.
count)
112 nextBlock =
new cBlock(current, 0);
113 current->
next = nextBlock;
119 current->
item[cn] = (T*) (tmp->clone());
147 int cn = (int) count %
MAXT;
148 while (current->
next)
149 current = current->
next;
150 if ((count > 0) && ((count %
MAXT) == 0))
153 if (!add)
return *
this;
155 add->
item[0] = (T*) (i.clone());
159 current->
item[cn] = (T*) (i.clone());
171 if (
this == &c)
return *
this;
175 if (c.
count == 0)
return *
this;
182 while (count < c.
count)
186 nextBlock =
new cBlock(current, 0);
187 current->
next = nextBlock;
193 current->
item[cn] = (T*) (tmp->clone());
208 if ((p < count) && (p >= 0))
210 cBlock const *current = &data;
211 int bn = (int) (p /
MAXT);
212 int cn = (int) p %
MAXT;
213 for (
int z=0; z<bn; z++)
214 current = current->
next;
215 return *(current->
item[cn]);
232 if ((p < 0) || (p > count))
return -1;
235 int bn = (int) p /
MAXT;
236 int cn = (int) p %
MAXT;
237 for (
int z=0; z<bn; z++)
238 current = current->
next;
239 delete current->
item[cn];
240 current->
item[cn] = (T*) (i.clone());
251 if ((p < 0) || (p > count))
return -1;
253 cBlock const *current = &data;
254 int bn = (int) p /
MAXT;
255 int cn = (int) p %
MAXT;
256 for (
int z=0; z<bn; z++)
257 current = current->
next;
258 t = *(current->
item[cn]);
269 if ((p < 0) || (p > count))
return -1;
271 cBlock const *current = &data;
272 int bn = (int) p /
MAXT;
273 int cn = (int) p %
MAXT;
274 for (
int z=0; z<bn; z++)
275 current = current->
next;
276 t = current->
item[cn];
286 for (
int z=0; z<count; z++)
288 this->get_element(temp, z);
298 int find(
const T& i,
int &pos)
const 301 for (
int z=0; z<count; z++)
303 this->get_element(temp, z);
315 int remove(
const T& i)
323 for (
int z=0; z<count; z++)
328 get_element(item, z);
329 newCollection += item;
334 operator =(newCollection);
346 if (count == 0)
return;
356 current = current->
next;
358 delete current->
item[cn];
364 while (current->
next)
365 current = current->
next;
366 while (current->
prev)
368 current = current->
prev;
369 delete current->
next;
382 #ifdef SNMP_PP_NAMESPACE 386 #endif // _SNMP_COLLECT_H_
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.
T operator[](const int p) const
Access an element in the collection.
int size() const
Get the size of the collection.
~SnmpCollection()
Destroy the collection.
int get_element(T &t, const int p) const
Get an element in the collection.
SnmpCollection(const SnmpCollection< T > &c)
Create a collection with another collection (copy constructor).
int find(const T &i, int &pos) const
Looks for an element in the collection.
void apply(void f(T &))
Apply an function to the entire collection, iterator.
int get_element(T *&t, const int p) const
Get a pointer to an element in the collection.
void clear()
Delete all elements within the collection.
SnmpCollection()
Create an empty collection.