Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Refactor -> Create implementation placement

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
tjcbs Posted - Oct 18 2014 : 9:03:44 PM
Create Implementation should place the implementation consistently with the header file.

So,

void A();
void New(); <-- Create Implementation
void B();

In this case, the implementation of New() should be placed between A() and B() in the c/cpp file, not at the end.

Edit: This does seem to at least come close, some of the time. However, it fails more often than not. Feel free to move to support, and let me know if you need a test case.
29   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Oct 27 2015 : 7:33:39 PM
Interesting, I know some things about templates, but there is always more to learn. Most cases where people talk about templates keep the implementations in the header file, but obviously not everyone

I am glad that Move Method Implementation is helping, this is a fairly recent addition. It does look helpful, and its ideal in this situation.
tjcbs Posted - Oct 27 2015 : 05:43:43 AM
You can explicitly instantiate templates. This is useful for template classes you really don't want implemented in the .h file, that are templated over a known range of values. In my particular case:

template class particleSystem_<true>;
template class particleSystem_<false>;


But no, I didn't know about Move Method Implementation to Source File, that makes it a lot better, thanks.
feline Posted - Oct 26 2015 : 3:14:48 PM
As I understand it, for a template class, the function implementation has to be included in the file that uses the method. This is why VA places the implementations into the .h file, since this is the file that you normally include.

I know it is valid to include a .cpp file, but I have virtually never seen this done.

Are you including your .cpp files, or are you using some other method to get your template code to compile?

Are you aware that after triggering "Create Method Implementations..." on the template class to generate the implementations, you can then trigger "Move Method Implementations to Source File..." on the template class name? This will give you a dialog listing the implementations that can be moved, with all of them selected by default.

This does require a second step, but its a fast second step to move all of the implementations to the cpp file.
tjcbs Posted - Oct 26 2015 : 12:18:14 AM
Another issue: if creating a template member function, VA always puts the implementation in the .h file, even if the class is implemented in a .cpp file.

VA should test whether or not a .cpp file exists, not whether the class is a template.
accord Posted - Oct 02 2015 : 04:00:24 AM
Thank you for taking the time to create the test files, I was able to reproduce the problem:

case=92499

This surely helps.
tjcbs Posted - Oct 01 2015 : 11:13:15 PM
I tried the test you described, and it worked correctly. However, inserting a new function into an existing header failed. I will send you a test case. No special keywords are being used.

Note, I am still using 10.9.2068.0
accord Posted - Sep 25 2015 : 8:12:20 PM
Let's focus on c-style function declarations, first. Can you post an example case where it fails? I put this simplified sample in a header file:

void Test1();
void Test2();
void Test3();

I triggered Created Implementation on Test1 first, and then Test3 and finally Test2. The order was kept in the cpp file. I know it's an oversimplified example, but my point was that it should work, but it certainly does not in your case. I suspect that you have a scenario when it fails, i.e. it's context dependent. The easiest would be if you could send in a header and cpp file pair where you can reproduce this problem. We would keep the files private. But I know it's not often possible, but it's worth asking.

You can send in files via the following form:
http://www.wholetomato.com/support/contact.asp

It's possible that you're using keywords which makes it fail. I tried "external" and it works for me. Do you have any special keyword or a macro in your function declarations?
tjcbs Posted - Sep 22 2015 : 01:25:32 AM
Hmm... It seems like it is still working in class cpp/h files. However, it is not working with c-style function declarations, nor is it working with header only classes. Was it my imagination that it was ever working with these cases?
accord Posted - Sep 19 2015 : 1:15:43 PM
Now we have a new "Code Generation" section of VA options dialog. If you fire up the dialog and go to that section, is it enabled?

VA Options -> Code Generation -> Maintain order in header and source files for generated C/C++ implementation

quote:
It was working for a while.

Was it working in the same files in which it's broken now?
Is it now broken in every single file or just in certain ones?
tjcbs Posted - Sep 17 2015 : 9:33:35 PM
quote:
Originally posted by sean

case=12454 is implemented in build 2059

If you do not like or want the new behavior, change reg value named FindSimilarLocation
it defaults to enabled/01
set to 00 to restore old behavior




This implementation seems fragile.

It was working for a while. Now, it has gone back to dumping the implementation at the end of the cpp file. Or, the beginning of the .h file, for header only classes.

VS2013, VA 10.9.2068.0

FindSimilarLocation is 01, FWIW.
sean Posted - Feb 13 2015 : 8:13:59 PM
case=12454 is implemented in build 2059

If you do not like or want the new behavior, change reg value named FindSimilarLocation
it defaults to enabled/01
set to 00 to restore old behavior
feline Posted - Nov 21 2014 : 4:23:49 PM
That makes perfect sense, and I have put a note on the case about this. Surprisingly I am not seeing a note about this yet, so you may be the first person to point this out
Mordachai Posted - Nov 21 2014 : 2:35:26 PM
+1 from me as well - and I'd prefer it to work both ways.

Commonly: I have to add a function, I create it to support another in the implementation file, then use "create declaration" -- but then I am sad when the declaration is stuffed onto the end of the class definition, instead of immediately before/after the function I've added this to support.

e.g.

class A
{
void MyCurrentMethod();
void Junk();
void UnrelatedJunk();
}

---
.cpp file:

void A::MyCurrentMethod()
{ ... }

void A::AnotherSupportMethod()
{ ... }

Now right click on AnotherSupportMethod and "create declaration" and I end up with:

class A
{
void MyCurrentMethod();
void Junk();
void UnrelatedJunk();
void AnotherSupportMethod();
}

But would prefer:

class A
{
void MyCurrentMethod();
void AnotherSupportMethod(); // <- same relative spot as in .cpp (or at least in same context as in .cpp - immediately following MyCurrentMethod()...
void Junk();
void UnrelatedJunk();
}

feline Posted - Nov 07 2014 : 1:00:34 PM
I have put a note onto the case about your interest in this, thank you, it is good to know which features people are most interested in.
kiro Posted - Nov 06 2014 : 07:52:04 AM
I just want to "upvote" the request, as I would love to have that feature too...
feline Posted - Oct 30 2014 : 8:30:50 PM
Ah, this explains why this is important. I suspect I knew that at some point, but I had forgotten that fact, thank you for reminding me. I have put in a feature request for this, since this does make sense:

case=86018
tjcbs Posted - Oct 28 2014 : 01:25:31 AM
If you define the function inside of a class, it is "inline" implicitly. But if you define it outside, it is not "inline" implicitly, and *has* to be declared "inline". Otherwise, you get multiple definition errors. Try it!

Similarly, every c-style function defined in a header *must* be "inline"d, or you get the same error.

(of course, the .h file has to be included by more than one .cpp file)
feline Posted - Oct 27 2014 : 9:24:31 PM
Since when are implementations in a header file without "inline" illegal? As I understand it inline is a request to the compiler, nothing more. The compiler will inline, or not inline the function based on its settings, and the conclusions its optimiser reaches about what to do. This page agrees, so I remember correctly:

http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx
tjcbs Posted - Oct 27 2014 : 6:50:38 PM
yes, alt-o does nothing. I have not marked the declarations with inline, since it is not necessary and clutters the interface with an implementation detail. But even if I do, Create Implementation does not preserve it.

In my opinion it is not common to Create Implementation without a cpp file, if the intention is to later create a cpp file. Whereas it is very common to have functionality implemented in a .h file. Furthermore, even if the function is later moved to a cpp file, the "inline" wouldn't hurt anything. By contrast, the implementations VA is creating now in the .h, without "inline", are illegal.
feline Posted - Oct 27 2014 : 5:00:55 PM
So you are working in a header file with no matching cpp file, so alt-o does nothing? I had been assuming you had a matching cpp file, since that is the situation that normally comes up when talking about Create Implementation.

In this case have you marked the declarations with inline?

There is a difference between not having created the cpp file yet, and not intending to create the cpp file, so I am wary about making assumptions just because there is currently no matching cpp file.
tjcbs Posted - Oct 24 2014 : 02:06:00 AM
I'm talking about functions created with this feature, not those already implemented. Currently, this feature creates a function in a header without "inline". Since it is auto-generated, I don't think about it, recompile the whole project (or at least big chunks of it, since a header changed), and get a bunch of duplicate link errors, then have to fix it and recompile again. It would be very nice if this feature added "inline" for non-templpated header functions, since it is always required.

To be totally clear, I am talking about declaring a function in a .h file, and then implementing it (with VA create implementation) at the bottom of that file. I always do this so that the interface stays clean and readable.
feline Posted - Oct 24 2014 : 12:33:15 AM
Are these implementations in the header file already present, or are you adding / moving them via VA somehow?

If they are already present have you considered a regular expression find to search for any that are missing the inline keyboard? Depending on your formatting, searching for something before { that does not contain inline may well work.
tjcbs Posted - Oct 23 2014 : 03:27:14 AM
I understand that this is just one of many features. A very nice bonus addition to this feature would be to automatically prepend "inline" to non-template functions implemented in a header file. I always forget to do this.
feline Posted - Oct 23 2014 : 12:34:02 AM
Looking up and down for a reference point is the basic plan. This is a popular idea, its just a matter of prioritising it along with everything else people are interested in
tjcbs Posted - Oct 22 2014 : 6:40:01 PM
You can still proceed upwards in the .h file until you find a function with an implementation. Just saying... :)
feline Posted - Oct 21 2014 : 2:53:26 PM
This is where the rules outlined in the case start, but this assumes that A() already has an implementation. This has been discussed before on the forum, and we have a plan, but its just one of many features that we are looking to add to VA. We are hoping to look at this fairly soon though, since this is a popular request.
tjcbs Posted - Oct 21 2014 : 03:14:45 AM
quote:
Originally posted by feline
This is relatively easy if you get to assume that the two files are currently in the same order, but often the aren't.



I had actually thought of that. One solution, in terms of the example I posted, is to simply ignore B() and insert New() after A(). This produces behavior that is correct if the two files are in the same order, and reasonable if they aren't.
feline Posted - Oct 20 2014 : 6:29:18 PM
We are looking to change this, so that Create Implementation and Move Implementation try and keep the same ordering in the cpp file as is in the header file:

case=12454

This is relatively easy if you get to assume that the two files are currently in the same order, but often the aren't.

BOP, you have a good point, and I have put a note onto the case about being able to turn this off. Note that the moved code is selected in the cpp file, so you can easily cut it and move it to the location you prefer.
BOP Posted - Oct 19 2014 : 8:29:45 PM
Maybe it needs a switch.

The way I operate I find that the way the implementation is currently stuck to
the end of the source file to actually be a >> feature.

This new code, other more recent code, and any other dubious code, which are the most likely
to need attention over the next few days can be quickly located in the future without even knowing,
or having forgotten, what they are all named. It keeps a timeline of these additions.

Having the most recent code so easily locatable without having to use bookmarks, which are
continually being cleared and redone, or having to use some "find" function or other marker is very handy.

Then when the code is old and tested I can cut and paste the block so that it sits next to
some more related code if needs be.

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000