Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate empty definitions given a header file

Tags:

c++

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

like image 380
user23434 Avatar asked Oct 22 '08 11:10

user23434


1 Answers

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).

like image 160
hazzen Avatar answered Oct 04 '22 14:10

hazzen