Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Alt-G and implementations of interfaces

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
Frunobulax Posted - Nov 28 2007 : 08:47:15 AM
1619/VS2005 SP1

Hi,

here is a behaviour that is somewhat annoying.

To keep our components modular we often declare interfaces and provide a factory and a default implementation (the latter is invisible to the "outer world"). So we have

class _MyInterface {
  virtual void doSomething() = 0;
};
typedef boost::shared_pointer<_MyInterface> MyInterface;

class MyFactory {
  MyInterface createInterface(...);
}


and in a different header

class _MyInterfaceImpl: public _MyInterface {
   virtual void doSomething() override;
}



Now if I want to jump to the implementation of _MyInterfaceImpl::doSomething using Alt-G, VAX will just jump to the abstract declaration in _MyInterface. This is not really unexpected since VAX does not offer to jump to members of derived classes. However, in the case of pure virtual functions it would be quite convenient if VAX would try to find implementations - at least as long as they are included in the current VS solution.

Regards, Thomas
7   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Dec 05 2007 : 3:41:09 PM
Good answers Your code is structured differently to mine, and you are solving different problems.

If you had a variable of the derived type in hand then VA View would be ideal, since it will show you the base class information.

The idea of a type of Find References that only searches for the derived classes has come up before:

case=6647

which is basically what we are looking for here, so long as the class member functions are also checked. In your code there only tends to be one derived class, but in the general sense, for "all" users this is unlikely to be the case, so I am looking for an idea that should scale well
Frunobulax Posted - Dec 04 2007 : 09:14:08 AM
quote:
Originally posted by feline

Frunobulax there are some interesting idea's here. I am not convinced alt-g is the correct place for this, for a few reasons.

quote:
Originally posted by Frunobulax

The typical case here is that there is exactly one implementation in a derived class, and the implementation is part of the solution (and should be known to VAX).


Not in my code

Personally if I have a virtual function, especially if I have an abstract virtual function I have multiple declarations of it in the different derived classes. Otherwise why make it abstract and virtual?



(a) Think of a data provider which reads data from a database, but maybe later you want to implement a mock provider that supplies a database-less implementation for unit tests. Or you plan to add another implementation that has better performance but requires more memory, and switches between implementations depending on the object.

Now the default case is that you create just one implementation, and add the other implementations only if required - which in many cases means "never".

(b) Another disadvantage of not putting the interface in a pure virtual class is that you have to recompile all units using this header even if you only change protected and private stuff. A typical case here is that interfaces are included in hundreds (and in many cases thousands) of files, but the implementation is only included in a small number of files (<=5).

(c) There are a number of cases where C++ interfaces are generated from some other interface (for example we have some back and forth between Java and C++ using JNI interfaces, or generate C++ from WSDL). In these case it is simply not possible to edit the C++ headers because changes will be lost if the master interface changes and new C++ interfaces are generated.

quote:

Next the point about pure virtual, what happens when it also has a declaration? Consider:

CTestClass
{
    int CalculateSomething() = 0 { return -1; }
};

not a very good example, but I have given abstract functions implementations in real world code before now.



This may happen, but it happens rarely. In this case I'd be happy to jump to this implementation :-)

quote:

It seems to me that some form of Find References is the solution here, which seems to be what accord is also thinking.

Here you need to find declarations and implementations in the base class, and all derived classes, but are not interested in any calls to the function.



Sure - I'm not zoomed in on Alt-G. But the information has to be cached too, because a "find references" can take quite a long time...

However, my motivation for using Alt-G is that in my use cases I treat the implementations in the implementation classes just as if I would implement the interfaces.

Regards, Thomas
feline Posted - Nov 30 2007 : 10:10:28 AM
Frunobulax there are some interesting idea's here. I am not convinced alt-g is the correct place for this, for a few reasons.

quote:
Originally posted by Frunobulax

The typical case here is that there is exactly one implementation in a derived class, and the implementation is part of the solution (and should be known to VAX).


Not in my code

Personally if I have a virtual function, especially if I have an abstract virtual function I have multiple declarations of it in the different derived classes. Otherwise why make it abstract and virtual?

Next the point about pure virtual, what happens when it also has a declaration? Consider:

CTestClass
{
    int CalculateSomething() = 0 { return -1; }
};

not a very good example, but I have given abstract functions implementations in real world code before now. The implementation is the default case, which you can use, but you have to think about it before it gets used, since you have to explicitly call it.

From your comments I assume you are sitting on a function call on a variable of type "baseClass *"

As soon as you look at GUI libraries, Qt is one I have worked with, you have virtual functions in the base class that you overload in your own GUI classes, so there are a lot of overloaded functions in different classes, all over the place.

This is different to the situation where the base class and all derived classes are inside the solution, and are "your" code, but it needs to be considered.

It seems to me that some form of Find References is the solution here, which seems to be what accord is also thinking.

Here you need to find declarations and implementations in the base class, and all derived classes, but are not interested in any calls to the function.
feline Posted - Nov 30 2007 : 09:53:15 AM
accord both of these are still in the list
Frunobulax Posted - Nov 30 2007 : 07:54:40 AM
quote:
Originally posted by feline

Just looking at the call you are jumping from, if you place the caret into this function call what does VA show you in the context and definition fields?

It shows the abstract definition.

quote:

If VA realises you are working on the derived class then alt-g should go to the correct declaration. But if you are working on a pointer to the base class (as is common with virtual functions) then VA will have no way of knowing which derived class you want to jump to.



I know. But I'm in the suggestions section here :-)
And I do suggest: If the function is pure virtual ("=0"), try to find implementations in derived classes.

quote:

Once you arrive at the base class you might want to use the IDE's "Class View" to find the derived classes.

VA's Find References on the function in the base class will find the function declaration and implementation in the derived classes, but will probably return to many results to be all that helpful in this particular case.


The typical case here is that there is exactly one implementation in a derived class, and the implementation is part of the solution (and should be known to VAX).

BTW, I know exactly where the function is defined. I just want VAX to do the "find the right library, open the right source file, find the right function" routine for me.

Regards, Thomas

accord Posted - Nov 29 2007 : 6:32:55 PM
quote:
Originally posted by feline

VA's Find References on the function in the base class will find the function declaration and implementation in the derived classes, but will probably return to many results to be all that helpful in this particular case.



Hide function callings should be great in this case
case=2867 <-- Is it still planned?
http://forum.wholetomato.com/forum/topic.asp?TOPIC_ID=5831&SearchTerms=find,references,filtering

fixing case=4442 will also help to find function definitions faster
feline Posted - Nov 29 2007 : 5:18:58 PM
Just looking at the call you are jumping from, if you place the caret into this function call what does VA show you in the context and definition fields?

It sounds like the main problem here is that VA thinks you are operating on an instance of the base class, rather than an instance of the derived class.

If VA realises you are working on the derived class then alt-g should go to the correct declaration. But if you are working on a pointer to the base class (as is common with virtual functions) then VA will have no way of knowing which derived class you want to jump to.

Once you arrive at the base class you might want to use the IDE's "Class View" to find the derived classes.

VA's Find References on the function in the base class will find the function declaration and implementation in the derived classes, but will probably return to many results to be all that helpful in this particular case.

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