2015-11-04 66 views
2

的等價物我正在通過橋接標頭後面的SwiftArchitect's example從Swift調用C++函數。對於C++函數簽名是這樣的:從Swift調用C++ - 什麼是std :: vector <T>

long GrabberInitializeAndProcess(
    unsigned char* pbInPixels, 
    int inStride, 
    unsigned char* pbOutPixels, 
    int outStride, 
    int width, 
    int height, 
    Point mqTopLeft, 
    Size mqSize, 
    std::vector<PolylineElement> * pForegroundMarks, 
    std::vector<PolylineElement> * pBackgroundMarks, 
    void* pGrabberState); 

(注:PointSize,並且PolylineElement是本地C++結構。)我在我的Objective-C++包裝使用std::vector<T>什麼簽名?

+1

'NSArray *',你的包裝將負責爲了彌合這兩種類型。 – Joe

+0

我在包裝PolylineElement時遇到了問題(這是一個四個整數的簡單結構),但我將其作爲一個單獨的問題來處理。你想添加你的評論作爲答案,我會把它標記爲這樣嗎? – dumbledad

回答

1

您正在使用vector作爲指針。當你需要在Swift中使用它時非常好。

您可以使用void*代替:

long GrabberInitializeAndProcess(
    unsigned char* pbInPixels, 
    int inStride, 
    unsigned char* pbOutPixels, 
    int outStride, 
    int width, 
    int height, 
    Point mqTopLeft, 
    Size mqSize, 
    void * pForegroundMarks, 
    void * pBackgroundMarks, 
    void* pGrabberState); 

而且在實施執行類型轉換。

或者,如果你需要的類型安全,你可以白:

typedef struct _vectorOfPolylineElement *vectorOfPolylineElementPtr; 

long GrabberInitializeAndProcess(
    unsigned char* pbInPixels, 
    int inStride, 
    unsigned char* pbOutPixels, 
    int outStride, 
    int width, 
    int height, 
    Point mqTopLeft, 
    Size mqSize, 
    vectorOfPolylineElementPtr pForegroundMarks, 
    vectorOfPolylineElementPtr pBackgroundMarks, 
    void* pGrabberState); 

而且在執行:

typedef struct _vectorOfPolylineElement 
{ 
    std::vector<PolylineElement> val; 
} *vectorOfPolylineElementPtr; 

如果你其實並不需要GrabberInitializeAndProcess載體,只是它的元素,你可以使用內存:

long GrabberInitializeAndProcess(
    unsigned char* pbInPixels, 
    int inStride, 
    unsigned char* pbOutPixels, 
    int outStride, 
    int width, 
    int height, 
    Point mqTopLeft, 
    Size mqSize, 
    PolylineElement * pForegroundMarks, 
    size_t foregroundMarksCount, 
    PolylineElement * pBackgroundMarks, 
    size_t backgroundMarksCount, 
    void* pGrabberState); 
相關問題