views:

188

answers:

4

Hey folks,

in my eyes it is good style to sort methods in header files in the same order as in the cpp file. But often this order gets crude during development.

Does anyone knows a tool which can reorder the methods in the cpp file to the order given in the header file?

Best regards, Gerrit

+1  A: 

I've found it effective to use a graphical diff tool to show the header and source file side by side to keep the documentation in sync and make sure everything's in the same order. (My employer bought me Araxis Merge, so that's what I use, but there are a variety of free and commercial tools that accomplish the same thing on a variety of platforms.)

This might be easier with a procedural C or C++ file, as opposed to an object-oriented C++ file where class member functions would have a different indentation level in the header than in the source file.

Commodore Jaeger
A: 
The headline says: sort methods in cpp file by header
The body says:  sort methods in header files in the same order as in the cpp file

Isn’t that contradictory? :-)

While is possible to edit the header or source files either by some tool or by hand, in real life, it is very hard to enforce/maintain that order.

My approach is to “view” the method names in alphabetical order. That is achievable by running doxygen on the files. In the doxygen config file, the following two options might be useful

SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = YES
ArunSaha
A: 

You can use a modeller (such as Umbrello) to model your classes and generate the appropriate code.

Yasky