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
 Recognizing Handles
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sl@sh
Tomato Guru

Switzerland
204 Posts

Posted - Sep 18 2007 :  06:14:50 AM  Show Profile  Reply with Quote
I am using a Handle class for some of my pointers, i. e. a class that works just like a pointer wrt. coding issues, but keeps track of all copied references and automatically releases the object once the last reference is gone.

One of the basic features of such a class is that it redefines the operator-> to point to the governed object. The class basically looks like this:
template <class X> class Handle {
    X* rep;
public:
    X* operator->() { return rep; }
// ...
};


Now I can define a variable as a Handle to another class and access it's members like this:
class CFoo {
    int m_bar;
public:
    int getBar() const {return m_bar;}
};
main()
{
    Handle<CFoo> pFoo;
    int somevalue = pFoo->getBar();
}


What I am missing is the suggestion box after typing the '->'. VA doesn't recognize the operator->() has been assigned to work as a pointer, so it doesn't provide the list of members from class CFoo.

My suggestion would be for VA to check operators typically used for referencing or dereferencing for possiblle overrides and supply a suggestion box with members of the returned class type.

I have to admit I haven't considered all the consequences: possibly, if you deal with operator->(), you might want to do the same with operator.(), or even operator&(). Considering that sometimes Handles are not quite defined the 'standard way' (i. e. as suggested by Bjarne Stroustrup) there might be some hidden traps...

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Sep 18 2007 :  1:10:26 PM  Show Profile  Reply with Quote
Effectively you are talking about a smart pointer class. The short answer is that VA already does this. I have two standard tests for this, that both work just fine for me.

One tests uses this variable:

	boost::shared_ptr<testBoostPtrListbox> pTest;


and the second test uses this class:

template <class T>
class SmartPtr
{
public:
	SmartPtr()
	{
		ptr = NULL;
		RefCount = NULL;
	}
	int Attached() const
	{
		return ptr != NULL;
	}

	T &operator*()
	{
		return *ptr;
	}

	T *operator->()
	{
		return ptr;
	}

	const T *operator->() const
	{
		return ptr;
	}

private:
	T *ptr;
	size_t *RefCount;
};

Lets start with the simple test. Can you add my class to one of your header files and then in the matching cpp file add this code:

class SimpleClass
{
public:
	SimpleClass();
	int one;
};

static void testSmartPointerArrayAccess()
{
	Block< SmartPtr< SimpleClass > > SomeVariable;

	int x = 0, y = 10;
	for (x = 0; x < y; x++)
	{
		if (SomeVariable[x]->one)
		{
			// type -> before the semi-colon, and make sure that VA suggests
			// "one" and "SimpleClass()"
			SomeVariable[x];
		}
	}
}


A little more complex than the situation you are describing, but an easy place to start.

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

sl@sh
Tomato Guru

Switzerland
204 Posts

Posted - Sep 19 2007 :  04:06:17 AM  Show Profile  Reply with Quote
Interesting, works alright for me as well. I again tried my original - rather complex - examples, and found that while some of them indeed don't suggest any completions (which triggered my suggestion) many instances work as well.

I suppose there's something in my code which prevents VA from properly showing suggestions in some places, but at the moment I am not able to pin down the reason. When I have time (i. e. not right now) I will try to strip down part of the code to see what it is that makes VA stumble. Both the working examples and those that don't are in the same file. I also noticed a few oddities VA doesn't seem to be able to cope with, but that might be due to the fact I'm doing a major refactoring right now and parts of the code are currently seriously out of whack. I'll get back to these VA problems once the code is back to 'normal'....

Edited by - sl@sh on Sep 19 2007 04:15:09 AM
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Sep 19 2007 :  10:56:55 AM  Show Profile  Reply with Quote
Thank you. I am certainly interested in any test cases that show this breaking.

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000