Converts classes/structs to a natvis format.
Having to convert a class or a struct to a natvis type representation is a bit of a PITA if you want to include all of the elements, want to be reminded as to what the types are being represented, get rid of all the function declarations/definitions and convert any comments or anything not recognised to comments.
This uses AutoHotKey to aid in quickly trying to convert classes/structures into a format which is still fairly readable.
I got tired of doing this manually so I used my knowledge of AHK and its regex engine to convert a class/struct to a natvis tag format.
Highlight a complete copy of the class/struct where you want it to be converted, and then press Ctrl-Shift-2. This will then replace the highlighted copy with the natvis block.
The indent character(s) is/are the leading whitespace(s) located directly to the left of the class/struct definition.
I normally do this directly in my .natvis file, but this will work in any editor, in any file.
-
Clone this repository in your Documents folder.
-
Download and install AutoHotKey if you haven't already.
-
In your %USERPROFILE%\Documents\AutoHotKey.ahk file, add to the end of the file:
#include %A_LineFile%\..\class2natvis\natvis.ahk
and save it.
-
Reload the AHK script
-
Go to your system tray and find the green H icon.
-
Right click on it and select
Reload This Script
. -
Now try it out! :)
class testClass : public baseClass
{
int function(LPCTSTR param1);
int function(LPCTSTR param2, int value)
{
/* some code here */
}
LPCSTR const strings[3]; // some LPCSTR strings
}
<Type Name='testClass'>
<DisplayString ExcludeView='preview'>{*this, view(preview)}</DisplayString>
<Expand>
<Item Name='baseClass [base]' ExcludeView='preview'>(baseClass*)this, nd</Item>
<!-- LPCSTR const [3] -->
<Item Name='strings'>strings</Item> <!-- some LPCSTR strings -->
</Expand>
</Type>
At the moment, this doesn't recognise function pointers or nested classes/struct, anonymous classes/structs and will convert only one class/struct at a time. There may be some ways that I've not thought of which may not recognising certain constructs. Feel free to leave a bug report or add a fix. I'm not very sure how the push/pull thing works on git so please be patient.