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.

325 lines
7.4 KiB

  1. {
  2. /*
  3. // Place your snippets for C here. Each snippet is defined under a snippet name and has a prefix, body and
  4. // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
  5. // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
  6. // same ids are connected.
  7. // Example:
  8. "Print to console": {
  9. "prefix": "log",
  10. "body": [
  11. "console.log('$1');",
  12. "$2"
  13. ],
  14. "description": "Log output to console"
  15. }
  16. */
  17. "virtual": {
  18. "prefix": "virtual",
  19. "body": [
  20. "virtual $1 $2() = 0;"
  21. ],
  22. "description": "virtual"
  23. },
  24. "use_namespace_core": {
  25. "prefix": "uc",
  26. "body": [
  27. "using namespace core;"
  28. ],
  29. "description": "using namespace core"
  30. },
  31. "while1": {
  32. "prefix": "while1",
  33. "body": [
  34. "while(1){sleep(1);}"
  35. ],
  36. "description": "while1"
  37. },
  38. "header": {
  39. "prefix": "#ifndef",
  40. "body": [
  41. "#ifndef $0",
  42. "#define $0",
  43. "#ifdef __cplusplus",
  44. "extern \"C\" {",
  45. "#endif",
  46. "",
  47. "",
  48. "#ifdef __cplusplus",
  49. "}",
  50. "#endif",
  51. "#endif",
  52. ],
  53. "description": "header"
  54. },
  55. "usname": {
  56. "prefix": "usname",
  57. "body": [
  58. "using namespace $1"
  59. ],
  60. "description": "usname"
  61. },
  62. "main": {
  63. "prefix": "main",
  64. "body": [
  65. "int main(int argc, char* const argv[]) {",
  66. "",
  67. "return 0;",
  68. "}",
  69. ],
  70. "description": "main"
  71. },
  72. "out": {
  73. "prefix": "out",
  74. "body": [
  75. "<<\"$1\"<<$2<<\"$3\"",
  76. ],
  77. "description": "out"
  78. },
  79. "struct": {
  80. "prefix": "struct",
  81. "body": [
  82. "typedef struct {",
  83. "$1",
  84. "}$0_t;",
  85. ],
  86. "description": "struct"
  87. },
  88. "mutex_rec": {
  89. "prefix": "mutex_rec",
  90. "body": [
  91. "#include <mutex>",
  92. "std::recursive_mutex lock_;",
  93. "std::lock_guard<std::recursive_mutex> lock(lock_);"
  94. ],
  95. "description": "mutex_rec"
  96. },
  97. "mutex_normal": {
  98. "prefix": "mutex_normal",
  99. "body": [
  100. "#include <mutex>",
  101. "std::mutex lock_;",
  102. "std::lock_guard<std::mutex> lock(lock_);"
  103. ],
  104. "description": "mutex_normal"
  105. },
  106. "for": {
  107. "prefix": "for",
  108. "body": [
  109. "for(auto& var : $2)",
  110. "{\n}"
  111. ],
  112. "description": "for"
  113. },
  114. "#pra": {
  115. "prefix": "#pra",
  116. "body": [
  117. "#pragma once",
  118. "#include <fstream>",
  119. "#include <iostream>",
  120. "#include <list>",
  121. "#include <map>",
  122. "#include <memory>",
  123. "#include <sstream>",
  124. "#include <string>",
  125. "#include <vector>",
  126. "#include <set>",
  127. "#include <functional>",
  128. "namespace zwsd {",
  129. "using namespace std;",
  130. "} // namespace zwsd",
  131. ],
  132. "description": "pragma once"
  133. },
  134. "create_service": {
  135. "prefix": "create_service",
  136. "body": [
  137. "//",
  138. "// Created by zwsd",
  139. "//",
  140. "",
  141. "#pragma once",
  142. "#include <fstream>",
  143. "#include <iostream>",
  144. "#include <list>",
  145. "#include <map>",
  146. "#include <memory>",
  147. "#include <memory>",
  148. "#include <set>",
  149. "#include <sstream>",
  150. "#include <string>",
  151. "#include <vector>",
  152. "",
  153. "#include \"zwtimecpp/core/core.hpp\"",
  154. "#include \"zwtimecpp/core/logger/logger.hpp\"",
  155. "#include \"zwtimecpp/core/logger/logger_factory.hpp\"",
  156. "",
  157. "",
  158. "/**",
  159. " * @brief",
  160. " *",
  161. " * service: $1",
  162. " *",
  163. " * 监听事件:",
  164. " * 依赖状态:",
  165. " * 依赖服务:",
  166. " * 作用:",
  167. " *",
  168. " */",
  169. "",
  170. "namespace zwsd {",
  171. "using namespace std;",
  172. "using namespace core;",
  173. "class $1 : public EventHandler,",
  174. " public enable_shared_from_this<$1> {",
  175. " ENABLE_LOGGER($1);",
  176. "",
  177. " shared_ptr<Core> core; //监听事件",
  178. "",
  179. " public:",
  180. " $1(const shared_ptr<Core> &core):core(core){};",
  181. "",
  182. " void initialize(){};",
  183. "",
  184. " virtual void onEvent(shared_ptr<BaseEvent> ptr) override{};",
  185. "};",
  186. "} // namespace zwsd"
  187. ],
  188. "description": "create_service"
  189. },
  190. "create_event": {
  191. "prefix": "create_event",
  192. "body": [
  193. "//",
  194. "// Created by zwsd",
  195. "//",
  196. "",
  197. "#pragma once",
  198. "#include <fstream>",
  199. "#include <iostream>",
  200. "#include <list>",
  201. "#include <map>",
  202. "#include <memory>",
  203. "#include <memory>",
  204. "#include <set>",
  205. "#include <sstream>",
  206. "#include <string>",
  207. "#include <vector>",
  208. "#include \"zwtimecpp/core/base/base_event.hpp\"",
  209. "#include \"zwtimecpp/core/utils/better-enums/enum.h\"",
  210. "namespace zwsd {",
  211. "using namespace std;",
  212. "using namespace core;",
  213. "class ${1} : public BaseEvent {",
  214. " DECLEAR_EVENT(${1});",
  215. "",
  216. " ${1}() {}",
  217. "",
  218. " public:",
  219. " public:",
  220. " static shared_ptr<${1}> create() {",
  221. " shared_ptr<${1}> var(new ${1}());",
  222. " return var;",
  223. " }",
  224. "};",
  225. "}"
  226. ],
  227. "description": "create_event"
  228. },
  229. "create_runner": {
  230. "prefix": "create_runner",
  231. "body": [
  232. "#include \"zwtimecpp/core/logger/logger.hpp\"",
  233. "#include \"zwtimecpp/core/test/test_utils/runner_manager.hpp\"",
  234. "#include \"zwtimecpp/core/thread/thread.hpp\"",
  235. "#include \"zwtimecpp/core/utils/argh/argh.h\"",
  236. "#include \"zwtimecpp/core/utils/better-enums/enum.h\"",
  237. "#include \"zwtimecpp/core/utils/memory_utils.hpp\"",
  238. "#include \"zwtimecpp/core/utils/nlohmann/json.hpp\"",
  239. "",
  240. "#include \"zwtimecpp/core/utils/cli_strong_version.hpp\"",
  241. "",
  242. "using namespace std;",
  243. "using namespace zwsd;",
  244. "using namespace core;",
  245. "using namespace cli;",
  246. "",
  247. "using namespace front_display_msg;",
  248. "",
  249. "class $1 : public Runner {",
  250. "ENABLE_LOGGER($1);",
  251. "",
  252. "public:",
  253. "virtual void run(int argc, const char **argv) override;",
  254. "virtual string introduction(logger_t logForHelp) override {",
  255. "logger->info(\"{}\\n\\t\\t{}\", \"-h\", \"\");",
  256. "logger->info(\"{}\\n\\t\\t{}\", \"-h\", \"\");",
  257. "return \"\";",
  258. "}",
  259. "};",
  260. "",
  261. "void $1::run(int argc, const char **argv) {",
  262. "//命令行参数demo ./runner_main $1 -n name",
  263. "//--string_full_name -b bool_value -i int_value",
  264. "#if 0",
  265. "argh::parser cmdl;",
  266. "string string_short_name;",
  267. "string string_full_name;",
  268. "int int_value;",
  269. "int times;",
  270. "bool bool_value;",
  271. "cmdl.add_params({\"n\"/*string short name*/, \"string_full_name\", \"i\"/*int value*/,\"b\"});",
  272. "cmdl.parse(argc, argv);",
  273. "cmdl(\"-n\", \"default value\") >> string_short_name;",
  274. "cmdl(\"--string_full_name\", \"default value\") >> string_full_name;",
  275. "cmdl(\"-i\", 1) >> int_value;",
  276. "bool_value = cmdl[\"b\"];",
  277. "logger->info(",
  278. "\"string_short_name {} string_full_name {} int_value {} times {} \"",
  279. "\"bool_value{}\",",
  280. "string_short_name, string_full_name, int_value, times, bool_value);",
  281. "#endif",
  282. "Core::initialize();",
  283. "shared_ptr<Core> core = Core::Instance();",
  284. "",
  285. "auto rootMenu = make_unique<cli::Menu>(\"cli\");",
  286. "cli::SetColor();",
  287. "rootMenu->Insert(\"echo\",",
  288. "[&](std::ostream &out, string eventName, string describe) {",
  289. "},",
  290. "\"广播事件 事件名字 事件描述\");",
  291. "",
  292. "CLI_START(rootMenu);",
  293. "ThisThread().sleep();",
  294. "}",
  295. "",
  296. "ENABLE_TEST2($1, \"$1\")"
  297. ],
  298. "description": "create_runner"
  299. },
  300. "create_gtest": {
  301. "prefix": "create_gtest",
  302. "body": [
  303. "#include \"gtest/gtest.h\"",
  304. "#include <functional>",
  305. "",
  306. "#include \"project_mock.hpp\"",
  307. "",
  308. "using namespace std;",
  309. "using namespace zwsd;",
  310. "using namespace core;",
  311. "",
  312. "using namespace testing;",
  313. "",
  314. "class ${1} : public testing::Test {",
  315. " public:",
  316. " void SetUp() override {}",
  317. "};",
  318. "",
  319. "TEST_F(${1}, test) {}",
  320. ],
  321. "description": "create_gtest"
  322. }
  323. }