Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在类中包含枚举,但不包含在SWIG中_C++_Enums_Swig - Fatal编程技术网

C++ 在类中包含枚举,但不包含在SWIG中

C++ 在类中包含枚举,但不包含在SWIG中,c++,enums,swig,C++,Enums,Swig,我必须映射到SWIG的一些接口使用来自类i和其他库的接口。 例如,我有一个类型为const boost::asio::ssl::context::file_format的参数,它引用的枚举定义为: // ssl/context_base.hpp // ~~~~~~~~~~~~~~~~~~~~ // [...] namespace boost { namespace asio { namespace ssl { class context_base { public: // [...]

我必须映射到SWIG的一些接口使用来自类i和其他库的接口。 例如,我有一个类型为
const boost::asio::ssl::context::file_format
的参数,它引用的枚举定义为:

// ssl/context_base.hpp
// ~~~~~~~~~~~~~~~~~~~~  
// [...]

namespace boost {
namespace asio {
namespace ssl {

class context_base
{
public:
  // [...]

  /// File format types.
  enum file_format
  {
    /// ASN.1 file.
    asn1,

    /// PEM file.
    pem
  };
};

} } }
如果我
%include
,那么所有的方法都将被生成,并给我带来许多不同的错误

如果我只是将整个定义从上面复制到
.i
文件,并且(在本例中)boost确实扩展了enum,那么我必须记住相应地更改接口文件

我更希望能够只包含boost头文件中的enum,但我找不到这样做的方法。只有函数可以忽略方法/类,但没有函数可以选择它们

有没有办法获取基于头文件生成的枚举?

使用预处理器:

#ifndef SWIG
//what you don't want in swig
#endif

最后,我找到了一个解决方案,即使用%rename忽略类中除枚举和枚举项之外的所有成员

%rename("$ignore", "not" %$isenum, "not" %$isenumitem, regextarget=1, fullname=1) "^boost::asio::ssl::context_base::"; 
%include <boost/asio/ssl/context_base.hpp>
%rename(“$ignore”,“not”%$isenum,“not”%$isenumitem,regextarget=1,fullname=1)”^boost::asio::ssl::context_base::”;
%包括

这并不完美,因为它会忽略从
boost::asio::ssl::context\u base::
开始的所有内容。但它确实解决了我的问题。

不幸的是,我无法修改systems boost库标题,因此这没有帮助