collect2.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*_############################################################################
  2. _##
  3. _## collect2.h
  4. _##
  5. _## SNMP++v3.2.23
  6. _## -----------------------------------------------
  7. _## Copyright (c) 2001-2007 Jochen Katz, Frank Fock
  8. _##
  9. _## This software is based on SNMP++2.6 from Hewlett Packard:
  10. _##
  11. _## Copyright (c) 1996
  12. _## Hewlett-Packard Company
  13. _##
  14. _## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
  15. _## Permission to use, copy, modify, distribute and/or sell this software
  16. _## and/or its documentation is hereby granted without fee. User agrees
  17. _## to display the above copyright notice and this license notice in all
  18. _## copies of the software and any documentation of the software. User
  19. _## agrees to assume all liability for the use of the software;
  20. _## Hewlett-Packard and Jochen Katz make no representations about the
  21. _## suitability of this software for any purpose. It is provided
  22. _## "AS-IS" without warranty of any kind, either express or implied. User
  23. _## hereby grants a royalty-free license to any and all derivatives based
  24. _## upon this software code base.
  25. _##
  26. _## Stuttgart, Germany, Sun Nov 11 15:10:59 CET 2007
  27. _##
  28. _##########################################################################*/
  29. // $Id: collect2.h 287 2007-03-22 22:37:09Z katz $
  30. #ifdef SNMP_PP_NAMESPACE
  31. namespace Snmp_pp {
  32. #endif
  33. template <class T> class SnmpCollection
  34. {
  35. class cBlock
  36. {
  37. public:
  38. cBlock(cBlock *p, cBlock *n) : prev(p), next(n) {};
  39. T *item[MAXT];
  40. cBlock *prev;
  41. cBlock *next;
  42. };
  43. public:
  44. /**
  45. * Create an empty collection.
  46. */
  47. SnmpCollection();
  48. /**
  49. * Create a collection using a single template object.
  50. */
  51. SnmpCollection(const T &t);
  52. /**
  53. * Create a collection with another collection (copy constructor).
  54. */
  55. SnmpCollection(const SnmpCollection<T> &c);
  56. /**
  57. * Destroy the collection.
  58. */
  59. ~SnmpCollection();
  60. /**
  61. * Get the size of the collection.
  62. */
  63. int size() const;
  64. /**
  65. * Append an item to the collection.
  66. */
  67. SnmpCollection& operator +=( const T &i);
  68. /**
  69. * Assign one collection to another.
  70. */
  71. SnmpCollection & operator = ( const SnmpCollection<T> &c);
  72. /**
  73. * Access an element in the collection.
  74. *
  75. * @return The requestet element or an empty element if out of bounds.
  76. */
  77. T operator[](const int p) const;
  78. /**
  79. * Set an element in the collection.
  80. *
  81. * @return 0 on success and -1 on failure.
  82. */
  83. int set_element( const T& i, const int p);
  84. /**
  85. * Get an element in the collection.
  86. *
  87. * @return 0 on success and -1 on failure.
  88. */
  89. int get_element(T& t, const int p) const;
  90. /**
  91. * Get a pointer to an element in the collection.
  92. *
  93. * @return 0 on success and -1 on failure.
  94. */
  95. int get_element(T *&t, const int p) const;
  96. /**
  97. * Apply an function to the entire collection, iterator.
  98. */
  99. void apply( void f( T&));
  100. /**
  101. * Looks for an element in the collection.
  102. *
  103. * @return TRUE if found.
  104. */
  105. int find( const T& i,int &pos) const;
  106. /**
  107. * Delete an element in the collection.
  108. */
  109. int remove( const T& i);
  110. /**
  111. * Delete all elements within the collection.
  112. */
  113. void clear();
  114. private:
  115. int count;
  116. cBlock data;
  117. };
  118. #ifdef SNMP_PP_NAMESPACE
  119. } // end of namespace Snmp_pp
  120. #endif