INL Splitter

Update:

This "project" has been abandoned. It's a little too intrusive. If you want something to manage your header/source file fiasco, check out autofunc.

What

This is a little awk script I spent about 8 hours creating one day. I got fed up with dealing with 2 separate files for every C++ class I create: the header and the source, the interface and the implementation, the declaration and the definition. So I decided to join them into a single file, which I call the INL file. This script helps me manage that file.

INL file

The INL file (or Inline file, if you will) is basically a C++ source file (.cc, .cpp, etc) and C++ header file (.h, .hpp, etc) joined into a single file. All functions are inlined, so it's easy to add new functions to a class. You can mark a member function that you would normally put in a .cc file with an "@" at the end of the function prototype line. When you run inlsplit on the INL file, it puts the bodies of all the @'ed functions into the .cc file, and keeps only the prototypes in the .h file. The INL file optionally has a "@source" directive, indicating that everything following will be placed at the top of the .cc file. Here is an example INL file:

class Class {
    int func1(char c)@
    { return c; }
    int func2stayinline(int b)
    { return b; }
};
@source
#include "class.h"

When processed with the inlsplit script, a .cc and .h file are produced, like so:

class.h class.cc
class Class {
    int func1(char c);
    int func2stayinline(int b)
    { return b; }
};
  
#include "class.h"
int Class::func1(char c)
    { return c; }
  

Why the INL suffix?

It stands for inline, and that's what we're doing! But that's the official reason. The *real* reason is that my editor (vim) recognizes .inl files as C++ program text by default, so I get syntax highlighting and other goodies. It's probably reserved for some other type of preprocessed C++ file type and I'm being a jerk by stealing their extension, but what the hell.

inlsplit

inlsplit turns a .inl file into the corresponding .cc and .h files, placing an include guard (#ifndef _HEADER_H...#endif) around the .h file. It can also optionally generate preprocessor directives in the output files to tell the C++ compiler what line it is on in the .inl file (for error messages).

inljoin

inljoin does the opposite of inlsplit. It'll take your existing .cc and .h files, and combine them into .inl files. It's not really all that useful, because you're mostly going to want to go the other way. But I decided to write it so I can convert my current projects into the beautiful .inl format.

DISCLAIMER:

I make no guarantee that this script won't garble the input and output files you feed it, erase your hard drive, and set your house on fire. Use it at your own risk. And always backup.

Download:

Ahh, finally. They're awk scripts, so you can just save them by right-clicking on them, or something. Whatever.