hash_deleter.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef HASH_DELETER_H
  15. #define HASH_DELETER_H
  16. #include <boost/shared_ptr.hpp>
  17. #include <util/lru_list.h>
  18. #include "hash_table.h"
  19. namespace isc {
  20. namespace nsas {
  21. /// \brief Delete Object from Hash Table
  22. ///
  23. /// This is the object passed to the LRU list constructors that deletes the
  24. /// ZoneEntry from the hash table when the zone is deleted from the LRU list.
  25. ///
  26. /// It is declared as a nested class so as to be able to access the
  27. /// hash table without the need to be declared as "friend" or the need
  28. /// to define accessor methods.
  29. template <typename T>
  30. class HashDeleter : public isc::util::LruList<T>::Dropped {
  31. public:
  32. /// \brief Constructor
  33. ///
  34. /// \param hashtable Reference to the hash table from which information is
  35. /// to be deleted. The table is assumed to remain in existence for the life
  36. /// of this object.
  37. ///
  38. /// \param hashtable Hash table from which the element should be deleted.
  39. HashDeleter(HashTable<T>& hashtable) : hashtable_(hashtable)
  40. {}
  41. /// \brief Destructor
  42. ///
  43. virtual ~HashDeleter(){}
  44. // The default copy constructor and assignment operator are correct for
  45. // this object.
  46. /// \brief Deletion Function
  47. ///
  48. /// Performs the deletion of the zone entry from the hash table.
  49. ///
  50. /// \param element Element to be deleted
  51. virtual void operator()(T* element) const;
  52. private:
  53. HashTable<T>& hashtable_; ///< Hash table to access element
  54. };
  55. // delete the object from the relevant hash table
  56. template <class T>
  57. void HashDeleter<T>::operator()(T* element) const {
  58. hashtable_.remove(element->hashKey());
  59. }
  60. } // namespace nsas
  61. } // namespace isc
  62. #endif // HASH_DELETER_H