define.h 3.7 KB

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