views:

466

answers:

3

I have a bunch of C++ header files with various class and function declarations. So far, when I've been writing the C++ source file implementations of the declared classes and functions, I've been manually:

  1. Copying the declarations from the header file to the corresponding source file.
  2. Deleting "class classname {" and the matching "};"
  3. Adding "classname::" onto the names of all the class functions.
  4. Replacing the semicolons after the function declarations with "{}".
  5. Deleting the keywords "virtual" and "static".

Only after all that work, which doesn't really do anything, can I actually go about implementing the functions. I am wondering if there is a tool out there somewhere that can automatically generate a ".cpp" file from a ".h" file, where the resulting ".cpp" contains empty stubs for the functions declared in the ".h" file (and for which an inline definition hasn't been given). A UNIX-friendly commandline tool would be preferred. Thanks.

UPDATE: A cross-platform tool would be ideal. If not, I am working on Mac OS X 10.6.

+7  A: 

Lazy C++ appears to be designed to address precisely that problem.

moonshadow
Lazy C++ does not appear to be installable on Mac OS X... which is what I am using. Are there any cross-platform generators that you know of that can be easily built from the source?
Michael Aaron Safyan
+1 Very interesting resource.
Dominic Rodger
@Michael: You can grab the source and cross-compile for OSX, see e.g. answer to http://stackoverflow.com/questions/1375201/lazy-c-chicken-and-egg-problem
moonshadow
@moonshadow, I'm trying to save time, remember? It would probably take less time for me to write my own tool than to attempt to coax gcc into building as a cross-toolchain.
Michael Aaron Safyan
@Christian Adam, I have downloaded the source... unfortunately, it is self-bootstrapping. It requires a binary of Lazy C++ to build Lazy C++.
Michael Aaron Safyan
@Michael: Once you have the set of .h and .cpp files for 'lzz' the build is trivial, you'd just copy the source to your mac and then build it there. The code is high quality C++. It always makes me laugh when I hear someone say: "it would probably take less time for me to write my own...". I would be interested in any examples you have from your past where that has turned out to be true!
Richard Corden
@Richard, true enough. I wasn't really serious about writing my own... that is why I asked the original question in the first place.
Michael Aaron Safyan
+2  A: 

The eclipse CDT has an "Implement method" feature which does just that (one method at a time). There is also a "Generate Getters and Setters" feature which also generates the appropriate code in the function bodies.

LumpN
Thanks. I'm looking for a commandline invocation, though... something that I can use in a "find" command to recursively generate ".cpp" files for all the header files in my project.
Michael Aaron Safyan
A: 

I found myself in your situation lately and manned up to write my own tool -- impl_me. It's a small Ruby script that uses SWIG as a parser backend. It writes to stdout so you can combine with your favorite nix toolset find/grep/sed/awk to tweak for your own preferences.

Because it's written in Ruby, it should be cross platform. SWIG is also cross platform so everything should be OK.

It's quite primitive at this stage and isn't as robust as Lazy C++ in terms of parsing strange templates and stuffs. Contributions are welcome :)

kizzx2