BsUtil.h 1.4 KB

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