From: Michal 'vorner' Vaner Date: Tue, 2 Oct 2012 19:05:33 +0000 (+0200) Subject: [2292] Get rid of the const_cast X-Git-Tag: trac2402_base~15^2~69 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bb347f194134acc2a3d1e7f2c6d6b4f0d56d2a17;p=thirdparty%2Fkea.git [2292] Get rid of the const_cast 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. --- diff --git a/src/lib/datasrc/memory/domaintree.h b/src/lib/datasrc/memory/domaintree.h index 4f1d94aca7..e54d8eaaed 100644 --- a/src/lib/datasrc/memory/domaintree.h +++ b/src/lib/datasrc/memory/domaintree.h @@ -1085,9 +1085,10 @@ public: /// Acts as described in the \ref find section. Result find(const isc::dns::Name& name, DomainTreeNode** node) const { - DomainTreeNodeChain node_path; + DomainTreeNodeChain > node_path; const isc::dns::LabelSequence ls(name); - return (find(ls, node, node_path, NULL, NULL)); + return (find >(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** node) const { DomainTreeNodeChain node_path; - DomainTreeNode *target_node = NULL; + const DomainTreeNode *target_node = NULL; const isc::dns::LabelSequence ls(name); - Result ret = (find(ls, &target_node, node_path, NULL, NULL)); + Result ret = (find >(ls, &target_node, + node_path, NULL, + NULL)); if (ret != NOTFOUND) { *node = target_node; } @@ -1113,7 +1116,8 @@ public: DomainTreeNodeChain& node_path) const { const isc::dns::LabelSequence ls(name); - return (find(ls, node, node_path, NULL, NULL)); + return (find >(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** node, DomainTreeNodeChain& node_path) const { - DomainTreeNode *target_node = NULL; + const DomainTreeNode *target_node = NULL; const isc::dns::LabelSequence ls(name); - Result ret = (find(ls, &target_node, node_path, NULL, NULL)); + Result ret = (find >(ls, &target_node, + node_path, NULL, + NULL)); if (ret != NOTFOUND) { *node = target_node; } @@ -1143,7 +1149,7 @@ public: bool (*callback)(const DomainTreeNode&, CBARG), CBARG callback_arg) const { - DomainTreeNode* target_node = NULL; + const DomainTreeNode* 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 + template Result find(const isc::dns::LabelSequence& target_labels_orig, - DomainTreeNode** node, - DomainTreeNodeChain& node_path, + NodeType** node, + DomainTreeNodeChain& node_path, bool (*callback)(const DomainTreeNode&, CBARG), CBARG callback_arg) const; @@ -1245,9 +1251,11 @@ public: bool (*callback)(const DomainTreeNode&, CBARG), CBARG callback_arg) const { - DomainTreeNode* target_node = NULL; - Result ret = find(target_labels, &target_node, node_path, - callback, callback_arg); + const DomainTreeNode* target_node = NULL; + Result ret = find >(target_labels, + &target_node, + node_path, callback, + callback_arg); if (ret != NOTFOUND) { *node = target_node; } @@ -1512,11 +1520,11 @@ DomainTree::deleteHelper(util::MemorySegment& mem_sgmt, } template -template +template typename DomainTree::Result DomainTree::find(const isc::dns::LabelSequence& target_labels_orig, - DomainTreeNode** target, - DomainTreeNodeChain& node_path, + NodeType** target, + DomainTreeNodeChain& node_path, bool (*callback)(const DomainTreeNode&, CBARG), CBARG callback_arg) const { @@ -1526,11 +1534,11 @@ DomainTree::find(const isc::dns::LabelSequence& target_labels_orig, " and label sequence"); } - DomainTreeNode* node; + NodeType* node; if (!node_path.isEmpty()) { // Get the top node in the node chain - node = const_cast*>(node_path.top()); + node = node_path.top(); // Start searching from its down pointer node = node->getDown(); } else { diff --git a/src/lib/datasrc/memory/zone_finder.cc b/src/lib/datasrc/memory/zone_finder.cc index 86dd87428c..11188a038b 100644 --- a/src/lib/datasrc/memory/zone_finder.cc +++ b/src/lib/datasrc/memory/zone_finder.cc @@ -428,7 +428,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());