]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2292] Get rid of the const_cast
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Tue, 2 Oct 2012 19:05:33 +0000 (21:05 +0200)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Tue, 2 Oct 2012 19:05:33 +0000 (21:05 +0200)
It was needed when extracting data from a domain tree chain. The chain
now can hold mutable pointers too, so we use that (and some amount of
template bureaucracy) to avoid the cast.

While the interface changed (on the core find function, it is not
possible to pass const node chain and have a mutable node get out), it
doesn't seem to influence the current code. Also, it is a private
interface anyway, so it should be safe.

src/lib/datasrc/memory/domaintree.h
src/lib/datasrc/memory/zone_finder.cc

index 4f1d94aca700455faadce87d4b22b662cee95c3b..e54d8eaaed3f8959c820677e2267035a7baa9905 100644 (file)
@@ -1085,9 +1085,10 @@ public:
     /// Acts as described in the \ref find section.
     Result find(const isc::dns::Name& name,
                 DomainTreeNode<T>** node) const {
-        DomainTreeNodeChain<T> node_path;
+        DomainTreeNodeChain<T, DomainTreeNode<T> > node_path;
         const isc::dns::LabelSequence ls(name);
-        return (find<void*>(ls, node, node_path, NULL, NULL));
+        return (find<void*, DomainTreeNode<T> >(ls, node, node_path, NULL,
+                                                NULL));
     }
 
     /// \brief Simple find returning immutable node.
@@ -1097,9 +1098,11 @@ public:
     Result find(const isc::dns::Name& name,
                 const DomainTreeNode<T>** node) const {
         DomainTreeNodeChain<T> node_path;
-        DomainTreeNode<T> *target_node = NULL;
+        const DomainTreeNode<T> *target_node = NULL;
         const isc::dns::LabelSequence ls(name);
-        Result ret = (find<void*>(ls, &target_node, node_path, NULL, NULL));
+        Result ret = (find<void*, const DomainTreeNode<T> >(ls, &target_node,
+                                                            node_path, NULL,
+                                                            NULL));
         if (ret != NOTFOUND) {
             *node = target_node;
         }
@@ -1113,7 +1116,8 @@ public:
                 DomainTreeNodeChain<T>& node_path) const
     {
         const isc::dns::LabelSequence ls(name);
-        return (find<void*>(ls, node, node_path, NULL, NULL));
+        return (find<void*, const DomainTreeNode<T> >(ls, node, node_path,
+                                                      NULL, NULL));
     }
 
     /// \brief Simple find returning immutable node, with node_path tracking
@@ -1123,9 +1127,11 @@ public:
     Result find(const isc::dns::Name& name, const DomainTreeNode<T>** node,
                 DomainTreeNodeChain<T>& node_path) const
     {
-        DomainTreeNode<T> *target_node = NULL;
+        const DomainTreeNode<T> *target_node = NULL;
         const isc::dns::LabelSequence ls(name);
-        Result ret = (find<void*>(ls, &target_node, node_path, NULL, NULL));
+        Result ret = (find<void*, const DomainTreeNode<T> >(ls, &target_node,
+                                                            node_path, NULL,
+                                                            NULL));
         if (ret != NOTFOUND) {
             *node = target_node;
         }
@@ -1143,7 +1149,7 @@ public:
                 bool (*callback)(const DomainTreeNode<T>&, CBARG),
                 CBARG callback_arg) const
     {
-        DomainTreeNode<T>* target_node = NULL;
+        const DomainTreeNode<T>* target_node = NULL;
         const isc::dns::LabelSequence ls(name);
         Result ret = find(ls, &target_node, node_path, callback,
                           callback_arg);
@@ -1227,10 +1233,10 @@ public:
     ///
     /// \return As in the description, but in case of callback returning
     ///     \c true, it returns immediately with the current node.
-    template <typename CBARG>
+    template <typename CBARG, typename NodeType>
     Result find(const isc::dns::LabelSequence& target_labels_orig,
-                DomainTreeNode<T>** node,
-                DomainTreeNodeChain<T>& node_path,
+                NodeType** node,
+                DomainTreeNodeChain<T, NodeType>& node_path,
                 bool (*callback)(const DomainTreeNode<T>&, CBARG),
                 CBARG callback_arg) const;
 
@@ -1245,9 +1251,11 @@ public:
                 bool (*callback)(const DomainTreeNode<T>&, CBARG),
                 CBARG callback_arg) const
     {
-        DomainTreeNode<T>* target_node = NULL;
-        Result ret = find(target_labels, &target_node, node_path,
-                          callback, callback_arg);
+        const DomainTreeNode<T>* target_node = NULL;
+        Result ret = find<CBARG, const DomainTreeNode<T> >(target_labels,
+                                                           &target_node,
+                                                           node_path, callback,
+                                                           callback_arg);
         if (ret != NOTFOUND) {
             *node = target_node;
         }
@@ -1512,11 +1520,11 @@ DomainTree<T>::deleteHelper(util::MemorySegment& mem_sgmt,
 }
 
 template <typename T>
-template <typename CBARG>
+template <typename CBARG, typename NodeType>
 typename DomainTree<T>::Result
 DomainTree<T>::find(const isc::dns::LabelSequence& target_labels_orig,
-                    DomainTreeNode<T>** target,
-                    DomainTreeNodeChain<T>& node_path,
+                    NodeType** target,
+                    DomainTreeNodeChain<T, NodeType>& node_path,
                     bool (*callback)(const DomainTreeNode<T>&, CBARG),
                     CBARG callback_arg) const
 {
@@ -1526,11 +1534,11 @@ DomainTree<T>::find(const isc::dns::LabelSequence& target_labels_orig,
                   " and label sequence");
     }
 
-    DomainTreeNode<T>* node;
+    NodeType* node;
 
     if (!node_path.isEmpty()) {
         // Get the top node in the node chain
-        node = const_cast<DomainTreeNode<T>*>(node_path.top());
+        node = node_path.top();
         // Start searching from its down pointer
         node = node->getDown();
     } else {
index 9403c4fec8b2525c312ca8c0022dd11a95e494b0..31a58d930e90e7755a4a78488aa1ba46b3c068da 100644 (file)
@@ -417,7 +417,7 @@ FindNodeResult findNode(const ZoneData& zone_data,
                         ZoneFinder::FindOptions options,
                         bool out_of_zone_ok = false)
 {
-    ZoneNode* node = NULL;
+    const ZoneNode* node = NULL;
     FindState state((options & ZoneFinder::FIND_GLUE_OK) != 0);
 
     const ZoneTree& tree(zone_data.getZoneTree());