base.hpp 806 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef _BASE_BASE_H_
  2. #define _BASE_BASE_H_
  3. #include <stddef.h>
  4. #include <string>
  5. #define CLOSE_ACTIVITY_WITH(activity_ptr) \
  6. EASYUICONTEXT->closeActivity(class_name(activity_ptr).c_str())
  7. /**
  8. * 数组长度
  9. */
  10. template <class T>
  11. int array_length(T&array) {
  12. return sizeof(array) / sizeof(array[0]);
  13. }
  14. /**
  15. * 释放指针,并将指针置为空
  16. */
  17. template <typename Ptr>
  18. void deleteptr(Ptr *p) {
  19. if (p == NULL) {
  20. return;
  21. }
  22. if(*p == NULL) {
  23. return;
  24. }
  25. delete *p;
  26. *p = NULL;
  27. }
  28. /**
  29. * 通过typid获得类名,不具备通用性
  30. */
  31. template <typename Ptr>
  32. std::string class_name(Ptr ptr) {
  33. if (ptr == NULL) {
  34. return "";
  35. }
  36. char* begin = (char*)typeid(*ptr).name();
  37. while (isdigit(*begin)) {
  38. ++begin;
  39. }
  40. return begin;
  41. }
  42. //} /* namespace base */
  43. #endif