yuanqiao 发表于 2017-5-8 11:43:50

使用SWIG和Python对C/C++进行单元测试(二)

  SWIG本质上是一个编译器,在最初的1.1版本中,它还不是很完善,有很多的C/C++指令以及数据类型不支持,而到了现在的1.3版,它基本上已经能够支持全部的C/C++特性。
  内容如下:

[*]Full C99 preprocessing.
[*]All ANSI C and C++ datatypes.
[*]Functions, variables, and constants.
[*]Classes.
[*]Single and multiple inheritance.
[*]Overloaded functions and methods.
[*]Overloaded operators.
[*]C++ templates (including member templates, specialization, and partial specialization).
[*]Namespaces.
[*]Variable length arguments.
[*]C++ smart pointers.
  现在唯一不支持的是内部类,它也将在今后的版本中得到支持。
简单数据类型
  整型:swig会把下列数据类型转换成脚本语言中的整型。

[*]int
[*]short
[*]long
[*]unsigned
[*]signed
[*]unsigned short
[*]unsigned long
[*]unsigned char
[*]signed char
[*]bool

  另外,虽然swig支持long long类型,但是在一些不支持long long的脚本语言中,比如Tcl、Perl5,long long会被转换成string类型,所以不能用来进行计算操作。
  浮点型:

[*]float
[*]double

  很多脚本中都是直接用double来表示浮点型。另外swig不支持不太被使用的long double类型
  字符串类型:
  char在脚本语言中被映射成一个长度为1的NULL结尾的ASCII字符串。
  char*则被映射成一个NULL结尾的8-bit字符串。
  另外,swig对wchar_t(Unicode)支持不太好,但一般采用UTF-8的形式来处理
  全局变量
  example.i
  example_test.py
页: [1]
查看完整版本: 使用SWIG和Python对C/C++进行单元测试(二)