这是我不久前提出的问题的延续。为通过参数返回的函数创建类型映射
上一题的接口文件如下:
%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"
我现在必须解析 gaiaTextReaderPtr 结构,它位于 structs.h 中。该结构位于以下代码的底部,尽管我也包含了其中的其他结构以提供完整的图片。
我在创建 SWIG 不透明数据类型的行下划线
/** Virtual Text driver: MAX number of fields */
#define VRTTXT_FIELDS_MAX 65535
/** Virtual Text driver: MAX block size (in bytes) */
#define VRTTXT_BLOCK_MAX 65535
/** Virtual Text driver: TEXT value */
#define VRTTXT_TEXT 1
/** Virtual Text driver: INTEGER value */
#define VRTTXT_INTEGER 2
/** Virtual Text driver: DOUBLE value */
#define VRTTXT_DOUBLE 3
/** Virtual Text driver: NULL value */
#define VRTTXT_NULL 4
/**
Container for Virtual Text record (line)
*/
struct vrttxt_line
{
/* a struct representing a full LINE (aka Record) */
/** current offset (parsing) */
off_t offset;
//__^________________________________________________________SWIGTYPE_p_off_t
/** line length (in bytes) */
int len;
/** array of field offsets (where each field starts) */
int field_offsets[VRTTXT_FIELDS_MAX];
//__^________________________________________________________SWIGTYPE_p_int
/** number of field into the record */
int num_fields;
/** validity flag */
int error;
};
/**
Container for Virtual Text record (line) offsets
*/
struct vrttxt_row
{
/* a struct storing Row offsets */
/** Line Number */
int line_no;
/** start offset */
off_t offset;
//__^________________________________________________________SWIGTYPE_p_off_t
/** record (line) length (in bytes) */
int len;
/** number of fields into this record */
int num_fields;
};
/**
Container for Virtual Text block of records
*/
struct vrttxt_row_block
{
/*
/ for efficiency sake, individual Row offsets
/ are grouped in reasonably sized blocks
*/
/** array of records [lines] */
struct vrttxt_row rows[VRTTXT_BLOCK_MAX];
/** number of records into the array */
int num_rows;
/** min Line Number */
int min_line_no;
/** max Line Number */
int max_line_no;
/** pointer to next item [linked list] */
struct vrttxt_row_block *next;
};
/**
Container for Virtual Text column (field) header
*/
struct vrttxt_column_header
{
/* a struct representing a Column (aka Field) header */
/** column name */
char *name;
/** data type: one of GAIA_NULL_VALUE, GAIA_INT_VALUE, GAIA_DOUBLE_VALUE, GAIA_TEXT_VALUE */
int type;
};
/**
Container for Virtual Text file handling
*/
typedef struct vrttxt_reader
{
/* the main TXT-Reader struct */
/** array of columns (fields) */
struct vrttxt_column_header columns[VRTTXT_FIELDS_MAX];
/** FILE handle */
FILE *text_file;
//__^________________________________________________________SWIGTYPE_p_FILE
/** handle to ICONV converter object */
void *toUtf8; /* the UTF-8 ICONV converter */
//__^________________________________________________________SWIGTYPE_p_void
/** field separator character */
char field_separator;
/** text separator character (quote) */
char text_separator;
/** decimal separator */
char decimal_separator;
/** TRUE if the first line contains column names */
int first_line_titles;
/** validity flag */
int error;
/** pointer to first block of records [linked list] */
struct vrttxt_row_block *first;
/** pointer to last block of records [linked list] */
struct vrttxt_row_block *last;
/** array of pointers to individual records [lines] */
struct vrttxt_row **rows;
//__^________________________________________________________SWIGTYPE_p_p_vrttxt_row
/** number of records */
int num_rows;
/** current Line Number */
int line_no;
/** max number of columns (fields) */
int max_fields;
/** current buffer size */
int current_buf_sz;
/** current buffer offset [parsing] */
int current_buf_off;
/** I/O buffer */
char *line_buffer;
/** current field buffer */
char *field_buffer;
/** array of field offsets [current record] */
int field_offsets[VRTTXT_FIELDS_MAX];
//__^________________________________________________________SWIGTYPE_p_int
/** array of field lengths [current record] */
int field_lens[VRTTXT_FIELDS_MAX];
//__^________________________________________________________SWIGTYPE_p_int
/** max field [current record] */
int max_current_field;
/** current record [line] ready for parsing */
int current_line_ready;
} gaiaTextReader;
/**
Typedef for Virtual Text file handling structure
\sa gaiaTextReader
*/
typedef gaiaTextReader *gaiaTextReaderPtr;
任何帮助将不胜感激!问候汉克
第二部分第
1 部分:其中一位开发人员对 void toUtf8 有这样的看法:
嗨,汉克,
“void *”指针只是一个通用的不透明内存指针;它基本上是一个手柄。
在特定上下文中,“void *toUtf8”引用了 ICONV 所需的内部结构。引用的对象必须通过先前调用 gaiaCreateUTF8Converter() 来创建,并且预计在调用 gaiaFreeUTF8Converter() 之前或之后被销毁;对 gaiaFreeUTF8Converter() 的每次调用都需要将此指针作为参数传递。
从您的 Java/SWIG 角度来看,它只是一个常量值,可以完全按原样来回传递。(任何直接更改、访问或取消引用此指针的尝试都可能很容易导致一些灾难 == 系统崩溃)
再见桑德罗
2: 我有几个其他结构,这些是gg_structs.h 中的最后一个,它们在使用以下内容时遇到问题。
/** COORDs mem-array */
double *Coords; /* X,Y [vertices] array */
目前我刚刚提出:
%apply double[] {double *};
这已经清除了它,但是我不确定这是否正确。我应该单独针对阵列吗?实际上,我很确定这是不正确的,只是查看了它创建的类并显示:
public void setCoords(double[] value) {
gg_structsJNI.gaiaLinestring_Coords_set(swigCPtr, this, value);
}
public double[] getCoords() {
return gg_structsJNI.gaiaLinestring_Coords_get(swigCPtr, this);
}
这不应该有一个: int 索引才能正常工作吗?对于双重我这样做:
%ignore Coords;
%include "gg_structs.h"
%extend gaiaLinestring {
void setCoords(int index, double value) {
$self->Coords[index] = value;
}
double getCoords(int index) {
return $self->Coords + index;
}
}
3:我有兴趣了解更多关于提供实现 AbstactSequentialList 的代理的信息。这就是所谓的动态代理吗?