124 lines
4.2 KiB
C++
124 lines
4.2 KiB
C++
/**
|
|
* @file include/ActivMiddleware/Misc/UnorderedHelper.h
|
|
*
|
|
* @brief Header file for unordered map/set helper functions.
|
|
*/
|
|
|
|
#if (!defined ACTIV_MISC_UNORDERED_HELPER_H)
|
|
#define ACTIV_MISC_UNORDERED_HELPER_H
|
|
|
|
#include "ActivMiddleware/Misc/FunctionObjects.h"
|
|
|
|
#include "ActivMiddleware/CxxYZ/type_traits.h"
|
|
#include "ActivMiddleware/CxxYZ/unordered_map.h"
|
|
#include "ActivMiddleware/CxxYZ/unordered_set.h"
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
/**
|
|
* @brief Case insensitive string hasher functor for boost unordered_(multi)?[map|set].
|
|
*/
|
|
struct CaseInsensitiveStringHash : public std::unary_function<const String, std::size_t>
|
|
{
|
|
/**
|
|
* @brief Function operator.
|
|
*
|
|
* @param str a reference to the string to hash.
|
|
*
|
|
* @return the hash value of the lowercase version of the string.
|
|
*/
|
|
size_t operator()(const String &str) const
|
|
{
|
|
size_t seed = 0;
|
|
for (String::const_iterator iter = str.begin(), iterEnd = str.end(); iterEnd != iter; ++iter)
|
|
{
|
|
Boost::hash_combine(seed, ::tolower(*iter));
|
|
}
|
|
|
|
return seed;
|
|
}
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief Case insensitive unordered_map wrapper class.
|
|
*
|
|
* E.g...
|
|
*
|
|
* typedef typename CaseInsensitiveUnorderedMap<String, int>::Type MyMapType;
|
|
* MyMapType myMap;
|
|
*/
|
|
template <typename Key, typename Mapped, typename Alloc = std::allocator<std::pair<Key const, Mapped> > >
|
|
struct CaseInsensitiveUnorderedMap
|
|
{
|
|
ACTIV_BOOST_STATIC_ASSERT((CxxYZ::is_same<Key, String>::value)); // Key type must be String.
|
|
|
|
typedef CxxYZ::unordered_map<Key, Mapped, CaseInsensitiveStringHash, CaseInsensitiveStringEqualComparisonObject, Alloc> Type;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief Case insensitive unordered_multimap wrapper class.
|
|
*
|
|
* E.g...
|
|
*
|
|
* typedef typename CaseInsensitiveUnorderedMultiMap<String, int>::Type MyMapType;
|
|
* MyMapType myMap;
|
|
*/
|
|
template <typename Key, typename Mapped, typename Alloc = std::allocator<std::pair<Key const, Mapped> > >
|
|
struct CaseInsensitiveUnorderedMultiMap
|
|
{
|
|
ACTIV_BOOST_STATIC_ASSERT((CxxYZ::is_same<Key, String>::value)); // Key type must be String.
|
|
|
|
typedef CxxYZ::unordered_multimap<Key, Mapped, CaseInsensitiveStringHash, CaseInsensitiveStringEqualComparisonObject, Alloc>
|
|
Type;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief Case insensitive unordered_set wrapper class.
|
|
*
|
|
* E.g...
|
|
*
|
|
* typedef typename CaseInsensitiveUnorderedSet<String>::Type MySetType;
|
|
* MyMapType myMap;
|
|
*/
|
|
template <typename Value, typename Alloc = std::allocator<Value> >
|
|
struct CaseInsensitiveUnorderedSet
|
|
{
|
|
ACTIV_BOOST_STATIC_ASSERT((CxxYZ::is_same<Value, String>::value)); // Key type must be String.
|
|
|
|
typedef CxxYZ::unordered_set<Value, CaseInsensitiveStringHash, CaseInsensitiveStringEqualComparisonObject, Alloc> Type;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief Case insensitive unordered_multiset wrapper class.
|
|
*
|
|
* E.g...
|
|
*
|
|
* typedef typename CaseInsensitiveUnorderedMultiSet<String>::Type MySetType;
|
|
* MyMapType myMap;
|
|
*/
|
|
template <typename Value, typename Alloc = std::allocator<Value> >
|
|
struct CaseInsensitiveUnorderedMultiSet
|
|
{
|
|
ACTIV_BOOST_STATIC_ASSERT((CxxYZ::is_same<Value, String>::value)); // Key type must be String.
|
|
|
|
typedef CxxYZ::unordered_multiset<Value, CaseInsensitiveStringHash, CaseInsensitiveStringEqualComparisonObject, Alloc> Type;
|
|
};
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_MISC_UNORDERED_HELPER_H)
|