hash_deleter.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // $Id$
  15. #ifndef __HASH_DELETER_H
  16. #define __HASH_DELETER_H
  17. #include <boost/shared_ptr.hpp>
  18. #include "hash_table.h"
  19. #include "lru_list.h"
  20. namespace isc {
  21. namespace nsas {
  22. /// \brief Delete Object from Hash Table
  23. ///
  24. /// This is the object passed to the LRU list constructors that deletes the
  25. /// ZoneEntry from the hash table when the zone is deleted from the LRU list.
  26. ///
  27. /// It is declared as a nested class so as to be able to access the
  28. /// hash table without the need to be declared as "friend" or the need
  29. /// to define accessor methods.
  30. template <typename T>
  31. class HashDeleter : public LruList<T>::Dropped {
  32. public:
  33. /// \brief Constructor
  34. ///
  35. /// \param hashtable Reference to the hash table from which information is
  36. /// to be deleted. The table is assumed to remain in existence for the life
  37. /// of this object.
  38. ///
  39. /// \param hashtable Hash table from which the element should be deleted.
  40. HashDeleter(HashTable<T>& hashtable) : hashtable_(hashtable)
  41. {}
  42. /// \brief Destructor
  43. ///
  44. virtual ~HashDeleter(){}
  45. // The default copy constructor and assignment operator are correct for
  46. // this object.
  47. /// \brief Deletion Function
  48. ///
  49. /// Performs the deletion of the zone entry from the hash table.
  50. ///
  51. /// \param element Element to be deleted
  52. virtual void operator()(T* element) const;
  53. private:
  54. HashTable<T>& hashtable_; ///< Hash table to access element
  55. };
  56. // delete the object from the relevant hash table
  57. template <class T>
  58. void HashDeleter<T>::operator()(T* element) const {
  59. hashtable_.remove(element->hashKey());
  60. }
  61. } // namespace nsas
  62. } // namespace isc
  63. #endif // __HASH_DELETER_H