By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,007 Members | 1,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,007 IT Pros & Developers. It's quick & easy.

Automatic C++ header generation?

P: n/a
I have begun designing and programming in C++ after a several years
away from software engineering/programming.

I am looking for an "automatic C++ header generator." I have what
seems to be fairly simple requirements:

1) command-line oriented tool
2) input .cpp files, output .h files
3) do not change the .cpp files if directed

The only tools I have found are "chic" and "lzz".

Chic apparently wants to talk to an Xserver, thus leading me to
believe it runs as a gui and is therefore does not appear to have a
cmdline-only option. (...and I'm unable to run it on a remote machine
easily)

lzz appears to 1) want to change the input .cpp file, and 2) can not
parse my more-complex .cpp file.

All of this seems quite disappointing. I was hoping this task would
not be hard to automate.

All of my source "g++ -ansi" compiles nicely.

Any toughts/suggestions?

-Matt

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Matt wrote:
I have begun designing and programming in C++ after a several years
away from software engineering/programming.

I am looking for an "automatic C++ header generator." I have what
seems to be fairly simple requirements:

1) command-line oriented tool
2) input .cpp files, output .h files
3) do not change the .cpp files if directed

The only tools I have found are "chic" and "lzz".

Chic apparently wants to talk to an Xserver, thus leading me to
believe it runs as a gui and is therefore does not appear to have a
cmdline-only option. (...and I'm unable to run it on a remote machine
easily)

lzz appears to 1) want to change the input .cpp file, and 2) can not
parse my more-complex .cpp file.

All of this seems quite disappointing. I was hoping this task would
not be hard to automate.

All of my source "g++ -ansi" compiles nicely.

Any toughts/suggestions?

-Matt

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


I been working on my own header generator tool, a GUI for
Windows platform. I was working on a database for inheritance
and include files. For example, you could select from various
design patterns: Singleton, equality, comparable, binary I/O,
and it would create the stencils for those methods in the class.

When specifying members, it would look up the types in the
database and provide the necessary include headers.

I've learned a lot more about C++, and coding styles since I
started the project. When I get the time, I need to go back
and redesign (refactor?) it. ;-)

In summary, this should not be a big task to write one yourself.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #2

P: n/a
Matt wrote:
I have begun designing and programming in C++ after a several years
away from software engineering/programming.

I am looking for an "automatic C++ header generator." I have what
seems to be fairly simple requirements:

1) command-line oriented tool
2) input .cpp files, output .h files
3) do not change the .cpp files if directed


Most things should be in .cpp files.

..h file should be very light.

If a brute-force script read a .cpp file and wrote a .h file, it wouldn't
know what to exclude. Large C++ programs can compile very slowly when their
..h files include more .h files, all containing much more stuff than each
translation unit actually needs.

Small C++ programs have no need of a .h file generator, because they should
have only a very few things to put in a .h file.

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #3

P: n/a
Matt wrote:
I am looking for an "automatic C++ header generator." I have what
seems to be fairly simple requirements:

1) command-line oriented tool
2) input .cpp files, output .h files
3) do not change the .cpp files if directed


I think you're doing it in the wrong direction. The interface has to be
determined and written first, and then the implementation should follow.

So, what you probably need is a program that reads the interface from
the given header file and generates the stub for the implementation.
For example:

////////////////////////////////////////////////////////
// input: C.h
////////////////////////////////////////////////////////

class C
{
public:
void foo(char a, int b) const;

private:
static const double data[];
};

////////////////////////////////////////////////////////
// output: C.c++
////////////////////////////////////////////////////////

#include "C.h"

const double C::data[] = { };

void C::foo(char a, int b) const
{
}

--
Seungbeom Kim

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #4

P: n/a

Hi,

Matt <ma**@downwithspammers-mengland.net> writes:
1) command-line oriented tool
Tick mark for lzz.
2) input .cpp files, output .h files
3) do not change the .cpp files if directed
I think that point 2 and 3 cannot be both satisfied in C++. The
problem constructs being templates and inlining.

In order for the inline and template bodies to be available, they
should either go into the header file or a seperate file to be
included by other translation units.

In order for the generator to see these definitions, it will need to
be in the 'source' to the tool, and if this 'source' is also going to
be seen by your compiler, then the tool would have to modify the
source so that the compiler doesn't get a duplicate definition.
lzz appears to 1) want to change the input .cpp file,
lzz was designed to be driven by a seperate '.lzz' file. However, the
syntax in this file was kept as *standard* C++. lzz then
intelligently places declarations and definitions into the resulting
'.h' and '.cpp' files. Where you desire seperate files for template
bodies or inline functions, it can also be configured to create those
files too.
and 2) can not parse my more-complex .cpp file.
I would be very interested to see exactly what you are trying to
parse. The author of lzz is responsible for the grammar
implementation in the front end of our C++ parser. We also use 'lzz'
in house, and we are not shy about using C++ features.

For someone just looking at lzz, I can imagine that there are some
simple things that might not be obvious. For example, so that lzz
doesn't need to worry about C++ declaration ambiguities you must
always declare function parameter names.

void foo (int const &) {} // not accepted
void foo (int const &i) {} // ok

This allows lzz to parse C++ without needing a heavy semantic backend.
All of this seems quite disappointing. I was hoping this task would
not be hard to automate.


We now have about 350k of lines of lzz code, and I now find it alien
to have to write both a header and source file. As you may have
noticed, I am not shy about promoting the use of lzz, I think it
should be part of everybodies tool kit.
If you have a set of examples that you feel should be handled, I know
that the author will be very responsive, even if it is just to modify
the help.

Since it would be OT here, if you mail me directly some of the
examples I too maybe able to help.
Regards,

Richard
--
Richard Corden
To reply remove 's' from address

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #5

P: n/a
"Matt" <ma**@downwithspammers-mengland.net> wrote in message
news:3s********************************@4ax.com...
I have begun designing and programming in C++ after a several years
away from software engineering/programming.

I am looking for an "automatic C++ header generator." I have what
seems to be fairly simple requirements:

1) command-line oriented tool
2) input .cpp files, output .h files
3) do not change the .cpp files if directed


Google for "Lazy C++".

Andrei

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #6

P: n/a
Hello Richard, et al,

Thanks so much for all the feedback to this point.

One of the problems I had to conquer was my misunderstanding of C++
header-file and body-file relationships. Once I got over that, things
became easier to understand.

In the end, however, I see that it might be difficult for me to
completely automate the generation of head files; there seems too much
benefit from human formatting and commenting. However, the automation
can help save a lot of mundane work.

The lzz problem with a specific part of source code remains; however,
it's not at this point a stumbling block, but if it is in the future,
I may email the lzz author(s) with the question/info.

Thanks again!
-Matt
On 21 Nov 2004 18:29:24 -0500, Richard Corden
<ri*************@hotmail.com> wrote:
We now have about 350k of lines of lzz code, and I now find it alien
to have to write both a header and source file. As you may have
noticed, I am not shy about promoting the use of lzz, I think it
should be part of everybodies tool kit.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Jul 22 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.