define.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #pragma once
  2. #include "typedef.h"
  3. #include "exception.h"
  4. #include "error.h"
  5. // 是否DEBUG调试内存申请情况
  6. #define DEBUG_MEM 0
  7. using namespace ylib;
  8. // 斜杆
  9. #ifdef _WIN32
  10. #define SEPRATOR std::string("\\")
  11. #else
  12. #define SEPRATOR std::string("/")
  13. #endif
  14. // 遍历STL
  15. #define for_iter(LOOP_VAR,LOOP_NUM) for(auto LOOP_VAR = LOOP_NUM.begin();LOOP_VAR != LOOP_NUM.end();LOOP_VAR++)
  16. #define for_riter(LOOP_VAR,LOOP_NUM) for(auto LOOP_VAR = LOOP_NUM.rbegin();LOOP_VAR != LOOP_NUM.rend();LOOP_VAR++)
  17. // 抛出异常
  18. //#define THROW_FORMAT(DATA,...) throw std::exception(std::format(DATA,__VA_ARGS__).c_str())
  19. #ifdef YLIB_STATIC
  20. #define YLIB_API
  21. #else
  22. #define NEWOBJ_EXPORT_API __declspec(dllexport)
  23. #ifdef EXPORT_DLL
  24. #define C_DLL_HEADER extern "C" __declspec(dllexport)
  25. #else
  26. #define C_DLL_HEADER extern "C" __declspec(dllimport)
  27. #endif
  28. #define C_CALL __stdcall
  29. #endif
  30. #define ylib_max(a,b) (((a) > (b)) ? (a) : (b))
  31. #define ylib_min(a,b) (((a) < (b)) ? (a) : (b))
  32. /**
  33. * @brief 定义命名空间 ylib
  34. */
  35. namespace ylib {
  36. /**
  37. * @brief 定义一个矩形结构体
  38. *
  39. * 包含四个成员变量:left, top, right, bottom,用于表示矩形的位置和大小。
  40. * 构造函数初始化了这四个变量的值为0。
  41. */
  42. struct Rect{
  43. Rect() { left = 0; top = 0; right = 0; bottom = 0; } // 默认构造函数,初始化矩形的位置和大小为0
  44. int left; // 矩形的左边界
  45. int top; // 矩形的上边界
  46. int right; // 矩形的右边界
  47. int bottom; // 矩形的下边界
  48. };
  49. struct Geometry {
  50. Geometry(){
  51. width = 0;
  52. height = 0;
  53. x = 0;
  54. y = 0;
  55. }
  56. int width;
  57. int height;
  58. int x;
  59. int y;
  60. };
  61. /**
  62. * @brief 定义一个键值对结构体模板
  63. *
  64. * 模板结构体,接受两个类型参数 K 和 V。
  65. * 包含两个成员变量:name 和 value,分别用于存储键和值。
  66. */
  67. template<typename K,typename V>
  68. struct KeyValue{
  69. K name; // 键
  70. V value; // 值
  71. };
  72. /**
  73. * @brief 定义一个带宽信息结构体
  74. */
  75. struct BandInfo
  76. {
  77. BandInfo() { // 默认构造函数,初始化带宽信息的所有成员变量为0
  78. }
  79. uint64 up_all = 0; // 上行总带宽
  80. uint64 down_all = 0; // 下行总带宽
  81. uint64 up_sec_byte = 0; // 上行第二字节带宽
  82. uint64 down_sec_byte = 0; // 下行第二字节带宽
  83. };
  84. // 地址信息
  85. struct AddressPort {
  86. std::string address; // 存储地址的字符串成员
  87. ushort port = 0; // 存储端口的整数成员
  88. //inline std::string to_string() { return address + std::to_string(port); }
  89. };
  90. // 控制台文本颜色
  91. enum ConsoleTextColor {
  92. BLUE = 0x0001,
  93. GREEN = 0x0002,
  94. RED = 0x0004,
  95. YELLOW = 0x0008,
  96. DEFAULT = RED | GREEN | BLUE,
  97. };
  98. // 文件类型
  99. enum FileType {
  100. IS_FILE,
  101. IS_DIRECTORY
  102. };
  103. // 磁盘容量
  104. struct DiskCapacity
  105. {
  106. // 用户可用剩余容量(一般用这个)
  107. uint64 freeBytesUser = 0;
  108. // 可用剩余容量
  109. uint64 freeBytes = 0;
  110. // 用户可用剩余容量
  111. uint64 totalBytes = 0;
  112. };
  113. // 网络接收类型
  114. enum receive_model
  115. {
  116. // 默认模型
  117. PUSH_DEFAULT,
  118. // 封装PACK
  119. PACK,
  120. // 自定义读取流
  121. PULL,
  122. };
  123. // 全路径
  124. class FullPath
  125. {
  126. public:
  127. std::string name;
  128. std::string path;
  129. public:
  130. std::string to_string() { return path + SEPRATOR + name; }
  131. };
  132. } // end of namespace ylib