小编SWi*_*ams的帖子

如何在包装包含向量的模板类时让SWIG应用模板?

我正在尝试使用SWIG来包装(在C#中)一些包含模板类的c ++代码,该模板类本身包含了一个std::vector<T>.我在互联网上看到了关于如何为矢量类型声明模板的各种参考,但是无法使用额外的抽象层来实现.这就是我在interface.i文件中所做的事情,例如:

// interface.i file    
%module myNamespaceWrapper
%{
#include "myVector.h"  
%}  

%include "myVector.h"
%include "std_string.i"
%include "std_vector.i"

namespace std {
%template(vector_MyType) vector<MyType*>;
%template(vector_Int) vector<int>;
}

namespace myNamespace {
%template(myVectorMyType) myVector<MyType*>;
%template(myVectorInt) myVector<int>;
}
Run Code Online (Sandbox Code Playgroud)

虽然这似乎可以自己正确地创建相应的C#类型,但我尝试定义的std :: vector模板不会应用于内部使用它们的其他类,通过头文件包含.为了告诉你我的意思,有一个c ++类,如:

// myVector.h
namespace myNamespace 
{    
    template<class T> 
    class myVector
    {

    private :
        std::vector<T> vect;

    public : 
        myVector(){}
        virtual ~myVector(){}

        virtual const std::vector<T> & getVect()
        {
            return vect;
        }

        virtual T& front()
        {
            return vect.front();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

即使我得到一个vector_MyType由SWIG创建的类,当它包装我的模板类时,它没有使用它,而是提供了很多这样的例子:

public …
Run Code Online (Sandbox Code Playgroud)

c# c++ swig templates vector

15
推荐指数
1
解决办法
1215
查看次数

如何为类类型创建OUTPUT类型图?

我以前在尝试将SWIG的OUTPUT类型映射应用于类类型时遇到了麻烦,并且问了之前的问题.

我在那里得到的答案很有帮助,但仍然要求我要求SWIG做以下事情:

%apply exportedClassType& OUTPUT { exportedClassType& result };
Run Code Online (Sandbox Code Playgroud)

这在SWIG 3.0.6上似乎对我不起作用,并带有以下消息:

Warning 453: Can't apply (exportedClassType &OUTPUT). No typemaps are defined.

从查看文档:

请注意,typemaps.i文件的主要用途是支持原始数据类型.编写这样的函数 void foo(Bar *OUTPUT); 可能没有预期的效果,因为typemaps.i没有为Bar定义OUTPUT规则.

它看起来不像是支持的.所以我想我的问题是,我需要在interface.i文件中定义什么样的组合图,以便生成的类类型的包装器代码来自:

// interface.i
%apply exportedClassType& OUTPUT { exportedClassType& result };
int getClassType(exportedClassType& result);

// interface_wrap.cxx
SWIGINTERN PyObject *_wrap_getClassType(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
  PyObject *resultobj = 0;
  exportedClassType *arg1 = 0 ;
  void *argp1 = 0 ;
  int res1 = 0 ;
  PyObject * obj0 = 0 ;
  int result; …
Run Code Online (Sandbox Code Playgroud)

c++ python swig

15
推荐指数
1
解决办法
965
查看次数

如何在nUnit 2.6.4 xml结果中显示堆栈跟踪?

我有一个nunit测试dll,我正在使用控制台运行程序,并且有很多失败的测试,但有异常.生成的xml文件太大了,我认为避免在xml输出中编写堆栈跟踪是个好主意,因为在我的情况下,它显示起来并没有用,只能编写异常消息.

然而,事实证明这比我预期的要困难得多.我看到了这两个链接,在哪里可以找到nunit使用的xsd文件以及如何自定义xml,但在2.6.4中/transform,控制台上的选项似乎已被弃用,叹​​了口气.

我不知道如何更改我的nUnit安装目录中的文件,这会影响输出吗?如果有人设法改变了nUnit的xml结果输出,那么请指出我正确的方向吗?

c# xml xsd nunit

10
推荐指数
1
解决办法
568
查看次数

如何在Python中为类类型应用SWIG OUTPUT类型图?

我在使用SWIG(版本3.0.6)围绕C++库生成Python包装器时遇到了一些麻烦.

我的问题涉及应用OUTPUT类型映射,特别是在指针/类类型引用的情况下.

为了说明,这是我想要的标准类型,它的工作原理:

// .h
int add(const long arg1,const long arg2,long& resultLong);

// interface.i
%apply long& OUTPUT { long& resultLong };
int add(const long arg1,const long arg2,long& resultLong);

// projectWrapper.py
def add(arg1, arg2):
    return _projectWrapper.add(arg1, arg2)
addTerm = _projectWrapper.add

// usage
>>> result = projectWrapper.add(2, 4)
>>> print result
[0, 6L]
Run Code Online (Sandbox Code Playgroud)

您不必传入"resultLong",但它会自动附加到结果中.大!

但是,当输出类型是指向类类型的指针时,这似乎没有像我期望的那样工作:

// .h
int GetClassType(const char* name, exportedClassType*& resultPointer);

class exportedClassType
{...}

// interface.i
%apply exportedClassType*& OUTPUT { exportedClassType*& resultPointer };    
int GetClassType(const char* name, exportedClassType*& resultPointer);

// …
Run Code Online (Sandbox Code Playgroud)

c++ python swig

10
推荐指数
1
解决办法
3219
查看次数

R 使用 as.Date() 转换带有 BST/GMT 标签的 POSIXct 日期

我需要在动物园对象的索引上使用 as.Date。一些日期在 BST 中,因此在转换时,我(仅)在这些条目上损失了一天。我根本不关心一小时的差异,甚至不关心日期的时间部分,我只想确保显示的日期保持不变。我猜这不是很难,但我无法做到。有人可以帮忙吗?

class(xtsRet)
#[1] "xts" "zoo"

index(xtsRet)
#[1] "2007-07-31 BST" "2007-08-31 BST" "2007-09-30 BST" "2007-10-31 GMT"

class(index(xtsRet))
#[1] "POSIXt"  "POSIXct"

index(xtsRet) <- as.Date(index(xtsRet))

index(xtsRet)
#[1] "2007-07-30" "2007-08-30" "2007-09-29" "2007-10-31"
Run Code Online (Sandbox Code Playgroud)

最小可重复的示例(不需要zoo包装):

my_date <- as.POSIXct("2007-04-01") # Users in non-UK timezone will need to
                                    # do as.POSIXct("2007-04-01", "Europe/London")
my_date
#[1] "2017-04-01 BST"

as.Date(my_date)
#[1] "2017-03-31"
Run Code Online (Sandbox Code Playgroud)

r date posixct binary-search-tree xts

3
推荐指数
1
解决办法
2450
查看次数

标签 统计

c++ ×3

swig ×3

c# ×2

python ×2

binary-search-tree ×1

date ×1

nunit ×1

posixct ×1

r ×1

templates ×1

vector ×1

xml ×1

xsd ×1

xts ×1