Commits

ssn...@4525493e-7705-40b1-a816-d608a930855b  committed bcb55af

Allow specifying a per-type default hash function for NavigationToken. Fix compilation warnings.

  • Participants
  • Parent commits 44449e4

Comments (0)

Files changed (5)

+2011-03-26  scott snyder  <snyder@bnl.gov>
+
+	* Tagging Navigation-00-08-11.
+	* Navigation/NavigationToken.h, Navigation/NavigationTokenHash.h:
+	Allow specifying a per-type default hash function.  We don't do
+	this by just specializing SG::hash in order to respect class
+	derivation.
+	* test/NavigableIterator_test.cxx, src/AthenaBarCodeImpl.cxx: Fix
+	gcc 4.6 compilation warnings.
+
 2011-03-11  Paolo Calafiura  <calaf@lxplus415.cern.ch>
 
 	* Tagging Navigation-00-08-10.

File Navigation/NavigationToken.h

 #include "Navigation/INavigationCondition.h"
 
 #include "Navigation/NavigationDefaults.h"
+#include "Navigation/NavigationTokenHash.h"
 #include "DataModel/tools/ArenaPoolSTLAllocator.h"
-#include "SGTools/unordered_map.h"
+#include "CxxUtils/unordered_map.h"
 
 #include <map>
 #include <list>
 
 template <typename CHILD,
           typename CHILDPAR=NavigationDefaults::DefaultWeight,
-          typename HASH=SG::hash<const CHILD*> >
+          typename HASH=NavigationTokenHash<CHILD> >
 class NavigationToken : public INavigationToken
 {
 

File Navigation/NavigationTokenHash.h

+// This file's extension implies that it's C, but it's really -*- C++ -*-.
+// $Id$
+/**
+ * @file Navigation/NavigationTokenHash.h
+ * @author scott snyder <snyder@bnl.gov>
+ * @date Mar, 2011
+ * @brief Allow overriding the default hash function used within
+ *        @a NavigationToken.
+ */
+
+
+#ifndef NAVIGATION_NAVIGATIONTOKENHASH_H
+#define NAVIGATION_NAVIGATIONTOKENHASH_H
+
+
+#include "CxxUtils/hashtable.h"
+
+
+/**
+ * @brief Allow overriding the default hash function used within
+ *        @a NavigationToken.
+ *
+ * @a NavigationToken relies on iterating over a hash table to define
+ * the order of the iteration.  Since we use pointers as keys, and
+ * pick up the default C++ function for pointers, that means that the
+ * order of iteration may not be reproducible from run to run.
+ *
+ * If this matters, you can define an alternate hash function that
+ * depends on the object contents, rather than on the pointer value.
+ * You can specify this as the @a HASH template argument to
+ * @a NavigationToken; or, to change the default for all uses
+ * of the type, you can add an override for @a navigationHash
+ * or a specialization for @a NavigationTokenHash.
+ */
+inline
+std::size_t navigationHash (const void* p)
+{
+  return SG::hash<const void*>() (p);
+}
+
+
+template <typename CHILD>
+struct NavigationTokenHash
+  : public std::unary_function<const CHILD*, std::size_t>
+{
+  std::size_t operator() (const CHILD* p) const
+  {
+    return navigationHash (p);
+  }
+};
+
+
+
+#endif // not NAVIGATION_NAVIGATIONTOKENHASH_H

File src/AthenaBarCodeImpl.cxx

     initABC();
 
   AthenaBarCodeVersion_t currversion = getVersion();
-  AthenaBarCode_t tmp2;
-  tmp2 = 0;
 
   try {
     setBits(SVersionBits, VersionBits, currversion + 1);

File test/NavigableIterator_test.cxx

 #include "Navigation/NavigableIterator.h"
 #include "Navigation/Navigable.h"
 #include "DataModel/DataVector.h"
+#include "CxxUtils/unused.h"
 #include "CLIDSvc/CLASS_DEF.h"
 
 #include "boost/type_traits/is_same.hpp"
 void test2 (NAV& nav)
 {
   typedef typename NAV::object_iter iter;
-  iter beg = nav.begin();
+  iter UNUSED(beg) = nav.begin();
   iter end = nav.end();
 
   iter mid = end;