This article is about a
free C++ code generator tool.
The code generator
does what its name says: it generates
source code based on an object model (like a UML
class drawing diagram tool ), which
represents the logical structure of your classes. It
also helps you develop your applications faster and
change things inside their structure, using a graphical
Using the Application
This submission is a tool,
so the source code will
not be discussed here. Instead, I will discuss how to
use the tool.
generator has a graphical
user interface by which you can build and manipulate
simple UML class
definitions on the screen. To insert a new class, select
the Insert->Class... option from the main
menu. The new class object will appear on the screen.
You can place it wherever you want by dragging it.
Similarly, to insert a new struct, select Insert->Struct...
from the main menu and the new struct object will appear
on the screen.
To change a class's
settings, double click on the class object. The
following dialog box will appear:
Here, you can change
the names of the class and its header and implementation
files. You can also add author information and a short
On the next page you
can add member variables and properties to your class:
The settings on this
tab page will be easily recognizable by C++
developers, so I will not waste space in this
article by explaining them all in detail. The
interesting option here is the Declare as
property checkbox which, when enabled, will
cause a pair of accessor methods (
SetPropertyName()) to be added to
read/write values directly to the member variable. You
have to specify a name for the property before you add
The next tab page is
for class methods:
Just as you can add
member variables, you can also add class methods by
declaring them on this tab page. A default method body
will be generated in the class implementation file.
There are also
additional class settings that you can change:
Here you can add
inheritance parents to this class (the classes that
current class is derived from), include MFC precompiled
headers, and turn on/off comment generation. Comments
are important since the code can turn into a real mess
later, and you will not be able to find what you need if
you don't add explanations to what you create.
Working with structs is
simpler than working with classes so I will not take the
time to explain it.
Using the Results
After you build your
class diagram you can select Build->Generate
files option from the main menu and
VisualClassBuilder will generate the required C++
files in the default output directory for you. From
there, you can add them to your Visual Studio (or other)
Also, you can print
the class diagram
you have built by selecting File->Print from
the main menu. To save your work, use File->Save.
To load a saved project, use File->Open.
Points of Interest
I needed a tool like
this one to speed up my work on different projects that
use a similar class structure, so that I could avoid
having to write the same source
code multiple times.
- Struct generation
- Class inheritance
- MFC precompiled
- Comments generation