Wrote another command to set up the cpp casts for me, going to try to kick the habit of using c casts everywhere.
http://i.imgur.com/XgDy9fm.gifv
in the prompt:
s = static_cast
d = dynamic_cast
c = const_cast
r = reinterpret_cast
Most of it was shamelessly copypasta'd from the #if 0 #endif command.
I was thinking, that for situations where you have T v1 = cast<T>(v2); it could deduce the type you are casting to, curious as to how you would approach that.
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 | CUSTOM_COMMAND_SIG(write_cpp_cast) {
const char sig_static[] = "static_cast<>(";
const char sig_dynamic[] = "dynamic_cast<>(";
const char sig_const[] = "const_cast<>(";
const char sig_reinterpret[] = "reinterpret_cast<>(";
const char sig_end[] = ")";
const int sz_static = sizeof(sig_static) - 1;
const int sz_dynamic = sizeof(sig_dynamic) - 1;
const int sz_const = sizeof(sig_const) - 1;
const int sz_reinterpret = sizeof(sig_reinterpret) - 1;
const int sz_end = sizeof(sig_end) - 1;
char type[8];
const char* cb;
int sz;
Query_Bar bar;
bar.prompt = make_lit_string("Cast type: ");
bar.string = make_fixed_width_string(type);
if (!query_user_string(app, &bar)) return;
end_query_bar(app, &bar, 0);
switch(type[0]){
case 's': {
cb = sig_static;
sz = sz_static;
}break;
case 'd': {
cb = sig_dynamic;
sz = sz_dynamic;
}break;
case 'c': {
cb = sig_const;
sz = sz_const;
}break;
case 'r': {
cb = sig_reinterpret;
sz = sz_reinterpret;
}break;
default: {
return;
}
}
View_Summary view = get_active_view(app, AccessOpen);
Buffer_Summary buffer = get_buffer(app, view.buffer_id, AccessOpen);
Range range = get_range(&view);
if (range.min < range.max){
Buffer_Edit edits[2];
char *str = 0;
char *base = (char*)partition_current(&global_part);
str = push_array(&global_part, char, sz);
memcpy(str, cb, sz);
edits[0].str_start = (int32_t)(str - base);
edits[0].len = sz;
edits[0].start = range.min;
edits[0].end = range.min;
str = push_array(&global_part, char, sz_end);
memcpy(str, sig_end, sz_end);
edits[1].str_start = (int32_t)(str - base);
edits[1].len = sz_end;
edits[1].start = range.max;
edits[1].end = range.max;
buffer_batch_edit(app, &buffer, base, global_part.pos, edits, ArrayCount(edits), BatchEdit_Normal);
if(view.cursor.pos < view.mark.pos){
view_set_cursor(app, &view, seek_line_char(view.cursor.line, view.cursor.character + sz - 2), 1);
}
else{
view_set_cursor(app, &view, seek_line_char(view.mark.line, view.mark.character + sz - 2), 1);
}
}
}
|