12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #ifndef _BASE_BASE_H_
- #define _BASE_BASE_H_
- #include <stddef.h>
- #include <string>
- #define CLOSE_ACTIVITY_WITH(activity_ptr) \
- EASYUICONTEXT->closeActivity(class_name(activity_ptr).c_str())
- /**
- * 数组长度
- */
- template <class T>
- int array_length(T&array) {
- return sizeof(array) / sizeof(array[0]);
- }
- /**
- * 释放指针,并将指针置为空
- */
- template <typename Ptr>
- void deleteptr(Ptr *p) {
- if (p == NULL) {
- return;
- }
- if(*p == NULL) {
- return;
- }
- delete *p;
- *p = NULL;
- }
- /**
- * 通过typid获得类名,不具备通用性
- */
- template <typename Ptr>
- std::string class_name(Ptr ptr) {
- if (ptr == NULL) {
- return "";
- }
- char* begin = (char*)typeid(*ptr).name();
- while (isdigit(*begin)) {
- ++begin;
- }
- return begin;
- }
- //} /* namespace base */
- #endif
|