Sign in to follow this  
ldramire

Made a tool you C++ guys may be interested in

Recommended Posts

Hey peeps, So I got tired of C & P'ing code and / or starting from scratch when writing source and header files so ... I made a program to do it for me! I thought I'd post here, get some feedback, and see if anyone would find it useful. You can find it at this incredibly lame page (put together in 5 minutes ... quite literally [grin]) http://www.rit.edu/~ldr2567/ClassMaker/ . It's a C# Winforms app so most of you should be able to run it. Let me know what you think. Any problems? Glaring problems in the C++ syntax? Noticable bugs I may have missed? Suggestions? Anything you would add? Remove? Change? Find it useful at all? Would you use it? You get the picture ... :) Thanks

Share this post


Link to post
Share on other sites
I was unable to get the tool to run, but from the screenshots I would say it offers an advantage over the built in class creation toolset in VS.NET :) If you cleaned it up and made it an add-in for VS.NET/Slickedit/Eclipse it would be a pretty cool tool. The problem besides it not running is the fact that its a seperate executable and it may be faster to just type out the file yourself unless it was a very complex definition and then program might save you a few seconds.

Share this post


Link to post
Share on other sites
The window never showed up. I ran it with and without any firewall/av present. It may have something to do with my configuration. I liked the screenshots though.


My Config:
P4 2.4ghz
1gb Ram
Windows XP SP2
Radeon 9800
All Libraries from a default VS.NET/.NET2.0/.NET1.1 install are present

Share this post


Link to post
Share on other sites
Looks good. Much better than the one provided by VS.NET 2003.

There's just a few suggestions I have:

(1) Support for inline files (either by adding a .inl or having all code in the .h file)

(2) I can specify a templated class, but I can not specify to inherit from a templated class. The syntax for inheriting from templated classes is slightly different than inheriting from non-templated classes.

Also, I think the generated syntax for C++ class templates is not correct OR VS.NET is not standards compliant (I think its the former though).

I tried compiling a templated class, but I received the Linker errors stating that the compiler could not find any of the class methods. From my experience with templates, I believe you have two options:

1) Keep everything in the .h file.

2) Include the .cpp (I usually name them .inl) right after the class definition in the .cpp file. So you'll have in the .h file

#ifndef A_H
#define A_H

template < typename T >
class A
{
/* declarations here */
};
#include "A.inl"

#endif



Other than that, very nice job. I should find this to be rather useful (It will save me from typing all those overloaded operator declarations).

Share this post


Link to post
Share on other sites
I second the opinion to make it as a plugin for your favorite (or multiple) IDEs.

Its better than the "improved" class designer I found on CodeProject.com a month ago.

Share this post


Link to post
Share on other sites
Thanks for the feedback.

Quote:
Original post by wyrzy
(1) Support for inline files (either by adding a .inl or having all code in the .h file)


I'm not familiar with inline files ... I'll look into that.

Quote:

(2) I can specify a templated class, but I can not specify to inherit from a templated class. The syntax for inheriting from templated classes is slightly different than inheriting from non-templated classes.

Interesting ... never knew that ... I'll look into that as well.

Quote:

Also, I think the generated syntax for C++ class templates is not correct OR VS.NET is not standards compliant (I think its the former though).


Strange ... that's how my textbook does it. Guess I'll look into that as well...

Quote:

...
2) Include the .cpp (I usually name them .inl) right after the class definition in the .cpp file. So you'll have in the .h file
*** Source Snippet Removed ***


You lost me there ... include the cpp after the definition in the cpp? Could you elaborate?

I'll look into the plugin idea ... if it's not too complicated ... I didn't intend to spend too much time on this.

Thanks again.

Share this post


Link to post
Share on other sites
The program will not run for me. I just get an error box saying "The application failed to initialize properly (0xc0000135). Click on OK to terminate the application." I tried downloading both the straight exe and the zip, both with the same result.

EDIT: Works fine on my other pc though

Share this post


Link to post
Share on other sites
In addition to the operator overloading, it would be nice to be able to specify function names and parameters as well, and maybe a quick comment description of what the function does. This way in the end all that would need to be done would be to open up the .cpp file and throw the code into the functions.

EDIT: Very cool idea by the way. I like it a lot. It can see it saving quite a bit of time if you are making lots of different classes...which I often do.

Share this post


Link to post
Share on other sites
Quote:
Original post by deadlydog
In addition to the operator overloading, it would be nice to be able to specify function names and parameters as well, and maybe a quick comment description of what the function does. This way in the end all that would need to be done would be to open up the .cpp file and throw the code into the functions.


I thought about that, but decided it wouldn't be worth the effort. I can't think of an effecient way to provide that functionality. In the time you'd select options and specify names and parameters, you could just have written the function in the files. Of course, if you can think of an effective way to do it, I'll consider it.

Quote:

EDIT: Very cool idea by the way. I like it a lot. It can see it saving quite a bit of time if you are making lots of different classes...which I often do.


Thanks! Glad you like and find it useful.

BTW, I'm adding the functionality to select a template base as suggested above. I'll update that and post soon.

Share this post


Link to post
Share on other sites
Quote:
Original post by ldramire
I'm not familiar with inline files ... I'll look into that.

Oh, Inline Files? They could as well just be named .cpp files. The only difference is that they are usually included directly into the .h files. Some people also call them .inc (Include) files (used in PHP as well). The point is that they are meant to avoid needing to place all the code in the header files when you want a class's functions to be inlined by the compiler. Its a way of making the code more readable. In the end, I basically use it for stuffing the definition of class's methods inside the header file.


Quote:
Original post by ldramire
Quote:

(2) I can specify a templated class, but I can not specify to inherit from a templated class. The syntax for inheriting from templated classes is slightly different than inheriting from non-templated classes.

Interesting ... never knew that ... I'll look into that as well.

Here's an example:
-----
template < typename T >
class Derived : public Base< T >
-----
Notice that when inheriting from class Base, you need the < T > after the class. But thats only if the type T from the derived and base classes will match, do you know what I mean? It would be perfectly legal to say " public Base< float > ", but I have never found I need to specialize in that way.

Quote:
Original post by ldramire
Quote:

Also, I think the generated syntax for C++ class templates is not correct OR VS.NET is not standards compliant (I think its the former though).


Strange ... that's how my textbook does it. Guess I'll look into that as well...

Hmm. I had a textbook that told me to write it in a fashion very similar, but to include the ".cpp" file at the botton of the .h file, because the compiler needs the definitions of all the class methods available at *compile time*, not run-time.

It doesn't compile with MS VS.NET. VS 6 and lower have a reputation for being non-standards compliant, but I have heard good things about templates and VS.NET.

Quote:
Original post by ldramire
Quote:

...
2) Include the .cpp (I usually name them .inl) right after the class definition in the .cpp file. So you'll have in the .h file
*** Source Snippet Removed ***


You lost me there ... include the cpp after the definition in the cpp? Could you elaborate?

No, include the .cpp file for the class right after the closing Brace in the header file. This allows the compiler to have access to the definitions of all the class methods at compile time. I usually name the .cpp a .inl file instead, just to remind me that I'm including it directly into the header.

Here's another example:

// Header file for class A
#ifndef A_H
#define A_H

template < typename T >
class A
{
A();
~A();
void DoStuff();
};

//Notice I include the .cpp file in the .h file, effectively moving all the text from the .cpp file to this line on the header file
#include "a.cpp"

#endif




// Source file for class A (i.e. Method Definitions)

//Notice how you *Do Not* #include "a.h" in this file

//constructor
template < typename T >
A< T >::A()
{
}

//destructor
template < typename T >
A< T >::~A()
{
}

//DoStuff
template < typename T >
void A< T >::DoStuff()
{
}




I could have just typed those 3 method definitions right after the Closing Brace and the semi-colon for class A, instead of #include'ing "a.cpp" in the header file.

The above example is a complete templated class (while is does essentially nothing).

Share this post


Link to post
Share on other sites
Thanks for the tips on inline files and template inheritance. I hate it when textbooks don't cover such useful information.

Just for you wyrzy I've updated the tool with options to allow inheritance from template base classes and inlining the source file.

The class you make must have at least as many parameters as the base, and must also be a template if the base is a template. I think that's the most common implementation I found and it saves me alot of headaches.

I tried including the .cpp file in the inline version, but that wouldn't compile (I think VS goes for the cpps first and craps out when it can't find the accompanying header), though the .inl version did, so it just defaults to that extension if you inline the source file.

Here's the link again of the updated version http://www.rit.edu/~ldr2567/ClassMaker/

Hopefully I didn't break something in adding new features. Thanks again everyone for all the suggestions. If you have any more, post 'em or PM me. Thanks.

Share this post


Link to post
Share on other sites
Thats great, I like it alot. On the subject of filling in functions and parameters, how about having a page with say 10 text fields on it. You tap in a bunch of function protypes, and a bit of a comment, then hit apply and it adds all those functions to the class, clears the boxes, then you're ready to go again. Certainly would beat typing them by hand, or using that damn AddFunction wizard in VS.NET!

Share this post


Link to post
Share on other sites
Dammit, you just gave me an idea, which means I have to stop what I'm doing and put that in there! [grin]

I'll see how quickly I can get that option in and post back. Thanks.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I don't know but for me it loads pretty slow.. like 10 secs to start up, 512megs of ram 2.4ghz processor and a mean graphics card :P just a good old radeon 9000 but it probably takes longer for me to load this program than adobe photoshop, dunno

Share this post


Link to post
Share on other sites
Nice additions, thanks! Something going wrong though, I made a test class, and then added a class, but the class delcaration appears outside the class!


#ifndef GTVECTOR_H
#define GTVECTOR_H

class gtVector
{
public:
gtVector();
~gtVector();

gtVector operator/(const gtVector& gtvector) const;
gtVector operator%(const gtVector& gtvector) const;
gtVector operator&(const gtVector& gtvector) const;
};
#endif
bool IsAlive();



Nice work though. What would be nice is the ability to load classes back in to modify them, and also maybe the ability to list the functions that you have added, so you know where you're up to (maybe just have a pane that lets you view the actual .h file. That would be great!

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
I don't know but for me it loads pretty slow.. like 10 secs to start up, 512megs of ram 2.4ghz processor and a mean graphics card :P just a good old radeon 9000 but it probably takes longer for me to load this program than adobe photoshop, dunno


That's really odd ... don't know what to tell you.

Quote:
Original post by JohnHurt
Nice additions, thanks! Something going wrong though, I made a test class, and then added a class, but the class delcaration appears outside the class!


I think you mean member function, right? Yeah ... appending to the end of the file was the easiest way to do it, even if it is outside the class definition. I made a note of this on that tab indicating that's what happens. Otherwise I'd have to parse through the file and figure out where to stick the thing and it felt like too much trouble [grin].

I'll work on it though ... shouldn't be too bad if I put some thought into it...check back after the weekend.

Quote:

Nice work though. What would be nice is the ability to load classes back in to modify them ...


I'd like to do that, but it'd be quite a challenge to be able to acurately parse a file that's been edited and fill in all the form's attributes accordingly. Doable, but it'll take time ... lots of time. I'll definitely make a note of that however, and keep in mind for later.

Quote:

... , and also maybe the ability to list the functions that you have added, so you know where you're up to (maybe just have a pane that lets you view the actual .h file. That would be great!


Good idea! I too keep losing track of which functions I've added ... that's definitely doable.

Thanks for the suggestions. Glad you're finding it useful. I'll work on some of the suggestions. Meanwhile I've made a few tweaks (fixed a bug or two, added "friend" functions) that's a slight improvement. Man I wish I'd actually put time into actually designing this thing...

Share this post


Link to post
Share on other sites
Sorry, I DID mean function (not enough sleep/too much alcohol!), but this is looking good all the time!

I'm interested in what language you're writing this in, 'cos I wouldn't mind colaborating.

Share this post


Link to post
Share on other sites

#ifndef BAR_H
#define BAR_H

#include <iostream>
using std::istream;
using std::ostream;

namespace FOO
{
class BAR



Never use using inside a header, ever.

Also, that box around the head-comment should be removed, or atleast off by default.

Share this post


Link to post
Share on other sites

//////////////////////////////////////////////////////////////////////////////
// operator<
//////////////////////////////////////////////////////////////////////////////
bool BAR::operator<(BAR& bar) const
{
return true;
}



Redundant (and HUGE) comments.

Share this post


Link to post
Share on other sites
Quote:
Original post by JohnHurt
Sorry, I DID mean function (not enough sleep/too much alcohol!), but this is looking good all the time!

I'm interested in what language you're writing this in, 'cos I wouldn't mind colaborating.


It's C# ... let me know how you'd like to help out.

Quote:
Original post by Deyja
*** Source Snippet Removed ***

Never use using inside a header, ever.

Also, that box around the head-comment should be removed, or atleast off by default.

Yeah, I didn't have "using" orginally ... I forget why I changed it. I'll put it back to using scope operator.
What box are you referring to? If you mean the comment line above and below the header, that's optional (just check the "Wrap with border" option) and it's saved so it'll stay off.

Quote:
Original post by Deyja
*** Source Snippet Removed ***

Redundant (and HUGE) comments.

The comments are there for you to fill in what the operator does. I guess I can add an option to include those comments.
They're so huge because there are tabs before each line, but I couln't figure out how to determine how many spaces there are in each tab to properly adjust it to the proper length. (If anyone knows how to do this, please let me know).

Oh, I've finally put together an actual website with my projects, so the tool can now be found here. Play my games while your there! Drop me feedback on the games and site.
Thanks

Share this post


Link to post
Share on other sites
Ok, patched a few things up:

Quote:
Original post by JohnHurt
... added a function, but the function delcaration appears outside the class!


New functions will now be properly added into the class scope in the header, and in the namespace scope (if there is one) in the source.

Quote:
Original post by Deyja
Never use using inside a header, ever.


The stream types are now scoped with the std namespace rather than a "using" declaration in the header file.

Quote:
Original post by DeyjaRedundant ... comments.

They're now optional for the overloaded operators.

Share this post


Link to post
Share on other sites
Sign in to follow this