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