BsUtil.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include <BsEnumClassHash.h>
  5. namespace bs
  6. {
  7. /** @addtogroup General
  8. * @{
  9. */
  10. /** Generates a new hash for the provided type using the default standard hasher and combines it with a previous hash. */
  11. template <class T>
  12. inline void hash_combine(std::size_t& seed, const T& v)
  13. {
  14. using HashType = typename std::conditional<std::is_enum<T>::value, EnumClassHash, std::hash<T>>::type;
  15. HashType hasher;
  16. seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
  17. }
  18. /** Generates an MD5 hash string for the provided source string. */
  19. String BS_UTILITY_EXPORT md5(const WString& source);
  20. /** Generates an MD5 hash string for the provided source string. */
  21. String BS_UTILITY_EXPORT md5(const String& source);
  22. /** Sets contents of a struct to zero. */
  23. template<class T>
  24. void bs_zero_out(T& s)
  25. {
  26. std::memset(&s, 0, sizeof(T));
  27. }
  28. /** Sets contents of a static array to zero. */
  29. template<class T, size_t N>
  30. void bs_zero_out(T(&arr)[N])
  31. {
  32. std::memset(arr, 0, sizeof(T) * N);
  33. }
  34. /** Sets contents of a block of memory to zero. */
  35. template<class T>
  36. void bs_zero_out(T * arr, size_t count)
  37. {
  38. assert(arr != nullptr);
  39. std::memset(arr, 0, sizeof(T) * count);
  40. }
  41. /** @} */
  42. }