You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 rivejä
700 B

  1. #pragma once
  2. #include <cxxabi.h>
  3. #include <iostream>
  4. #if defined(__linux__)
  5. # include <endian.h>
  6. #elif defined(__FreeBSD__) || defined(__NetBSD__)
  7. # include <sys/endian.h>
  8. #elif defined(__OpenBSD__)
  9. # include <sys/types.h>
  10. # define be16toh(x) betoh16(x)
  11. # define be32toh(x) betoh32(x)
  12. # define be64toh(x) betoh64(x)
  13. #endif
  14. namespace utl
  15. {
  16. inline int bit_count(uint32_t u)
  17. {
  18. u = u
  19. - ((u >> 1) & 033333333333)
  20. - ((u >> 2) & 011111111111);
  21. return ((u + (u >> 3)) & 030707070707) % 63;
  22. }
  23. template<class T, class S>
  24. inline bool try_cast(T* t, S*& s)
  25. {
  26. s = dynamic_cast<S*>(t);
  27. return static_cast<bool>(s);
  28. }
  29. }