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.
我有一个第三方图书馆,出于各种原因我还不想链接。我不想删除我的代码但删除对其API的所有引用,所以我想生成它的虚拟实现。
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
有没有我可以使用的工具,在给定头文件的情况下吐出类的空定义?可以返回nulls,false和默认值为0。我不想在飞行中做任何事情或任何聪明的事情 - 我看过的模拟对象库显得非常重量级?理想情况下,我希望使用类似的东西
$ generate-definition my_header.h > dummy_implemtation.cpp
I'm using Linux, GCC4.1
我正在使用Linux,GCC4.1
2 个解决方案
#1
1
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.
这是一个比你想象的更难的问题,因为解析C ++很快就会成为一项艰巨的任务。您最好的选择是选择一个具有良好界面的现有解析器。
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.
在最糟糕的情况下,您可以使用SWIG - > Python,然后使用反射来打印虚拟实现。
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).
对不起,这只是一个半答案,但我认为没有现成的工具可以做到这一点(除了模拟框架,这可能与使用解析器的工作量相同)。
#2
0
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.
创建一个读取头文件并创建源文件的测试应用程序。测试应用程序应解析头文件以了解函数名称。
#1
1
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.
这是一个比你想象的更难的问题,因为解析C ++很快就会成为一项艰巨的任务。您最好的选择是选择一个具有良好界面的现有解析器。
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.
在最糟糕的情况下,您可以使用SWIG - > Python,然后使用反射来打印虚拟实现。
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).
对不起,这只是一个半答案,但我认为没有现成的工具可以做到这一点(除了模拟框架,这可能与使用解析器的工作量相同)。
#2
0
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.
创建一个读取头文件并创建源文件的测试应用程序。测试应用程序应解析头文件以了解函数名称。