-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpp.code-snippets
563 lines (563 loc) · 15.1 KB
/
cpp.code-snippets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
{
"if": {
"prefix": "if",
"body": [
"if ($1) {",
"\t${TM_SELECTED_TEXT}$0",
"}"
],
"description": "Inserts an if statement. Optionally wraps selected text in `if {}` block."
},
"else if": {
"prefix": "else if",
"body": [
"else if ($1) {",
"\t${TM_SELECTED_TEXT}$0",
"}"
],
"description": "Inserts an else if block. Optionally wraps selected text in `else if {}` block."
},
"else": {
"prefix": "else",
"body": [
"else {",
"\t${TM_SELECTED_TEXT}$0",
"}"
],
"description": "Inserts an else block. Optionally wraps selected text in `else {}` block."
},
"do": {
"prefix": "do",
"body": [
"do {",
"\t${TM_SELECTED_TEXT}$0",
"} while (${1:false});"
],
"description": "Inserts a do...while loop. Optionally wraps selected text in `do {} while ()`."
},
"while": {
"prefix": "while",
"body": [
"while (${1:true}) {",
"\t${TM_SELECTED_TEXT}$0",
"}"
],
"description": "Inserts a while loop. Optionally wraps selected text in `while () {}`."
},
"for": {
"prefix": "for",
"body": [
"for (${1:${2|int,size_t,auto|} ${3:index} = ${4:0}}; ${5:$3 ${6|<,>,<=,>=,==,!=|} ${7:length}}; ${8:${9|++,--|}$3}) {",
"\t${TM_SELECTED_TEXT}$0",
"}"
],
"description": "Inserts a for loop. Configures loop variable, condition, and increment. Wrapables."
},
"switch": {
"prefix": "switch",
"body": [
"switch ($1:${TM_SELECTED_TEXT}) {",
"case $4:",
"\t$0",
"\tbreak;",
"",
"",
"default:",
"\t${2}${3:break}};",
"}"
],
"description": "Inserts a switch statement. Optionally uses selected text as expression."
},
"case": {
"prefix": "case",
"body": [
"case $1:",
"\t${TM_SELECTED_TEXT}$0",
"\tbreak;"
],
"description": "Inserts a case label and statement. Optionally wraps selected text."
},
"enum": {
"prefix": "enum",
"body": [
"enum e${1:EnumID} {",
"\t${2:e${1:EnumID}_None} = ${3:0},",
"\t${4:e${1:EnumID}_Item},",
"\t${5:k${1:EnumID}_Count}$0",
"};"
],
"description": "Inserts an enum with name, default value, items, and count value."
},
"struct": {
"prefix": "struct",
"body": [
"struct ${1:StructID} {",
"\t${2:int} ${3:structMember};",
"\t${4:${TM_SELECTED_TEXT}}$0",
"};"
],
"description": "Inserts a struct with name, member variables. Optionally wrapables."
},
"func": {
"prefix": "func",
"body": [
"${6:void} ${1:FuncID}(${2:${3:int} ${4:arg}$5}) {",
"\t${7:${TM_SELECTED_TEXT}}$0",
"}"
],
"description": "Inserts a function with return type, name, parameters, and body. Wrapables."
},
"typedef": {
"prefix": "typedef",
"body": [
"typedef ${1:char} ${2:Byte};$0"
],
"description": "Inserts a typedef to create an alias for a type."
},
"typedefenum": {
"prefix": "typedefenum",
"body": [
"typedef enum e${1:EnumAlias} {",
"\t${2:e${1:EnumAlias}_None} = ${3:0},",
"\t${4:e${1:EnumAlias}_Item},",
"\t${5:k${1:EnumAlias}_Count}$0",
"} ${1:EnumAlias};"
],
"description": "Inserts a typedef enum with name, default value, items, and count."
},
"typedefstruct": {
"prefix": "typedefstruct",
"body": [
"typedef struct ${1:StructAlias} ${1:StructAlias};",
"struct ${1:StructAlias} {",
"\t${2:int} ${3:structMember};",
"\t${4:${TM_SELECTED_TEXT}}$0",
"};"
],
"description": "Inserts a typedef struct with name, member variables. Optionally wrapables."
},
"typedeffunc": {
"prefix": "typedeffuncptr",
"body": [
"typedef ${1:int} (*${2:FuncAlias})(${3:int}, ${4:int});$0"
],
"description": "Inserts a typedef for a function pointer with return type and args."
},
"#extern": {
"prefix": "#extern",
"body": [
"#if defined(__cplusplus)",
"extern \"C\" {",
"#endif // defined(__cplusplus)",
"",
"${TM_SELECTED_TEXT}$0",
"",
"#if defined(__cplusplus)",
"}",
"#endif // defined(__cplusplus)"
],
"description": "Wraps code with extern \"C\" for C++ compatibility when linking with C code."
},
"#guard": {
"prefix": "#guard",
"body": [
"#ifndef ${1:${TM_FILENAME}}",
"#define ${1:${TM_FILENAME}}",
"",
"${TM_SELECTED_TEXT}$0",
"",
"#endif // !${1:${TM_FILENAME}}"
],
"description": "Wraps code with an include guard based on the current file name."
},
"#unused": {
"prefix": "#unused",
"body": [
"#ifdef UNUSED_CODE",
"${TM_SELECTED_TEXT}$0",
"#endif // $UNUSED_CODE"
],
"description": "Wraps code in an #ifdef UNUSED_CODE block to enable/disable code."
},
"#ifdef": {
"prefix": "#ifdef",
"body": [
"#ifdef $1",
"${TM_SELECTED_TEXT}$0",
"#endif // $1"
],
"description": "Wraps code in an #ifdef block with a user-specified condition."
},
"#ifndef": {
"prefix": "#ifndef",
"body": [
"#ifndef $1",
"${TM_SELECTED_TEXT}$0",
"#endif // !$1"
],
"description": "Wraps code in an #ifndef block with a user-specified condition."
},
"#ifdefined": {
"prefix": "#ifdefined",
"body": [
"#if defined($1)",
"${TM_SELECTED_TEXT}$0",
"#endif // defined($1)"
],
"description": "Wraps code in an #if defined() block with a user-specified condition."
},
"#ifndefined": {
"prefix": "#ifndefined",
"body": [
"#if !defined($1)",
"${TM_SELECTED_TEXT}$0",
"#endif // !defined($1)"
],
"description": "Wraps code in an #if !defined() block with a user-specified condition."
},
"#if": {
"prefix": "#if",
"body": [
"#if $1",
"${TM_SELECTED_TEXT}$0",
"#endif // $1"
],
"description": "Wraps code in an #if block with a user-specified condition."
},
"#ifn": {
"prefix": "#ifn",
"body": [
"#if !$1",
"${TM_SELECTED_TEXT}$0",
"#endif // !$1"
],
"description": "Wraps code in an #if block with a negated user-specified condition."
},
"#inc<": {
"prefix": "#inc<",
"body": [
"#include <${1:${TM_SELECTED_TEXT}}$0>"
],
"description": "Inserts an #include statement for a system header file."
},
"#inc\"": {
"prefix": "#inc\"",
"body": [
"#include \"${1:${TM_SELECTED_TEXT}}$0\""
],
"description": "Inserts an #include statement for a user header file."
},
"#def": {
"prefix": "#def",
"body": [
"#define $1 $2",
"$0"
],
"description": "Defines a preprocessor macro with an optional value."
},
"//cfoff": {
"prefix": "//cfoff",
"body": [
"// clang-format off",
"${TM_SELECTED_TEXT}$0",
"// clang-format on"
],
"description": "Wraps selected code in // clang-format off/on comments to disable formatting."
},
"//nolt": {
"prefix": "//nolt",
"body": [
"// NOLINT${1:(${2:check-name})$0"
],
"description": "Adds // NOLINT comment to suppress lint warnings on the current line."
},
"//noltn": {
"prefix": "//noltn",
"body": [
"// NOLINTNEXTLINE${1:(${2:check-name})$0"
],
"description": "Adds // NOLINTNEXTLINE comment to suppress lint warnings on the next line."
},
"//noltr": {
"prefix": "//noltr",
"body": [
"// NOLINTBEGIN${1:(${2:check-name})}",
"${TM_SELECTED_TEXT}$0",
"// NOLINTEND${1:(${2:check-name})}"
],
"description": "Wraps selected code in // NOLINTBEGIN/END comments to suppress lint warnings."
},
"#region": {
"prefix": "#region",
"body": [
"// #region $1",
"${TM_SELECTED_TEXT}$0",
"// #endregion // $1"
],
"description": "Wraps selected code in // #region comments for code folding and organization."
},
"//cmtbox": {
"prefix": "//cmtbox",
"body": [
"/*********************************",
" * ${TM_SELECTED_TEXT}$1",
" *********************************/",
"$0"
],
"description": "Wraps selected text in a /* ... */ comment box for emphasis."
},
"//cmtsep*": {
"prefix": "//cmtsep*",
"body": [
"/******** ${TM_SELECTED_TEXT}$1 ********/$0"
],
"description": "Creates a /*** ... ***/ comment separator line with selected text."
},
"//cmtsep-": {
"prefix": "//cmtsep-",
"body": [
"/*------- ${TM_SELECTED_TEXT}$1 -------*/$0"
],
"description": "Creates a /*-- ... --*/ comment separator line with selected text."
},
"//sep*": {
"prefix": "//sep*",
"body": [
"/*********************************/$0"
],
"description": "Inserts a /******/ comment separator line."
},
"//sep-": {
"prefix": "//sep-",
"body": [
"/*-------------------------------*/$0"
],
"description": "Inserts a /*----*/ comment separator line."
},
"#section": {
"prefix": "#section",
"body": [
"/******** $1 ********/",
"// #region $2",
"",
"${TM_SELECTED_TEXT}",
"$0",
"// #endregion // $2",
"/*------- $1 -------*/"
],
"description": "Wraps /.../ cmtsep line and #region around selected text with labels."
},
"#headeronly": {
"prefix": "#headeronly",
"body": [
"/*********************************",
" * $1",
" *********************************/",
"// #region $2",
"",
"${TM_SELECTED_TEXT}",
"$0",
"// #endregion // $2",
"/*-------------------------------*/"
],
"description": "Wraps /.../ cmtbox and #region around selected text with label."
},
"//heading": {
"prefix": "//heading",
"body": [
"/**",
" * @file ${TM_FILENAME}",
" * @author ${1:FirstName} ${2:LastName}${3:(${4:NickName})} <${5:email.address@example.com}>",
" *",
" * @brief $6",
" * @details $7",
" *",
" * @version ${8:0.1}",
" * @date ${9:${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}}",
" *",
" * @copyright ${10:'$'cprt|licn}",
" */"
],
"description": "Inserts a C-style doxygen /** ... */ comment block with file info."
},
"#header": {
"prefix": "#header",
"body": [
"/**",
" * @file ${TM_FILENAME}",
" * @author ${1:FirstName} ${2:LastName}${3:(${4:NickName})} <${5:email.address@example.com}>",
" *",
" * @brief $6",
" * @details $7",
" *",
" * @version ${8:0.1}",
" * @date ${9:${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}}",
" *",
" * @copyright ${10:'$'cprt|licn}",
" */",
"",
"",
"#ifndef ${11:${TM_FILENAME}}",
"#define ${11:${TM_FILENAME}}",
"",
"#if defined(__cplusplus)",
"extern \"C\" {",
"#endif // defined(__cplusplus)",
"",
"$0",
"// #region Header_File_Inclusions",
"${12:// when NEEDED instead of Forward_Declarations}",
"// #endregion // Header_File_Inclusions",
"",
"// #region Pre-Processor_Definitions",
"$13",
"// #endregion // Pre-Processor_Definitions",
"",
"// #region Forward_Declarations",
"${14:// when NEEDED in this header file}",
"// #endregion // Forward_Declarations",
"",
"",
"// #region Public_Types",
"${15:// definitions: const, enum, struct, ...}",
"// #endregion // Public_Types",
"",
"// #region Public_Data",
"${16:// declarations: global, extern, static with extern}",
"// #endregion // Public_Data",
"",
"",
"// #region Inline_Functions",
"${17:// definitions}",
"// #endregion // Inline_Functions",
"",
"// #region Public_Function_Prototypes",
"${18:// declarations}",
"// #endregion // Public_Function_Prototypes",
"",
"",
"#if defined(__cplusplus)",
"}",
"#endif // defined(__cplusplus)",
"",
"#endif // !${11:${TM_FILENAME}}"
],
"description": "Creates a C header file template with common sections. Wraps /.../."
},
"#source": {
"prefix": "#source",
"body": [
"/**",
" * @file ${TM_FILENAME}",
" * @author ${1:FirstName} ${2:LastName}${3:(${4:NickName})} <${5:email.address@example.com}>",
" *",
" * @brief $6",
" * @details $7",
" *",
" * @version ${8:0.1}",
" * @date ${9:${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}}",
" *",
" * @copyright ${10:'$'cprt|licn}",
" */",
"",
"$0",
"// #region Header_File_Inclusions",
"${11:// only those that are NECESSARY}",
"// #endregion // Header_File_Inclusions",
"",
"// #region Pre-Processor_Definitions",
"$12",
"// #endregion // Pre-Processor_Definitions",
"",
"",
"// #region Private_Types",
"${13:// definitions: const, enum, struct, ...}",
"// #endregion // Private_Types",
"",
"// #region Private_Data",
"${14:// definitions}",
"// #endregion // Private_Data",
"",
"// #region Private_Function_Prototypes",
"${15:// declarations}",
"// #endregion // Private_Function_Prototypes",
"",
"",
"// #region Public_Data",
"${16:// definitions}",
"// #endregion // Public_Data",
"",
"// #region Public_Functions",
"${17:// definitions}",
"// #endregion // Public_Functions",
"",
"// #region Private_Functions",
"${18:// definitions}",
"// #endregion // Private_Functions"
],
"description": "Creates a C source file template with common sections. Wraps /.../."
},
"main": {
"prefix": "main",
"body": [
"int main(${1:${2|const int,int|} argc, ${3|const char*,char*|} argv[]}) {",
"\t$0",
"\t",
"\treturn 0;",
"}"
],
"description": "Generates a main function declaration with command line arguments."
},
"namesp": {
"prefix": "namesp",
"body": [
"namespace $1 {",
"${TM_SELECTED_TEXT}$0",
"} // namespace $1"
],
"description": "Wraps the selected code in a namespace block."
},
"usingn": {
"prefix": "usingn",
"body": [
"using namespace $0"
],
"description": "Inserts a using namespace statement."
},
"foreach": {
"prefix": "foreach",
"body": [
"for (${1|const auto&,auto&,auto|} $2 : $3) {",
"\t${TM_SELECTED_TEXT}$0",
"}"
],
"description": "Inserts a range-based for loop. Optionally wraps selected text in loop."
},
"try": {
"prefix": "try",
"body": [
"try {",
"\t${1:${TM_SELECTED_TEXT}}$2",
"} catch (const std::exception& $3) {",
"\t$0",
"}"
],
"description": "Wraps the selected code in a try-catch block."
},
"class": {
"prefix": "class",
"body": [
"class $1 ${2:: ${3:virtual} ${4|public,protected,private|} ${5:base}} {",
"\t${6:${TM_SELECTED_TEXT}}$0",
"};"
],
"description": "Generates a class declaration with inheritance options."
},
"template": {
"prefix": "template",
"body": [
"template <typename ${1:T}$2>$0"
],
"description": "Inserts a template declaration."
}
}