tags:

views:

170

answers:

2

I have a 3rd-party library which for various reasons I don't wish to link against yet. I don't want to butcher my code though to remove all reference to its API, so I'd like to generate a dummy implementation of it.

Is there any tool I can use which spits out empty definitions of classes given their header files? It's fine to return nulls, false and 0 by default. I don't want to do anything on-the-fly or anything clever - the mock object libraries I've looked at appear quite heavy-weight? Ideally I want something to use like

$ generate-definition my_header.h > dummy_implemtation.cpp

I'm using Linux, GCC4.1

A: 

Create one test application which reads the header file and creates the source file. Test application should parse the header file to know the function names.

Vinay
+1  A: 

This is a harder problem than you might like, as parsing C++ can quickly become a difficult task. Your best bet would be to pick an existing parser with a nice interface.

A quick search found this thread which has many recommendations for parsers to do something similar.

At the very worst you might be able to use SWIG --> Python, and then use reflection on that to print a dummy implementation.

Sorry this is only a half-answer, but I don't think there is an existing tool to do this (other than a mocking framework, which is probably the same amount of work as using a parser).

hazzen