nat_linden  committed b44ef9e

MAINT-1175: Properly pass LLRegistry's COMPARATOR to underlying map.
Although LLRegistry and LLRegistrySingleton have always defined a COMPARATOR
template parameter, it wasn't used for the underlying map. Therefore every
type, including any pointer type, was being compared using std::less. This
happens to work most of the time -- but is tripping us up now.
Pass COMPARATOR to underlying std::map. Fix a couple minor bugs in
LLRegistryDefaultComparator (never before used!). Specialize for const char*.
Remove CompareTypeID and LLCompareTypeID because we now actively forbid using
LLRegistry<std::type_info*, ...>; remove only known reference
(LLWidgetNameRegistry definition).

  • Participants
  • Parent commits ed03a29

Comments (0)

Files changed (3)

File indra/llcommon/llinitparam.h

-		struct CompareTypeID
-		{
-			bool operator()(const std::type_info* lhs, const std::type_info* rhs) const
-			{
-				return lhs->before(*rhs);
-			}
-		};
 		typedef std::vector<std::pair<std::string, bool> >					name_stack_t;
 		typedef std::pair<name_stack_t::iterator, name_stack_t::iterator>	name_stack_range_t;
 		typedef std::vector<std::string>									possible_values_t;

File indra/llcommon/llregistry.h

 #include "llsingleton.h"
 template <typename T>
-class LLRegistryDefaultComparator
+struct LLRegistryDefaultComparator
-	bool operator()(const T& lhs, const T& rhs) { return lhs < rhs; }
+	bool operator()(const T& lhs, const T& rhs) const { return lhs < rhs; }
+// comparator for const char* registry keys
+template <>
+struct LLRegistryDefaultComparator<const char*>
+	bool operator()(const char* lhs, const char* rhs) const
+	{
+		return strcmp(lhs, rhs) < 0;
+	}
 template <typename KEY, typename VALUE, typename COMPARATOR = LLRegistryDefaultComparator<KEY> >
 		friend class LLRegistry<KEY, VALUE, COMPARATOR>;
-		typedef std::map<KEY, VALUE> registry_map_t;
+		typedef std::map<KEY, VALUE, COMPARATOR> registry_map_t;
 		bool add(ref_const_key_t key, ref_const_value_t value)

File indra/llui/lluictrlfactory.h

 class LLView;
-// sort functor for typeid maps
-struct LLCompareTypeID
-	bool operator()(const std::type_info* lhs, const std::type_info* rhs) const
-	{
-		return lhs->before(*rhs);
-	}
 // lookup widget constructor funcs by widget name
 template <typename DERIVED_TYPE>
 class LLChildRegistry : public LLRegistrySingleton<std::string, LLWidgetCreatorFunc, DERIVED_TYPE>
 // lookup widget name by type (actually by std::type_info::name())
 class LLWidgetNameRegistry 
-:	public LLRegistrySingleton<const char*, std::string, LLWidgetNameRegistry , LLCompareTypeID>
+:	public LLRegistrySingleton<const char*, std::string, LLWidgetNameRegistry>
 // lookup function for generating empty param block by widget type