Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Generate empty function bodies automatically
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

davidm
New Member

7 Posts

Posted - Dec 02 2004 :  08:21:14 AM  Show Profile
I think a feature to generate empty function bodies automatically (in a cpp file) after they'd been declared in a header file would be really useful.

Ideally, to give some control as to where the unimplemented functions went, this would be 'triggered' from the cpp file itself. (This is one reason why I seldom just use the Microsoft "Add member function" option. Instead, I write my class definition then copy the definition into the cpp file and mangle it into an empty implementation.)

It would be even better if the generated implementation could have configurable options for whether to put spaces inside brackets, how many parameters to allow on each line, what spacing to use at the start of subsequent lines etc.

My colleagues like this idea, but does anyone else?

David

LarryLeonard
Tomato Guru

USA
1041 Posts

Posted - Dec 02 2004 :  09:35:21 AM  Show Profile
Have you looked into VAX's "Code Templates"? Might do some of what you want...
Go to Top of Page

davidm
New Member

7 Posts

Posted - Dec 02 2004 :  10:04:10 AM  Show Profile
Thanks for the suggestion. I'd never looked at Code Templates in VA, as we had another addin previously which did all that we needed. However, I don't think they go quite far enough for the following reasons:

1. The expanded code would replace the original function definitions, and end up in the header file. (Admittedly, I could copy the definitions into the C++ file first - but this is an extra step.)

2. I can't see a way of inserting the class name, needed to prefix the implementations with "ClassName::". (It could be prompted for, but again this is an extra step.)

3. At best, a code template solution could only deal with a single function at a time (unlesss I'm missing something) - ideally, I'd like to be able to generate multiple empty function bodies at once.

Regards,

David
Go to Top of Page

davidm
New Member

7 Posts

Posted - Dec 02 2004 :  10:10:24 AM  Show Profile
Just to clarify, I'd like to write something like:

class MyClass
{
public:
    MyClass();
    ~MyClass();
    void Method1();
    void Method2();
};

in a .h file, then move to a .cpp file and ask VAX to generate:

MyClass::MyClass()
{
}

MyClass::~MyClass()
{
}

void MyClass::Method1()
{
}

void MyClass::Method2()
{
}


Ideally any comments before the declarations in the header would be copied to the implementation too.

Edited by - davidm on Dec 02 2004 10:13:08 AM
Go to Top of Page

Ruskialt
Junior Member

Denmark
22 Posts

Posted - Dec 02 2004 :  11:19:26 AM  Show Profile
I wouldn't like comments to be copied too, because this will only confuse things if you change the comment one day - will it be changed in the corrosponding cpp/h file too, probably not? Having copies of stuff lying around always impose sync problems.

I like the aspect of keeping h/cpp "syncronized" though (now that c++ deals with h and cpp file), eg if you change the parameter list for a function in the header, this will change the cpp too.

Don't know if this is within scope of VA though...
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Dec 03 2004 :  3:13:39 PM  Show Profile
quote:
Originally posted by davidm

Just to clarify, I'd like to write something like


*considers*
you can do most of this with macro's. assuming a constant layout for your classes then a macro will handle the basic cases for you. the more complicated you make the macro, the better it will function

*gives some thought to this*

now i see the idea, i want this macro myself

lets try this:
place the caret anywhere on the header line, and follow the following key press sequence, each time the key to press is in square brackets:

[ctrl-c] - copies the current line in .NET 2003
[alt+o] - use VAX to open the cpp file
[ctrl-end] - lets put the function somewhere sensible
[ctrl-v]
[up arrow]
[alt-o] - back to the header
[alt + up arrow] - use VAX to get to the head of the class
[up arrow] - onto the class name line
[ctrl + right arrow]
[shift + ctrl + right arrow]
[shift + left arrow] - class name is now highlighted
[ctrl-c]
[alt-o]
[ctrl-i]
[(] - caret jumps to the open bracket, after the function name
[ctrl + left arrow]
[ctrl + left arrow]
[ctrl + v]
[::]
[escape]
[end]
[backspace]
[enter]
[{]
[enter]
[}]

*doh* *swears at the IDE*
you cannot record incremental searches in the IDE, which means i cannot use one to jump to the open bracket, which means i cannot reliably position the caret when i want it when forming the function body.

this would be a very simple macro to write in VIM, since i could position the caret at the correct position quite easily *sigh*

if anyone knows the VB Macro command to jump to the first instance of a character on a line, then i will produce the macro to do this job and post it. this seems to be the only stumbling block with this macro.

you need to jump to the brackets, to allow the macro to operate on complex return types. since the function may be const you cannot assume that the last two characters on the line are );

so, given some help i can do this anyone happen to know the answer?

zen is the art of being at one with the two'ness
Go to Top of Page

davidm
New Member

7 Posts

Posted - Dec 05 2004 :  04:47:35 AM  Show Profile
I like the idea, feline - thanks. It doesn't feel quite as slick as using just VAX, but it does look very close to working...

(The idea of using VAX to switch between the the header and cpp is neat, as is your method for grabbing the classname.)


Edited by - davidm on Dec 05 2004 04:48:41 AM
Go to Top of Page

davidm
New Member

7 Posts

Posted - Dec 05 2004 :  06:18:14 AM  Show Profile
quote:
Originally posted by Ruskialt

I wouldn't like comments to be copied too, because this will only confuse things if you change the comment one day - will it be changed in the corrosponding cpp/h file too, probably not? Having copies of stuff lying around always impose sync problems.



Keeping things synchronized is an issue - but I still like to label functions in the cpp with a brief comment indicating what they do, if just to give the cpp some structure. Very much personal taste, though...

quote:

I like the aspect of keeping h/cpp "syncronized" though (now that c++ deals with h and cpp file), eg if you change the parameter list for a function in the header, this will change the cpp too.

Don't know if this is within scope of VA though...



I suspect this is definitely outside the scope of VA, although it would be really useful. Some time I really must get round to investigating the code object model in VS 2003 - I suspect it could make something like this a lot easier to implement...
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Dec 06 2004 :  4:38:24 PM  Show Profile
the good news is that you can use CTRL_F while recording a macro. the bad news is that alt_o does not work on my machine when i play back a macro.

i cannot use the VAX menu to swap between the cpp and .h files while recording the macro since this option is disabled once you start to record a macro.

then i tried to use ctrl_tab to swap between the cpp and .h files. even when the key press sequence is correct this does not work correctly when i play back the macro *grrr*

it has reached the point where i am seriously considering making myself this macro in gVIM, and running it there. it is to hard to anticipate the results of the macro when you play it back.

i recall the comment that you can implement VAX's alt_o feature as a macro, so if i can find some info on this i may yet be able to produce this macro and post it. anyone remember where they have seen this statement? or can anyone point me in the right direction?

zen is the art of being at one with the two'ness
Go to Top of Page

davidm
New Member

7 Posts

Posted - Dec 10 2004 :  10:12:53 AM  Show Profile
So, does anybody else agree with me that this (in some form) would be a useful new feature for VAX? Or am I on my own here?

Regards,

David

Edited by - davidm on Dec 10 2004 10:14:19 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Dec 13 2004 :  2:56:19 PM  Show Profile
i have had a couple more goes at writing a macro to do this. the problem with any simple set of rules is that it falls over on more complex situations.

i got as far as:

class feline_test
{
    enum TYPE { ROUND, SQUARE, POINTY };

    TYPE getType() const;
}

when i enter the function body, the return type turns into:
feline_test::TYPE

*sigh* plus it is a pain to get the class name without upsetting the content of the find dialog, since inline functions "break" alt + up arrow.

so i have put in a request, and we will see what happens. this is a logical extension of the existing feature in VAX to insert the parameters when creating a function body manually, so perhaps WT will agree and impliment this

case=471

zen is the art of being at one with the two'ness
Go to Top of Page

davidm
New Member

7 Posts

Posted - Dec 13 2004 :  8:25:02 PM  Show Profile
That's excellent news, Feline, thanks very much! It would be great to see this feature in VAX at some point...

David

Edited by - davidm on Dec 13 2004 8:25:34 PM
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000