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
 Struct to Class refactoring
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mcaron
New Member

4 Posts

Posted - Sep 17 2009 :  08:34:58 AM  Show Profile  Reply with Quote
It would be really handy to have a VA refactoring option to convert a C++ struct into a basic C++ shell class. I've inherited a lot of code where the initial programmer was quite fond of using structs, but now they would be better served as classes. I know structs and classes are kissing cousins, but sometimes converting a struct to a class is really the "right" thing to do. Not to mention being able to do this would allow for a quick way to create a class with a large number of data items quickly. Something along the lines of:

struct foo
{
int a;
float b;
}

Either select the entire struct or place the cursor on the line "struct foo" and select Class from Struct in the refactor menu to get:

foo.h
class foo
{
public:
//constructors
foo();
//destructors
~foo();
//accessors
inline int GetA() const {return a;};
inline float GetB() const {return b;};
//mutators
inline void SetA(const int val) {a = val};
inline void SetB(const float val) {b = val};
private:
int a;
float b;
}

foo.cpp
foo::foo()
{
}

foo::~foo()
{
}

It is a heck of a lot of typing, even with VA, to make such a transformation. Adding initializers to the constructor, a populated copy constructor, and a populated assignment operator would be icing on the cake. Doing the conversion in place in the file the struct was defined in and making all the new functions in that file would work, since it is a trivial matter to use move to source or move to header to slide function definitions around.

-Mike

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Sep 17 2009 :  2:30:34 PM  Show Profile  Reply with Quote
It is quite unlikely we would add such a specialised refactoring. However you could make quite a good start simply by using VA Snippets. If you had a snippet like:

class $clipboard$
{
public:
    // constructors
    $clipboard$();
    // destructors
    ~$clipboard$();

    // accessors
    // mutators

private:
    $selected$
}

$clipboard$::$clipboard$()
{
}

$clipboard$::~$clipboard$()
{
}

you could copy the struct name and then select the member variables inside the struct, before triggering the VA Snippet. It would then do some of the typing and reorganising for you. It would not be helpful, but it would help quite a bit.

We are considering adding a command to make a default copy constructor:

case=3945

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