1

C api > Java に変換しており、次の関数プロトタイプがあります。

/*
 Retrieves an individual field value from the current Line
 \param reader pointer to Text Reader object.
 \param field_num relative field [aka column] index: first field has index 0.
 \param type on completion this variable will contain the value type.
 \param value on completion this variable will contain the current field value.
 \return 0 on failure: any other value on success.
 */

extern int gaiaTextReaderFetchField (gaiaTextReaderPtr reader, int field_num, int *type, const char **value);

期待どおりに返されたステータスを取得したいのですが、「タイプ」を int として、「値」を文字列として返します (割り当て解除されません)。

ドキュメントから、戻り値を保持できるいくつかの構造体を作成することがわかりました。

誰か私と一緒にこの最初のものを作るのを手伝ってくれませんか?

4

1 に答える 1

0

関数宣言が header.h というファイルに存在すると仮定すると、次のようなことができます。

%module test

%{
#include "header.h"
%}

%inline %{
  %immutable;
  struct FieldFetch {
    int status;
    int type;
    char *value;
  };
  %mutable;

  struct FieldFetch gaiaTextReaderFetchField(gaiaTextReaderPtr reader, int field_num) {
    struct FieldFetch result;
    result.status = gaiaTextReaderFetchField(reader, field_num, &result.type, &result.value);
    return result;
  }
%}

%ignore gaiaTextReaderFetchField;
%include "header.h"

これにより、「実際の」ものが隠され、gaiaTextReaderFetchField代わりに、出力パラメーターと呼び出しの結果の両方を (変更不可能な) 構造体で返すバージョンに置き換えられます。

(戻りステータスを 0 に%javaexceptionすることで、構造体に配置する代わりに使用して、必要に応じて代わりに例外をスローさせることができます)

于 2012-10-12T20:59:48.670 に答える