views:

234

answers:

2

I'm working on a C++ project in which there are a lot of classes that have classes, methods and includes all in a single file. This is a big problem, because frequently the method implementations require #include statements, and any file that wants to use a class inherits these #includes transitively. I was just thinking that it would be nice to have a tool that did the following operation on a C++ header file:

  1. Parse a C++ header file into two pieces: a header file that declares a class, its data and the methods of that class and a separate file that implements the methods.
  2. Removes unnecessary includes from the header file.
  3. Adds the necessary includes to the implementation file.

I understand that parsing C++ is very difficult, but even something that worked imperfectly would be an improvement over the repetitive text editing that I'm doing right now. Is there anything that does anything like this? Or am I stuck with the decision between rolling my own solution or hammering through this with my text editor?

+2  A: 

Are you looking for something like Lazy C++?

Lzz is a tool that automates many onerous C++ programming tasks. It can save you a lot of time and make coding more enjoyable. Given a sequence of declarations Lzz will generate your header and source files.

Example from the same place:

    // A.lzz
    class A
    {
    public:
      inline void f (int i) { ... }
      void g (int j = 0) { ... }
    };
    bool operator == (A const & a1, A const & a2) { ... }

Lzz will generate a header file:

    // A.h
    #ifndef LZZ_A_h
    #define LZZ_A_h
    class A
    {
    public:
      void f (int i);
      void g (int j = 0);
    };
    inline void A::f (int i) { ... }
    bool operator == (A const & a1, A const & a2);
    #endif

And a source file:

    // A.cpp
    #include "A.h"
    void A::g (int j) { ... }
    bool operator == (A const & a1, A const & a2) { ... }
AraK
It's very possible! Thanks for the link, I'll look at it.
James Thompson
+1  A: 

Step 1 should be easy enough to do, although I don't have any recommendations. 2 and 3 are much more difficult. Take a look at this question.

KeithB