Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Struct to Class refactoring

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
mcaron Posted - Sep 17 2009 : 08:34:58 AM
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
1   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Sep 17 2009 : 2:30:34 PM
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

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